boa-constructor /Companions/LibCompanions.py

Language Python Lines 704
MD5 Hash dfe0bc4a8df56e76e596d748fe0242c2 Estimated Cost $12,556 (why?)
Repository https://bitbucket.org/cwt/boa-constructor View Raw File View Project SPDX
  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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
#-----------------------------------------------------------------------------
# Name:        LibCompanions.py
# Purpose:
#
# Author:      Riaan Booysen
#
# Created:     2003
# RCS-ID:      $Id$
# Copyright:   (c) 2003 - 2007
# Licence:     GPL
#-----------------------------------------------------------------------------
print 'importing Companions.LibCompanions'

import wx

from Utils import _

import Constructors, ContainerCompanions, BasicCompanions
from BaseCompanions import WindowDTC
from BasicCompanions import StaticTextDTC, TextCtrlDTC, ComboBoxDTC
from ContainerCompanions import PanelDTC

from PropEdit import PropertyEditors, InspectorEditorControls
import EventCollections

from PropEdit import MaskedEditFmtCodeDlg, BitmapListEditorDlg


class GenStaticTextDTC(StaticTextDTC):
    handledConstrParams = ('parent', 'ID')
    windowIdName = 'ID'

    def writeImports(self):
        return '\n'.join( (StaticTextDTC.writeImports(self), 'import wx.lib.stattext'))

#-------------------------------------------------------------------------------

##class MaskConstrPropEdit(PropertyEditors.StrConstrPropEdit):
##    def inspectorEdit(self):
##        self.editorCtrl = InspectorEditorControls.TextCtrlButtonIEC(self, self.value)
##        self.editorCtrl.createControl(self.parent, self.idx, self.width, self.edit)
##
##    def edit(self, event):
##        pass

class FormatCodePropEdit(PropertyEditors.StrPropEdit):
    def inspectorEdit(self):
        self.editorCtrl = InspectorEditorControls.TextCtrlButtonIEC(self, self.value)
        self.editorCtrl.createControl(self.parent, self.idx, self.width, self.edit)

    def edit(self, event):
        dlg = MaskedEditFmtCodeDlg.MaskedEditFormatCodesDlg(self.parent, self.value)
        try:
            if dlg.ShowModal() != wx.ID_OK:
                return

            self.value = dlg.getFormatCode()
            self.editorCtrl.setValue(self.value)
            self.inspectorPost(False)
        finally:
            dlg.Destroy()

class AutoFormatPropMixin:
    dependents = ['mask', 'datestyle', 'formatcodes',
                  'description', 'excludeChars', 'validRegex']

    def __init__(self):
        self.editors['Autoformat'] = PropertyEditors.StringEnumPropEdit

        from wx.lib.masked import maskededit
        autofmt = maskededit.masktags.keys()
        autofmt.sort()
        self.options['Autoformat'] = [s for s in ['']+autofmt]
        self.names['Autoformat'] = {}
        for opt in self.options['Autoformat']:
            self.names['Autoformat'][opt] = opt

        self.mutualDepProps += ['Autoformat'] + [s[0].upper()+s[1:]
                                                 for s in self.dependents]

    def properties(self):
        props = {'Autoformat': ('CompnRoute', self.GetAutoformat,
                                              self.SetAutoformat)}
        return props

    def GetAutoformat(self, x):
        return self.control.GetAutoformat()

    def SetAutoformat(self, val):
        currVals = {}
        for dp in self.dependents:
            currVals[dp] = self.control.GetCtrlParameter(dp)

        self.control.SetAutoformat(val)

        # call delayed so that Inspector may update first
        wx.CallAfter(self.revertAutoFormatDeps, currVals)

    def revertAutoFormatDeps(self, currVals):
        # revert source for properties that were changed to default values
        for dp in self.dependents:
            newVal = self.control.GetCtrlParameter(dp)
            if newVal != currVals[dp]:
                prop = dp[0].upper()+dp[1:]
                self.propRevertToDefault(prop, 'Set'+prop)


class MaskedDTCMixin:
    def __init__(self):
        BoolPE = PropertyEditors.BoolPropEdit
        StrEnumPE = PropertyEditors.StringEnumPropEdit
        BITPropEdit = PropertyEditors.BITPropEditor
        self.editors.update({'AutoCompleteKeycodes': BITPropEdit,
                             'UseFixedWidthFont': BoolPE,
                             'RetainFieldValidation': BoolPE,
                             'Datestyle': StrEnumPE,
                             'Choices': BITPropEdit,
                             'ChoiceRequired': BoolPE,
                             'CompareNoCase': BoolPE,
                             'EmptyInvalid': BoolPE,
                             'ValidRequired': BoolPE,
                             'Formatcodes': FormatCodePropEdit,
                            })

        self.options['Datestyle'] = ['YMD','MDY','YDM','DYM','DMY','MYD']
        self.names['Datestyle'] = {}
        for opt in self.options['Datestyle']:
            self.names['Datestyle'][opt] = opt

    def hideDesignTime(self):
        return ['Demo', 'Fields', 'Autoformat', 'ValidFunc']

class BaseMaskedTextCtrlDTC(TextCtrlDTC, MaskedDTCMixin):
    def __init__(self, name, designer, parent, ctrlClass):
        TextCtrlDTC.__init__(self, name, designer, parent, ctrlClass)
        MaskedDTCMixin.__init__(self)

    def designTimeSource(self, position = 'wx.DefaultPosition', size = 'wx.DefaultSize'):
        dts = TextCtrlDTC.designTimeSource(self, position, size)
        dts['value'] = "''"
        return dts

    def hideDesignTime(self):
        return TextCtrlDTC.hideDesignTime(self) + MaskedDTCMixin.hideDesignTime(self)


class MaskedTextCtrlDTC(BaseMaskedTextCtrlDTC, AutoFormatPropMixin):
    def __init__(self, name, designer, parent, ctrlClass):
        BaseMaskedTextCtrlDTC.__init__(self, name, designer, parent, ctrlClass)
        AutoFormatPropMixin.__init__(self)

    def properties(self):
        props = BaseMaskedTextCtrlDTC.properties(self)
        props.update(AutoFormatPropMixin.properties(self))
        return props

    def writeImports(self):
        return '\n'.join( (BaseMaskedTextCtrlDTC.writeImports(self), 'import wx.lib.masked.textctrl'))

class IpAddrCtrlDTC(BaseMaskedTextCtrlDTC):
    def writeImports(self):
        return '\n'.join( (BaseMaskedTextCtrlDTC.writeImports(self), 'import wx.lib.masked.ipaddrctrl'))


class MaskedComboBoxDTC(ComboBoxDTC, MaskedDTCMixin, AutoFormatPropMixin):
    def __init__(self, name, designer, parent, ctrlClass):
        ComboBoxDTC.__init__(self, name, designer, parent, ctrlClass)
        MaskedDTCMixin.__init__(self)
        AutoFormatPropMixin.__init__(self)

    def designTimeSource(self, position = 'wx.DefaultPosition', size = 'wx.DefaultSize'):
        dts = ComboBoxDTC.designTimeSource(self, position, size)
        dts['value'] = "''"
        return dts

    def properties(self):
        props = ComboBoxDTC.properties(self)
        props.update(AutoFormatPropMixin.properties(self))
        return props

    def hideDesignTime(self):
        return ComboBoxDTC.hideDesignTime(self) + \
               MaskedDTCMixin.hideDesignTime(self)
##               ['Mark', 'EmptyInvalid']

    def writeImports(self):
        return '\n'.join( (ComboBoxDTC.writeImports(self), 'import wx.lib.masked.combobox'))

class MaskedNumCtrlDTC(TextCtrlDTC, MaskedDTCMixin):
    def __init__(self, name, designer, parent, ctrlClass):
        TextCtrlDTC.__init__(self, name, designer, parent, ctrlClass)
        MaskedDTCMixin.__init__(self)

        self.editors.update({'Min': PropertyEditors.BITPropEditor,
                             'Max': PropertyEditors.BITPropEditor,
                             'Bounds': PropertyEditors.BITPropEditor})

        self.mutualDepProps += ['Bounds', 'Min', 'Max']

    def designTimeSource(self, position = 'wx.DefaultPosition', size = 'wx.DefaultSize'):
        dts = TextCtrlDTC.designTimeSource(self, position, size)
        dts['value'] = '0'
        return dts

    def events(self):
        return TextCtrlDTC.events(self) + ['MaskedNumCtrlEvent']

    def writeImports(self):
        return '\n'.join( (TextCtrlDTC.writeImports(self), 'import wx.lib.masked.numctrl'))

    def hideDesignTime(self):
        return TextCtrlDTC.hideDesignTime(self) + \
               MaskedDTCMixin.hideDesignTime(self)
##               ['Datestyle', 'AutoCompleteKeycodes', 'ExcludeChars',
##               'IncludeChars', 'Choices', 'ChoiceRequired', 'CompareNoCase',
##               'ValidRange']


#-------------------------------------------------------------------------------

class SpinButtonEnumConstrPropEdit(PropertyEditors.ObjEnumConstrPropEdit):
    def getObjects(self):
        designer = self.companion.designer#.controllerView
        windows = designer.getObjectsOfClass(wx.SpinButton)
        windowNames = windows.keys()
        windowNames.sort()
        res = ['None'] + windowNames
        if self.value != 'None':
            res.insert(1, self.value)
        return res

    def getDisplayValue(self):
        return `self.valueToIECValue()`

    def getCtrlValue(self):
        return self.companion.GetSpinButton()
    def setCtrlValue(self, oldValue, value):
        self.companion.SetSpinButton(value)

class SpinButtonClassLinkPropEdit(PropertyEditors.ClassLinkPropEdit):
    linkClass = wx.SpinButton

#EventCollections.EventCategories['TimeCtrlEvent'] = (EVT_TIMEUPDATE,)
#EventCollections.commandCategories.append('TimeCtrlEvent')

# XXX min, max & limited params not supported yet
# XXX should be implemented as a wxDateTime property editor using
# XXX this very time ctrl, a problem is how to handle None values.

class TimeCtrlDTC(MaskedTextCtrlDTC):
    def __init__(self, name, designer, parent, ctrlClass):
        MaskedTextCtrlDTC.__init__(self, name, designer, parent, ctrlClass)
        BoolPE = PropertyEditors.BoolConstrPropEdit
        ColourPE = PropertyEditors.ColourConstrPropEdit
        self.editors.update({'Format24Hours': BoolPE,
                             'SpinButton': SpinButtonClassLinkPropEdit,
                             'OutOfBoundsColour': ColourPE,
                             'DisplaySeconds': BoolPE,
                             'UseFixedWidthFont': BoolPE,
                             'Format': PropertyEditors.StringEnumPropEdit})

        format = ['24HHMMSS', '24HHMM', 'HHMMSS', 'HHMM']
        self.options['Format'] = format
        self.names['Format'] = {}
        for name in format: self.names['Format'][name] = name


        self._spinbutton = None
        self.initPropsThruCompanion.extend(['SpinButton', 'BindSpinButton'])

    def constructor(self):
        constr = MaskedTextCtrlDTC.constructor(self)
        constr.update({'Format24Hours':     'fmt24hr',
                       'DisplaySeconds':    'display_seconds',
                       'OutOfBoundsColour': 'oob_color',
                       'UseFixedWidthFont': 'useFixedWidthFont',
                      })
        return constr

    def designTimeSource(self, position = 'wx.DefaultPosition', size = 'wx.DefaultSize'):
        dts = MaskedTextCtrlDTC.designTimeSource(self, position, size)
        dts.update({'value': "'12:00:00 AM'",
                    'fmt24hr': 'False',
                    'display_seconds': 'True',
                    'oob_color': "wx.NamedColour('Yellow')",
                    'useFixedWidthFont': 'True',
                   })
        return dts

    def properties(self):
        props = MaskedTextCtrlDTC.properties(self)
        if 'Autoformat' in props:
            del props['Autoformat']
        props['SpinButton'] = ('CompnRoute', self.GetSpinButton,
                                             self.BindSpinButton)
##        props['Format24Hours'] = ('CompnRoute', self.GetFormat24Hours,
##                                                self.SetFormat24Hours)
##        props['DisplaySeconds'] = ('CompnRoute', self.GetDisplaySeconds,
##                                                 self.SetDisplaySeconds)

        return props

    def dependentProps(self):
        return MaskedTextCtrlDTC.dependentProps(self) + ['SpinButton', 'BindSpinButton']

    def events(self):
        return MaskedTextCtrlDTC.events(self) + ['TimeCtrlEvent']

    def writeImports(self):
        return '\n'.join( (MaskedTextCtrlDTC.writeImports(self), 'import wx.lib.masked.timectrl'))

##    def hideDesignTime(self):
##        return MaskedTextCtrlDTC.hideDesignTime(self) + ['Mask',
##               'Datestyle', 'AutoCompleteKeycodes', 'EmptyBackgroundColour',
##               'SignedForegroundColour', 'GroupChar', 'DecimalChar',
##               'ShiftDecimalChar', 'UseParensForNegatives', 'ExcludeChars',
##               'IncludeChars', 'Choices', 'ChoiceRequired', 'CompareNoCase',
##               'AutoSelect', 'ValidRegex', 'ValidRange']

    def GetSpinButton(self, x):
        return self._spinbutton

    def BindSpinButton(self, value):
        self._spinbutton = value
        if value is not None:
            spins = self.designer.getObjectsOfClass(wx.SpinButton)
            if value in spins:
                self.control.BindSpinButton(spins[value])

##    def GetDisplaySeconds(self, x):
##        return self.eval(self.textConstr.params['display_seconds'])
##
##    def SetDisplaySeconds(self, value):
##        self.textConstr.params['display_seconds'] = self.eval(value)

#-------------------------------------------------------------------------------

#EventCollections.EventCategories['IntCtrlEvent'] = (EVT_INT,)
#EventCollections.commandCategories.append('IntCtrlEvent')


class IntCtrlDTC(TextCtrlDTC):
    def __init__(self, name, designer, parent, ctrlClass):
        TextCtrlDTC.__init__(self, name, designer, parent, ctrlClass)
        BoolPE = PropertyEditors.BoolConstrPropEdit
        ColourPE = PropertyEditors.ColourConstrPropEdit
        self.editors.update({'Min': PropertyEditors.BITPropEditor,
                             'Max': PropertyEditors.BITPropEditor,
                             'Limited': BoolPE,
                             'AllowNone': BoolPE,
                             'AllowLong': BoolPE,
                             'DefaultColour': ColourPE,
                             'OutOfBoundsColour': ColourPE})

    def constructor(self):
        constr = TextCtrlDTC.constructor(self)
        constr.update({'Min': 'min', 'Max': 'max', 'Limited': 'limited',
            'AllowNone': 'allow_none', 'AllowLong': 'allow_long',
            'DefaultColour': 'default_color', 'OutOfBoundsColour': 'oob_color'})
        return constr

    def designTimeSource(self, position = 'wx.DefaultPosition', size = 'wx.DefaultSize'):
        dts = TextCtrlDTC.designTimeSource(self, position, size)
        dts.update({'value': '0',
                    'min': 'None',
                    'max': 'None',
                    'limited': 'False',
                    'allow_none': 'False',
                    'allow_long': 'False',
                    'default_color': 'wx.BLACK',
                    'oob_color': 'wx.RED'})
        return dts

##    def hideDesignTime(self):
##        return TextCtrlDTC.hideDesignTime(self) + ['Bounds', 'InsertionPoint']

    def events(self):
        return TextCtrlDTC.events(self) + ['IntCtrlEvent']

    def writeImports(self):
        return '\n'.join( (TextCtrlDTC.writeImports(self), 'import wx.lib.intctrl'))

#-------------------------------------------------------------------------------

class AnalogClockDTC(WindowDTC):
    def __init__(self, name, designer, parent, ctrlClass):
        WindowDTC.__init__(self, name, designer, parent, ctrlClass)
        
##        wx.lib.analogclock.SHOW_QUARTERS_TICKS, 
##        wx.lib.analogclock.SHOW_HOURS_TICKS,
##        wx.lib.analogclock.SHOW_MINUTES_TICKS,
##        wx.lib.analogclock.ROTATE_TICKS,
##        wx.lib.analogclock.SHOW_HOURS_HAND,
##        wx.lib.analogclock.SHOW_MINUTES_HAND,
##        wx.lib.analogclock.SHOW_SECONDS_HAND,
##        wx.lib.analogclock.SHOW_SHADOWS,
##        wx.lib.analogclock.OVERLAP_TICKS,
##        wx.lib.analogclock.DEFAULT_CLOCK_STYLE,

##        wx.lib.analogclock.TICKS_NONE,
##        wx.lib.analogclock.TICKS_SQUARE,
##        wx.lib.analogclock.TICKS_CIRCLE,
##        wx.lib.analogclock.TICKS_POLY,
##        wx.lib.analogclock.TICKS_DECIMAL,
##        wx.lib.analogclock.TICKS_ROMAN,
##        wx.lib.analogclock.TICKS_BINARY,
##        wx.lib.analogclock.TICKS_HEX,

    def hideDesignTime(self):
        return WindowDTC.hideDesignTime(self) + ['HandSize', 'HandBorderWidth',
              'HandBorderColour', 'HandFillColour', 'TickSize', 'TickStyle', 
              'TickOffset', 'TickBorderWidth', 'TickBorderColour', 
              'TickFillColour', 'TickFont', 'ClockStyle']

    def writeImports(self):
        return '\n'.join( (WindowDTC.writeImports(self), 'import wx.lib.analogclock'))

#-------------------------------------------------------------------------------

class ScrolledPanelDTC(Constructors.WindowConstr, 
                       ContainerCompanions.ScrolledWindowDTC):
    """Currently you need to manually add the following call to the source
    after self._init_ctrls(parent).
    
    e.g.
    self.panel1.SetupScrolling(scroll_x=True, scroll_y=True, rate_x=20, rate_y=20)
    """
    def __init__(self, name, designer, parent, ctrlClass):
        ContainerCompanions.ScrolledWindowDTC.__init__(self, name, designer, parent, ctrlClass)

    def designTimeSource(self, position = 'wx.DefaultPosition', size = 'wx.DefaultSize'):
        return {'pos':   position,
                'size': self.getDefCtrlSize(),
                'style': 'wx.TAB_TRAVERSAL',
                'name':  `self.name`}

    def writeImports(self):
        return '\n'.join( (ContainerCompanions.ScrolledWindowDTC.writeImports(self),
                          'import wx.lib.scrolledpanel'))

#-------------------------------------------------------------------------------

EventCollections.EventCategories['HyperLinkEvent'] = (
    'wx.lib.hyperlink.EVT_HYPERLINK_LEFT',
    'wx.lib.hyperlink.EVT_HYPERLINK_MIDDLE',
    'wx.lib.hyperlink.EVT_HYPERLINK_RIGHT')

#Link Visited LinkRollover

class HyperLinkCtrlDTC(BasicCompanions.StaticTextDTC):
    def __init__(self, name, designer, parent, ctrlClass):
       BasicCompanions.StaticTextDTC.__init__(self, name, designer, parent, ctrlClass)
       self.editors.update({
            'AutoBrowse': PropertyEditors.BoolPropEdit,
            'Bold': PropertyEditors.BoolPropEdit,
            'DoPopup': PropertyEditors.BoolPropEdit,
            'EnableRollover': PropertyEditors.BoolPropEdit,
            'OpenInSameWindow': PropertyEditors.BoolPropEdit,
            'ReportErrors': PropertyEditors.BoolPropEdit,
            'Visited': PropertyEditors.BoolPropEdit,
        })

    def constructor(self):
        return {'Position': 'pos', 'Size': 'size', 'Label': 'label',
                'Style': 'style', 'Name': 'name', 'URL': 'URL'}

    def initDesignTimeControl(self):
        BasicCompanions.StaticTextDTC.initDesignTimeControl(self)
        self.control.AutoBrowse(False)

    def writeImports(self):
        return '\n'.join( (BasicCompanions.StaticTextDTC.writeImports(self),
                          'import wx.lib.hyperlink'))

    def events(self):
        return BasicCompanions.StaticTextDTC.events(self) + ['HyperLinkEvent']

    def properties(self):
        return {
            'AutoBrowse': ('CompnRoute', self.GetAutoBrowse, self.AutoBrowse),
            'Bold': ('CompnRoute', self.GetBold, self.SetBold), 
        }

    def GetAutoBrowse(self, x):
        for prop in self.textPropList:
            if prop.prop_setter == 'AutoBrowse':
                return prop.params[0].lower() == 'true'
        return True

    def AutoBrowse(self, value):
        pass

    def GetBold(self, x):
        return self.control.GetBold()

    def SetBold(self, value):
        self.control.SetBold(value)
        self.control.UpdateLink()


#-------------------------------------------------------------------------------

class FileBrowseButtonDTC(PanelDTC):
    def __init__(self, name, designer, parent, ctrlClass):
        PanelDTC.__init__(self, name, designer, parent, ctrlClass)
        StrPropEdit = PropertyEditors.StrConstrPropEdit
        self.editors.update({
            'LabelText': StrPropEdit, 'ButtonText': StrPropEdit,
            'ToolTip': StrPropEdit, 'DialogTitle': StrPropEdit,
            'StartDirectory': StrPropEdit, 'InitialValue': StrPropEdit, 
            'FileMask': StrPropEdit,
        })
    
    def designTimeSource(self, position='wx.DefaultPosition', size='wx.DefaultSize'):
        return {'pos':   position,
                'size': 'wx.Size(296, 48)',
                'style': 'wx.TAB_TRAVERSAL',
                'labelText': `'File Entry:'`,
                'buttonText': `'Browse'`,
                'toolTip': `'Type filename or click browse to choose file'`,
                'dialogTitle': `'Choose a file'`,
                'startDirectory': `'.'`,
                'initialValue': `''`,
                'fileMask': `'*.*'`,
                }

    def constructor(self):
        return {'Position': 'pos', 'Size': 'size', 'Style': 'style',
                'LabelText': 'labelText', 'ButtonText': 'buttonText',
                'ToolTip': 'toolTip', 'DialogTitle': 'dialogTitle',
                'StartDirectory': 'startDirectory', 
                'InitialValue': 'initialValue', 'FileMask': 'fileMask'}

    def writeImports(self):
        return '\n'.join( (PanelDTC.writeImports(self),
                          'import wx.lib.filebrowsebutton'))

class FileBrowseButtonWithHistoryDTC(FileBrowseButtonDTC): 
    pass

class DirBrowseButtonDTC(FileBrowseButtonDTC):
    def designTimeSource(self, position='wx.DefaultPosition', size='wx.DefaultSize'):
        return {'pos':   position,
                'size': 'wx.Size(296, 48)',
                'style': 'wx.TAB_TRAVERSAL',
                'labelText': `'Select a directory:'`,
                'buttonText': `'Browse'`,
                'toolTip': `'Type directory name or browse to select'`,
                'dialogTitle': `''`,
                'startDirectory': `'.'`,
                'newDirectory': 'False',
                }

    def constructor(self):
        return {'Position': 'pos', 'Size': 'size', 'Style': 'style',
                'LabelText': 'labelText', 'ButtonText': 'buttonText',
                'ToolTip': 'toolTip', 'DialogTitle': 'dialogTitle',
                'StartDirectory': 'startDirectory', 
                'NewDirectory': 'newDirectory'}
    

class MultiSplitterWindowDTC(PanelDTC):
    def __init__(self, name, designer, parent, ctrlClass):
        PanelDTC.__init__(self, name, designer, parent, ctrlClass)

class BitmapsConstrPropEdit(PropertyEditors.ConstrPropEdit):
    def getValue(self):
        if self.editorCtrl:
            self.value = self.editorCtrl.getValue()
        else:
            self.value = self.getCtrlValue()
        return self.value

    def inspectorEdit(self):
        self.editorCtrl = InspectorEditorControls.ButtonIEC(self, self.value)
        self.editorCtrl.createControl(self.parent, self.idx, self.width, self.edit)

    def edit(self, event):
        dlg = BitmapListEditorDlg.BitmapListEditorDlg(self.parent, self.value, self.companion)
        try:
            if dlg.ShowModal() == wx.ID_OK:
                self.value = dlg.getBitmapsSource()
                self.editorCtrl.setValue(self.value)
                self.inspectorPost(False)
        finally:
            dlg.Destroy()

class ThrobberDTC(PanelDTC):
    def __init__(self, name, designer, parent, ctrlClass):
        PanelDTC.__init__(self, name, designer, parent, ctrlClass)
        self.editors.update({'Bitmaps': BitmapsConstrPropEdit})

    def designTimeSource(self, position='wx.DefaultPosition', size='wx.DefaultSize'):
        return {'pos':   position,
                'size': self.getDefCtrlSize(),
                'style': '0',
                'name': `self.name`,
                'bitmap': '[wx.NullBitmap]', 
                'frameDelay': '0.1',
                'label': 'None',
                'overlay': 'None',
                'reverse': '0',
                'rest': '0',
                'current': '0',
                'direction': '1'}

    def constructor(self):
        return {'Position': 'pos', 'Size': 'size', 'Style': 'style', 'Name': 'name',
                'Bitmaps': 'bitmap', 'FrameDelay': 'frameDelay', 'Label': 'label', 
                'Overlay': 'overlay', 'Reverse': 'reverse', 'Rest': 'rest', 
                'Current': 'current', 'Direction': 'direction'}

    def writeImports(self):
        return '\n'.join( (PanelDTC.writeImports(self),
                          'import wx.lib.throbber'))


class TickerDTC(WindowDTC):
    def __init__(self, name, designer, parent, ctrlClass):
        WindowDTC.__init__(self, name, designer, parent, ctrlClass)
        self.editors['Start'] = PropertyEditors.BoolConstrPropEdit

    def writeImports(self):
        return '\n'.join((WindowDTC.writeImports(self), 'import wx.lib.ticker'))

    def constructor(self):
        return {'Position': 'pos', 'Size': 'size', 'Style': 'style', 
                'Name': 'name', 'Text': 'text', 'Start': 'start',
                'Direction': 'direction'}

    def designTimeSource(self, position = 'wx.DefaultPosition', size = 'wx.DefaultSize'):
        return {'text': `self.name`,
                'start': 'False',
                'direction': `'rtl'`,
                'pos': position,
                'size': size,
                'style': '0',
                'name': `self.name`}
                                
#-------------------------------------------------------------------------------

import wx.lib.stattext
import wx.lib.masked.textctrl
import wx.lib.masked.ipaddrctrl
import wx.lib.masked.combobox
import wx.lib.masked.numctrl
import wx.lib.masked.timectrl
import wx.lib.intctrl

import wx.lib.scrolledpanel
import wx.lib.hyperlink

import Plugins

Plugins.registerPalettePage('Library', _('Library'))

Plugins.registerComponents('Library',
      (wx.lib.stattext.GenStaticText, 'wx.lib.stattext.GenStaticText', GenStaticTextDTC),
      (wx.lib.masked.textctrl.TextCtrl, 'wx.lib.masked.textctrl.TextCtrl', MaskedTextCtrlDTC),
      (wx.lib.masked.ipaddrctrl.IpAddrCtrl, 'wx.lib.masked.ipaddrctrl.IpAddrCtrl', IpAddrCtrlDTC),
      (wx.lib.masked.combobox.ComboBox, 'wx.lib.masked.combobox.ComboBox', MaskedComboBoxDTC),
      (wx.lib.masked.numctrl.NumCtrl, 'wx.lib.masked.numctrl.NumCtrl', MaskedNumCtrlDTC),
      (wx.lib.masked.timectrl.TimeCtrl, 'wx.lib.masked.timectrl.TimeCtrl', TimeCtrlDTC),
      (wx.lib.intctrl.IntCtrl, 'wx.lib.intctrl.IntCtrl', IntCtrlDTC),
      (wx.lib.scrolledpanel.ScrolledPanel, 'wx.lib.scrolledpanel.ScrolledPanel', ScrolledPanelDTC),
      (wx.lib.hyperlink.HyperLinkCtrl, 'wx.lib.hyperlink.HyperLinkCtrl', HyperLinkCtrlDTC),       
    )

try:
    import wx.lib.splitter
    Plugins.registerComponent('Library', wx.lib.splitter.MultiSplitterWindow, 'wx.lib.splitter.MultiSplitterWindow', MultiSplitterWindowDTC)
except ImportError: pass

try:
    import wx.lib.analogclock
    Plugins.registerComponent('Library', wx.lib.analogclock.AnalogClock, 'wx.lib.analogclock.AnalogClock', AnalogClockDTC)
except (ImportError, AttributeError): pass
    
try:
    import wx.lib.filebrowsebutton 
    Plugins.registerComponents('Library',
      (wx.lib.filebrowsebutton.FileBrowseButton, 'wx.lib.filebrowsebutton.FileBrowseButton', FileBrowseButtonDTC),
      (wx.lib.filebrowsebutton.FileBrowseButtonWithHistory, 'wx.lib.filebrowsebutton.FileBrowseButtonWithHistory', FileBrowseButtonWithHistoryDTC),
      (wx.lib.filebrowsebutton.DirBrowseButton, 'wx.lib.filebrowsebutton.DirBrowseButton', DirBrowseButtonDTC))
except ImportError: pass

try:
    import wx.lib.throbber
    Plugins.registerComponent('Library', wx.lib.throbber.Throbber, 'wx.lib.throbber.Throbber', ThrobberDTC)
except ImportError: pass

try:
    import wx.lib.ticker
    Plugins.registerComponent('Library', wx.lib.ticker.Ticker, 'wx.lib.ticker.Ticker', TickerDTC)
except ImportError: pass


EventCollections.EventCategories['MaskedNumCtrlEvent'] = ('wx.lib.masked.numctrl.EVT_NUM',)
EventCollections.commandCategories.append('MaskedNumCtrlEvent')
EventCollections.EventCategories['TimeCtrlEvent'] = ('wx.lib.masked.timectrl.EVT_TIMEUPDATE',)
EventCollections.commandCategories.append('TimeCtrlEvent')
EventCollections.EventCategories['IntCtrlEvent'] = ('wx.lib.intctrl.EVT_INT',)
EventCollections.commandCategories.append('IntCtrlEvent')
Back to Top