X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c878ceeae8d69f231477ef0f207766093547ab86..f8167d6ee27a9e99a7b1161efbc0bcdb1a220b40:/wxPython/wx/lib/masked/maskededit.py?ds=sidebyside diff --git a/wxPython/wx/lib/masked/maskededit.py b/wxPython/wx/lib/masked/maskededit.py index 1c528c9c66..ec0d1de1fc 100644 --- a/wxPython/wx/lib/masked/maskededit.py +++ b/wxPython/wx/lib/masked/maskededit.py @@ -86,7 +86,7 @@ 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.) @@ -528,7 +528,7 @@ Naming Conventions 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 @@ -1581,7 +1581,7 @@ class Field: 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 @@ -1915,9 +1915,8 @@ class MaskedEditMixin: 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() @@ -1992,9 +1991,8 @@ class MaskedEditMixin: 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() @@ -2684,10 +2682,11 @@ class MaskedEditMixin: ## 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: @@ -3090,7 +3089,7 @@ class MaskedEditMixin: 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: @@ -4890,7 +4889,7 @@ class MaskedEditMixin: """ 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, @@ -4999,7 +4998,7 @@ class MaskedEditMixin: 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: @@ -5153,7 +5152,7 @@ class MaskedEditMixin: 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 @@ -5258,11 +5257,11 @@ class MaskedEditMixin: ## 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() @@ -5274,27 +5273,27 @@ class MaskedEditMixin: # ## 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 @@ -5773,22 +5772,22 @@ class MaskedEditMixin: 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 @@ -5797,7 +5796,7 @@ class MaskedEditMixin: # 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()) @@ -5807,9 +5806,9 @@ class MaskedEditMixin: 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): @@ -6352,7 +6351,7 @@ i=1 ## 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. ## ## @@ -6376,7 +6375,7 @@ i=1 ## 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