provides a single "unified" interface for masked controls. Those for
masked.TextCtrl, masked.ComboBox and masked.IpAddrCtrl are all documented
below; the others have their own demo pages and interface descriptions.
- (See end of following discussion for how to configure the wxMaskedCtrl()
+ (See end of following discussion for how to configure the wx.MaskedCtrl()
to select the above control types.)
the function for getting the start and end of the
current text selection. The reason for this is
that not all controls have the same function name for
- doing this; eg. wxTextCtrl uses .GetSelection(),
+ doing this; eg. wx.TextCtrl uses .GetSelection(),
whereas we had to write a .GetMark() function for
wxComboBox, because .GetSelection() for the control
gets the currently selected list item from the combo
class MaskedEditMixin:
"""
This class allows us to abstract the masked edit functionality that could
- be associated with any text entry control. (eg. wxTextCtrl, wxComboBox, etc.)
+ be associated with any text entry control. (eg. wx.TextCtrl, wx.ComboBox, etc.)
"""
valid_ctrl_params = {
'mask': 'XXXXXXXXXXXXX', ## mask string for formatting this control
if self._autofit:
## dbg('setting client size to:', self._CalcSize())
- size = self._CalcSize()
- self.SetSizeHints(size)
- self.SetClientSize(size)
+ self.SetClientSize(self._CalcSize())
+ self.SetSizeHints(self.GetSize())
# Set value/type-specific formatting
self._applyFormatting()
self._SetInitialValue()
if self._autofit:
- size = self._CalcSize()
- self.SetSizeHints(size)
- self.SetClientSize(size)
+ self.SetClientSize(self._CalcSize())
+ self.SetSizeHints(self.GetSize())
# Set value/type-specific formatting
self._applyFormatting()
## dbg(indent=0)
return bValid
- ##! WS: For some inexplicable reason, every wxTextCtrl.SetValue
- ## call is generating two (2) EVT_TEXT events.
+ ##! WS: For some inexplicable reason, every wx.TextCtrl.SetValue
+ ## call is generating two (2) EVT_TEXT events. On certain platforms,
+ ## (eg. linux/GTK) the 1st is an empty string value.
## This is the only mechanism I can find to mask this problem:
- if newvalue == self._curValue:
+ if newvalue == self._curValue or len(newvalue) == 0:
## dbg('ignoring bogus text change event', indent=0)
pass
else:
def _OnCtrl_A(self,event=None):
""" Handles ctrl-a keypress in control. Should return False to skip other processing. """
end = self._goEnd(getPosOnly=True)
- if not event or event.ShiftDown():
+ if not event or (isinstance(event, wx.KeyEvent) and event.ShiftDown()):
wx.CallAfter(self._SetInsertionPoint, 0)
wx.CallAfter(self._SetSelection, 0, self._masklength)
else:
"""
This event handler is currently necessary to work around new default
behavior as of wxPython2.3.3;
- The TAB key auto selects the entire contents of the wxTextCtrl *after*
+ The TAB key auto selects the entire contents of the wx.TextCtrl *after*
the EVT_SET_FOCUS event occurs; therefore we can't query/adjust the selection
*here*, because it hasn't happened yet. So to prevent this behavior, and
preserve the correct selection when the focus event is not due to tab,
if self._isFloat and groupcharpos > self._decimalpos:
# 1st one found on right-hand side is past decimal point
## dbg('groupchar in fraction; illegal')
- valid = False
+ return False
elif self._isFloat:
integer = value[:self._decimalpos].strip()
else:
The trouble is that, a priori, there's no explicit notification of
why the focus event we received. However, the whole reason we need to
- do this is because the default behavior on TAB traveral in a wxTextCtrl is
+ do this is because the default behavior on TAB traveral in a wx.TextCtrl is
now to select the entire contents of the window, something we don't want.
So we can *now* test the selection range, and if it's "the whole text"
we can assume the cause, change the insertion point to the start of
## dbg('current value: "%s"' % value)
sel_start, sel_to = self._GetSelection() ## check for a range of selected text
## dbg('selected text: "%s"' % value[sel_start:sel_to].strip())
- do = wxTextDataObject()
+ do = wx.TextDataObject()
do.SetText(value[sel_start:sel_to].strip())
- wxTheClipboard.Open()
- wxTheClipboard.SetData(do)
- wxTheClipboard.Close()
+ wx.TheClipboard.Open()
+ wx.TheClipboard.SetData(do)
+ wx.TheClipboard.Close()
if sel_to - sel_start != 0:
self._OnErase()
#
## def _Copy( self ):
## """
-## Override the wxTextCtrl's .Copy function, with our own
+## Override the wx.TextCtrl's .Copy function, with our own
## that does validation. Need to strip trailing spaces.
## """
## sel_start, sel_to = self._GetSelection()
## select_len = sel_to - sel_start
-## textval = wxTextCtrl._GetValue(self)
+## textval = wx.TextCtrl._GetValue(self)
##
-## do = wxTextDataObject()
+## do = wx.TextDataObject()
## do.SetText(textval[sel_start:sel_to].strip())
-## wxTheClipboard.Open()
-## wxTheClipboard.SetData(do)
-## wxTheClipboard.Close()
+## wx.TheClipboard.Open()
+## wx.TheClipboard.SetData(do)
+## wx.TheClipboard.Close()
def _getClipboardContents( self ):
""" Subroutine for getting the current contents of the clipboard.
"""
- do = wxTextDataObject()
- wxTheClipboard.Open()
- success = wxTheClipboard.GetData(do)
- wxTheClipboard.Close()
+ do = wx.TextDataObject()
+ wx.TheClipboard.Open()
+ success = wx.TheClipboard.GetData(do)
+ wx.TheClipboard.Close()
if not success:
return None
def _OnContextMenu(self, event):
## dbg('MaskedEditMixin::OnContextMenu()', indent=1)
- menu = wxMenu()
- menu.Append(wxID_UNDO, "Undo", "")
+ menu = wx.Menu()
+ menu.Append(wx.ID_UNDO, "Undo", "")
menu.AppendSeparator()
- menu.Append(wxID_CUT, "Cut", "")
- menu.Append(wxID_COPY, "Copy", "")
- menu.Append(wxID_PASTE, "Paste", "")
- menu.Append(wxID_CLEAR, "Delete", "")
+ menu.Append(wx.ID_CUT, "Cut", "")
+ menu.Append(wx.ID_COPY, "Copy", "")
+ menu.Append(wx.ID_PASTE, "Paste", "")
+ menu.Append(wx.ID_CLEAR, "Delete", "")
menu.AppendSeparator()
- menu.Append(wxID_SELECTALL, "Select All", "")
+ menu.Append(wx.ID_SELECTALL, "Select All", "")
- EVT_MENU(menu, wxID_UNDO, self._OnCtrl_Z)
- EVT_MENU(menu, wxID_CUT, self._OnCtrl_X)
- EVT_MENU(menu, wxID_COPY, self._OnCtrl_C)
- EVT_MENU(menu, wxID_PASTE, self._OnCtrl_V)
- EVT_MENU(menu, wxID_CLEAR, self._OnClear)
- EVT_MENU(menu, wxID_SELECTALL, self._OnCtrl_A)
+ wx.EVT_MENU(menu, wx.ID_UNDO, self._OnCtrl_Z)
+ wx.EVT_MENU(menu, wx.ID_CUT, self._OnCtrl_X)
+ wx.EVT_MENU(menu, wx.ID_COPY, self._OnCtrl_C)
+ wx.EVT_MENU(menu, wx.ID_PASTE, self._OnCtrl_V)
+ wx.EVT_MENU(menu, wx.ID_CLEAR, self._OnClear)
+ wx.EVT_MENU(menu, wx.ID_SELECTALL, self._OnCtrl_A)
# ## WSS: The base control apparently handles
# enable/disable of wID_CUT, wxID_COPY, wxID_PASTE
# so we're keeping track of previous values ourselves.
# Therefore, we have to override the default update for
# that item on the menu:
- EVT_UPDATE_UI(self, wxID_UNDO, self._UndoUpdateUI)
+ wx.EVT_UPDATE_UI(self, wx.ID_UNDO, self._UndoUpdateUI)
self._contextMenu = menu
self.PopupMenu(menu, event.GetPosition())
def _UndoUpdateUI(self, event):
if self._prevValue is None or self._prevValue == self._curValue:
- self._contextMenu.Enable(wxID_UNDO, False)
+ self._contextMenu.Enable(wx.ID_UNDO, False)
else:
- self._contextMenu.Enable(wxID_UNDO, True)
+ self._contextMenu.Enable(wx.ID_UNDO, True)
def _OnCtrlParametersChanged(self):
## non-british spellings still supported for backward-compatibility.
## 20. Added '&' mask specification character for punctuation only (no letters
## or digits).
-## 21. Added (in a separate file) wxMaskedCtrl() factory function to provide
+## 21. Added (in a separate file) wx.MaskedCtrl() factory function to provide
## unified interface to the masked edit subclasses.
##
##
## 2. Fixed EUDATE* autoformats, fixed IsDateType mask list, and added ability to
## use 3-char months for dates, and EUDATETIME, and EUDATEMILTIME autoformats.
## 3. Made all date autoformats automatically pick implied "datestyle".
-## 4. Added IsModified override, since base wxTextCtrl never reports modified if
+## 4. Added IsModified override, since base wx.TextCtrl never reports modified if
## .SetValue used to change the value, which is what the masked edit controls
## use internally.
## 5. Fixed bug in date position adjustment on 2 to 4 digit date conversion when