Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Make a dialog if I press the „x“
-
@cvp, nice!
Below a slightly expanded version that shows how you can make this work even if the device is rotated by using
flex
, and how you can pause the scene while the dialog is open.from scene import * import console import ui class MyScene (Scene): def setup(self): w,h = ui.get_screen_size() self.view.add_subview( ui.Button(frame=(w-64,0,64,64), flex='LB', action=self.close)) SpriteNode( 'spc:PlayerShip1Orange', parent=self, position = self.size / 4, ).run_action( Action.repeat_forever( Action.rotate_by(.5)) ) def close(self,sender): self.paused = True if console.alert('close scene?','','yes','no',hide_cancel_button=True) == 1: self.view.close() self.paused = False run(MyScene())
-
@mikael more than nice, sometimes i wonder what i'm doing here
-
@cvp, you are being polite, it was your idea.
-
@mikael I have first tried to change target action of close UIButton, possible but not so easy because some consequences.
-
-
That here is my code, but it doesn‘t work really:
import ui import console from scene import * class Scene(ui.View): def __init__(self): self.background_color = 'gray' self.name = 'Test' #def close(self,sender): self.paused = True if console.alert('Close Scene?','','Yes','No',hide_cancel_button=True) == 1: self.view.close() self.paused = False s = Scene() s.present('fullscreen')
-
@Python567 why is your Scene an ui.View? See @mikael 's code
-
@Python567 if you want to use an ui.View, try
import ui import console from scene import * class Scene(ui.View): def __init__(self): self.background_color = 'gray' self.name = 'Test' def will_close(self): #self.paused = True if console.alert('Close Scene?','','Yes','No',hide_cancel_button=True) == 2: return #self.paused = False s = Scene() s.present('fullscreen')
-
-
@cvp if I click „no“ on your code, the skript will close completely!
-
@Python567 you're right. Shame on me. I forgot that, like scene.stop, view.will_close allow to add process at end but not to avoid closing. Thus, you have to present without title and to build your own close button
-
import ui import console class Scene(ui.View): def __init__(self): self.background_color = 'gray' self.name = 'Test' self.add_subview(ui.Button(frame=(2,12,32,32),title='x',action=self.bclose)) def bclose(self,sender): if console.alert('Close Scene?','','Yes','No',hide_cancel_button=True) == 2: return self.close() s = Scene() s.present('fullscreen', hide_title_bar=True)
-
@cvp thanks