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

« back to all changes in this revision

Viewing changes to Companions/MaskedEditFmtCodeDlg.py

  • Committer: Bazaar Package Importer
  • Author(s): Luca Falavigna
  • Date: 2008-04-29 16:05:23 UTC
  • mfrom: (3.1.6 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080429160523-24y12jcjem5m8z80
Tags: 0.6.1-4
* Urgency high to fix RC bugs.
* debian/control:
  - Move to XS-Python-Version: >= 2.4 (Closes: #476929, #477145).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#Boa:Dialog:MaskedEditFormatCodesDlg
2
 
 
3
 
import wx
4
 
from wx.lib.anchors import LayoutAnchors
5
 
 
6
 
formatCodes = [
7
 
 ('_', 'Allow spaces'),
8
 
 ('!', 'Force upper'),
9
 
 ('^', 'Force lower'),
10
 
 ('R', 'Right-align field(s)'),
11
 
 ('r', 'Right-insert in field(s) (implies R)'),
12
 
 ('<', 'Stay in field until explicit navigation out of it'),
13
 
 ('>', 'Allow insert/delete within partially filled fields'),
14
 
 (',', 'Allow comma to be typed as grouping character; auto-group/regroup digits in\ninteger fields (if result fits) when leaving such a field.'),
15
 
 ('-', 'Prepend and reserve leading space for sign to mask and allow signed values (negative #s shown in red by default)'),
16
 
 ('0', 'integer fields get leading zeros'),
17
 
 ('D', 'Date[/time] field'),
18
 
 ('T', 'Time field'),
19
 
 ('F', 'Auto-Fit: the control calulates its size from the length of the template mask'),
20
 
 ('V', 'Validate entered chars against ValidRegex, blocking invalid characters'),
21
 
 ('S', 'select entire field when navigating to new field'),
22
 
]
23
 
 
24
 
[wxID_MASKEDEDITFORMATCODESDLG, wxID_MASKEDEDITFORMATCODESDLGBTNCANCEL,
25
 
 wxID_MASKEDEDITFORMATCODESDLGBTNOK,
26
 
 wxID_MASKEDEDITFORMATCODESDLGCLBFORMATCODES,
27
 
 wxID_MASKEDEDITFORMATCODESDLGSTATICTEXT1,
28
 
 wxID_MASKEDEDITFORMATCODESDLGTCFORMATCODEPROPVAL,
29
 
] = [wx.NewId() for _init_ctrls in range(6)]
30
 
 
31
 
class MaskedEditFormatCodesDlg(wx.Dialog):
32
 
    def _init_ctrls(self, prnt):
33
 
        # generated method, don't edit
34
 
        wx.Dialog.__init__(self, id=wxID_MASKEDEDITFORMATCODESDLG,
35
 
              name='MaskedEditFormatCodesDlg', parent=prnt, pos=wx.Point(433,
36
 
              218), size=wx.Size(436, 399),
37
 
              style=wx.RESIZE_BORDER | wx.DEFAULT_DIALOG_STYLE,
38
 
              title='Masked Edit - Format Codes')
39
 
        self.SetClientSize(wx.Size(428, 372))
40
 
        self.SetAutoLayout(True)
41
 
        self.Center(wx.BOTH)
42
 
 
43
 
        self.clbFormatCodes =wx.CheckListBox(choices=[],
44
 
              id=wxID_MASKEDEDITFORMATCODESDLGCLBFORMATCODES,
45
 
              name='clbFormatCodes', parent=self, pos=wx.Point(8, 33),
46
 
              size=wx.Size(413, 258), style=wx.LB_HSCROLL | wx.LB_SINGLE)
47
 
        self.clbFormatCodes.SetConstraints(LayoutAnchors(self.clbFormatCodes,
48
 
              True, True, True, True))
49
 
        self.clbFormatCodes.Bind(wx.EVT_CHECKLISTBOX, self.OnClbformatcodesChecklistbox, id=wxID_MASKEDEDITFORMATCODESDLGCLBFORMATCODES)
50
 
 
51
 
        self.tcFormatCodePropVal =wx.TextCtrl(id=wxID_MASKEDEDITFORMATCODESDLGTCFORMATCODEPROPVAL,
52
 
              name='tcFormatCodePropVal', parent=self, pos=wx.Point(8, 299),
53
 
              size=wx.Size(413, 25), style=0, value=self.formatCode)
54
 
        self.tcFormatCodePropVal.SetConstraints(LayoutAnchors(self.tcFormatCodePropVal,
55
 
              True, False, True, True))
56
 
 
57
 
        self.btnOK =wx.Button(id=wx.ID_OK, label='OK', name='btnOK', parent=self,
58
 
              pos=wx.Point(261, 340), size=wx.Size(75, 23), style=0)
59
 
        self.btnOK.SetConstraints(LayoutAnchors(self.btnOK, False, False, True,
60
 
              True))
61
 
 
62
 
        self.btnCancel =wx.Button(id=wx.ID_CANCEL, label='Cancel',
63
 
              name='btnCancel', parent=self, pos=wx.Point(346, 340),
64
 
              size=wx.Size(75, 23), style=0)
65
 
        self.btnCancel.SetConstraints(LayoutAnchors(self.btnCancel, False,
66
 
              False, True, True))
67
 
 
68
 
        self.staticText1 =wx.StaticText(id=wxID_MASKEDEDITFORMATCODESDLGSTATICTEXT1,
69
 
              label='A string of formatting codes that modify behavior of the control.',
70
 
              name='staticText1', parent=self, pos=wx.Point(8, 5),
71
 
              size=wx.Size(409, 24), style=wx.NO_BORDER | wx.ST_NO_AUTORESIZE)
72
 
        self.staticText1.SetConstraints(LayoutAnchors(self.staticText1, True,
73
 
              True, True, False))
74
 
 
75
 
    def __init__(self, parent, formatCode=''):
76
 
        self.formatCode = ''
77
 
        self.formatCode = formatCode
78
 
 
79
 
        self._init_ctrls(parent)
80
 
 
81
 
        if wx.Platform == '__WXGTK__': fontSize = 13
82
 
        else:                         fontSize = 9
83
 
 
84
 
        self.clbFormatCodes.SetFont(wx.Font(fontSize, wx.MODERN, wx.NORMAL, wx.BOLD))
85
 
        self.tcFormatCodePropVal.SetFont(wx.Font(fontSize+1, wx.MODERN, wx.NORMAL, wx.BOLD))
86
 
 
87
 
        for fc, desc in formatCodes:
88
 
            fmtCode = fc
89
 
            if len(fmtCode) < 4:
90
 
                fmtCode = ' %s  '%fmtCode
91
 
 
92
 
            self.clbFormatCodes.Append('%s - %s'%(fmtCode, desc))
93
 
            if formatCode.find(fc) != -1:
94
 
                self.clbFormatCodes.Check(self.clbFormatCodes.GetCount()-1, True)
95
 
 
96
 
        self.rebuildFmtCodePropVal()
97
 
 
98
 
    def rebuildFmtCodePropVal(self):
99
 
        r = []
100
 
        for idx in range(self.clbFormatCodes.GetCount()):
101
 
            if self.clbFormatCodes.IsChecked(idx):
102
 
                r.append(formatCodes[idx][0])
103
 
 
104
 
        self.tcFormatCodePropVal.SetValue(''.join(r))
105
 
 
106
 
    def getFormatCode(self):
107
 
        return self.tcFormatCodePropVal.GetValue()
108
 
 
109
 
    def OnClbformatcodesChecklistbox(self, event):
110
 
        self.rebuildFmtCodePropVal()
111
 
 
112
 
 
113
 
 
114
 
if __name__ == '__main__':
115
 
    app =wx.PySimpleApp()
116
 
    wx.InitAllImageHandlers()
117
 
    dlg = MaskedEditFormatCodesDlg(None, 'F_,-')
118
 
    try:
119
 
        dlg.ShowModal()
120
 
    finally:
121
 
        dlg.Destroy()
122
 
    app.MainLoop()