- Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathMacApp.py
More file actions
Latest commit
executable file
·152 lines (110 loc) · 4.49 KB
/
Copy pathMacApp.py
File metadata and controls
executable file
·152 lines (110 loc) · 4.49 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/env pythonw
"""
MacApp.py
This is a small, simple app that tried to do all the right things on
OS-X -- putting standard menus in the right place, etc. It should work
just fine on other platforms as well : that's the beauty of wx!
"""
importwx
classDemoFrame(wx.Frame):
""" This window displays a button """
def__init__(self, title="Micro App"):
wx.Frame.__init__(self, None , -1, title)
MenuBar=wx.MenuBar()
FileMenu=wx.Menu()
item=FileMenu.Append(wx.ID_EXIT, item="&Exit")
self.Bind(wx.EVT_MENU, self.OnQuit, item)
item=FileMenu.Append(wx.ID_ANY, item="&Open")
self.Bind(wx.EVT_MENU, self.OnOpen, item)
item=FileMenu.Append(wx.ID_PREFERENCES, item="&Preferences")
self.Bind(wx.EVT_MENU, self.OnPrefs, item)
MenuBar.Append(FileMenu, "&File")
HelpMenu=wx.Menu()
item=HelpMenu.Append(wx.ID_HELP, "Test &Help",
"Help for this simple test")
self.Bind(wx.EVT_MENU, self.OnHelp, item)
## this gets put in the App menu on OS-X
item=HelpMenu.Append(wx.ID_ABOUT, "&About",
"More information About this program")
self.Bind(wx.EVT_MENU, self.OnAbout, item)
MenuBar.Append(HelpMenu, "&Help")
self.SetMenuBar(MenuBar)
btn=wx.Button(self, label="Quit")
btn.Bind(wx.EVT_BUTTON, self.OnQuit )
self.Bind(wx.EVT_CLOSE, self.OnQuit)
s=wx.BoxSizer(wx.VERTICAL)
s.Add((200, 50))
s.Add(btn, 0, wx.CENTER, wx.ALL, 20)
s.Add((200, 50))
self.SetSizerAndFit(s)
defOnQuit(self,Event):
self.Destroy()
defOnAbout(self, event):
dlg=wx.MessageDialog(self, "This is a small program to test\n"
"the use of menus on Mac, etc.\n",
"About Me", wx.OK|wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
defOnHelp(self, event):
dlg=wx.MessageDialog(self, "This would be help\n"
"If there was any\n",
"Test Help", wx.OK|wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
defOnOpen(self, event):
dlg=wx.MessageDialog(self, "This would be an open Dialog\n"
"If there was anything to open\n",
"Open File", wx.OK|wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
defOnPrefs(self, event):
dlg=wx.MessageDialog(self, "This would be an preferences Dialog\n"
"If there were any preferences to set.\n",
"Preferences", wx.OK|wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
classMyApp(wx.App):
def__init__(self, *args, **kwargs):
wx.App.__init__(self, *args, **kwargs)
# This catches events when the app is asked to activate by some other
# process
self.Bind(wx.EVT_ACTIVATE_APP, self.OnActivate)
defOnInit(self):
frame=DemoFrame()
frame.Show()
importsys
forfinsys.argv[1:]:
self.OpenFileMessage(f)
returnTrue
defBringWindowToFront(self):
try: # it's possible for this event to come when the frame is closed
self.GetTopWindow().Raise()
except:
pass
defOnActivate(self, event):
# if this is an activate event, rather than something else, like iconize.
ifevent.GetActive():
self.BringWindowToFront()
event.Skip()
defOpenFileMessage(self, filename):
dlg=wx.MessageDialog(None,
"This app was just asked to open:\n%s\n"%filename,
"File Dropped",
wx.OK|wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
defMacOpenFile(self, filename):
"""Called for files droped on dock icon, or opened via finders context menu"""
print(filename)
print("%s dropped on app"%(filename)) #code to load filename goes here.
self.OpenFileMessage(filename)
defMacReopenApp(self):
"""Called when the doc icon is clicked, and ???"""
self.BringWindowToFront()
defMacNewFile(self):
pass
defMacPrintFile(self, file_path):
pass
if__name__=="__main__":
app=MyApp(False)
app.MainLoop()