[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r8176 - in trunk/gnue-forms/src: GFObjects input/displayHandlers
From: |
johannes |
Subject: |
[gnue] r8176 - in trunk/gnue-forms/src: GFObjects input/displayHandlers uidrivers/wx26/widgets |
Date: |
Wed, 22 Feb 2006 07:06:10 -0600 (CST) |
Author: johannes
Date: 2006-02-22 07:06:09 -0600 (Wed, 22 Feb 2006)
New Revision: 8176
Modified:
trunk/gnue-forms/src/GFObjects/GFButton.py
trunk/gnue-forms/src/input/displayHandlers/Dropdown.py
trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py
trunk/gnue-forms/src/uidrivers/wx26/widgets/button.py
trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py
Log:
Further fixes for input widgets (dropdowns should work fine now)
Modified: trunk/gnue-forms/src/GFObjects/GFButton.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFButton.py 2006-02-22 11:05:06 UTC (rev
8175)
+++ trunk/gnue-forms/src/GFObjects/GFButton.py 2006-02-22 13:06:09 UTC (rev
8176)
@@ -42,7 +42,9 @@
'PRE-FOCUSOUT': 'Pre-FocusOut',
'POST-FOCUSOUT': 'Post-FocusOut',
'PRE-FOCUSIN': 'Pre-FocusIn',
- 'POST-FOCUSIN': 'Post-FocusIn'}
+ 'POST-FOCUSIN': 'Post-FocusIn',
+ 'ON-NEXT-ENTRY': 'On-Next-Entry',
+ 'ON-PREVIOUS-ENTRY': 'On-Previous-Entry'}
def initialize(self):
Modified: trunk/gnue-forms/src/input/displayHandlers/Dropdown.py
===================================================================
--- trunk/gnue-forms/src/input/displayHandlers/Dropdown.py 2006-02-22
11:05:06 UTC (rev 8175)
+++ trunk/gnue-forms/src/input/displayHandlers/Dropdown.py 2006-02-22
13:06:09 UTC (rev 8176)
@@ -75,7 +75,10 @@
self._buildDisplay()
self._cursor = len(self.display)
+ # Make sure to keep the UI in sync !
+ self.generateRefreshEvent()
+
# TODO: Replace with format mask
def _buildDisplayHelper(self, value, editing):
if value in (None, ""):
Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py 2006-02-22
11:05:06 UTC (rev 8175)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py 2006-02-22
13:06:09 UTC (rev 8176)
@@ -147,9 +147,13 @@
"""
widget = self.widgets [index]
- widget.SetFocus ()
+ if isinstance (widget, wx.ComboBox) and 'wxMac' in wx.PlatformInfo:
+ widget._entry.SetFocus ()
+ else:
+ widget.SetFocus ()
+
# ---------------------------------------------------------------------------
# On lose of the focus we un-select ComboBox-Entries
# ---------------------------------------------------------------------------
@@ -174,25 +178,14 @@
try:
if self._gfObject.style in ['dropdown', 'listbox']:
if self._gfObject._field._allowedValues != widget._origAllowedValues:
- widget.Freeze ()
+ self._updateChoices ()
- try:
- widget.Clear ()
- widget._origAllowedValues = self._gfObject._field._allowedValues
- choices = self._gfObject._field.allowedValues () [1]
- choices.sort ()
-
- for item in choices:
- widget.Append (item)
-
- finally:
- widget.Thaw ()
-
if isinstance (widget, wx.StaticText):
widget.SetLabel (value)
elif isinstance (widget, wx.ListBox):
- widget.SetStringSelection (value, True)
+ if value:
+ widget.SetStringSelection (value, True)
else:
widget.SetValue (value)
@@ -219,7 +212,10 @@
widget = self.widgets [index]
if isinstance (widget, wx.ComboBox):
- widget.SetMark (position, position)
+ if 'wxMac' in wx.PlatformInfo:
+ widget._entry.SetInsertionPoint (position)
+ else:
+ widget.SetMark (position, position)
elif hasattr (widget, 'SetInsertionPoint'):
widget.SetInsertionPoint (position)
@@ -241,7 +237,32 @@
widget = self.widgets [index]
if isinstance (widget, wx.ComboBox):
- widget.SetMark (selection1, selection2)
+ if 'wxMac' in wx.PlatformInfo:
+ widget._entry.SetSelection (selection1, selection2)
+ else:
+ widget.SetMark (selection1, selection2)
elif hasattr (widget, 'SetSelection'):
widget.SetSelection (selection1, selection2)
+
+
+ # ---------------------------------------------------------------------------
+ # Update the choices of a ComboBox or a Listbox
+ # ---------------------------------------------------------------------------
+
+ def _updateChoices (self, widget):
+
+ widget.Freeze ()
+
+ try:
+ choices = self._gfObject._field._allowedValuesReverse.keys ()
+ choices.sort ()
+
+ widget.Clear ()
+ for dsc in choices:
+ widget.Append (dsc, self._gfObject._field._allowedValuesReverse [dsc])
+
+ widget._origAllowedValues = self._gfObject._field._allowedValues
+
+ finally:
+ widget.Thaw ()
Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/button.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/button.py 2006-02-22
11:05:06 UTC (rev 8175)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/button.py 2006-02-22
13:06:09 UTC (rev 8176)
@@ -48,11 +48,10 @@
pos = (self.itemX, self.itemY + offs)
size = (self.itemWidth, -1)
- newWidget = wx.Button (event.container, wx.ID_ANY, self._gfObject.label,
- pos, size)
+ newWidget = wx.Button (event.container, -1, self._gfObject.label, pos,
size)
+ newWidget.Bind (wx.EVT_BUTTON, self.__click)
+ newWidget.Bind (wx.EVT_SET_FOCUS, self.__setFocus)
- newWidget.Connect (-1, -1, wx.wxEVT_COMMAND_BUTTON_CLICKED, self.__click)
-
return newWidget
@@ -63,8 +62,19 @@
def __click (self, event):
self._eventHandler (events.Event ('buttonActivated', self._gfObject))
+ event.Skip ()
+ # ---------------------------------------------------------------------------
+
+ def __setFocus (self, event):
+
+ if self._form._currentEntry != self._gfObject:
+ self._request ('FOCUS', data = self._gfObject)
+
+ event.Skip ()
+
+
# =============================================================================
# Configuration data
# =============================================================================
Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py 2006-02-22
11:05:06 UTC (rev 8175)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py 2006-02-22
13:06:09 UTC (rev 8176)
@@ -48,64 +48,139 @@
Create the wx widget.
"""
- cellH = self._uiDriver.cellHeight
- ctrlH = self._uiDriver.controlHeight.get (self._gfObject.style, cellH)
+ self.__calculateSizes ()
+ func = getattr (self, "_build%s" % self._gfObject.style.title ())
+ widget = func (event.container)
+
+ return widget
+
+
+ # ---------------------------------------------------------------------------
+ # Calculate the position and size of a widget
+ # ---------------------------------------------------------------------------
+
+ def __calculateSizes (self):
+
+ cellH = self._uiDriver.cellHeight
+ ctrlH = self._uiDriver.controlHeight.get (self._gfObject.style, cellH)
offset = (cellH - ctrlH) / 2
- pos = (self.itemX, self.itemY + offset)
- lines = hasattr (self._gfObject, 'Char__height') and \
- self._gfObject.Char__height or 1
- size = (self.itemWidth, lines == 1 and -1 or self.itemHeight)
- # ----- label style entries
- if self._gfObject.style == 'label':
- newWidget = wx.StaticText (event.container, wx.ID_ANY, "x", pos, size)
+ self.__lines = getattr (self._gfObject, 'Char__height', 1)
+ self.__size = (self.itemWidth, self.__lines == 1 and -1 or
self.itemHeight)
+ self.__pos = (self.itemX, self.itemY + offset)
+ self.__cellH = cellH
- # ----- dropdown- and listbox-entries
- elif self._gfObject.style in ['dropdown', 'listbox']:
- choices = self._gfObject._field.allowedValues () [1]
- choices.sort ()
+ if self._gfObject.style == 'default' and self.__lines > 1:
+ self.__size = (self.itemWidth,
+ (self.__lines * cellH) - (cellH - offset * 2))
- if self._gfObject.style == 'dropdown':
- newWidget = wx.ComboBox (event.container, wx.ID_ANY, "", pos, size,
- choices, wx.CB_DROPDOWN | wx.CB_SORT)
- changeEvt = wx.wxEVT_COMMAND_COMBOBOX_SELECTED
- else:
- newWidget = wx.ListBox (event.container, wx.ID_ANY, pos, size, choices,
- wx.LB_SINGLE | wx.LB_SORT)
- changeEvt = wx.wxEVT_COMMAND_LISTBOX_SELECTED
+ # ---------------------------------------------------------------------------
+ # Widget construction methods
+ # ---------------------------------------------------------------------------
- newWidget.Connect (-1, -1, changeEvt, self.__itemSelected)
- newWidget._origAllowedValues = self._gfObject._field._allowedValues
+ def _buildDefault (self, parent, password = False):
+ """
+ """
- # ----- checkbox-entries
- elif self._gfObject.style == 'checkbox':
- newWidget = wx.CheckBox (event.container, wx.ID_ANY,
- self._gfObject.label, pos)
- wx.EVT_CHECKBOX (newWidget, newWidget.GetId (), self.__toggleCheckbox)
+ xFlags = wx.TE_PROCESS_TAB
- # ----- text-entries
+ if password:
+ xFlags |= wx.TE_PASSWORD
+
+ if self.__lines > 1:
+ xFlags |= wx.TE_MULTILINE
+
+ result = wx.TextCtrl (parent, -1, '', self.__pos, self.__size, xFlags)
+
+ result.Bind (wx.EVT_CHAR, self.__keypress)
+ result.Bind (wx.EVT_LEFT_UP, self.__leftMouseUp)
+ result.Bind (wx.EVT_SET_FOCUS, self.__setFocus)
+
+ return result
+
+
+ # ---------------------------------------------------------------------------
+
+ def _buildPassword (self, parent):
+
+ return self._buildDefault (parent, True)
+
+
+ # ---------------------------------------------------------------------------
+
+ def _buildLabel (self, parent):
+ """
+ """
+
+ return wx.StaticText (parent, -1, "", self.__pos, self.__size)
+
+
+ # ---------------------------------------------------------------------------
+
+ def _buildCheckbox (self, parent):
+ """
+ """
+
+ result = wx.CheckBox (parent, -1, self._gfObject.label, self.__pos)
+ result.Bind (wx.EVT_CHECKBOX, self.__toggleCheckbox)
+ result.Bind (wx.EVT_SET_FOCUS, self.__setFocus)
+
+ return result
+
+
+ # ---------------------------------------------------------------------------
+
+ def _buildDropdown (self, parent):
+ """
+ """
+
+ result = wx.ComboBox (parent, -1, "", self.__pos, self.__size, [],
+ wx.CB_DROPDOWN)
+
+ self._updateChoices (result)
+
+ # On wxMac a Combobox is a container holding a TextCtrl and a Choice. So we
+ # have to bind Char- and Focus-Events to the textCtrl instead of the
+ # container widget.
+ if 'wxMac' in wx.PlatformInfo:
+ for child in result.GetChildren ():
+ if isinstance (child, wx.TextCtrl):
+ item = result._entry = child
+ break
else:
- if lines == 1:
- size = (self.itemWidth, -1)
- flags = 0
- else:
- size = (self.itemWidth, (lines * cellH) - (cellH - offset * 2))
- flags = wx.TE_MULTILINE
+ item = result
- newWidget = wx.TextCtrl (event.container, -1, '', pos, size,
- wx.TE_PROCESS_TAB | flags)
- newWidget.Connect (-1, -1, wx.wxEVT_SET_FOCUS, self.__setFocus)
- newWidget.Connect (-1, -1, wx.wxEVT_CHAR, self.__keypress)
+ result.Bind (wx.EVT_COMBOBOX, self.__itemSelected)
+ item.Bind (wx.EVT_CHAR, self.__keypress)
+ item.Bind (wx.EVT_LEFT_UP, self.__leftMouseUp)
+ item.Bind (wx.EVT_SET_FOCUS, self.__setFocus)
- if self._gfObject.style in ['default', 'dropdown']:
- newWidget.Connect (-1, -1, wx.wxEVT_LEFT_UP, self.__leftMouseUp)
+ # On MWS a ComboBox widget does not get an EVT_CHAR event for the left- and
+ # right-keys. That's why we need to add a EVT_KEY_DOWN-handler here
+ if 'wxMSW' in wx.PlatformInfo:
+ result.Bind (wx.EVT_KEY_DOWN, self.__mswKeyDown)
- return newWidget
+ return result
# ---------------------------------------------------------------------------
+
+ def _buildListbox (self, parent):
+ """
+ """
+
+ result = wx.ListBox (parent, -1, self.__pos, self.__size, [], wx.LB_SINGLE)
+ self._updateChoices (result)
+
+ result.Bind (wx.EVT_LISTBOX, self.__itemSelected)
+ result.Bind (wx.EVT_SET_FOCUS, self.__setFocus)
+
+ return result
+
+
+ # ---------------------------------------------------------------------------
# Make sure to keep the focus in gf-layer in sync with the UI
# ---------------------------------------------------------------------------
@@ -137,13 +212,14 @@
elif isinstance (widget, wx.ComboBox):
(left, right) = widget.GetMark ()
+ event.Skip ()
+
if left == right:
self._request ('CURSORMOVE', position = left)
else:
self._request ('SELECTWITHMOUSE', position1 = left, position2 = right,
cursor = widget.GetInsertionPoint ())
- event.Skip ()
# ---------------------------------------------------------------------------
@@ -161,10 +237,14 @@
def __itemSelected (self, event):
- self._request ('REPLACEVALUE', index = event.GetSelection (),
- text = event.GetString ())
+ widget = event.GetEventObject ()
+ currVal = widget.GetClientData (event.GetSelection ())
+ if currVal != self._gfObject.getValue ():
+ self._request ('REPLACEVALUE', index = event.GetSelection (),
+ text = event.GetString ())
+
# ---------------------------------------------------------------------------
# Process a key-press in an entry
# ---------------------------------------------------------------------------
@@ -174,33 +254,49 @@
keycode = event.GetKeyCode ()
unikey = event.GetUnicodeKey ()
- if self._gfObject.style == 'listbox' and (keycode in [wx.WXK_UP,
- wx.WXK_DOWN, wx.WXK_SPACE, wx.WXK_PRIOR, wx.WXK_NEXT, wx.WXK_HOME,
- wx.WXK_END]):
+ (command, args) = GFKeyMapper.KeyMapper.getEvent (keycode,
+ event.ShiftDown (),
+ event.CmdDown (),
+ event.AltDown ())
+
+ # This is a temporary workaround: since the KeyMapper encapsulates all
+ # unknown keys into a UserCommand we have no chance on Mac to enter
+ # symbols like @ or the euro-sign.
+ if 'wxMac' in wx.PlatformInfo and command == 'USERCOMMAND':
+ command = None
+
+ if command:
+ self._request (command, triggerName = args)
+
+ elif unikey == keycode or unikey > 127:
+ self._keypress (unichr (unikey))
+
+ else:
event.Skip ()
- else:
+
+ # ---------------------------------------------------------------------------
+ # Key-Down-Eventtrap for wx.MSW's ComboBox widgets
+ # ---------------------------------------------------------------------------
+
+ def __mswKeyDown (self, event):
+
+ keycode = event.GetKeyCode ()
+ unikey = event.GetUnicodeKey ()
+ command = None
+
+ if keycode in [wx.WXK_LEFT, wx.WXK_RIGHT]:
(command, args) = GFKeyMapper.KeyMapper.getEvent (keycode,
event.ShiftDown (),
event.CmdDown (),
event.AltDown ())
- # This is a temporary workaround: since the KeyMapper encapsulates all
- # unknown keys into a UserCommand we have no chance on Mac to enter
- # symbols like @ or the euro-sign.
- if 'wxMac' in wx.PlatformInfo and command == 'USERCOMMAND':
- command = None
+ if command:
+ self._request (command, triggerName = args)
+ else:
+ event.Skip ()
- if command:
- self._request (command, triggerName = args)
- elif unikey == keycode or unikey > 127:
- self._keypress (unichr (unikey))
-
- else:
- event.Skip ()
-
-
# =============================================================================
# Configuration
# =============================================================================
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r8176 - in trunk/gnue-forms/src: GFObjects input/displayHandlers uidrivers/wx26/widgets,
johannes <=