Source

boa-constructor / Companions.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
#----------------------------------------------------------------------
# Name:        Companions.py
# Purpose:     Classes implementing the design time behaviour of ctrls
#
# Author:      Riaan Booysen
#
# Created:     1999
# RCS-ID:      $Id$
# Copyright:   (c) 1999, 2000 Riaan Booysen
# Licence:     GPL
#----------------------------------------------------------------------

from wxPython.wx import *
from PropertyEditors import *
from Enumerations import *
from EventCollections import *
from BaseCompanions import *
from Constructors import *
from Preferences import wxDefaultFrameSize, wxDefaultFramePos
import HelpCompanions

class BaseFrameDTC(ContainerDTC):
    def __init__(self, name, designer, frameCtrl):
        ContainerDTC.__init__(self, name, designer, None, None)
        self.control = frameCtrl
        
    def generateWindowId(self):
        if self.designer: 
            self.id = Utils.windowIdentifier(self.designer.GetName(), '')
        else: self.id = `NewId()`

    def events(self):
        return ContainerDTC.events(self) + ['FrameEvent']

    def SetName(self, oldValue, newValue):
        print 'setting frame name from', oldValue, 'to', newValue
        self.name = newValue
        self.designer.renameFrame(oldValue, newValue)

    def designTimeSource(self):
        return {'title': `self.name`,
                'pos':  `wxDefaultFramePos`,
                'size': `wxDefaultFrameSize`,
                'name': `self.name`,
                'style': 'wxDEFAULT_FRAME_STYLE'}

class FrameDTC(FramesConstr, BaseFrameDTC):
    wxDocs = 'wx104.htm'


EventCategories['DialogEvent'] = (EVT_INIT_DIALOG,)
class DialogDTC(FramesConstr, BaseFrameDTC):
    wxDocs = HelpCompanions.wxDialogDocs
    def designTimeSource(self):
        dts = BaseFrameDTC.designTimeSource(self)
        dts.update({'style': 'wxDEFAULT_DIALOG_STYLE'})
        return dts

    def events(self):
        return BaseFrameDTC.events(self) + ['DialogEvent']

class MiniFrameDTC(FramesConstr, BaseFrameDTC):
    wxDocs = HelpCompanions.wxMiniFrameDocs

class MDIParentFrameDTC(FramesConstr, BaseFrameDTC):
    wxDocs = HelpCompanions.wxMDIParentFrameDocs
    def designTimeSource(self):
        dts = BaseFrameDTC.designTimeSource(self)
        dts.update({'style': 'wxDEFAULT_FRAME_STYLE | wxVSCROLL | wxHSCROLL'})
        return dts

class MDIChildFrameDTC(FramesConstr, BaseFrameDTC):
    wxDocs = HelpCompanions.wxMDIChildFrameDocs


EventCategories['PanelEvent'] = (EVT_SYS_COLOUR_CHANGED,)
class PanelDTC(WindowConstr, ContainerDTC):
    wxDocs = HelpCompanions.wxPanelDocs
    def designTimeSource(self, position, size = 'wxDefaultSize'):
        return {'pos': position,
        	'size': size,
        	'style': 'wxTAB_TRAVERSAL',
        	'name': `self.name`}

    def events(self):
        return ContainerDTC.events(self) + ['PanelEvent']

class ScrolledWindowDTC(WindowConstr, ContainerDTC):
    wxDocs = HelpCompanions.wxScrolledWindowDocs
    def designTimeSource(self, position, size = 'wxDefaultSize'):
        return {'pos': position,
        	'size': size,
        	'style': 'wxTAB_TRAVERSAL',
        	'name': `self.name`}

    def events(self):
        return ContainerDTC.events(self) + ['ScrollEvent']

EventCategories['NotebookEvent'] = (EVT_NOTEBOOK_PAGE_CHANGED,
                                    EVT_NOTEBOOK_PAGE_CHANGING)
class NotebookDTC(WindowConstr, ContainerDTC):
    wxDocs = HelpCompanions.wxNotebookDocs
    def designTimeSource(self, position, size = 'wxDefaultSize'):
        return {'pos': position,
        	'size': size,
        	'style': '0',
        	'name': `self.name`}

    def events(self):
        return ContainerDTC.events(self) + ['NotebookEvent']

EventCategories['ButtonEvent'] = (EVT_BUTTON,)
commandCategories.append('ButtonEvent')
class ButtonDTC(LabeledInputConstr, WindowDTC):
    wxDocs = HelpCompanions.wxButtonDocs
    def designTimeSource(self, position, size = 'wxDefaultSize'):
        return {'label': `self.name`,
                'pos': position,
        	'size': size,
        	'name': `self.name`,
        	'style': '0'}
    
    def events(self):
        return WindowDTC.events(self) + ['ButtonEvent']

class ListCtrlDTC(MultiItemCtrlsConstr, WindowDTC):
    wxDocs = HelpCompanions.wxListCtrlDocs
    def designTimeSource(self, position, size = 'wxDefaultSize'):
        return {'pos': position,
        	'size': size,
        	'style': 'wxLC_ICON',
        	'validator': 'wxDefaultValidator',
        	'name': `self.name`}
            
    def events(self):
        return WindowDTC.events(self) + ['ListEvent']
    
class TreeCtrlDTC(MultiItemCtrlsConstr, WindowDTC):
    wxDocs = HelpCompanions.wxTreeCtrlDocs
    def designTimeSource(self, position, size = 'wxDefaultSize'):
        return {'pos': position,
        	'size': size,
        	'style': 'wxTR_HAS_BUTTONS',
        	'validator': 'wxDefaultValidator',
        	'name': `self.name`}
        
    def events(self):
        return WindowDTC.events(self) + ['TreeEvent']

class ScrollBarDTC(MultiItemCtrlsConstr, WindowDTC):
    wxDocs = HelpCompanions.wxScrollBarDocs
    def designTimeSource(self, position, size = 'wxDefaultSize'):
        return {'pos': position,
        	'size': size,
        	'style': 'wxSB_HORIZONTAL',
        	'name': `self.name`}
            
    def events(self):
        return WindowDTC.events(self) + ['ScrollEvent']
    

class ComboBoxDTC(ComboConstr, ChoicedDTC):
    wxDocs = HelpCompanions.wxComboBoxDocs
    def designTimeSource(self, position, size = 'wxDefaultSize'):
        return {'value': `self.name`,
                'pos': position,
        	'size': size,
        	'name': `self.name`}
    
class ChoiceDTC(ListConstr, ChoicedDTC):
    wxDocs = HelpCompanions.wxChoiceDocs = 'wx41.htm'
    def designTimeSource(self, position, size = 'wxDefaultSize'):
        return {'pos': position,
        	'size': size,
        	'choices': `[]`,
        	'style': '0',
        	'validator': 'wxDefaultValidator',
        	'name': `self.name`}

class StaticTextDTC(LabeledNonInputConstr, WindowDTC):
    wxDocs = HelpCompanions.wxStaticTextDocs
    def designTimeSource(self, position, size = 'wxDefaultSize'):
        return {'label': `self.name`,
        	'pos': position,
        	'size': size,
        	'style': '0',
        	'name': `self.name`}

EventCategories['TextCtrlEvent'] = (EVT_TEXT, EVT_TEXT_ENTER)
class TextCtrlDTC(TextCtrlConstr, WindowDTC):
    wxDocs = HelpCompanions.wxTextCtrlDocs
    def designTimeSource(self, position, size = 'wxDefaultSize'):
        return {'value': `self.name`,
        	'pos': position,
        	'size': size,
        	'style': '0',
        	'name': `self.name`}
    def events(self):
        return WindowDTC.events(self) + ['TextCtrlEvent']

EventCategories['RadioButtonEvent'] = (EVT_RADIOBUTTON,)
class RadioButtonDTC(LabeledInputConstr, WindowDTC):
    wxDocs = HelpCompanions.wxRadioButtonDocs
    def __init__(self, name, designer, parent, ctrlClass):
        WindowDTC.__init__(self, name, designer, parent, ctrlClass)
        self.editors['Value'] = BoolPropEdit
    def designTimeSource(self, position, size = 'wxDefaultSize'):
        return {'label': `self.name`,
        	'pos': position,
        	'size': size,
        	'style': '0'}
    def events(self):
        return WindowDTC.events(self) + ['RadioButtonEvent']

EventCategories['CheckBoxEvent'] = (EVT_CHECKBOX,)
class CheckBoxDTC(LabeledInputConstr, WindowDTC):
    wxDocs = HelpCompanions.wxCheckBoxDocs = 'wx39.htm'
    def __init__(self, name, designer, parent, ctrlClass):
        WindowDTC.__init__(self, name, designer, parent, ctrlClass)
        self.editors['Value'] = BoolPropEdit
    def designTimeSource(self, position, size = 'wxDefaultSize'):
        return {'label': `self.name`,
        	'pos': position,
        	'size': size,
        	'style': '0'}
    def events(self):
        return WindowDTC.events(self) + ['CheckBoxEvent']

class SpinButtonDTC(WindowConstr, WindowDTC):
    wxDocs = HelpCompanions.wxSpinButtonDocs
    def designTimeSource(self, position, size = 'wxDefaultSize'):
        return {'pos': position,
        	'size': size,
        	'style': 'wxSP_HORIZONTAL',
# cfd       	'validator': 'wxDefaultValidator',
        	'name': `self.name`}
    def events(self):
        return WindowDTC.events(self) + ['SpinEvent', 'CmdScrollEvent']
    
# XXX FreqTick handled wrong
class SliderDTC(SliderConstr, WindowDTC):
    wxDocs = HelpCompanions.wxSliderDocs
    def __init__(self, name, designer, parent, ctrlClass):
        WindowDTC.__init__(self, name, designer, parent, ctrlClass)
        self.editors['MinValue'] = IntConstrPropEdit
        self.editors['MaxValue'] = IntConstrPropEdit
    def designTimeSource(self, position, size = 'wxDefaultSize'):
        return {'value': '0',
        	'minValue': '0',
        	'maxValue': '100',
        	'point': position,
        	'size': size,
        	'style': 'wxSL_HORIZONTAL',
        	'validator': 'wxDefaultValidator',
        	'name': `self.name`}

class GaugeDTC(GaugeConstr, WindowDTC):
    wxDocs = HelpCompanions.wxGaugeDocs
    def designTimeSource(self, position, size = 'wxDefaultSize'):
        return {'range': '100',
        	'pos': position,
        	'size': size,
        	'style': 'wxGA_HORIZONTAL',
        	'validator': 'wxDefaultValidator',
        	'name': `self.name`}

class StaticBoxDTC(LabeledNonInputConstr, WindowDTC):
##    def __init__(self, name, designer, parent, ctrlClass):
##        WindowDTC.__init__(self, name, designer, parent, ctrlClass)
##        self.container = true
    wxDocs = HelpCompanions.wxStaticBox = 'wx220.htm'
    def designTimeSource(self, position, size = 'wxDefaultSize'):
        return {'label': `self.name`,
        	'pos': position,
        	'size': size,
        	'style': '0',
        	'name': `self.name`}

class StaticLineDTC(WindowConstr, WindowDTC):
##    def __init__(self, name, designer, parent, ctrlClass):
##        WindowDTC.__init__(self, name, designer, parent, ctrlClass)
##        self.container = true
    def designTimeSource(self, position, size = 'wxDefaultSize'):
        return {'pos': position,
        	'size': size,
        	'style': '0',
        	'name': `self.name`}
    

class ListBoxDTC(ListConstr, ChoicedDTC):
    wxDocs = HelpCompanions.wxListBoxDocs
    def designTimeSource(self, position, size = 'wxDefaultSize'):
        return {'pos': position,
        	'size': size,
        	'choices': `[]`,
        	'style': '0',
        	'validator': 'wxDefaultValidator',
        	'name': `self.name`}

class CheckListBoxDTC(ListConstr, ChoicedDTC):
    wxDocs = HelpCompanions.wxCheckListBoxDocs
    def designTimeSource(self, position, size = 'wxDefaultSize'):
        return {'pos': position,
        	'size': size,
        	'choices': `[]`,
        	'style': '0',
        	'validator': 'wxDefaultValidator',
        	'name': `self.name`}


class BitmapButtonDTC(BitmapButtonConstr, WindowDTC):
    wxDocs = HelpCompanions.wxBitmapButtonDocs
    def designTimeSource(self, position, size = 'wxDefaultSize'):
        return {'bitmap': 'wxNullBitmap',
                'pos': position,
        	'size': size,
        	'style': 'wxBU_AUTODRAW',
        	'validator': 'wxDefaultValidator',
        	'name': `self.name`}

    def events(self):
        return WindowDTC.events(self) + ['ButtonEvent']
    
class StaticBitmapDTC(StaticBitmapConstr, WindowDTC):
    wxDocs = HelpCompanions.wxStaticBitmapDocs
    def designTimeSource(self, position, size = 'wxDefaultSize'):
        return {'bitmap': 'wxNullBitmap',
                'pos': position,
        	'size': size,
        	'style': '0',
        	'name': `self.name`}


class RadioBoxDTC(RadioBoxConstr, ChoicedDTC):
    wxDocs = HelpCompanions.wxRadioBoxDocs
    def __init__(self, name, designer, parent, ctrlClass):
        ChoicedDTC.__init__(self, name, designer, parent, ctrlClass)
        self.editors['MajorDimension'] = MajorDimensionConstrPropEdit
    def designTimeSource(self, position, size = 'wxDefaultSize'):
        return {'label': `self.name`,
        	'point': position,
        	'size': size,
        	'choices': `['asd']`,
        	'majorDimension': '1',
        	'style': 'wxRA_SPECIFY_COLS',
        	'validator': 'wxDefaultValidator',
        	'name': `self.name`}

class GridDTC(WindowConstr, WindowDTC):
    wxDocs = HelpCompanions.wxGridDocs
    def __init__(self, name, designer, parent, ctrlClass):
        WindowDTC.__init__(self, name, designer, parent, ctrlClass)
        self.editors['Editable'] = self.editors['EditInPlace'] = BoolPropEdit
    def designTimeSource(self, position, size = 'wxDefaultSize'):
        return {'pos': position,
        	'size': size,
        	'style': '0',
        	'name': `self.name`}


class HtmlWindowDTC(HtmlWindowConstr, WindowDTC):
    def __init__(self, name, designer, parent, ctrlClass):
        WindowDTC.__init__(self, name, designer, parent, ctrlClass)
        del self.editors['Style']

    def designTimeSource(self, position, size = 'wxDefaultSize'):
        return {'pos': position,
        	'size': size,
#        	'style': 'wxHW_SCROLLBAR_AUTO',
        	'name': `self.name`}

    def events(self):
        return WindowDTC.events(self) + ['ScrollEvent']

class FontDTC(HelperDTC):
    def __init__(self, name, designer, ctrl, obj):
        HelperDTC.__init__(self, name, designer, ctrl, obj)
        self.editors = {'Family'    : EnumPropEdit,
        		'Style'     : EnumPropEdit,
        		'Weight'    : EnumPropEdit,
                        'Underlined': BoolPropEdit,
                       }
        self.options = {'Family': fontFamily,
        		'Style' : fontStyle,
        		'Weight': fontWeight,
                       }
        self.names = {'Family': fontFamilyNames,
           	      'Style' : fontStyleNames,
        	      'Weight': fontWeightNames,
                     }
 
class ColourDTC(HelperDTC):
    def __init__(self, name, designer, ctrl, obj):
        HelperDTC.__init__(self, name, designer, ctrl, obj)
        self.editors = {'Red'    : RedColPE,
        		'Green'  : GreenColPE,
        		'Blue'   : BlueColPE,
                       }
    def properties(self):
        return {'Red'  : (wxColour.Get.im_func, wxColour.Set.im_func),
                'Green': (wxColour.Get.im_func, wxColour.Set.im_func),
                'Blue' : (wxColour.Get.im_func, wxColour.Set.im_func)
        }