mirror of
https://github.com/wxWidgets/wxWidgets.git
synced 2026-09-20 12:59:31 +08:00
MaskedEdit updates from Will Sadkin:
- Added '*' mask char that means "all ansii chars" (ords 32-255)
- Added proper unicode support to masked controls and wx.tools.dbg
- Fixed two reported missing import bugs introduced by package
creation
- Converted masked package doc strings to reST format for better
epydoc support
- lots of doc string improvements and function hiding to better
reflect package's public contents.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29787 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -324,7 +324,10 @@ def runTest( frame, nb, log ):
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
import wx.lib.masked.numctrl as mnum
|
||||
overview = mnum.__doc__
|
||||
overview = """<html>
|
||||
<PRE><FONT SIZE=-1>
|
||||
""" + mnum.__doc__ + """
|
||||
</FONT></PRE>"""
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys,os
|
||||
|
||||
@@ -21,11 +21,12 @@ class TestPanel( scrolled.ScrolledPanel ):
|
||||
|
||||
text1 = wx.StaticText( self, -1, "12-hour format:")
|
||||
self.time12 = masked.TimeCtrl( self, -1, name="12 hour control" )
|
||||
spin1 = wx.SpinButton( self, -1, wx.DefaultPosition, (-1,20), 0 )
|
||||
h = self.time12.GetSize().height
|
||||
spin1 = wx.SpinButton( self, -1, wx.DefaultPosition, (-1,h), wx.SP_VERTICAL )
|
||||
self.time12.BindSpinButton( spin1 )
|
||||
|
||||
text2 = wx.StaticText( self, -1, "24-hour format:")
|
||||
spin2 = wx.SpinButton( self, -1, wx.DefaultPosition, (-1,20), 0 )
|
||||
spin2 = wx.SpinButton( self, -1, wx.DefaultPosition, (-1,h), wx.SP_VERTICAL )
|
||||
self.time24 = masked.TimeCtrl(
|
||||
self, -1, name="24 hour control", fmt24hr=True,
|
||||
spinButton = spin2
|
||||
@@ -226,7 +227,10 @@ def runTest( frame, nb, log ):
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
import wx.lib.masked.timectrl as timectl
|
||||
overview = timectl.__doc__
|
||||
overview = """<html>
|
||||
<PRE><FONT SIZE=-1>
|
||||
""" + timectl.__doc__ + """
|
||||
</FONT></PRE>"""
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys,os
|
||||
|
||||
@@ -147,6 +147,24 @@ holding down the mouse button.
|
||||
wxGTK: Enable key based navigation through notebook tabs as in the
|
||||
native control with Left and right keys. Support for vetoing.
|
||||
|
||||
FloatCanvas updates from Chris Barker
|
||||
|
||||
PyPlot updates from Gordon Williams:
|
||||
- Added bar graph demo
|
||||
- Modified line end shape from round to square.
|
||||
- Removed FloatDCWrapper for conversion to ints and ints in arguments
|
||||
|
||||
|
||||
MaskedEdit updates from Will Sadkin:
|
||||
- Added '*' mask char that means "all ansii chars" (ords 32-255)
|
||||
- Added proper unicode support to masked controls and wx.tools.dbg
|
||||
- Fixed two reported missing import bugs introduced by package
|
||||
creation
|
||||
- Converted masked package doc strings to reST format for better
|
||||
epydoc support
|
||||
- lots of doc string improvements and function hiding to better
|
||||
reflect package's public contents.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -13,19 +13,29 @@
|
||||
#
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
import wx
|
||||
"""
|
||||
Provides masked edit capabilities within a ComboBox format, as well as
|
||||
a base class from which you can derive masked comboboxes tailored to a specific
|
||||
function. See maskededit module overview for how to configure the control.
|
||||
"""
|
||||
|
||||
import wx, types, string
|
||||
from wx.lib.masked import *
|
||||
|
||||
# jmg 12/9/03 - when we cut ties with Py 2.2 and earlier, this would
|
||||
# be a good place to implement the 2.3 logger class
|
||||
from wx.tools.dbg import Logger
|
||||
dbg = Logger()
|
||||
##dbg = Logger()
|
||||
##dbg(enable=0)
|
||||
|
||||
## ---------- ---------- ---------- ---------- ---------- ---------- ----------
|
||||
## Because calling SetSelection programmatically does not fire EVT_COMBOBOX
|
||||
## events, we have to do it ourselves when we auto-complete.
|
||||
class MaskedComboBoxSelectEvent(wx.PyCommandEvent):
|
||||
"""
|
||||
Because calling SetSelection programmatically does not fire EVT_COMBOBOX
|
||||
events, the derived control has to do it itself when it auto-completes.
|
||||
"""
|
||||
def __init__(self, id, selection = 0, object=None):
|
||||
wx.PyCommandEvent.__init__(self, wx.wxEVT_COMMAND_COMBOBOX_SELECTED, id)
|
||||
|
||||
@@ -40,8 +50,9 @@ class MaskedComboBoxSelectEvent(wx.PyCommandEvent):
|
||||
|
||||
class BaseMaskedComboBox( wx.ComboBox, MaskedEditMixin ):
|
||||
"""
|
||||
This masked edit control adds the ability to use a masked input
|
||||
on a combobox, and do auto-complete of such values.
|
||||
Base class for generic masked edit comboboxes; allows auto-complete of values.
|
||||
It is not meant to be instantiated directly, but rather serves as a base class
|
||||
for any subsequent refinements.
|
||||
"""
|
||||
def __init__( self, parent, id=-1, value = '',
|
||||
pos = wx.DefaultPosition,
|
||||
@@ -138,8 +149,8 @@ class BaseMaskedComboBox( wx.ComboBox, MaskedEditMixin ):
|
||||
self._SetInitialValue(value)
|
||||
|
||||
|
||||
self._SetKeycodeHandler(wx.WXK_UP, self.OnSelectChoice)
|
||||
self._SetKeycodeHandler(wx.WXK_DOWN, self.OnSelectChoice)
|
||||
self._SetKeycodeHandler(wx.WXK_UP, self._OnSelectChoice)
|
||||
self._SetKeycodeHandler(wx.WXK_DOWN, self._OnSelectChoice)
|
||||
|
||||
if setupEventHandling:
|
||||
## Setup event handlers
|
||||
@@ -148,7 +159,7 @@ class BaseMaskedComboBox( wx.ComboBox, MaskedEditMixin ):
|
||||
self.Bind(wx.EVT_LEFT_DCLICK, self._OnDoubleClick) ## select field under cursor on dclick
|
||||
self.Bind(wx.EVT_RIGHT_UP, self._OnContextMenu ) ## bring up an appropriate context menu
|
||||
self.Bind(wx.EVT_CHAR, self._OnChar ) ## handle each keypress
|
||||
self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown ) ## for special processing of up/down keys
|
||||
self.Bind(wx.EVT_KEY_DOWN, self._OnKeyDownInComboBox ) ## for special processing of up/down keys
|
||||
self.Bind(wx.EVT_KEY_DOWN, self._OnKeyDown ) ## for processing the rest of the control keys
|
||||
## (next in evt chain)
|
||||
self.Bind(wx.EVT_TEXT, self._OnTextChange ) ## color control appropriately & keep
|
||||
@@ -173,11 +184,11 @@ class BaseMaskedComboBox( wx.ComboBox, MaskedEditMixin ):
|
||||
""" Set the font, then recalculate control size, if appropriate. """
|
||||
wx.ComboBox.SetFont(self, *args, **kwargs)
|
||||
if self._autofit:
|
||||
dbg('calculated size:', self._CalcSize())
|
||||
## dbg('calculated size:', self._CalcSize())
|
||||
self.SetClientSize(self._CalcSize())
|
||||
width = self.GetSize().width
|
||||
height = self.GetBestSize().height
|
||||
dbg('setting client size to:', (width, height))
|
||||
## dbg('setting client size to:', (width, height))
|
||||
self.SetBestFittingSize((width, height))
|
||||
|
||||
|
||||
@@ -355,11 +366,11 @@ class BaseMaskedComboBox( wx.ComboBox, MaskedEditMixin ):
|
||||
|
||||
def Append( self, choice, clientData=None ):
|
||||
"""
|
||||
This function override is necessary so we can keep track of any additions to the list
|
||||
of choices, because wxComboBox doesn't have an accessor for the choice list.
|
||||
The code here is the same as in the SetParameters() mixin function, but is
|
||||
done for the individual value as appended, so the list can be built incrementally
|
||||
without speed penalty.
|
||||
This base control function override is necessary so the control can keep track
|
||||
of any additions to the list of choices, because wx.ComboBox doesn't have an
|
||||
accessor for the choice list. The code here is the same as in the
|
||||
SetParameters() mixin function, but is done for the individual value
|
||||
as appended, so the list can be built incrementally without speed penalty.
|
||||
"""
|
||||
if self._mask:
|
||||
if type(choice) not in (types.StringType, types.UnicodeType):
|
||||
@@ -408,8 +419,9 @@ class BaseMaskedComboBox( wx.ComboBox, MaskedEditMixin ):
|
||||
|
||||
def Clear( self ):
|
||||
"""
|
||||
This function override is necessary so we can keep track of any additions to the list
|
||||
of choices, because wxComboBox doesn't have an accessor for the choice list.
|
||||
This base control function override is necessary so the derived control can
|
||||
keep track of any additions to the list of choices, because wx.ComboBox
|
||||
doesn't have an accessor for the choice list.
|
||||
"""
|
||||
if self._mask:
|
||||
self._choices = []
|
||||
@@ -421,8 +433,8 @@ class BaseMaskedComboBox( wx.ComboBox, MaskedEditMixin ):
|
||||
|
||||
def _OnCtrlParametersChanged(self):
|
||||
"""
|
||||
Override mixin's default OnCtrlParametersChanged to detect changes in choice list, so
|
||||
we can update the base control:
|
||||
This overrides the mixin's default OnCtrlParametersChanged to detect
|
||||
changes in choice list, so masked.Combobox can update the base control:
|
||||
"""
|
||||
if self.controlInitialized and self._choices != self._ctrl_constraints._choices:
|
||||
wx.ComboBox.Clear(self)
|
||||
@@ -433,7 +445,7 @@ class BaseMaskedComboBox( wx.ComboBox, MaskedEditMixin ):
|
||||
|
||||
def GetMark(self):
|
||||
"""
|
||||
This function is a hack to make up for the fact that wxComboBox has no
|
||||
This function is a hack to make up for the fact that wx.ComboBox has no
|
||||
method for returning the selected portion of its edit control. It
|
||||
works, but has the nasty side effect of generating lots of intermediate
|
||||
events.
|
||||
@@ -470,7 +482,7 @@ class BaseMaskedComboBox( wx.ComboBox, MaskedEditMixin ):
|
||||
|
||||
def SetSelection(self, index):
|
||||
"""
|
||||
Necessary for bookkeeping on choice selection, to keep current value
|
||||
Necessary override for bookkeeping on choice selection, to keep current value
|
||||
current.
|
||||
"""
|
||||
## dbg('MaskedComboBox::SetSelection(%d)' % index)
|
||||
@@ -481,7 +493,7 @@ class BaseMaskedComboBox( wx.ComboBox, MaskedEditMixin ):
|
||||
wx.ComboBox.SetSelection(self, index)
|
||||
|
||||
|
||||
def OnKeyDown(self, event):
|
||||
def _OnKeyDownInComboBox(self, event):
|
||||
"""
|
||||
This function is necessary because navigation and control key
|
||||
events do not seem to normally be seen by the wxComboBox's
|
||||
@@ -495,7 +507,7 @@ class BaseMaskedComboBox( wx.ComboBox, MaskedEditMixin ):
|
||||
event.Skip() # let mixin default KeyDown behavior occur
|
||||
|
||||
|
||||
def OnSelectChoice(self, event):
|
||||
def _OnSelectChoice(self, event):
|
||||
"""
|
||||
This function appears to be necessary, because the processing done
|
||||
on the text of the control somehow interferes with the combobox's
|
||||
@@ -569,13 +581,13 @@ class BaseMaskedComboBox( wx.ComboBox, MaskedEditMixin ):
|
||||
|
||||
def _OnReturn(self, event):
|
||||
"""
|
||||
For wxComboBox, it seems that if you hit return when the dropdown is
|
||||
For wx.ComboBox, it seems that if you hit return when the dropdown is
|
||||
dropped, the event that dismisses the dropdown will also blank the
|
||||
control, because of the implementation of wxComboBox. So here,
|
||||
we look and if the selection is -1, and the value according to
|
||||
(the base control!) is a value in the list, then we schedule a
|
||||
control, because of the implementation of wxComboBox. So this function
|
||||
examines the selection and if it is -1, and the value according to
|
||||
(the base control!) is a value in the list, then it schedules a
|
||||
programmatic wxComboBox.SetSelection() call to pick the appropriate
|
||||
item in the list. (and then do the usual OnReturn bit.)
|
||||
item in the list. (and then does the usual OnReturn bit.)
|
||||
"""
|
||||
## dbg('MaskedComboBox::OnReturn', indent=1)
|
||||
## dbg('current value: "%s"' % self.GetValue(), 'current index:', self.GetSelection())
|
||||
@@ -589,17 +601,20 @@ class BaseMaskedComboBox( wx.ComboBox, MaskedEditMixin ):
|
||||
|
||||
class ComboBox( BaseMaskedComboBox, MaskedEditAccessorsMixin ):
|
||||
"""
|
||||
This extra level of inheritance allows us to add the generic set of
|
||||
masked edit parameters only to this class while allowing other
|
||||
classes to derive from the "base" masked combobox control, and provide
|
||||
a smaller set of valid accessor functions.
|
||||
The "user-visible" masked combobox control, this class is
|
||||
identical to the BaseMaskedComboBox class it's derived from.
|
||||
(This extra level of inheritance allows us to add the generic
|
||||
set of masked edit parameters only to this class while allowing
|
||||
other classes to derive from the "base" masked combobox control,
|
||||
and provide a smaller set of valid accessor functions.)
|
||||
See BaseMaskedComboBox for available methods.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class PreMaskedComboBox( BaseMaskedComboBox, MaskedEditAccessorsMixin ):
|
||||
"""
|
||||
This allows us to use XRC subclassing.
|
||||
This class exists to support the use of XRC subclassing.
|
||||
"""
|
||||
# This should really be wx.EVT_WINDOW_CREATE but it is not
|
||||
# currently delivered for native controls on all platforms, so
|
||||
@@ -617,9 +632,14 @@ class PreMaskedComboBox( BaseMaskedComboBox, MaskedEditAccessorsMixin ):
|
||||
self.Unbind(self._firstEventType)
|
||||
self._PostInit()
|
||||
|
||||
i=0
|
||||
__i = 0
|
||||
## CHANGELOG:
|
||||
## ====================
|
||||
## Version 1.2
|
||||
## 1. Converted docstrings to reST format, added doc for ePyDoc.
|
||||
## 2. Renamed helper functions, vars etc. not intended to be visible in public
|
||||
## interface to code.
|
||||
##
|
||||
## Version 1.1
|
||||
## 1. Added .SetFont() method that properly resizes control
|
||||
## 2. Modified control to support construction via XRC mechanism.
|
||||
|
||||
@@ -15,44 +15,43 @@
|
||||
# o Removed wx prefix
|
||||
#
|
||||
|
||||
"""<html><body>
|
||||
<P>
|
||||
<B>masked.Ctrl</B> is actually a factory function for several types of
|
||||
"""
|
||||
|
||||
*masked.Ctrl* is actually a factory function for several types of
|
||||
masked edit controls:
|
||||
<P>
|
||||
<UL>
|
||||
<LI><b>masked.TextCtrl</b> - standard masked edit text box</LI>
|
||||
<LI><b>masked.ComboBox</b> - adds combobox capabilities</LI>
|
||||
<LI><b>masked.IpAddrCtrl</b> - adds logical input semantics for IP address entry</LI>
|
||||
<LI><b>masked.TimeCtrl</b> - special subclass handling lots of time formats as values</LI>
|
||||
<LI><b>masked.NumCtrl</b> - special subclass handling numeric values</LI>
|
||||
</UL>
|
||||
<P>
|
||||
<B>masked.Ctrl</B> works by looking for a special <b><i>controlType</i></b>
|
||||
|
||||
================= =========================================================
|
||||
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*
|
||||
parameter in the variable arguments of the control, to determine
|
||||
what kind of instance to return.
|
||||
controlType can be one of:
|
||||
<PRE><FONT SIZE=-1>
|
||||
controlType can be one of::
|
||||
|
||||
controlTypes.TEXT
|
||||
controlTypes.COMBO
|
||||
controlTypes.IPADDR
|
||||
controlTypes.TIME
|
||||
controlTypes.NUMBER
|
||||
</FONT></PRE>
|
||||
|
||||
These constants are also available individually, ie, you can
|
||||
use either of the following:
|
||||
<PRE><FONT SIZE=-1>
|
||||
use either of the following::
|
||||
|
||||
from wxPython.wx.lib.masked import Ctrl, COMBO, TEXT, NUMBER, TIME
|
||||
from wxPython.wx.lib.masked import Ctrl, controlTypes
|
||||
</FONT></PRE>
|
||||
|
||||
If not specified as a keyword argument, the default controlType is
|
||||
controlTypes.TEXT.
|
||||
<P>
|
||||
Each of the above classes has its own unique arguments, but MaskedCtrl
|
||||
provides a single "unified" interface for masked controls. Masked.TextCtrl,
|
||||
masked.ComboBox and masked.IpAddrCtrl are all documented below; the others have
|
||||
their own demo pages and interface descriptions.
|
||||
</body></html>
|
||||
|
||||
Each of the above classes has its own unique arguments, but Masked.Ctrl
|
||||
provides a single "unified" interface for masked controls.
|
||||
|
||||
|
||||
"""
|
||||
|
||||
from wx.lib.masked import TextCtrl, ComboBox, IpAddrCtrl
|
||||
|
||||
@@ -14,20 +14,27 @@
|
||||
# address with extra whitespace removed.
|
||||
#
|
||||
#----------------------------------------------------------------------------
|
||||
"""
|
||||
Provides a smart text input control that understands the structure and
|
||||
limits of IP Addresses, and allows automatic field navigation as the
|
||||
user hits '.' when typing.
|
||||
"""
|
||||
|
||||
import wx
|
||||
import wx, types, string
|
||||
from wx.lib.masked import BaseMaskedTextCtrl
|
||||
|
||||
# jmg 12/9/03 - when we cut ties with Py 2.2 and earlier, this would
|
||||
# be a good place to implement the 2.3 logger class
|
||||
from wx.tools.dbg import Logger
|
||||
dbg = Logger()
|
||||
##dbg = Logger()
|
||||
##dbg(enable=0)
|
||||
|
||||
class IpAddrCtrlAccessorsMixin:
|
||||
# Define IpAddrCtrl's list of attributes having their own
|
||||
# Get/Set functions, exposing only those that make sense for
|
||||
# an IP address control.
|
||||
"""
|
||||
Defines IpAddrCtrl's list of attributes having their own
|
||||
Get/Set functions, exposing only those that make sense for
|
||||
an IP address control.
|
||||
"""
|
||||
|
||||
exposed_basectrl_params = (
|
||||
'fields',
|
||||
@@ -116,6 +123,11 @@ class IpAddrCtrl( BaseMaskedTextCtrl, IpAddrCtrlAccessorsMixin ):
|
||||
|
||||
|
||||
def OnDot(self, event):
|
||||
"""
|
||||
Defines what action to take when the '.' character is typed in the
|
||||
control. By default, the current field is right-justified, and the
|
||||
cursor is placed in the next field.
|
||||
"""
|
||||
## dbg('IpAddrCtrl::OnDot', indent=1)
|
||||
pos = self._adjustPos(self._GetInsertionPoint(), event.GetKeyCode())
|
||||
oldvalue = self.GetValue()
|
||||
@@ -133,6 +145,9 @@ class IpAddrCtrl( BaseMaskedTextCtrl, IpAddrCtrlAccessorsMixin ):
|
||||
|
||||
|
||||
def GetAddress(self):
|
||||
"""
|
||||
Returns the control value, with any spaces removed.
|
||||
"""
|
||||
value = BaseMaskedTextCtrl.GetValue(self)
|
||||
return value.replace(' ','') # remove spaces from the value
|
||||
|
||||
@@ -144,6 +159,12 @@ class IpAddrCtrl( BaseMaskedTextCtrl, IpAddrCtrlAccessorsMixin ):
|
||||
return False
|
||||
|
||||
def SetValue(self, value):
|
||||
"""
|
||||
Takes a string value, validates it for a valid IP address,
|
||||
splits it into an array of 4 fields, justifies it
|
||||
appropriately, and inserts it into the control.
|
||||
Invalid values will raise a ValueError exception.
|
||||
"""
|
||||
## dbg('IpAddrCtrl::SetValue(%s)' % str(value), indent=1)
|
||||
if type(value) not in (types.StringType, types.UnicodeType):
|
||||
## dbg(indent=0)
|
||||
@@ -151,6 +172,7 @@ class IpAddrCtrl( BaseMaskedTextCtrl, IpAddrCtrlAccessorsMixin ):
|
||||
|
||||
bValid = True # assume True
|
||||
parts = value.split('.')
|
||||
|
||||
if len(parts) != 4:
|
||||
bValid = False
|
||||
else:
|
||||
@@ -184,6 +206,15 @@ class IpAddrCtrl( BaseMaskedTextCtrl, IpAddrCtrlAccessorsMixin ):
|
||||
BaseMaskedTextCtrl.SetValue(self, value)
|
||||
## dbg(indent=0)
|
||||
|
||||
i=0
|
||||
__i=0
|
||||
## CHANGELOG:
|
||||
## ====================
|
||||
## Version 1.2
|
||||
## 1. Fixed bugs involving missing imports now that these classes are in
|
||||
## their own module.
|
||||
## 2. Added doc strings for ePyDoc.
|
||||
## 3. Renamed helper functions, vars etc. not intended to be visible in public
|
||||
## interface to code.
|
||||
##
|
||||
## Version 1.1
|
||||
## Made ipaddrctrls allow right-insert in subfields, now that insert/cut/paste works better
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+310
-293
File diff suppressed because it is too large
Load Diff
@@ -15,51 +15,50 @@
|
||||
# masked.TimeCtrl, and masked.IpAddrCtrl.
|
||||
#
|
||||
#----------------------------------------------------------------------------
|
||||
"""
|
||||
Provides a generic, fully configurable masked edit text control, as well as
|
||||
a base class from which you can derive masked controls tailored to a specific
|
||||
function. See maskededit module overview for how to configure the control.
|
||||
"""
|
||||
|
||||
import wx
|
||||
from wx.lib.masked import *
|
||||
|
||||
# jmg 12/9/03 - when we cut ties with Py 2.2 and earlier, this would
|
||||
# be a good place to implement the 2.3 logger class
|
||||
from wx.tools.dbg import Logger
|
||||
dbg = Logger()
|
||||
##dbg = Logger()
|
||||
##dbg(enable=1)
|
||||
|
||||
# ## TRICKY BIT: to avoid a ton of boiler-plate, and to
|
||||
# ## automate the getter/setter generation for each valid
|
||||
# ## control parameter so we never forget to add the
|
||||
# ## functions when adding parameters, this loop
|
||||
# ## programmatically adds them to the class:
|
||||
# ## (This makes it easier for Designers like Boa to
|
||||
# ## deal with masked controls.)
|
||||
#
|
||||
# ## To further complicate matters, this is done with an
|
||||
# ## extra level of inheritance, so that "general" classes like
|
||||
# ## MaskedTextCtrl can have all possible attributes,
|
||||
# ## while derived classes, like TimeCtrl and MaskedNumCtrl
|
||||
# ## can prevent exposure of those optional attributes of their base
|
||||
# ## class that do not make sense for their derivation. Therefore,
|
||||
# ## we define
|
||||
# ## BaseMaskedTextCtrl(TextCtrl, MaskedEditMixin)
|
||||
# ## and
|
||||
# ## MaskedTextCtrl(BaseMaskedTextCtrl, MaskedEditAccessorsMixin).
|
||||
# ##
|
||||
# ## This allows us to then derive:
|
||||
# ## MaskedNumCtrl( BaseMaskedTextCtrl )
|
||||
# ##
|
||||
# ## and not have to expose all the same accessor functions for the
|
||||
# ## derived control when they don't all make sense for it.
|
||||
# ##
|
||||
|
||||
class BaseMaskedTextCtrl( wx.TextCtrl, MaskedEditMixin ):
|
||||
"""
|
||||
This is the primary derivation from MaskedEditMixin. It provides
|
||||
a general masked text control that can be configured with different
|
||||
masks. It's actually a "base masked textCtrl", so that the
|
||||
MaskedTextCtrl class can be derived from it, and add those
|
||||
accessor functions to it that are appropriate to the general class,
|
||||
whilst other classes can derive from BaseMaskedTextCtrl, and
|
||||
only define those accessor functions that are appropriate for
|
||||
those derivations.
|
||||
masks.
|
||||
|
||||
However, this is done with an extra level of inheritance, so that
|
||||
"general" classes like masked.TextCtrl can have all possible attributes,
|
||||
while derived classes, like masked.TimeCtrl and masked.NumCtrl
|
||||
can prevent exposure of those optional attributes of their base
|
||||
class that do not make sense for their derivation. Therefore,
|
||||
we define::
|
||||
|
||||
BaseMaskedTextCtrl(TextCtrl, MaskedEditMixin)
|
||||
|
||||
and::
|
||||
|
||||
masked.TextCtrl(BaseMaskedTextCtrl, MaskedEditAccessorsMixin).
|
||||
|
||||
This allows us to then derive::
|
||||
|
||||
masked.NumCtrl( BaseMaskedTextCtrl )
|
||||
|
||||
and not have to expose all the same accessor functions for the
|
||||
derived control when they don't all make sense for it.
|
||||
|
||||
In practice, BaseMaskedTextCtrl should never be instantiated directly,
|
||||
but should only be used in derived classes.
|
||||
"""
|
||||
|
||||
def __init__( self, parent, id=-1, value = '',
|
||||
@@ -119,12 +118,12 @@ class BaseMaskedTextCtrl( wx.TextCtrl, MaskedEditMixin ):
|
||||
#### dbg("MaskedTextCtrl::_SetSelection(%(sel_start)d, %(sel_to)d)" % locals())
|
||||
return self.SetSelection( sel_start, sel_to )
|
||||
|
||||
def SetSelection(self, sel_start, sel_to):
|
||||
"""
|
||||
This is just for debugging...
|
||||
"""
|
||||
## def SetSelection(self, sel_start, sel_to):
|
||||
## """
|
||||
## This is just for debugging...
|
||||
## """
|
||||
## dbg("MaskedTextCtrl::SetSelection(%(sel_start)d, %(sel_to)d)" % locals())
|
||||
wx.TextCtrl.SetSelection(self, sel_start, sel_to)
|
||||
## wx.TextCtrl.SetSelection(self, sel_start, sel_to)
|
||||
|
||||
|
||||
def _GetInsertionPoint(self):
|
||||
@@ -134,12 +133,12 @@ class BaseMaskedTextCtrl( wx.TextCtrl, MaskedEditMixin ):
|
||||
#### dbg("MaskedTextCtrl::_SetInsertionPoint(%(pos)d)" % locals())
|
||||
self.SetInsertionPoint(pos)
|
||||
|
||||
def SetInsertionPoint(self, pos):
|
||||
"""
|
||||
This is just for debugging...
|
||||
"""
|
||||
## def SetInsertionPoint(self, pos):
|
||||
## """
|
||||
## This is just for debugging...
|
||||
## """
|
||||
## dbg("MaskedTextCtrl::SetInsertionPoint(%(pos)d)" % locals())
|
||||
wx.TextCtrl.SetInsertionPoint(self, pos)
|
||||
## wx.TextCtrl.SetInsertionPoint(self, pos)
|
||||
|
||||
|
||||
def _GetValue(self):
|
||||
@@ -149,6 +148,7 @@ class BaseMaskedTextCtrl( wx.TextCtrl, MaskedEditMixin ):
|
||||
"""
|
||||
return self.GetValue()
|
||||
|
||||
|
||||
def _SetValue(self, value):
|
||||
"""
|
||||
Allow mixin to set the raw value of the control with this function.
|
||||
@@ -163,7 +163,7 @@ class BaseMaskedTextCtrl( wx.TextCtrl, MaskedEditMixin ):
|
||||
|
||||
def SetValue(self, value):
|
||||
"""
|
||||
This function redefines the externally accessible .SetValue to be
|
||||
This function redefines the externally accessible .SetValue() to be
|
||||
a smart "paste" of the text in question, so as not to corrupt the
|
||||
masked control. NOTE: this must be done in the class derived
|
||||
from the base wx control.
|
||||
@@ -226,6 +226,7 @@ class BaseMaskedTextCtrl( wx.TextCtrl, MaskedEditMixin ):
|
||||
wx.CallAfter(self._SetSelection, replace_to, replace_to)
|
||||
## dbg(indent=0)
|
||||
|
||||
|
||||
def SetFont(self, *args, **kwargs):
|
||||
""" Set the font, then recalculate control size, if appropriate. """
|
||||
wx.TextCtrl.SetFont(self, *args, **kwargs)
|
||||
@@ -316,10 +317,10 @@ class BaseMaskedTextCtrl( wx.TextCtrl, MaskedEditMixin ):
|
||||
|
||||
def IsModified(self):
|
||||
"""
|
||||
This function overrides the raw wxTextCtrl method, because the
|
||||
This function overrides the raw wx.TextCtrl method, because the
|
||||
masked edit mixin uses SetValue to change the value, which doesn't
|
||||
modify the state of this attribute. So, we keep track on each
|
||||
keystroke to see if the value changes, and if so, it's been
|
||||
modify the state of this attribute. So, the derived control keeps track
|
||||
on each keystroke to see if the value changes, and if so, it's been
|
||||
modified.
|
||||
"""
|
||||
return wx.TextCtrl.IsModified(self) or self.modified
|
||||
@@ -334,17 +335,20 @@ class BaseMaskedTextCtrl( wx.TextCtrl, MaskedEditMixin ):
|
||||
|
||||
class TextCtrl( BaseMaskedTextCtrl, MaskedEditAccessorsMixin ):
|
||||
"""
|
||||
This extra level of inheritance allows us to add the generic set of
|
||||
masked edit parameters only to this class while allowing other
|
||||
classes to derive from the "base" masked text control, and provide
|
||||
a smaller set of valid accessor functions.
|
||||
The "user-visible" masked text control; it is identical to the
|
||||
BaseMaskedTextCtrl class it's derived from.
|
||||
(This extra level of inheritance allows us to add the generic
|
||||
set of masked edit parameters only to this class while allowing
|
||||
other classes to derive from the "base" masked text control,
|
||||
and provide a smaller set of valid accessor functions.)
|
||||
See BaseMaskedTextCtrl for available methods.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class PreMaskedTextCtrl( BaseMaskedTextCtrl, MaskedEditAccessorsMixin ):
|
||||
"""
|
||||
This allows us to use XRC subclassing.
|
||||
This class exists to support the use of XRC subclassing.
|
||||
"""
|
||||
# This should really be wx.EVT_WINDOW_CREATE but it is not
|
||||
# currently delivered for native controls on all platforms, so
|
||||
@@ -362,9 +366,13 @@ class PreMaskedTextCtrl( BaseMaskedTextCtrl, MaskedEditAccessorsMixin ):
|
||||
self.Unbind(self._firstEventType)
|
||||
self._PostInit()
|
||||
|
||||
i=0
|
||||
__i=0
|
||||
## CHANGELOG:
|
||||
## ====================
|
||||
## Version 1.2
|
||||
## - Converted docstrings to reST format, added doc for ePyDoc.
|
||||
## removed debugging override functions.
|
||||
##
|
||||
## Version 1.1
|
||||
## 1. Added .SetFont() method that properly resizes control
|
||||
## 2. Modified control to support construction via XRC mechanism.
|
||||
|
||||
+235
-203
File diff suppressed because it is too large
Load Diff
@@ -147,8 +147,14 @@ class Logger:
|
||||
return
|
||||
|
||||
if self._dbg and len(args) and not self._suspend:
|
||||
# (emulate print functionality)
|
||||
strs = [str(arg) for arg in args]
|
||||
# (emulate print functionality; handle unicode as best as possible:)
|
||||
strs = []
|
||||
for arg in args:
|
||||
try:
|
||||
strs.append(str(arg))
|
||||
except:
|
||||
strs.append(repr(arg))
|
||||
|
||||
output = ' '.join(strs)
|
||||
if self.name: output = self.name+': ' + output
|
||||
output = ' ' * 3 * self._indent + output
|
||||
|
||||
Reference in New Issue
Block a user