~ubuntu-branches/ubuntu/trusty/boa-constructor/trusty

« back to all changes in this revision

Viewing changes to Companions/LibCompanions.py

  • Committer: Bazaar Package Importer
  • Author(s): Cédric Delfosse
  • Date: 2007-01-23 21:32:29 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070123213229-1d9lxp9c4dutjwv5
Add a .desktop file (Closes: #349081)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#-----------------------------------------------------------------------------
2
 
# Name:        LibCompanions.py
3
 
# Purpose:
4
 
#
5
 
# Author:      Riaan Booysen
6
 
#
7
 
# Created:     2003
8
 
# RCS-ID:      $Id: LibCompanions.py,v 1.5 2004/08/16 13:16:56 riaan Exp $
9
 
# Copyright:   (c) 2003 - 2004
10
 
# Licence:     GPL
11
 
#-----------------------------------------------------------------------------
12
 
print 'importing Companions.LibCompanions'
13
 
 
14
 
from wxPython.wx import *
15
 
 
16
 
##from wxPython.lib.colourselect import ColourSelect, EVT_COLOURSELECT
17
 
from wxPython.lib.stattext import wxGenStaticText
18
 
 
19
 
from BaseCompanions import WindowDTC
20
 
from BasicCompanions import StaticTextDTC, TextCtrlDTC, ComboBoxDTC
21
 
 
22
 
from PropEdit import PropertyEditors, InspectorEditorControls
23
 
import EventCollections
24
 
 
25
 
 
26
 
import MaskedEditFmtCodeDlg
27
 
 
28
 
##class ColourSelectDTC(ButtonDTC):
29
 
##    def __init__(self, name, designer, parent, ctrlClass):
30
 
##        ButtonDTC.__init__(self, name, designer, parent, ctrlClass)
31
 
##
32
 
##    def designTimeSource(self, position = 'wxDefaultPosition', size = 'wxDefaultSize'):
33
 
##        return {'label': `self.name`,
34
 
##                'bcolour': `(0, 0, 0)`,
35
 
##                'pos': position,
36
 
##                'size': size,
37
 
##                'name': `self.name`,
38
 
##                'style': '0'}
39
 
##
40
 
##    def events(self):
41
 
##        return WindowDTC.events(self) + ['ButtonEvent']
42
 
##
43
 
##    def defaultAction(self):
44
 
##        insp = self.designer.inspector
45
 
##        insp.pages.SetSelection(2)
46
 
##        insp.events.doAddEvent('ButtonEvent', 'EVT_BUTTON')
47
 
 
48
 
 
49
 
class GenStaticTextDTC(StaticTextDTC):
50
 
    handledConstrParams = ('parent', 'ID')
51
 
    windowIdName = 'ID'
52
 
 
53
 
    def writeImports(self):
54
 
        return 'from wxPython.lib.stattext import wxGenStaticText'
55
 
 
56
 
#-------------------------------------------------------------------------------
57
 
 
58
 
##class MaskConstrPropEdit(PropertyEditors.StrConstrPropEdit):
59
 
##    def inspectorEdit(self):
60
 
##        self.editorCtrl = InspectorEditorControls.TextCtrlButtonIEC(self, self.value)
61
 
##        self.editorCtrl.createControl(self.parent, self.idx, self.width, self.edit)
62
 
##
63
 
##    def edit(self, event):
64
 
##        pass
65
 
 
66
 
class FormatCodePropEdit(PropertyEditors.StrPropEdit):
67
 
    def inspectorEdit(self):
68
 
        self.editorCtrl = InspectorEditorControls.TextCtrlButtonIEC(self, self.value)
69
 
        self.editorCtrl.createControl(self.parent, self.idx, self.width, self.edit)
70
 
 
71
 
    def edit(self, event):
72
 
        dlg = MaskedEditFmtCodeDlg.MaskedEditFormatCodesDlg(self.parent, self.value)
73
 
        try:
74
 
            if dlg.ShowModal() != wxID_OK:
75
 
                return
76
 
 
77
 
            self.value = dlg.getFormatCode()
78
 
            self.editorCtrl.setValue(self.value)
79
 
            self.inspectorPost(false)
80
 
        finally:
81
 
            dlg.Destroy()
82
 
 
83
 
class AutoFormatPropMixin:
84
 
    dependents = ['mask', 'datestyle', 'formatcodes',
85
 
                  'description', 'excludeChars', 'validRegex']
86
 
    
87
 
    def __init__(self):
88
 
        self.editors['Autoformat'] = PropertyEditors.StringEnumPropEdit
89
 
 
90
 
        from wxPython.lib import maskededit 
91
 
        autofmt = maskededit.masktags.keys()
92
 
        autofmt.sort()
93
 
        self.options['Autoformat'] = [s for s in ['']+autofmt]
94
 
        self.names['Autoformat'] = {}
95
 
        for opt in self.options['Autoformat']: 
96
 
            self.names['Autoformat'][opt] = opt
97
 
        
98
 
        self.mutualDepProps += ['Autoformat'] + [s[0].upper()+s[1:] 
99
 
                                                 for s in self.dependents]
100
 
 
101
 
    def properties(self):
102
 
        props = {'Autoformat': ('CompnRoute', self.GetAutoformat, 
103
 
                                              self.SetAutoformat)}
104
 
        return props
105
 
 
106
 
    def GetAutoformat(self, x):
107
 
        return self.control.GetAutoformat()
108
 
 
109
 
    def SetAutoformat(self, val):
110
 
        currVals = {}
111
 
        for dp in self.dependents:
112
 
            currVals[dp] = self.control.GetCtrlParameter(dp)
113
 
 
114
 
        self.control.SetAutoformat(val)
115
 
        
116
 
        # call delayed so that Inspector may update first
117
 
        wxCallAfter(self.revertAutoFormatDeps, currVals)
118
 
    
119
 
    def revertAutoFormatDeps(self, currVals):
120
 
        # revert source for properties that were changed to default values
121
 
        for dp in self.dependents:
122
 
            newVal = self.control.GetCtrlParameter(dp)
123
 
            if newVal != currVals[dp]:
124
 
                prop = dp[0].upper()+dp[1:]
125
 
                self.propRevertToDefault(prop, 'Set'+prop)
126
 
 
127
 
 
128
 
class MaskedDTCMixin:
129
 
    def __init__(self):
130
 
        BoolPE = PropertyEditors.BoolPropEdit
131
 
        StrEnumPE = PropertyEditors.StringEnumPropEdit
132
 
        BITPropEdit = PropertyEditors.BITPropEditor
133
 
        self.editors.update({'AutoCompleteKeycodes': BITPropEdit,
134
 
                             'UseFixedWidthFont': BoolPE, 
135
 
                             'RetainFieldValidation': BoolPE,
136
 
                             'Datestyle': StrEnumPE,
137
 
                             'Choices': BITPropEdit,
138
 
                             'ChoiceRequired': BoolPE, 
139
 
                             'CompareNoCase': BoolPE, 
140
 
                             'EmptyInvalid': BoolPE, 
141
 
                             'ValidRequired': BoolPE, 
142
 
                             'Formatcodes': FormatCodePropEdit,
143
 
                            })
144
 
 
145
 
        self.options['Datestyle'] = ['YMD','MDY','YDM','DYM','DMY','MYD']
146
 
        self.names['Datestyle'] = {}
147
 
        for opt in self.options['Datestyle']: 
148
 
            self.names['Datestyle'][opt] = opt
149
 
        
150
 
    def hideDesignTime(self):
151
 
        return ['Demo', 'Fields', 'Autoformat', 'ValidFunc']
152
 
 
153
 
class BaseMaskedTextCtrlDTC(TextCtrlDTC, MaskedDTCMixin):
154
 
    def __init__(self, name, designer, parent, ctrlClass):
155
 
        TextCtrlDTC.__init__(self, name, designer, parent, ctrlClass)
156
 
        MaskedDTCMixin.__init__(self)
157
 
 
158
 
    def designTimeSource(self, position = 'wxDefaultPosition', size = 'wxDefaultSize'):
159
 
        dts = TextCtrlDTC.designTimeSource(self, position, size)
160
 
        dts['value'] = "''"
161
 
        return dts
162
 
 
163
 
    def hideDesignTime(self):
164
 
        return TextCtrlDTC.hideDesignTime(self) + MaskedDTCMixin.hideDesignTime(self)
165
 
 
166
 
    def writeImports(self):
167
 
        return 'from wxPython.lib.maskededit import *'
168
 
 
169
 
class MaskedTextCtrlDTC(BaseMaskedTextCtrlDTC, AutoFormatPropMixin):
170
 
    def __init__(self, name, designer, parent, ctrlClass):
171
 
        BaseMaskedTextCtrlDTC.__init__(self, name, designer, parent, ctrlClass)
172
 
        AutoFormatPropMixin.__init__(self)
173
 
 
174
 
    def properties(self):
175
 
        props = BaseMaskedTextCtrlDTC.properties(self)
176
 
        props.update(AutoFormatPropMixin.properties(self))
177
 
        return props
178
 
 
179
 
 
180
 
class IpAddrCtrlDTC(BaseMaskedTextCtrlDTC):
181
 
    pass
182
 
##    def hideDesignTime(self):
183
 
##        return BaseMaskedTextCtrlDTC.hideDesignTime(self) + ['Datestyle', 
184
 
##               'AutoCompleteKeycodes', 'SignedForegroundColour', 
185
 
##               'GroupChar', 'DecimalChar', 'ShiftDecimalChar', 
186
 
##               'UseParensForNegatives', 'ExcludeChars', 'IncludeChars',
187
 
##               'CompareNoCase']
188
 
 
189
 
class MaskedComboBoxDTC(ComboBoxDTC, MaskedDTCMixin, AutoFormatPropMixin):
190
 
    def __init__(self, name, designer, parent, ctrlClass):
191
 
        ComboBoxDTC.__init__(self, name, designer, parent, ctrlClass)
192
 
        MaskedDTCMixin.__init__(self)
193
 
        AutoFormatPropMixin.__init__(self)
194
 
 
195
 
    def designTimeSource(self, position = 'wxDefaultPosition', size = 'wxDefaultSize'):
196
 
        dts = ComboBoxDTC.designTimeSource(self, position, size)
197
 
        dts['value'] = "''"
198
 
        return dts
199
 
 
200
 
    def properties(self):
201
 
        props = ComboBoxDTC.properties(self)
202
 
        props.update(AutoFormatPropMixin.properties(self))
203
 
        return props
204
 
 
205
 
    def hideDesignTime(self):
206
 
        return ComboBoxDTC.hideDesignTime(self) + \
207
 
               MaskedDTCMixin.hideDesignTime(self)
208
 
##               ['Mark', 'EmptyInvalid']
209
 
 
210
 
    def writeImports(self):
211
 
        return 'from wxPython.lib.maskededit import *'
212
 
 
213
 
class MaskedNumCtrlDTC(TextCtrlDTC, MaskedDTCMixin):
214
 
    def __init__(self, name, designer, parent, ctrlClass):
215
 
        TextCtrlDTC.__init__(self, name, designer, parent, ctrlClass)
216
 
        MaskedDTCMixin.__init__(self)
217
 
 
218
 
        self.editors.update({'Min': PropertyEditors.BITPropEditor, 
219
 
                             'Max': PropertyEditors.BITPropEditor, 
220
 
                             'Bounds': PropertyEditors.BITPropEditor})
221
 
 
222
 
        self.mutualDepProps += ['Bounds', 'Min', 'Max']
223
 
 
224
 
    def designTimeSource(self, position = 'wxDefaultPosition', size = 'wxDefaultSize'):
225
 
        dts = TextCtrlDTC.designTimeSource(self, position, size)
226
 
        dts['value'] = '0'
227
 
        return dts
228
 
 
229
 
    def events(self):
230
 
        return TextCtrlDTC.events(self) + ['MaskedNumCtrlEvent']
231
 
 
232
 
    def writeImports(self):
233
 
        return 'from wxPython.lib.maskednumctrl import *'
234
 
 
235
 
    def hideDesignTime(self):
236
 
        return TextCtrlDTC.hideDesignTime(self) + \
237
 
               MaskedDTCMixin.hideDesignTime(self) 
238
 
##               ['Datestyle', 'AutoCompleteKeycodes', 'ExcludeChars', 
239
 
##               'IncludeChars', 'Choices', 'ChoiceRequired', 'CompareNoCase', 
240
 
##               'ValidRange']
241
 
 
242
 
 
243
 
#-------------------------------------------------------------------------------
244
 
 
245
 
class SpinButtonEnumConstrPropEdit(PropertyEditors.ObjEnumConstrPropEdit):
246
 
    def getObjects(self):
247
 
        designer = self.companion.designer#.controllerView
248
 
        windows = designer.getObjectsOfClass(wxSpinButtonPtr)
249
 
        windowNames = windows.keys()
250
 
        windowNames.sort()
251
 
        res = ['None'] + windowNames
252
 
        if self.value != 'None':
253
 
            res.insert(1, self.value)
254
 
        return res
255
 
 
256
 
    def getDisplayValue(self):
257
 
        return `self.valueToIECValue()`
258
 
        
259
 
    def getCtrlValue(self):
260
 
        return self.companion.GetSpinButton()
261
 
    def setCtrlValue(self, oldValue, value):
262
 
        self.companion.SetSpinButton(value)
263
 
 
264
 
class SpinButtonClassLinkPropEdit(PropertyEditors.ClassLinkPropEdit):
265
 
    linkClass = wxSpinButtonPtr
266
 
    
267
 
#EventCollections.EventCategories['TimeCtrlEvent'] = (EVT_TIMEUPDATE,)
268
 
#EventCollections.commandCategories.append('TimeCtrlEvent')
269
 
 
270
 
# XXX min, max & limited params not supported yet
271
 
# XXX should be implemented as a wxDateTime property editor using
272
 
# XXX this very time ctrl, a problem is how to handle None values.
273
 
 
274
 
class TimeCtrlDTC(MaskedTextCtrlDTC):
275
 
    def __init__(self, name, designer, parent, ctrlClass):
276
 
        MaskedTextCtrlDTC.__init__(self, name, designer, parent, ctrlClass)
277
 
        BoolPE = PropertyEditors.BoolConstrPropEdit
278
 
        ColourPE = PropertyEditors.ColourConstrPropEdit
279
 
        self.editors.update({'Format24Hours': BoolPE, 
280
 
                             'SpinButton': SpinButtonClassLinkPropEdit,
281
 
                             'OutOfBoundsColour': ColourPE,
282
 
                             'DisplaySeconds': BoolPE,
283
 
                             'UseFixedWidthFont': BoolPE, 
284
 
                             'Format': PropertyEditors.StringEnumPropEdit})
285
 
 
286
 
        format = ['MILHHMMSS', 'MILHHMM', 'HHMMSS', 'HHMM']
287
 
        self.options['Format'] = format
288
 
        self.names['Format'] = {}
289
 
        for name in format: self.names['Format'][name] = name
290
 
            
291
 
 
292
 
        self._spinbutton = None
293
 
        self.initPropsThruCompanion.extend(['SpinButton', 'BindSpinButton'])
294
 
 
295
 
    def constructor(self):
296
 
        constr = MaskedTextCtrlDTC.constructor(self)
297
 
        constr.update({'Format24Hours':     'fmt24hr', 
298
 
                       'DisplaySeconds':    'display_seconds',
299
 
                       'OutOfBoundsColour': 'oob_color',
300
 
                       'UseFixedWidthFont': 'useFixedWidthFont',
301
 
                      })
302
 
        return constr
303
 
 
304
 
    def designTimeSource(self, position = 'wxDefaultPosition', size = 'wxDefaultSize'):
305
 
        dts = MaskedTextCtrlDTC.designTimeSource(self, position, size)
306
 
        dts.update({'value': "'12:00:00 AM'",
307
 
                    'fmt24hr': 'False',
308
 
                    'display_seconds': 'True',
309
 
                    'oob_color': "wxNamedColour('Yellow')",
310
 
                    'useFixedWidthFont': 'True',
311
 
                   })
312
 
        return dts
313
 
 
314
 
    def properties(self):
315
 
        props = MaskedTextCtrlDTC.properties(self)
316
 
        if props.has_key('Autoformat'):
317
 
            del props['Autoformat']
318
 
        props['SpinButton'] = ('CompnRoute', self.GetSpinButton, 
319
 
                                             self.BindSpinButton)
320
 
##        props['Format24Hours'] = ('CompnRoute', self.GetFormat24Hours, 
321
 
##                                                self.SetFormat24Hours)
322
 
##        props['DisplaySeconds'] = ('CompnRoute', self.GetDisplaySeconds, 
323
 
##                                                 self.SetDisplaySeconds)
324
 
                                                
325
 
        return props
326
 
 
327
 
    def dependentProps(self):
328
 
        return MaskedTextCtrlDTC.dependentProps(self) + ['SpinButton', 'BindSpinButton']
329
 
 
330
 
    def events(self):
331
 
        return MaskedTextCtrlDTC.events(self) + ['TimeCtrlEvent']
332
 
 
333
 
    def writeImports(self):
334
 
        return 'from wxPython.lib.timectrl import *'
335
 
 
336
 
##    def hideDesignTime(self):
337
 
##        return MaskedTextCtrlDTC.hideDesignTime(self) + ['Mask',
338
 
##               'Datestyle', 'AutoCompleteKeycodes', 'EmptyBackgroundColour',
339
 
##               'SignedForegroundColour', 'GroupChar', 'DecimalChar', 
340
 
##               'ShiftDecimalChar', 'UseParensForNegatives', 'ExcludeChars', 
341
 
##               'IncludeChars', 'Choices', 'ChoiceRequired', 'CompareNoCase',
342
 
##               'AutoSelect', 'ValidRegex', 'ValidRange']
343
 
 
344
 
    def GetSpinButton(self, x):
345
 
        return self._spinbutton
346
 
        
347
 
    def BindSpinButton(self, value):
348
 
        self._spinbutton = value
349
 
        if value is not None:
350
 
            spins = self.designer.getObjectsOfClass(wxSpinButtonPtr)
351
 
            if value in spins:
352
 
                self.control.BindSpinButton(spins[value])
353
 
 
354
 
##    def GetDisplaySeconds(self, x):
355
 
##        return self.eval(self.textConstr.params['display_seconds'])
356
 
##
357
 
##    def SetDisplaySeconds(self, value):
358
 
##        self.textConstr.params['display_seconds'] = self.eval(value)
359
 
 
360
 
#-------------------------------------------------------------------------------
361
 
 
362
 
#EventCollections.EventCategories['IntCtrlEvent'] = (EVT_INT,)
363
 
#EventCollections.commandCategories.append('IntCtrlEvent')
364
 
 
365
 
 
366
 
class IntCtrlDTC(TextCtrlDTC):
367
 
    def __init__(self, name, designer, parent, ctrlClass):
368
 
        TextCtrlDTC.__init__(self, name, designer, parent, ctrlClass)
369
 
        BoolPE = PropertyEditors.BoolConstrPropEdit
370
 
        ColourPE = PropertyEditors.ColourConstrPropEdit
371
 
        self.editors.update({'Min': PropertyEditors.BITPropEditor, 
372
 
                             'Max': PropertyEditors.BITPropEditor, 
373
 
                             'Limited': BoolPE,
374
 
                             'AllowNone': BoolPE,
375
 
                             'AllowLong': BoolPE,
376
 
                             'DefaultColour': ColourPE,
377
 
                             'OutOfBoundsColour': ColourPE})
378
 
 
379
 
    def constructor(self):
380
 
        constr = TextCtrlDTC.constructor(self)
381
 
        constr.update({'Min': 'min', 'Max': 'max', 'Limited': 'limited',
382
 
            'AllowNone': 'allow_none', 'AllowLong': 'allow_long',
383
 
            'DefaultColour': 'default_color', 'OutOfBoundsColour': 'oob_color'})
384
 
        return constr
385
 
 
386
 
    def designTimeSource(self, position = 'wxDefaultPosition', size = 'wxDefaultSize'):
387
 
        dts = TextCtrlDTC.designTimeSource(self, position, size)
388
 
        dts.update({'value': '0',
389
 
                    'min': 'None',
390
 
                    'max': 'None',
391
 
                    'limited': 'False',
392
 
                    'allow_none': 'False',
393
 
                    'allow_long': 'False',
394
 
                    'default_color': 'wxBLACK',
395
 
                    'oob_color': 'wxRED'})
396
 
        return dts
397
 
 
398
 
##    def hideDesignTime(self):
399
 
##        return TextCtrlDTC.hideDesignTime(self) + ['Bounds', 'InsertionPoint']
400
 
 
401
 
    def events(self):
402
 
        return TextCtrlDTC.events(self) + ['IntCtrlEvent']
403
 
 
404
 
    def writeImports(self):
405
 
        return 'from wxPython.lib.intctrl import *'
406
 
 
407
 
 
408
 
#-------------------------------------------------------------------------------
409
 
 
410
 
import PaletteStore
411
 
 
412
 
PaletteStore.paletteLists['wxPython.lib'] = []
413
 
PaletteStore.palette.append(['wxPython.lib', 'Editor/Tabs/Basic',
414
 
                             PaletteStore.paletteLists['wxPython.lib']])
415
 
 
416
 
# XXX clean up special casing when 2.4.1 is minimum!
417
 
 
418
 
libPalette = [wxGenStaticText]
419
 
libCompInfo = {wxGenStaticText:  ['wxGenStaticText',  GenStaticTextDTC]}
420
 
 
421
 
try:
422
 
    from wxPython.lib.maskednumctrl import wxMaskedNumCtrl, EVT_MASKEDNUM
423
 
    from wxPython.lib.maskededit import wxMaskedTextCtrl, wxMaskedComboBox, wxIpAddrCtrl, Field
424
 
    from wxPython.lib.timectrl import wxTimeCtrl, EVT_TIMEUPDATE
425
 
except ImportError: # <= 2.4.1.2
426
 
    pass
427
 
else:
428
 
    libPalette.extend([wxMaskedTextCtrl, wxIpAddrCtrl, wxMaskedComboBox, 
429
 
                       wxMaskedNumCtrl, wxTimeCtrl])
430
 
    libCompInfo.update({
431
 
        wxMaskedTextCtrl: ['wxMaskedTextCtrl', MaskedTextCtrlDTC], 
432
 
        wxIpAddrCtrl:     ['wxIpAddrCtrl',     IpAddrCtrlDTC],
433
 
        wxMaskedComboBox: ['wxMaskedComboBox', MaskedComboBoxDTC], 
434
 
        wxMaskedNumCtrl:  ['wxMaskedNumCtrl',  MaskedNumCtrlDTC],
435
 
        wxTimeCtrl:       ['wxTimeCtrl',       TimeCtrlDTC],
436
 
    })
437
 
 
438
 
    EventCollections.EventCategories['MaskedNumCtrlEvent'] = (EVT_MASKEDNUM,)
439
 
    EventCollections.commandCategories.append('MaskedNumCtrlEvent')    
440
 
 
441
 
    EventCollections.EventCategories['TimeCtrlEvent'] = (EVT_TIMEUPDATE,)
442
 
    EventCollections.commandCategories.append('TimeCtrlEvent')    
443
 
    
444
 
from wxPython.lib.intctrl import wxIntCtrl, EVT_INT
445
 
 
446
 
EventCollections.EventCategories['IntCtrlEvent'] = (EVT_INT,)
447
 
EventCollections.commandCategories.append('IntCtrlEvent')
448
 
 
449
 
libPalette.append(wxIntCtrl)
450
 
libCompInfo[wxIntCtrl] = ['wxIntCtrl', IntCtrlDTC]
451
 
 
452
 
PaletteStore.paletteLists['wxPython.lib'].extend(libPalette)
453
 
PaletteStore.compInfo.update(libCompInfo)
 
1
#-----------------------------------------------------------------------------
 
2
# Name:        LibCompanions.py
 
3
# Purpose:
 
4
#
 
5
# Author:      Riaan Booysen
 
6
#
 
7
# Created:     2003
 
8
# RCS-ID:      $Id: LibCompanions.py,v 1.10 2005/07/04 19:14:24 riaan Exp $
 
9
# Copyright:   (c) 2003 - 2005
 
10
# Licence:     GPL
 
11
#-----------------------------------------------------------------------------
 
12
print 'importing Companions.LibCompanions'
 
13
 
 
14
import wx
 
15
 
 
16
from BaseCompanions import WindowDTC
 
17
from BasicCompanions import StaticTextDTC, TextCtrlDTC, ComboBoxDTC
 
18
 
 
19
from PropEdit import PropertyEditors, InspectorEditorControls
 
20
import EventCollections
 
21
 
 
22
 
 
23
import MaskedEditFmtCodeDlg
 
24
 
 
25
 
 
26
class GenStaticTextDTC(StaticTextDTC):
 
27
    handledConstrParams = ('parent', 'ID')
 
28
    windowIdName = 'ID'
 
29
 
 
30
    def writeImports(self):
 
31
        return 'import wx.lib.stattext'
 
32
 
 
33
#-------------------------------------------------------------------------------
 
34
 
 
35
##class MaskConstrPropEdit(PropertyEditors.StrConstrPropEdit):
 
36
##    def inspectorEdit(self):
 
37
##        self.editorCtrl = InspectorEditorControls.TextCtrlButtonIEC(self, self.value)
 
38
##        self.editorCtrl.createControl(self.parent, self.idx, self.width, self.edit)
 
39
##
 
40
##    def edit(self, event):
 
41
##        pass
 
42
 
 
43
class FormatCodePropEdit(PropertyEditors.StrPropEdit):
 
44
    def inspectorEdit(self):
 
45
        self.editorCtrl = InspectorEditorControls.TextCtrlButtonIEC(self, self.value)
 
46
        self.editorCtrl.createControl(self.parent, self.idx, self.width, self.edit)
 
47
 
 
48
    def edit(self, event):
 
49
        dlg = MaskedEditFmtCodeDlg.MaskedEditFormatCodesDlg(self.parent, self.value)
 
50
        try:
 
51
            if dlg.ShowModal() != wx.ID_OK:
 
52
                return
 
53
 
 
54
            self.value = dlg.getFormatCode()
 
55
            self.editorCtrl.setValue(self.value)
 
56
            self.inspectorPost(False)
 
57
        finally:
 
58
            dlg.Destroy()
 
59
 
 
60
class AutoFormatPropMixin:
 
61
    dependents = ['mask', 'datestyle', 'formatcodes',
 
62
                  'description', 'excludeChars', 'validRegex']
 
63
 
 
64
    def __init__(self):
 
65
        self.editors['Autoformat'] = PropertyEditors.StringEnumPropEdit
 
66
 
 
67
        from wx.lib.masked import maskededit
 
68
        autofmt = maskededit.masktags.keys()
 
69
        autofmt.sort()
 
70
        self.options['Autoformat'] = [s for s in ['']+autofmt]
 
71
        self.names['Autoformat'] = {}
 
72
        for opt in self.options['Autoformat']:
 
73
            self.names['Autoformat'][opt] = opt
 
74
 
 
75
        self.mutualDepProps += ['Autoformat'] + [s[0].upper()+s[1:]
 
76
                                                 for s in self.dependents]
 
77
 
 
78
    def properties(self):
 
79
        props = {'Autoformat': ('CompnRoute', self.GetAutoformat,
 
80
                                              self.SetAutoformat)}
 
81
        return props
 
82
 
 
83
    def GetAutoformat(self, x):
 
84
        return self.control.GetAutoformat()
 
85
 
 
86
    def SetAutoformat(self, val):
 
87
        currVals = {}
 
88
        for dp in self.dependents:
 
89
            currVals[dp] = self.control.GetCtrlParameter(dp)
 
90
 
 
91
        self.control.SetAutoformat(val)
 
92
 
 
93
        # call delayed so that Inspector may update first
 
94
        wx.CallAfter(self.revertAutoFormatDeps, currVals)
 
95
 
 
96
    def revertAutoFormatDeps(self, currVals):
 
97
        # revert source for properties that were changed to default values
 
98
        for dp in self.dependents:
 
99
            newVal = self.control.GetCtrlParameter(dp)
 
100
            if newVal != currVals[dp]:
 
101
                prop = dp[0].upper()+dp[1:]
 
102
                self.propRevertToDefault(prop, 'Set'+prop)
 
103
 
 
104
 
 
105
class MaskedDTCMixin:
 
106
    def __init__(self):
 
107
        BoolPE = PropertyEditors.BoolPropEdit
 
108
        StrEnumPE = PropertyEditors.StringEnumPropEdit
 
109
        BITPropEdit = PropertyEditors.BITPropEditor
 
110
        self.editors.update({'AutoCompleteKeycodes': BITPropEdit,
 
111
                             'UseFixedWidthFont': BoolPE,
 
112
                             'RetainFieldValidation': BoolPE,
 
113
                             'Datestyle': StrEnumPE,
 
114
                             'Choices': BITPropEdit,
 
115
                             'ChoiceRequired': BoolPE,
 
116
                             'CompareNoCase': BoolPE,
 
117
                             'EmptyInvalid': BoolPE,
 
118
                             'ValidRequired': BoolPE,
 
119
                             'Formatcodes': FormatCodePropEdit,
 
120
                            })
 
121
 
 
122
        self.options['Datestyle'] = ['YMD','MDY','YDM','DYM','DMY','MYD']
 
123
        self.names['Datestyle'] = {}
 
124
        for opt in self.options['Datestyle']:
 
125
            self.names['Datestyle'][opt] = opt
 
126
 
 
127
    def hideDesignTime(self):
 
128
        return ['Demo', 'Fields', 'Autoformat', 'ValidFunc']
 
129
 
 
130
class BaseMaskedTextCtrlDTC(TextCtrlDTC, MaskedDTCMixin):
 
131
    def __init__(self, name, designer, parent, ctrlClass):
 
132
        TextCtrlDTC.__init__(self, name, designer, parent, ctrlClass)
 
133
        MaskedDTCMixin.__init__(self)
 
134
 
 
135
    def designTimeSource(self, position = 'wx.DefaultPosition', size = 'wx.DefaultSize'):
 
136
        dts = TextCtrlDTC.designTimeSource(self, position, size)
 
137
        dts['value'] = "''"
 
138
        return dts
 
139
 
 
140
    def hideDesignTime(self):
 
141
        return TextCtrlDTC.hideDesignTime(self) + MaskedDTCMixin.hideDesignTime(self)
 
142
 
 
143
 
 
144
class MaskedTextCtrlDTC(BaseMaskedTextCtrlDTC, AutoFormatPropMixin):
 
145
    def __init__(self, name, designer, parent, ctrlClass):
 
146
        BaseMaskedTextCtrlDTC.__init__(self, name, designer, parent, ctrlClass)
 
147
        AutoFormatPropMixin.__init__(self)
 
148
 
 
149
    def properties(self):
 
150
        props = BaseMaskedTextCtrlDTC.properties(self)
 
151
        props.update(AutoFormatPropMixin.properties(self))
 
152
        return props
 
153
 
 
154
    def writeImports(self):
 
155
        return 'import wx.lib.masked.textctrl'
 
156
 
 
157
class IpAddrCtrlDTC(BaseMaskedTextCtrlDTC):
 
158
    def writeImports(self):
 
159
        return 'import wx.lib.masked.ipaddrctrl'
 
160
 
 
161
 
 
162
class MaskedComboBoxDTC(ComboBoxDTC, MaskedDTCMixin, AutoFormatPropMixin):
 
163
    def __init__(self, name, designer, parent, ctrlClass):
 
164
        ComboBoxDTC.__init__(self, name, designer, parent, ctrlClass)
 
165
        MaskedDTCMixin.__init__(self)
 
166
        AutoFormatPropMixin.__init__(self)
 
167
 
 
168
    def designTimeSource(self, position = 'wx.DefaultPosition', size = 'wx.DefaultSize'):
 
169
        dts = ComboBoxDTC.designTimeSource(self, position, size)
 
170
        dts['value'] = "''"
 
171
        return dts
 
172
 
 
173
    def properties(self):
 
174
        props = ComboBoxDTC.properties(self)
 
175
        props.update(AutoFormatPropMixin.properties(self))
 
176
        return props
 
177
 
 
178
    def hideDesignTime(self):
 
179
        return ComboBoxDTC.hideDesignTime(self) + \
 
180
               MaskedDTCMixin.hideDesignTime(self)
 
181
##               ['Mark', 'EmptyInvalid']
 
182
 
 
183
    def writeImports(self):
 
184
        return 'import wx.lib.masked.combobox'
 
185
 
 
186
class MaskedNumCtrlDTC(TextCtrlDTC, MaskedDTCMixin):
 
187
    def __init__(self, name, designer, parent, ctrlClass):
 
188
        TextCtrlDTC.__init__(self, name, designer, parent, ctrlClass)
 
189
        MaskedDTCMixin.__init__(self)
 
190
 
 
191
        self.editors.update({'Min': PropertyEditors.BITPropEditor,
 
192
                             'Max': PropertyEditors.BITPropEditor,
 
193
                             'Bounds': PropertyEditors.BITPropEditor})
 
194
 
 
195
        self.mutualDepProps += ['Bounds', 'Min', 'Max']
 
196
 
 
197
    def designTimeSource(self, position = 'wx.DefaultPosition', size = 'wx.DefaultSize'):
 
198
        dts = TextCtrlDTC.designTimeSource(self, position, size)
 
199
        dts['value'] = '0'
 
200
        return dts
 
201
 
 
202
    def events(self):
 
203
        return TextCtrlDTC.events(self) + ['MaskedNumCtrlEvent']
 
204
 
 
205
    def writeImports(self):
 
206
        return 'import wx.lib.masked.numctrl'
 
207
 
 
208
    def hideDesignTime(self):
 
209
        return TextCtrlDTC.hideDesignTime(self) + \
 
210
               MaskedDTCMixin.hideDesignTime(self)
 
211
##               ['Datestyle', 'AutoCompleteKeycodes', 'ExcludeChars',
 
212
##               'IncludeChars', 'Choices', 'ChoiceRequired', 'CompareNoCase',
 
213
##               'ValidRange']
 
214
 
 
215
 
 
216
#-------------------------------------------------------------------------------
 
217
 
 
218
class SpinButtonEnumConstrPropEdit(PropertyEditors.ObjEnumConstrPropEdit):
 
219
    def getObjects(self):
 
220
        designer = self.companion.designer#.controllerView
 
221
        windows = designer.getObjectsOfClass(wx.SpinButton)
 
222
        windowNames = windows.keys()
 
223
        windowNames.sort()
 
224
        res = ['None'] + windowNames
 
225
        if self.value != 'None':
 
226
            res.insert(1, self.value)
 
227
        return res
 
228
 
 
229
    def getDisplayValue(self):
 
230
        return `self.valueToIECValue()`
 
231
 
 
232
    def getCtrlValue(self):
 
233
        return self.companion.GetSpinButton()
 
234
    def setCtrlValue(self, oldValue, value):
 
235
        self.companion.SetSpinButton(value)
 
236
 
 
237
class SpinButtonClassLinkPropEdit(PropertyEditors.ClassLinkPropEdit):
 
238
    linkClass = wx.SpinButton
 
239
 
 
240
#EventCollections.EventCategories['TimeCtrlEvent'] = (EVT_TIMEUPDATE,)
 
241
#EventCollections.commandCategories.append('TimeCtrlEvent')
 
242
 
 
243
# XXX min, max & limited params not supported yet
 
244
# XXX should be implemented as a wxDateTime property editor using
 
245
# XXX this very time ctrl, a problem is how to handle None values.
 
246
 
 
247
class TimeCtrlDTC(MaskedTextCtrlDTC):
 
248
    def __init__(self, name, designer, parent, ctrlClass):
 
249
        MaskedTextCtrlDTC.__init__(self, name, designer, parent, ctrlClass)
 
250
        BoolPE = PropertyEditors.BoolConstrPropEdit
 
251
        ColourPE = PropertyEditors.ColourConstrPropEdit
 
252
        self.editors.update({'Format24Hours': BoolPE,
 
253
                             'SpinButton': SpinButtonClassLinkPropEdit,
 
254
                             'OutOfBoundsColour': ColourPE,
 
255
                             'DisplaySeconds': BoolPE,
 
256
                             'UseFixedWidthFont': BoolPE,
 
257
                             'Format': PropertyEditors.StringEnumPropEdit})
 
258
 
 
259
        format = ['MILHHMMSS', 'MILHHMM', 'HHMMSS', 'HHMM']
 
260
        self.options['Format'] = format
 
261
        self.names['Format'] = {}
 
262
        for name in format: self.names['Format'][name] = name
 
263
 
 
264
 
 
265
        self._spinbutton = None
 
266
        self.initPropsThruCompanion.extend(['SpinButton', 'BindSpinButton'])
 
267
 
 
268
    def constructor(self):
 
269
        constr = MaskedTextCtrlDTC.constructor(self)
 
270
        constr.update({'Format24Hours':     'fmt24hr',
 
271
                       'DisplaySeconds':    'display_seconds',
 
272
                       'OutOfBoundsColour': 'oob_color',
 
273
                       'UseFixedWidthFont': 'useFixedWidthFont',
 
274
                      })
 
275
        return constr
 
276
 
 
277
    def designTimeSource(self, position = 'wx.DefaultPosition', size = 'wx.DefaultSize'):
 
278
        dts = MaskedTextCtrlDTC.designTimeSource(self, position, size)
 
279
        dts.update({'value': "'12:00:00 AM'",
 
280
                    'fmt24hr': 'False',
 
281
                    'display_seconds': 'True',
 
282
                    'oob_color': "wx.NamedColour('Yellow')",
 
283
                    'useFixedWidthFont': 'True',
 
284
                   })
 
285
        return dts
 
286
 
 
287
    def properties(self):
 
288
        props = MaskedTextCtrlDTC.properties(self)
 
289
        if props.has_key('Autoformat'):
 
290
            del props['Autoformat']
 
291
        props['SpinButton'] = ('CompnRoute', self.GetSpinButton,
 
292
                                             self.BindSpinButton)
 
293
##        props['Format24Hours'] = ('CompnRoute', self.GetFormat24Hours,
 
294
##                                                self.SetFormat24Hours)
 
295
##        props['DisplaySeconds'] = ('CompnRoute', self.GetDisplaySeconds,
 
296
##                                                 self.SetDisplaySeconds)
 
297
 
 
298
        return props
 
299
 
 
300
    def dependentProps(self):
 
301
        return MaskedTextCtrlDTC.dependentProps(self) + ['SpinButton', 'BindSpinButton']
 
302
 
 
303
    def events(self):
 
304
        return MaskedTextCtrlDTC.events(self) + ['TimeCtrlEvent']
 
305
 
 
306
    def writeImports(self):
 
307
        return 'import wx.lib.masked.timectrl'
 
308
 
 
309
##    def hideDesignTime(self):
 
310
##        return MaskedTextCtrlDTC.hideDesignTime(self) + ['Mask',
 
311
##               'Datestyle', 'AutoCompleteKeycodes', 'EmptyBackgroundColour',
 
312
##               'SignedForegroundColour', 'GroupChar', 'DecimalChar',
 
313
##               'ShiftDecimalChar', 'UseParensForNegatives', 'ExcludeChars',
 
314
##               'IncludeChars', 'Choices', 'ChoiceRequired', 'CompareNoCase',
 
315
##               'AutoSelect', 'ValidRegex', 'ValidRange']
 
316
 
 
317
    def GetSpinButton(self, x):
 
318
        return self._spinbutton
 
319
 
 
320
    def BindSpinButton(self, value):
 
321
        self._spinbutton = value
 
322
        if value is not None:
 
323
            spins = self.designer.getObjectsOfClass(wx.SpinButton)
 
324
            if value in spins:
 
325
                self.control.BindSpinButton(spins[value])
 
326
 
 
327
##    def GetDisplaySeconds(self, x):
 
328
##        return self.eval(self.textConstr.params['display_seconds'])
 
329
##
 
330
##    def SetDisplaySeconds(self, value):
 
331
##        self.textConstr.params['display_seconds'] = self.eval(value)
 
332
 
 
333
#-------------------------------------------------------------------------------
 
334
 
 
335
#EventCollections.EventCategories['IntCtrlEvent'] = (EVT_INT,)
 
336
#EventCollections.commandCategories.append('IntCtrlEvent')
 
337
 
 
338
 
 
339
class IntCtrlDTC(TextCtrlDTC):
 
340
    def __init__(self, name, designer, parent, ctrlClass):
 
341
        TextCtrlDTC.__init__(self, name, designer, parent, ctrlClass)
 
342
        BoolPE = PropertyEditors.BoolConstrPropEdit
 
343
        ColourPE = PropertyEditors.ColourConstrPropEdit
 
344
        self.editors.update({'Min': PropertyEditors.BITPropEditor,
 
345
                             'Max': PropertyEditors.BITPropEditor,
 
346
                             'Limited': BoolPE,
 
347
                             'AllowNone': BoolPE,
 
348
                             'AllowLong': BoolPE,
 
349
                             'DefaultColour': ColourPE,
 
350
                             'OutOfBoundsColour': ColourPE})
 
351
 
 
352
    def constructor(self):
 
353
        constr = TextCtrlDTC.constructor(self)
 
354
        constr.update({'Min': 'min', 'Max': 'max', 'Limited': 'limited',
 
355
            'AllowNone': 'allow_none', 'AllowLong': 'allow_long',
 
356
            'DefaultColour': 'default_color', 'OutOfBoundsColour': 'oob_color'})
 
357
        return constr
 
358
 
 
359
    def designTimeSource(self, position = 'wx.DefaultPosition', size = 'wx.DefaultSize'):
 
360
        dts = TextCtrlDTC.designTimeSource(self, position, size)
 
361
        dts.update({'value': '0',
 
362
                    'min': 'None',
 
363
                    'max': 'None',
 
364
                    'limited': 'False',
 
365
                    'allow_none': 'False',
 
366
                    'allow_long': 'False',
 
367
                    'default_color': 'wx.BLACK',
 
368
                    'oob_color': 'wx.RED'})
 
369
        return dts
 
370
 
 
371
##    def hideDesignTime(self):
 
372
##        return TextCtrlDTC.hideDesignTime(self) + ['Bounds', 'InsertionPoint']
 
373
 
 
374
    def events(self):
 
375
        return TextCtrlDTC.events(self) + ['IntCtrlEvent']
 
376
 
 
377
    def writeImports(self):
 
378
        return 'import wx.lib.intctrl'
 
379
 
 
380
 
 
381
#-------------------------------------------------------------------------------
 
382
 
 
383
import wx.lib.stattext
 
384
import wx.lib.masked.textctrl
 
385
import wx.lib.masked.ipaddrctrl
 
386
import wx.lib.masked.combobox
 
387
import wx.lib.masked.numctrl
 
388
import wx.lib.masked.timectrl
 
389
import wx.lib.intctrl
 
390
 
 
391
import Plugins
 
392
 
 
393
Plugins.registerPalettePage('Library', 'Library')
 
394
 
 
395
Plugins.registerComponents('Library',
 
396
      (wx.lib.stattext.GenStaticText, 'wx.lib.stattext.GenStaticText', GenStaticTextDTC),
 
397
      (wx.lib.masked.textctrl.TextCtrl, 'wx.lib.masked.textctrl.TextCtrl', MaskedTextCtrlDTC),
 
398
      (wx.lib.masked.ipaddrctrl.IpAddrCtrl, 'wx.lib.masked.ipaddrctrl.IpAddrCtrl', IpAddrCtrlDTC),
 
399
      (wx.lib.masked.combobox.ComboBox, 'wx.lib.masked.combobox.ComboBox', MaskedComboBoxDTC),
 
400
      (wx.lib.masked.numctrl.NumCtrl, 'wx.lib.masked.numctrl.NumCtrl', MaskedNumCtrlDTC),
 
401
      (wx.lib.masked.timectrl.TimeCtrl, 'wx.lib.masked.timectrl.TimeCtrl', TimeCtrlDTC),
 
402
      (wx.lib.intctrl.IntCtrl, 'wx.lib.intctrl.IntCtrl', IntCtrlDTC),
 
403
    )
 
404
 
 
405
EventCollections.EventCategories['MaskedNumCtrlEvent'] = ('wx.lib.masked.numctrl.EVT_MASKEDNUM',)
 
406
EventCollections.commandCategories.append('MaskedNumCtrlEvent')
 
407
EventCollections.EventCategories['TimeCtrlEvent'] = ('wx.lib.masked.timectrl.EVT_TIMEUPDATE',)
 
408
EventCollections.commandCategories.append('TimeCtrlEvent')
 
409
EventCollections.EventCategories['IntCtrlEvent'] = ('wx.lib.intctrl.EVT_INT',)
 
410
EventCollections.commandCategories.append('IntCtrlEvent')