4
__version__ = "$Revision: 1.1 $"
5
__date__ = "$Date: 2005/03/28 05:37:31 $"
8
from PythonCard import about, dialog, model
13
class Launcher(model.Background):
15
def setupSizers(self):
16
sizer1 = wx.BoxSizer(wx.VERTICAL)
17
sizer2 = wx.BoxSizer(wx.HORIZONTAL)
18
sizer3 = wx.BoxSizer(wx.VERTICAL)
19
sizer4 = wx.BoxSizer(wx.HORIZONTAL)
20
comp = self.components
22
btnFlags = wx.LEFT | wx.ALIGN_BOTTOM
23
vertFlags = wx.LEFT | wx.TOP | wx.ALIGN_LEFT
25
sizer4.Add(comp.btnLaunch, 1, btnFlags, 5)
26
sizer4.Add(comp.btnDescription, 1, btnFlags, 5)
27
sizer4.Add(comp.btnSource, 1, btnFlags, 5)
28
sizer4.Add(comp.btnResource, 1, btnFlags, 5)
30
sizer3.Add(comp.stcCmdLineArgs, 0, wx.LEFT | wx.BOTTOM | wx.ALIGN_TOP, 5)
31
sizer3.Add(comp.chkDebugMenu, 0, vertFlags, 5)
32
sizer3.Add(comp.chkLogging, 0, vertFlags, 5)
33
sizer3.Add(comp.chkMessageWatcher, 0, vertFlags, 5)
34
sizer3.Add(comp.chkNamespaceViewer, 0, vertFlags, 5)
35
sizer3.Add(comp.chkPropertyEditor, 0, vertFlags, 5)
36
sizer3.Add(comp.chkShell, 0, vertFlags, 5)
37
sizer3.Add((5, 5), 1) # spacer
38
sizer3.Add(sizer4, 1, wx.ALIGN_BOTTOM | wx.EXPAND)
40
sizer2.Add(comp.listSamples, 0, wx.RIGHT | wx.ALIGN_TOP, 5)
41
sizer2.Add(sizer3, 1, wx.EXPAND)
43
sizer1.Add(sizer2, 0, vertFlags)
44
sizer1.Add((5, 5), 0) # spacer
45
sizer1.Add(comp.stcDescription, 0, wx.LEFT | wx.TOP | wx.BOTTOM | wx.ALIGN_LEFT | wx.EXPAND, 5)
46
sizer1.Add(comp.fldDescription, 1, wx.EXPAND)
50
sizer1.SetSizeHints(self)
51
self.panel.SetSizer(sizer1)
52
self.panel.SetAutoLayout(1)
56
def on_initialize(self, event):
59
self.showDescription()
61
self.readme = open('readme.txt').read()
65
def getCommandLineArgs(self):
67
if self.components.chkDebugMenu.checked:
69
if self.components.chkLogging.checked:
71
if self.components.chkMessageWatcher.checked:
73
if self.components.chkNamespaceViewer.checked:
75
if self.components.chkPropertyEditor.checked:
77
if self.components.chkShell.checked:
81
def on_launch_command(self, event):
82
name = self.components.listSamples.stringSelection
84
path = self.application.applicationDirectory
86
path = os.path.join(self.application.applicationDirectory, name)
87
if os.path.exists(os.path.join(path, name + ".pyw")):
88
filename = os.path.join(path, name + ".pyw")
90
filename = os.path.join(path, name + ".py")
91
args = self.getCommandLineArgs()
93
# os.spawnv probably works on all platforms
94
# and regardless of the quoting needs for paths with
95
# and without spaces, but each platform is separate
96
# below until that is confirmed
98
filename = '"' + filename + '"'
99
python = sys.executable
101
pythonQuoted = '"' + python + '"'
103
pythonQuoted = python
104
os.spawnv(os.P_NOWAIT, python, [pythonQuoted, filename] + args)
106
def showDescription(self):
107
path = self.components.listSamples.stringSelection
108
if path == "samples":
112
path = os.path.join(path, name)
113
desc = open(path).read()
114
self.components.fldDescription.text = desc
115
self.components.stcDescription.text = 'Description: ' + path
119
if self.components.fldSource.visible:
120
self.components.fldSource.visible = 0
121
self.sizer1.Remove(self.components.fldSource)
122
self.sizer1.Add(self.components.fldDescription, 1, wx.EXPAND)
123
self.components.fldDescription.visible = 1
126
def on_showDescription_command(self, event):
127
self.showDescription()
129
def showSource(self, source):
130
name = self.components.listSamples.stringSelection
131
if name == "samples":
136
if source == 'source':
137
p = os.path.join(path, name + '.py')
138
if os.path.exists(p):
141
path = os.path.join(path, name + '.pyw')
142
self.components.stcDescription.text = 'Source code: ' + path
144
path = os.path.join(path, name + '.rsrc.py')
145
self.components.stcDescription.text = 'Resource: ' + path
146
src = open(path).read()
148
# you can't change the text of a CodeEditor
149
# component if it isn't editable
150
# should we change that?
151
self.components.fldSource.editable = 1
152
self.components.fldSource.text = src
153
self.components.fldSource.editable = 0
157
if self.components.fldDescription.visible:
158
self.components.fldDescription.visible = 0
159
self.sizer1.Remove(self.components.fldDescription)
160
self.sizer1.Add(self.components.fldSource, 1, wx.EXPAND)
161
self.components.fldSource.visible = 1
164
def on_showSource_command(self, event):
165
self.showSource('source')
167
def on_showResource_command(self, event):
168
self.showSource('resource')
170
def on_listSamples_select(self, event):
171
if self.components.stcDescription.text.startswith('Description'):
172
self.showDescription()
173
elif self.components.stcDescription.text.startswith('Source code'):
174
self.showSource('source')
176
self.showSource('resource')
178
def on_listSamples_mouseDoubleClick(self, event):
179
self.on_launch_command(None)
181
def on_menuHelpPythonCardHomePage_select(self, event):
182
webbrowser.open('http://pythoncard.sourceforge.net/', 1, 1)
184
def on_menuHelpOnlineDocumentation_select(self, event):
185
webbrowser.open('http://pythoncard.sourceforge.net/documentation.html', 1, 1)
187
def on_menuHelpAbout_select(self, event):
188
dialog.scrolledMessageDialog(self, self.readme, 'About samples...')
190
def on_doHelpAboutPythonCard_command(self, event):
191
about.aboutPythonCardDialog(self)
193
if __name__ == '__main__':
194
app = model.Application(Launcher)