-
Notifications
You must be signed in to change notification settings - Fork 8
/
sourceconst.py
156 lines (120 loc) · 3.47 KB
/
sourceconst.py
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
153
154
155
156
#-----------------------------------------------------------------------------
# Name: sourceconst.py
# Purpose: Central place for constants, templates and snippets used by the
# code generation process
#
# Author: Riaan Booysen
#
# Created: 2001/19/02
# RCS-ID: $Id$
# Copyright: (c) 2001 - 2007 Riaan Booysen
# Licence: GPL
#-----------------------------------------------------------------------------
import os
import Preferences, Utils
idnt = Utils.getIndentBlock()
methodIndent = idnt
bodyIndent = idnt * 2
def wsfix(s):
return s.replace('\t', idnt).replace('\n', os.linesep)
boaIdent = '#Boa'
boaClass = 'BoaApp'
init_ctrls = '_init_ctrls'
init_coll = '_init_coll_'
init_utils = '_init_utils'
init_props = '_init_props'
init_events = '_init_events'
init_sizers = '_init_sizers'
code_gen_warning = "generated method, don't edit"
defEnvPython = wsfix('#!/usr/bin/env python\n')
defCodingUtf8 = wsfix('# -*- coding: utf-8 -*-\n')
# XXX Frame Companion could return this source in writeImports?
defImport = wsfix('import wx\n\n')
defSig = defCodingUtf8 + boaIdent + wsfix(':%(modelIdent)s:%(main)s\n\n')
defCreateClass = wsfix('''def create(parent):
\treturn %(main)s(parent)
''')
srchWindowIdsLC = '\[wx.NewId\(\) for %s in range\((?P<count>\d+)\)\]'
srchWindowIds = '\[(?P<winids>[A-Za-z0-9_, ]*)\] = ' + srchWindowIdsLC
srchWindowIdsCont = '(?P<any>.*)\] = ' + srchWindowIdsLC
defWindowIdsCont = wsfix('] = [wx.NewId() for %(idIdent)s in range(%(idCount)d)]\n')
defWindowIds = wsfix('[%(idNames)s') + defWindowIdsCont
defClass = wsfix('''
class %(main)s(%(defaultName)s):
\tdef ''' + init_ctrls + '''(self, prnt):
\t\t%(defaultName)s.__init__(%(params)s)
\tdef __init__(self, parent):
\t\tself.''' + init_ctrls + '''(parent)
''')
defApp = wsfix('''import %(mainModule)s
modules = {'%(mainModule)s' : [1, 'Main frame of Application', 'none://%(mainModule)s.py']}
class BoaApp(wx.App):
\tdef OnInit(self):
\t\tself.main = %(mainModule)s.create(None)
\t\tself.main.Show()
\t\tself.SetTopWindow(self.main)
\t\treturn True
def main():
\tapplication = BoaApp(0)
\tapplication.MainLoop()
if __name__ == '__main__':
\tmain()
''')
defInfoBlock = wsfix('''#-----------------------------------------------------------------------------
# Name: %(Name)s
# Purpose: %(Purpose)s
#
# Author: %(Author)s
#
# Created: %(Created)s
# RCS-ID: %(RCS-ID)s
# Copyright: %(Copyright)s
# Licence: %(Licence)s
#-----------------------------------------------------------------------------
''')
defSetup_py = wsfix('''
from distutils.core import setup
setup(name = '%(name)s',
version = '%(version)s',
scripts = [%(scripts)s],
)
''')
defPackageSrc = wsfix('''# Package initialisation
''')
defPyApp = wsfix('''modules = {}
def main():
\tpass
if __name__ == '__main__':
\tmain()
''')
simpleModuleRunSrc = wsfix('''
if __name__ == '__main__':
\tpass # add a call to run your script here
''')
simpleAppFrameRunSrc = wsfix('''
if __name__ == '__main__':
\tapp = wx.PySimpleApp()
\tframe = create(None)
\tframe.Show()
\tapp.MainLoop()
''')
simpleAppDialogRunSrc = wsfix('''
if __name__ == '__main__':
\tapp = wx.PySimpleApp()
\tdlg = create(None)
\ttry:
\t\tdlg.ShowModal()
\tfinally:
\t\tdlg.Destroy()
\tapp.MainLoop()
''')
simpleAppPopupRunSrc = wsfix('''
if __name__ == '__main__':
\tapp = wx.PySimpleApp()
\tframe = wx.Frame(None, -1, 'Parent')
\tframe.SetAutoLayout(True)
\tframe.Show()
\tpopup = create(frame)
\tpopup.Show(True)
\tapp.MainLoop()
''')