Beispiel #1
0
 def __init__(self,
              parent,
              hours,
              minutes,
              seconds,
              readonly=False,
              negative_value=False,
              *args,
              **kwargs):
     # If the control is read only (meaning it could potentially have to
     # show negative values) or if the value is actually negative, allow
     # the minus sign in the mask. Otherwise only allow for numbers.
     mask = 'X{9}:##:##' if negative_value or readonly else '#{9}:##:##'
     hours = self.__hour_string(hours, negative_value)
     super(TimeDeltaCtrl,
           self).__init__(parent,
                          mask=mask,
                          formatcodes='FS',
                          fields=[
                              masked.Field(formatcodes='Rr',
                                           defaultValue=hours),
                              masked.Field(defaultValue='%02d' % minutes),
                              masked.Field(defaultValue='%02d' % seconds)
                          ],
                          *args,
                          **kwargs)
Beispiel #2
0
 def set_value(self, hours, minutes, seconds, negative_value=False):
     hours = self.__hour_string(hours, negative_value)
     self.SetCtrlParameters(formatcodes='FS',
                            fields=[
                                masked.Field(formatcodes='Rr',
                                             defaultValue=hours),
                                masked.Field(defaultValue='%02d' % minutes),
                                masked.Field(defaultValue='%02d' % seconds)
                            ])
     self.Refresh()
Beispiel #3
0
 def __init__(self,
              parent,
              timeDelta=defaultTimeDelta,
              readonly=False,
              *args,
              **kwargs):
     super(TimeDeltaEntry, self).__init__(parent, *args, **kwargs)
     hours, minutes, seconds = timeDelta.hoursMinutesSeconds()
     self._entry = widgets.masked.TextCtrl(
         self,
         mask='#{6}:##:##',
         formatcodes='FS',
         fields=[
             masked.Field(formatcodes='r', defaultValue='%6d' % hours),
             masked.Field(defaultValue='%02d' % minutes),
             masked.Field(defaultValue='%02d' % seconds)
         ])
     if readonly:
         self._entry.Disable()
     self.add(self._entry, flag=wx.EXPAND | wx.ALL, proportion=1)
     self.fit()
Beispiel #4
0
    def __init__(self, parent, log):
        self.log = log
        scroll.ScrolledPanel.__init__(self, parent, -1)
        self.sizer = wx.BoxSizer(wx.VERTICAL)

        labelMaskedCombos = wx.StaticText(
            self, -1, """\
These are some examples of masked.ComboBox:""")
        labelMaskedCombos.SetForegroundColour("Blue")

        label_statecode = wx.StaticText(
            self, -1, """\
A state selector; only
"legal" values can be
entered:""")
        statecode = masked.ComboBox(self,
                                    -1,
                                    masked.states[0],
                                    choices=masked.states,
                                    autoformat="USSTATE")

        label_statename = wx.StaticText(
            self, -1, """\
A state name selector,
with auto-select:""")

        # Create this one using factory function:
        statename = masked.Ctrl(self,
                                -1,
                                masked.state_names[0],
                                controlType=masked.controlTypes.COMBO,
                                choices=masked.state_names,
                                autoformat="USSTATENAME",
                                autoSelect=True)
        statename.SetCtrlParameters(formatcodes='F!V_')

        numerators = [str(i) for i in range(1, 4)]
        denominators = [
            string.ljust(str(i), 2) for i in [2, 3, 4, 5, 8, 16, 32, 64]
        ]
        fieldsDict = {
            0: masked.Field(choices=numerators, choiceRequired=False),
            1: masked.Field(choices=denominators, choiceRequired=True)
        }
        choices = []
        for n in numerators:
            for d in denominators:
                if n != d:
                    choices.append('%s/%s' % (n, d))

        label_fraction = wx.StaticText(
            self, -1, """\
A masked ComboBox for fraction selection.
Choices for each side of the fraction can
be selected with PageUp/Down:""")

        fraction = masked.Ctrl(self,
                               -1,
                               "",
                               controlType=masked.controlTypes.COMBO,
                               choices=choices,
                               choiceRequired=True,
                               mask="#/##",
                               formatcodes="F_",
                               validRegex="^\d\/\d\d?",
                               fields=fieldsDict)

        label_code = wx.StaticText(
            self, -1, """\
A masked ComboBox to validate
text from a list of numeric codes:""")

        choices = ["91", "136", "305", "4579"]
        code = masked.ComboBox(self,
                               -1,
                               choices[0],
                               choices=choices,
                               choiceRequired=True,
                               formatcodes="F_r",
                               mask="####")

        label_selector = wx.StaticText(
            self, -1, """\
Programmatically set
choice sets:""")
        self.list_selector = wx.ComboBox(self,
                                         -1,
                                         '',
                                         choices=['list1', 'list2', 'list3'])
        self.dynamicbox = masked.Ctrl(
            self,
            -1,
            '    ',
            controlType=masked.controlTypes.COMBO,
            mask='XXXX',
            formatcodes='F_',
            # these are to give dropdown some initial height,
            # as base control apparently only sets that size
            # during initial construction <sigh>:
            choices=['', '1', '2', '3', '4', '5'])

        self.dynamicbox.Clear(
        )  # get rid of initial choices used to size the dropdown

        labelIpAddrs = wx.StaticText(
            self, -1, """\
Here are some examples of IpAddrCtrl, a control derived from masked.TextCtrl:"""
        )
        labelIpAddrs.SetForegroundColour("Blue")

        label_ipaddr1 = wx.StaticText(self, -1, "An empty control:")
        ipaddr1 = masked.IpAddrCtrl(self, -1, style=wx.TE_PROCESS_TAB)

        label_ipaddr2 = wx.StaticText(self, -1, "A restricted mask:")
        ipaddr2 = masked.IpAddrCtrl(self, -1, mask=" 10.  1.109.###")

        label_ipaddr3 = wx.StaticText(
            self, -1, """\
A control with restricted legal values:
10. (1|2) . (129..255) . (0..255)""")
        ipaddr3 = masked.Ctrl(self,
                              -1,
                              controlType=masked.controlTypes.IPADDR,
                              mask=" 10.  #.###.###")
        ipaddr3.SetFieldParameters(
            0, validRegex="1|2",
            validRequired=False)  # requires entry to match or not allowed

        # This allows any value in penultimate field, but colors anything outside of the range invalid:
        ipaddr3.SetFieldParameters(1,
                                   validRange=(129, 255),
                                   validRequired=False)

        labelNumerics = wx.StaticText(
            self, -1, """\
Here are some useful configurations of a masked.TextCtrl for integer and floating point input that still treat
the control as a text control.  (For a true numeric control, check out the masked.NumCtrl class!)"""
        )
        labelNumerics.SetForegroundColour("Blue")

        label_intctrl1 = wx.StaticText(
            self, -1, """\
An integer entry control with
shifting insert enabled:""")
        self.intctrl1 = masked.TextCtrl(self,
                                        -1,
                                        name='intctrl',
                                        mask="#{9}",
                                        formatcodes='_-,F>')
        label_intctrl2 = wx.StaticText(
            self, -1, """\
     Right-insert integer entry:""")
        self.intctrl2 = masked.TextCtrl(self,
                                        -1,
                                        name='intctrl',
                                        mask="#{9}",
                                        formatcodes='_-,Fr')

        label_floatctrl = wx.StaticText(
            self, -1, """\
A floating point entry control
with right-insert for ordinal:""")
        self.floatctrl = masked.TextCtrl(self,
                                         -1,
                                         name='floatctrl',
                                         mask="#{9}.#{2}",
                                         formatcodes="F,_-R",
                                         useParensForNegatives=False)
        self.floatctrl.SetFieldParameters(
            0, formatcodes='r<', validRequired=True
        )  # right-insert, require explicit cursor movement to change fields
        self.floatctrl.SetFieldParameters(
            1, defaultValue='00')  # don't allow blank fraction

        label_numselect = wx.StaticText(
            self, -1, """\
<= Programmatically set the value
     of the float entry ctrl:""")
        numselect = wx.ComboBox(self,
                                -1,
                                choices=[
                                    '', '111', '222.22', '-3',
                                    '54321.666666666', '-1353.978', '1234567',
                                    '-1234567', '123456789', '-123456789.1',
                                    '1234567890.', '-1234567890.1'
                                ])

        parens_check = wx.CheckBox(
            self, -1, "Use () to indicate negatives in above controls")

        gridCombos = wx.FlexGridSizer(cols=4, vgap=10, hgap=10)
        gridCombos.Add(label_statecode, 0, wx.ALIGN_LEFT)
        gridCombos.Add(statecode, 0, wx.ALIGN_LEFT)
        gridCombos.Add(label_fraction, 0, wx.ALIGN_LEFT)
        gridCombos.Add(fraction, 0, wx.ALIGN_LEFT)
        gridCombos.Add(label_statename, 0, wx.ALIGN_LEFT)
        gridCombos.Add(statename, 0, wx.ALIGN_LEFT)
        gridCombos.Add(label_code, 0, wx.ALIGN_LEFT)
        gridCombos.Add(code, 0, wx.ALIGN_LEFT)
        gridCombos.Add(label_selector, 0, wx.ALIGN_LEFT)
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(self.list_selector, 0, wx.ALIGN_LEFT)
        hbox.Add(wx.StaticText(self, -1, ' => '), 0, wx.ALIGN_LEFT)
        hbox.Add(self.dynamicbox, 0, wx.ALIGN_LEFT)
        gridCombos.Add(hbox, 0, wx.ALIGN_LEFT)

        gridIpAddrs = wx.FlexGridSizer(cols=4, vgap=10, hgap=15)
        gridIpAddrs.Add(label_ipaddr1, 0, wx.ALIGN_LEFT)
        gridIpAddrs.Add(ipaddr1, 0, wx.ALIGN_LEFT)
        gridIpAddrs.Add(label_ipaddr2, 0, wx.ALIGN_LEFT)
        gridIpAddrs.Add(ipaddr2, 0, wx.ALIGN_LEFT)
        gridIpAddrs.Add(label_ipaddr3, 0, wx.ALIGN_LEFT)
        gridIpAddrs.Add(ipaddr3, 0, wx.ALIGN_LEFT)

        gridNumerics = wx.FlexGridSizer(cols=4, vgap=10, hgap=10)
        gridNumerics.Add(label_intctrl1, 0, wx.ALIGN_LEFT)
        gridNumerics.Add(self.intctrl1, 0, wx.ALIGN_LEFT)
        gridNumerics.Add(label_intctrl2, 0, wx.ALIGN_RIGHT)
        gridNumerics.Add(self.intctrl2, 0, wx.ALIGN_LEFT)
        gridNumerics.Add(label_floatctrl, 0, wx.ALIGN_LEFT)
        gridNumerics.Add(self.floatctrl, 0, wx.ALIGN_LEFT)
        gridNumerics.Add(label_numselect, 0, wx.ALIGN_RIGHT)
        gridNumerics.Add(numselect, 0, wx.ALIGN_LEFT)

        self.sizer.Add(labelMaskedCombos, 0, wx.ALIGN_LEFT | wx.ALL, 5)
        self.sizer.Add(gridCombos, 0, wx.ALIGN_LEFT | wx.ALL, border=5)
        self.sizer.Add(wx.StaticLine(self, -1),
                       0,
                       wx.EXPAND | wx.TOP | wx.BOTTOM,
                       border=8)
        self.sizer.Add(labelIpAddrs, 0, wx.ALIGN_LEFT | wx.ALL, 5)
        self.sizer.Add(gridIpAddrs, 0, wx.ALIGN_LEFT | wx.ALL, border=5)
        self.sizer.Add(wx.StaticLine(self, -1),
                       0,
                       wx.EXPAND | wx.TOP | wx.BOTTOM,
                       border=8)
        self.sizer.Add(labelNumerics, 0, wx.ALIGN_LEFT | wx.ALL, 5)
        self.sizer.Add(gridNumerics, 0, wx.ALIGN_LEFT | wx.ALL, border=5)
        self.sizer.Add(parens_check, 0, wx.ALIGN_LEFT | wx.ALL, 5)

        self.SetSizer(self.sizer)
        self.SetAutoLayout(1)
        self.SetupScrolling()

        self.Bind(wx.EVT_COMBOBOX, self.OnComboSelection, id=fraction.GetId())
        self.Bind(wx.EVT_COMBOBOX, self.OnComboSelection, id=code.GetId())
        self.Bind(wx.EVT_COMBOBOX, self.OnComboSelection, id=statecode.GetId())
        self.Bind(wx.EVT_COMBOBOX, self.OnComboSelection, id=statename.GetId())
        self.Bind(wx.EVT_TEXT, self.OnTextChange, id=code.GetId())
        self.Bind(wx.EVT_TEXT, self.OnTextChange, id=statecode.GetId())
        self.Bind(wx.EVT_TEXT, self.OnTextChange, id=statename.GetId())
        self.Bind(wx.EVT_COMBOBOX,
                  self.OnListSelection,
                  id=self.list_selector.GetId())

        self.Bind(wx.EVT_TEXT, self.OnTextChange, id=self.intctrl1.GetId())
        self.Bind(wx.EVT_TEXT, self.OnTextChange, id=self.intctrl2.GetId())
        self.Bind(wx.EVT_TEXT, self.OnTextChange, id=self.floatctrl.GetId())
        self.Bind(wx.EVT_COMBOBOX, self.OnNumberSelect, id=numselect.GetId())
        self.Bind(wx.EVT_CHECKBOX, self.OnParensCheck, id=parens_check.GetId())

        self.Bind(wx.EVT_TEXT, self.OnIpAddrChange, id=ipaddr1.GetId())
        self.Bind(wx.EVT_TEXT, self.OnIpAddrChange, id=ipaddr2.GetId())
        self.Bind(wx.EVT_TEXT, self.OnIpAddrChange, id=ipaddr3.GetId())
Beispiel #5
0
    def __init__(self, parent, log):
        self.log = log
        scroll.ScrolledPanel.__init__(self, parent, -1)
        self.sizer = wx.BoxSizer(wx.VERTICAL)

        label = wx.StaticText(
            self, -1, """\
These controls have field-specific choice lists and allow autocompletion.

Down arrow or Page Down in an uncompleted field with an auto-completable field will attempt
to auto-complete a field if it has a choice list.
Page Down and Shift-Down arrow will also auto-complete, or cycle through the complete list.
Page Up and Shift-Up arrow will similarly cycle backwards through the list.
""")

        label.SetForegroundColour("Blue")
        self.sizer.Add(label, 0, wx.ALIGN_LEFT | wx.ALL, 5)

        description = wx.StaticText(self, -1, "Description")
        autofmt = wx.StaticText(self, -1, "AutoFormat Code")
        fields = wx.StaticText(self, -1, "Field Objects")
        ctrl = wx.StaticText(self, -1, "Masked TextCtrl")

        description.SetFont(wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD))
        autofmt.SetFont(wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD))
        fields.SetFont(wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD))
        ctrl.SetFont(wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD))

        grid = wx.FlexGridSizer(cols=4, vgap=10, hgap=10)
        grid.Add(description, 0, wx.ALIGN_LEFT)
        grid.Add(autofmt, 0, wx.ALIGN_LEFT)
        grid.Add(fields, 0, wx.ALIGN_LEFT)
        grid.Add(ctrl, 0, wx.ALIGN_LEFT)

        autoformat = "USPHONEFULLEXT"
        fieldsDict = {
            0:
            masked.Field(choices=["617", "781", "508", "978", "413"],
                         choiceRequired=True)
        }
        fieldsLabel = """\
{0: Field(choices=[
            "617","781",
            "508","978","413"],
          choiceRequired=True)}"""
        grid.Add(wx.StaticText(self, -1, "Restricted Area Code"), 0,
                 wx.ALIGN_LEFT)
        grid.Add(wx.StaticText(self, -1, autoformat), 0, wx.ALIGN_LEFT)
        grid.Add(wx.StaticText(self, -1, fieldsLabel), 0, wx.ALIGN_LEFT)
        grid.Add(
            masked.TextCtrl(self,
                            -1,
                            "",
                            autoformat=autoformat,
                            fields=fieldsDict,
                            demo=True,
                            name=autoformat), 0, wx.ALIGN_LEFT)

        autoformat = "EXPDATEMMYY"
        fieldsDict = {
            1: masked.Field(choices=["03", "04", "05"], choiceRequired=True)
        }
        fieldsLabel = """\
{1: Field(choices=[
            "03", "04", "05"],
          choiceRequired=True)}"""
        exp = masked.TextCtrl(self,
                              -1,
                              "",
                              autoformat=autoformat,
                              fields=fieldsDict,
                              demo=True,
                              name=autoformat)

        grid.Add(wx.StaticText(self, -1, "Restricted Expiration"), 0,
                 wx.ALIGN_LEFT)
        grid.Add(wx.StaticText(self, -1, autoformat), 0, wx.ALIGN_LEFT)
        grid.Add(wx.StaticText(self, -1, fieldsLabel), 0, wx.ALIGN_LEFT)
        grid.Add(exp, 0, wx.ALIGN_LEFT)

        fieldsDict = {
            0: masked.Field(choices=["02134", "02155"], choiceRequired=True),
            1: masked.Field(choices=["1234", "5678"], choiceRequired=False)
        }
        fieldsLabel = """\
{0: Field(choices=["02134","02155"],
          choiceRequired=True),
 1: Field(choices=["1234", "5678"],
          choiceRequired=False)}"""
        autoformat = "USZIPPLUS4"
        zip = masked.TextCtrl(self,
                              -1,
                              "",
                              autoformat=autoformat,
                              fields=fieldsDict,
                              demo=True,
                              name=autoformat)

        grid.Add(wx.StaticText(self, -1, "Restricted Zip + 4"), 0,
                 wx.ALIGN_LEFT)
        grid.Add(wx.StaticText(self, -1, autoformat), 0, wx.ALIGN_LEFT)
        grid.Add(wx.StaticText(self, -1, fieldsLabel), 0, wx.ALIGN_LEFT)
        grid.Add(zip, 0, wx.ALIGN_LEFT)

        self.sizer.Add(grid, 0, wx.ALIGN_LEFT | wx.ALL, border=5)
        self.SetSizer(self.sizer)
        self.SetAutoLayout(1)
        self.SetupScrolling()