>I would like to know if there is a way to disable closing my app when
>clicking on the X closing button on the top-right.
This is actually fairly simple. Basically, you just need to on_close
method. From here, you can conditionally allow it to exit, print a message
or whatever. Here is a (very) simple example:
[From noexit.py]
#!/usr/bin/python
"""
__version__ = "$Revision: 1.3 $"
__date__ = "$Date: 2004/04/14 02:38:47 $"
"""
from PythonCard import model, dialog
class MyBackground(model.Background):
def on_initialize(self, event):
pass
def on_close(self, event):
if self.components.ChkAllowExit.checked:
event.skip()
else:
pass
#dialog.alertDialog(self, "Check the box to allow closing", "No
Exit")
if __name__ == '__main__':
app = model.Application(MyBackground)
app.MainLoop()
[From noexit.rsrc.py]
{'application':{'type':'Application',
'name':'Template',
'backgrounds': [
{'type':'Background',
'name':'NoExit',
'title':'Exit Example',
'size':(250, 150),
'components': [
{'type':'CheckBox',
'name':'ChkAllowExit',
'position':(80, 25),
'label':'Allow Exit',
},
] # end components
} # end background
] # end backgrounds
} }
If ChkAllowExit is not checked (default), nothing will happen. You could
also change the pass to an alert or something similar. If the user checks
the box, on_close will pass the close event on and the application will
close normally.
-Daryl
(Sorry for posting a whole programme and resource file. I tried to keep it
as short as possible.)
|