2003-11-12 16:34:20 -05:00
|
|
|
#----------------------------------------------------------------------------
|
2004-04-19 19:24:37 -04:00
|
|
|
# Name: wxPython.lib.masked.ctrl.py
|
2003-11-12 16:34:20 -05:00
|
|
|
# Author: Will Sadkin
|
|
|
|
# Created: 09/24/2003
|
|
|
|
# Copyright: (c) 2003 by Will Sadkin
|
|
|
|
# RCS-ID: $Id$
|
|
|
|
# License: wxWindows license
|
|
|
|
#----------------------------------------------------------------------------
|
2003-12-16 19:34:40 -05:00
|
|
|
# 12/09/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
|
|
|
#
|
|
|
|
# o Updated for wx namespace (minor)
|
2004-04-19 19:24:37 -04:00
|
|
|
#
|
2003-12-22 14:09:54 -05:00
|
|
|
# 12/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
|
|
|
#
|
|
|
|
# o Removed wx prefix
|
2004-04-19 19:24:37 -04:00
|
|
|
#
|
2003-11-12 16:34:20 -05:00
|
|
|
|
2004-10-11 18:13:18 -04:00
|
|
|
"""
|
|
|
|
|
|
|
|
*masked.Ctrl* is actually a factory function for several types of
|
2003-11-12 16:34:20 -05:00
|
|
|
masked edit controls:
|
2004-10-11 18:13:18 -04:00
|
|
|
|
|
|
|
================= =========================================================
|
|
|
|
masked.TextCtrl standard masked edit text box
|
|
|
|
masked.ComboBox adds combobox capabilities
|
|
|
|
masked.IpAddrCtrl adds logical input semantics for IP address entry
|
|
|
|
masked.TimeCtrl special subclass handling lots of time formats as values
|
|
|
|
masked.NumCtrl special subclass handling numeric values
|
|
|
|
================= =========================================================
|
|
|
|
|
|
|
|
masked.Ctrl works by looking for a special *controlType*
|
2003-11-12 16:34:20 -05:00
|
|
|
parameter in the variable arguments of the control, to determine
|
|
|
|
what kind of instance to return.
|
2004-10-11 18:13:18 -04:00
|
|
|
controlType can be one of::
|
|
|
|
|
2004-04-19 19:24:37 -04:00
|
|
|
controlTypes.TEXT
|
|
|
|
controlTypes.COMBO
|
2003-11-12 16:34:20 -05:00
|
|
|
controlTypes.IPADDR
|
|
|
|
controlTypes.TIME
|
|
|
|
controlTypes.NUMBER
|
2004-10-11 18:13:18 -04:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
These constants are also available individually, ie, you can
|
2004-10-11 18:13:18 -04:00
|
|
|
use either of the following::
|
|
|
|
|
2004-04-19 19:24:37 -04:00
|
|
|
from wxPython.wx.lib.masked import Ctrl, COMBO, TEXT, NUMBER, TIME
|
|
|
|
from wxPython.wx.lib.masked import Ctrl, controlTypes
|
2004-10-11 18:13:18 -04:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
If not specified as a keyword argument, the default controlType is
|
2004-04-19 19:24:37 -04:00
|
|
|
controlTypes.TEXT.
|
2004-10-11 18:13:18 -04:00
|
|
|
|
|
|
|
Each of the above classes has its own unique arguments, but Masked.Ctrl
|
|
|
|
provides a single "unified" interface for masked controls.
|
|
|
|
|
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
"""
|
|
|
|
|
2004-04-19 19:24:37 -04:00
|
|
|
from wx.lib.masked import TextCtrl, ComboBox, IpAddrCtrl
|
|
|
|
from wx.lib.masked import NumCtrl
|
|
|
|
from wx.lib.masked import TimeCtrl
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
|
|
|
|
# "type" enumeration for class instance factory function
|
2004-04-19 19:24:37 -04:00
|
|
|
TEXT = 0
|
|
|
|
COMBO = 1
|
2003-11-12 16:34:20 -05:00
|
|
|
IPADDR = 2
|
|
|
|
TIME = 3
|
|
|
|
NUMBER = 4
|
|
|
|
|
|
|
|
# for ease of import
|
|
|
|
class controlTypes:
|
2004-04-19 19:24:37 -04:00
|
|
|
TEXT = TEXT
|
|
|
|
COMBO = COMBO
|
2003-11-12 16:34:20 -05:00
|
|
|
IPADDR = IPADDR
|
|
|
|
TIME = TIME
|
|
|
|
NUMBER = NUMBER
|
|
|
|
|
|
|
|
|
2004-04-19 19:24:37 -04:00
|
|
|
def Ctrl( *args, **kwargs):
|
2003-11-12 16:34:20 -05:00
|
|
|
"""
|
|
|
|
Actually a factory function providing a unifying
|
|
|
|
interface for generating masked controls.
|
|
|
|
"""
|
|
|
|
if not kwargs.has_key('controlType'):
|
2004-04-19 19:24:37 -04:00
|
|
|
controlType = TEXT
|
2003-11-12 16:34:20 -05:00
|
|
|
else:
|
|
|
|
controlType = kwargs['controlType']
|
|
|
|
del kwargs['controlType']
|
|
|
|
|
2004-04-19 19:24:37 -04:00
|
|
|
if controlType == TEXT:
|
|
|
|
return TextCtrl(*args, **kwargs)
|
2003-11-12 16:34:20 -05:00
|
|
|
|
2004-04-19 19:24:37 -04:00
|
|
|
elif controlType == COMBO:
|
|
|
|
return ComboBox(*args, **kwargs)
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
elif controlType == IPADDR:
|
2003-12-22 14:09:54 -05:00
|
|
|
return IpAddrCtrl(*args, **kwargs)
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
elif controlType == TIME:
|
2003-12-22 14:09:54 -05:00
|
|
|
return TimeCtrl(*args, **kwargs)
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
elif controlType == NUMBER:
|
2004-04-19 19:24:37 -04:00
|
|
|
return NumCtrl(*args, **kwargs)
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
else:
|
|
|
|
raise AttributeError(
|
|
|
|
"invalid controlType specified: %s" % repr(controlType))
|
2003-10-01 20:58:06 -04:00
|
|
|
|
|
|
|
|