⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 maskednumctrl.py

📁 用wxPython编写GUI程序的样例代码
💻 PY
📖 第 1 页 / 共 2 页
字号:
            self.target_ctl.SetParameters( integerWidth = width)
            # Now resize and fit the dialog as appropriate:
            self.grid2.SetItemMinSize(self.target_ctl, self.target_ctl.GetSize())
            self.outer_box.Fit( self.panel )
            self.outer_box.SetSizeHints( self.panel )


    def OnSetFractionWidth(self, event ):
        width = self.fractionwidth.GetValue()
        self.log.write("setting fraction width to %d\n" % width)
        self.target_ctl.SetParameters( fractionWidth = width)
        # Now resize and fit the dialog as appropriate:
        self.grid2.SetItemMinSize(self.target_ctl, self.target_ctl.GetSize())
        self.outer_box.Fit( self.panel )
        self.outer_box.SetSizeHints( self.panel )


    def OnSetGroupChar( self, event ):
        char = self.groupchar.GetValue()
        if self.target_ctl.GetDecimalChar() == char:
            self.log.write("group and decimal chars must be different\n")
            self.groupchar.SetForegroundColour(wx.RED)
        else:
            self.groupchar.SetForegroundColour(wx.BLACK)
            self.log.write("setting group char to %s\n" % char)
            self.target_ctl.SetGroupChar( char )

    def OnSetDecimalChar( self, event ):
        char = self.decimalchar.GetValue()
        if self.target_ctl.GetGroupChar() == char:
            self.log.write("group and decimal chars must be different\n")
            self.decimalchar.SetForegroundColour(wx.RED)
        else:
            self.decimalchar.SetForegroundColour(wx.BLACK)
            self.log.write("setting decimal char to %s\n" % char)
            self.target_ctl.SetDecimalChar( char )


    def OnSetMin( self, event ):
        self.min.Enable( self.set_min.GetValue() )
        self.SetTargetMinMax()

    def OnSetMax( self, event ):
        self.max.Enable( self.set_max.GetValue() )
        self.SetTargetMinMax()


    def OnSetLimited( self, event ):
        limited = self.limit_target.GetValue()
        self.target_ctl.SetLimited( limited )
        limit_on_field_change = self.limit_on_field_change.GetValue()
        if limited and limit_on_field_change:
            self.limit_on_field_change.SetValue(False)
            self.target_ctl.SetLimitOnFieldChange( False )
        self.SetTargetMinMax()


    def OnSetLimitOnFieldChange( self, event ):
        limit_on_field_change = self.limit_on_field_change.GetValue()
        self.target_ctl.SetLimitOnFieldChange( limit_on_field_change )
        limited = self.limit_target.GetValue()
        if limited and limit_on_field_change:
            self.limit_target.SetValue(False)
            self.target_ctl.SetLimited( False )

    def SetTargetMinMax( self, event=None ):
        min = max = None
        if self.set_min.GetValue():
            min = self.min.GetValue()
        if self.set_max.GetValue():
            max = self.max.GetValue()

        cur_min, cur_max = self.target_ctl.GetBounds()

        if min != cur_min and not self.target_ctl.SetMin( min ):
            if self.target_ctl.GetMax() is None and cur_max > min:
                self.log.write( "min (%d) won't fit in control -- bound not set\n" % min )
            else:
                self.log.write( "min (%d) > current max (%d) -- bound not set\n" % ( min, self.target_ctl.GetMax() ) )
            self.min.SetParameters( signedForegroundColour=wx.RED, foregroundColour=wx.RED )
        else:
            self.min.SetParameters( signedForegroundColour=wx.BLACK, foregroundColour=wx.BLACK )
        self.min.Refresh()

        if max != cur_max and not self.target_ctl.SetMax( max ):
            if self.target_ctl.GetMax() is None and cur_min < max:
                self.log.write( "max (%d) won't fit in control -- bound not set\n" % max )
            else:
                self.log.write( "max (%d) < current min (%d) -- bound not set\n" % ( max, self.target_ctl.GetMin() ) )
            self.max.SetParameters( signedForegroundColour=wx.RED, foregroundColour=wx.RED )
        else:
            self.max.SetParameters( signedForegroundColour=wx.BLACK, foregroundColour=wx.BLACK )
        self.max.Refresh()

        if min != cur_min or max != cur_max:
            new_min, new_max = self.target_ctl.GetBounds()
            self.log.write( "current min, max:  (%s, %s)\n" % ( str(new_min), str(new_max) ) )


    def OnSetAllowNone( self, event ):
        self.target_ctl.SetAllowNone( self.allow_none.GetValue() )


    def OnSetGroupDigits( self, event ):
        self.target_ctl.SetGroupDigits( self.group_digits.GetValue() )
        # Now resize and fit the dialog as appropriate:
        self.grid2.SetItemMinSize(self.target_ctl, self.target_ctl.GetSize())
        self.outer_box.Fit( self.panel )
        self.outer_box.SetSizeHints( self.panel )


    def OnSetAllowNegative( self, event ):
        if self.allow_negative.GetValue():
            self.use_parens.Enable(True)
            self.target_ctl.SetParameters(allowNegative=True,
                                          useParensForNegatives = self.use_parens.GetValue())
        else:
            self.target_ctl.SetAllowNegative(False)
        # Now resize and fit the dialog as appropriate:
        self.grid2.SetItemMinSize(self.target_ctl, self.target_ctl.GetSize())
        self.outer_box.Fit( self.panel )
        self.outer_box.SetSizeHints( self.panel )


    def OnSetUseParens( self, event ):
        self.target_ctl.SetUseParensForNegatives( self.use_parens.GetValue() )
        # Now resize and fit the dialog as appropriate:
        self.grid2.SetItemMinSize(self.target_ctl, self.target_ctl.GetSize())
        self.outer_box.Fit( self.panel )
        self.outer_box.SetSizeHints( self.panel )


    def OnSetSelectOnEntry( self, event ):
        self.target_ctl.SetSelectOnEntry( self.select_on_entry.GetValue() )


    def OnTargetChange( self, event ):
        ctl = event.GetEventObject()
        value = ctl.GetValue()
        ib_str = [ "  (out of bounds)", "" ]
        self.log.write( "value = %s (%s)%s\n" % ( repr(value), repr(type(value)), ib_str[ ctl.IsInBounds(value) ] ) )


    def OnNumberSelect( self, event ):
        value = event.GetString()
        if value:
            if value.find('.') != -1:
                numvalue = float(value)
            else:
                numvalue = long(value)
        else:
            numvalue = value   # try to clear the value again

        try:
            self.target_ctl.SetValue(numvalue)
        except:
            type, value, tb = sys.exc_info()
            for line in traceback.format_exception_only(type, value):
                self.log.write(line)


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

def runTest( frame, nb, log ):
    win = TestPanel( nb, log )
    return win

#----------------------------------------------------------------------
import wx.lib.masked.numctrl as mnum
overview = """<html>
<PRE><FONT SIZE=-1>
""" + mnum.__doc__ + """
</FONT></PRE>"""

if __name__ == '__main__':
    import sys,os
    import run
    run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -