~toolpart/+junk/pythoncard

« back to all changes in this revision

Viewing changes to samples/samples.pyw

  • Committer: Bazaar Package Importer
  • Author(s): Sandro Tosi
  • Date: 2010-03-04 23:55:10 UTC
  • mfrom: (3.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20100304235510-3v6lbhzwrgm0pcca
Tags: 0.8.2-1
* QA upload.
* New upstream release
* debian/control
  - set maintainer to QA group
  - set Homepage field, removing the URL from packages description
  - bump versioned b-d-i on python-support, to properly support Python module
  - replace b-d on python-all-dev with python-all, since building only
    arch:all packages
  - replace Source-Version substvar with source:Version
  - add ${misc:Depends} to binary packages Depends
* debian/watch
  - updated to use the SourceForge redirector; thanks to Raphael Geissert for
    the report and to Dario Minnucci for the patch; Closes: #449904
* debian/{pythoncard-doc, python-pythoncard}.install
  - use wildcards instead of site-packages to fix build with python 2.6;
    thanks to Ilya Barygin for the report and patch; Closes: #572332
* debian/pythoncard-doc.doc-base
  - set section to Programmin/Python
* debian/pythoncard-tools.menu
  - set menu main section to Applications
* debian/pythoncard-tools.postinst
  - removed, needed only to update the menu, but it's now created by debhelper

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
"""
 
4
__version__ = "$Revision: 1.1 $"
 
5
__date__ = "$Date: 2005/03/28 05:37:31 $"
 
6
"""
 
7
 
 
8
from PythonCard import about, dialog, model
 
9
import os, sys
 
10
import webbrowser
 
11
import wx
 
12
 
 
13
class Launcher(model.Background):
 
14
 
 
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
 
21
        
 
22
        btnFlags = wx.LEFT | wx.ALIGN_BOTTOM
 
23
        vertFlags = wx.LEFT | wx.TOP | wx.ALIGN_LEFT
 
24
 
 
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)
 
29
 
 
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)
 
39
 
 
40
        sizer2.Add(comp.listSamples, 0, wx.RIGHT | wx.ALIGN_TOP, 5)
 
41
        sizer2.Add(sizer3, 1, wx.EXPAND)
 
42
 
 
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)
 
47
        self.sizer1 = sizer1
 
48
        
 
49
        sizer1.Fit(self)
 
50
        sizer1.SetSizeHints(self)
 
51
        self.panel.SetSizer(sizer1)
 
52
        self.panel.SetAutoLayout(1)
 
53
        self.panel.Layout()
 
54
        self.visible = True
 
55
 
 
56
    def on_initialize(self, event):
 
57
        self.setupSizers()
 
58
        
 
59
        self.showDescription()
 
60
        try:
 
61
            self.readme = open('readme.txt').read()
 
62
        except:
 
63
            self.readme = ''
 
64
 
 
65
    def getCommandLineArgs(self):
 
66
        args = []
 
67
        if self.components.chkDebugMenu.checked:
 
68
            args.append('-d')
 
69
        if self.components.chkLogging.checked:
 
70
            args.append('-l')
 
71
        if self.components.chkMessageWatcher.checked:
 
72
            args.append('-m')
 
73
        if self.components.chkNamespaceViewer.checked:
 
74
            args.append('-n')
 
75
        if self.components.chkPropertyEditor.checked:
 
76
            args.append('-p')
 
77
        if self.components.chkShell.checked:
 
78
            args.append('-s')
 
79
        return args
 
80
 
 
81
    def on_launch_command(self, event):
 
82
        name = self.components.listSamples.stringSelection
 
83
        if name == "samples":
 
84
            path = self.application.applicationDirectory
 
85
        else:
 
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")
 
89
        else:
 
90
            filename = os.path.join(path, name + ".py")
 
91
        args = self.getCommandLineArgs()
 
92
        # KEA 2002-04-28
 
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
 
97
        if ' ' in filename:
 
98
            filename = '"' + filename + '"'
 
99
        python = sys.executable
 
100
        if ' ' in python:
 
101
            pythonQuoted = '"' + python + '"'
 
102
        else:
 
103
            pythonQuoted = python
 
104
        os.spawnv(os.P_NOWAIT, python, [pythonQuoted, filename] + args)
 
105
 
 
106
    def showDescription(self):
 
107
        path = self.components.listSamples.stringSelection
 
108
        if path == "samples":
 
109
            path = ""
 
110
        name = 'readme.txt'
 
111
        try:
 
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
 
116
        except:
 
117
            pass
 
118
 
 
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
 
124
            self.sizer1.Layout()
 
125
 
 
126
    def on_showDescription_command(self, event):
 
127
        self.showDescription()
 
128
 
 
129
    def showSource(self, source):
 
130
        name = self.components.listSamples.stringSelection
 
131
        if name == "samples":
 
132
            path = ""
 
133
        else:
 
134
            path = name
 
135
        try:
 
136
            if source == 'source':
 
137
                p = os.path.join(path, name + '.py')
 
138
                if os.path.exists(p):
 
139
                    path = p
 
140
                else:
 
141
                    path = os.path.join(path, name + '.pyw')
 
142
                self.components.stcDescription.text = 'Source code: ' + path
 
143
            else:
 
144
                path = os.path.join(path, name + '.rsrc.py')
 
145
                self.components.stcDescription.text = 'Resource: ' + path
 
146
            src = open(path).read()
 
147
            # KEA 2002-06-21
 
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
 
154
        except:
 
155
            pass
 
156
 
 
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
 
162
            self.sizer1.Layout()
 
163
 
 
164
    def on_showSource_command(self, event):
 
165
        self.showSource('source')
 
166
 
 
167
    def on_showResource_command(self, event):
 
168
        self.showSource('resource')
 
169
 
 
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')
 
175
        else:
 
176
            self.showSource('resource')
 
177
 
 
178
    def on_listSamples_mouseDoubleClick(self, event):
 
179
        self.on_launch_command(None)
 
180
 
 
181
    def on_menuHelpPythonCardHomePage_select(self, event):
 
182
        webbrowser.open('http://pythoncard.sourceforge.net/', 1, 1) 
 
183
 
 
184
    def on_menuHelpOnlineDocumentation_select(self, event):
 
185
        webbrowser.open('http://pythoncard.sourceforge.net/documentation.html', 1, 1) 
 
186
 
 
187
    def on_menuHelpAbout_select(self, event):
 
188
        dialog.scrolledMessageDialog(self, self.readme, 'About samples...')
 
189
 
 
190
    def on_doHelpAboutPythonCard_command(self, event):
 
191
        about.aboutPythonCardDialog(self)
 
192
 
 
193
if __name__ == '__main__':
 
194
    app = model.Application(Launcher)
 
195
    app.MainLoop()