File: wx.ModalDialogHook.1.py

package info (click to toggle)
wxpython4.0 4.0.4%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 211,112 kB
  • sloc: cpp: 888,355; python: 223,130; makefile: 52,087; ansic: 45,780; sh: 3,012; xml: 1,534; perl: 264
file content (48 lines) | stat: -rw-r--r-- 1,618 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

    class MyModalDialogHook(wx.ModalDialogHook):

        def __init__(self, parent):

            wx.ModalDialogHook.__init__(self, parent)


        def Enter(self, dialog):

            # Just for demonstration purposes, intercept all uses of
            # wx.FileDialog. Notice that self doesn't provide any real
            # sandboxing, of course, the program can still read and write
            # files by not using wx.FileDialog to ask the user for their
            # names.
            if isinstance(dialog, wx.FileDialog):

                wx.LogError("Access to file system disallowed.")

                # Skip showing the file dialog entirely.
                return wx.ID_CANCEL


            self.lastEnter = wx.DateTime.Now()

            # Allow the dialog to be shown as usual.
            return wx.ID_NONE


        def Exit(self, dialog):

            # Again, just for demonstration purposes, show how long did
            # the user take to dismiss the dialog. Notice that we
            # shouldn't use wx.LogMessage() here as self would result in
            # another modal dialog call and hence infinite recursion. In
            # general, the hooks should be as unintrusive as possible.
            wx.LogDebug("%s dialog took %s to be dismissed",
                       dialog.GetClassInfo().GetClassName(),
                       (wx.DateTime.Now() - self.lastEnter).Format())



    if __name__ == '__main__':

        app = wx.App(0)
        self.myHook = MyModalDialogHook(None)
        self.myHook.Register()
        app.MainLoop()