Author: reinhard Date: 2009-10-27 11:00:31 -0500 (Tue, 27 Oct 2009) New Revision: 10012
Modified: trunk/gnue-forms/src/GFObjects/GFBlock.py trunk/gnue-forms/src/GFObjects/GFGrid.py trunk/gnue-forms/src/GFObjects/GFTabStop.py trunk/gnue-forms/src/uidrivers/qt3/widgets/entry.py trunk/gnue-forms/src/uidrivers/qt4/widgets/entry.py trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py Log: Treat cursor up/down and page up/down keys in grids as reasonable as possible. Modified: trunk/gnue-forms/src/GFObjects/GFBlock.py =================================================================== --- trunk/gnue-forms/src/GFObjects/GFBlock.py 2009-10-27 07:34:59 UTC (rev 10011) +++ trunk/gnue-forms/src/GFObjects/GFBlock.py 2009-10-27 16:00:31 UTC (rev 10012) @@ -461,6 +461,15 @@ record. """ + if self.__visible_start == 0 and adjustment < 0: + # Already at top: move to first record. + self.first_record() + + if self.__visible_start + self._rows == self.__record_count \ + and adjustment > 0: + # Already at bottom: move to last record. + self.last_record() + self._event_scroll_to_record(self.__visible_start + adjustment) # ------------------------------------------------------------------------- Modified: trunk/gnue-forms/src/GFObjects/GFGrid.py =================================================================== --- trunk/gnue-forms/src/GFObjects/GFGrid.py 2009-10-27 07:34:59 UTC (rev 10011) +++ trunk/gnue-forms/src/GFObjects/GFGrid.py 2009-10-27 16:00:31 UTC (rev 10012) @@ -95,6 +95,45 @@ # ------------------------------------------------------------------------- + # Public methods + # ------------------------------------------------------------------------- + + def line_up(self): + """ + Move the database cursor behind this grid up one record. + """ + + self._block.prev_record() + + # ------------------------------------------------------------------------- + + def line_down(self): + """ + Move the database cursor behind this grid down one record. + """ + + self._block.next_record() + + # ------------------------------------------------------------------------- + + def page_up(self): + """ + Scroll the grid up (backwards) by one screen page. + """ + + self._block._event_scroll_delta(-(self.__rows-1)) + + # ------------------------------------------------------------------------- + + def page_down(self): + """ + Scroll the grid down (forward) by one screen page. + """ + + self._block._event_scroll_delta(self.__rows-1) + + + # ------------------------------------------------------------------------- # Call the UI widget to adjust the scrollbar to a given position # ------------------------------------------------------------------------- Modified: trunk/gnue-forms/src/GFObjects/GFTabStop.py =================================================================== --- trunk/gnue-forms/src/GFObjects/GFTabStop.py 2009-10-27 07:34:59 UTC (rev 10011) +++ trunk/gnue-forms/src/GFObjects/GFTabStop.py 2009-10-27 16:00:31 UTC (rev 10012) @@ -68,7 +68,8 @@ # GFInstance. This is the event handler that display handlers self.subEventHandler = events.EventController() - self._page = None + self._page = None + self.__grid_link = None self._rows = 1 self._gap = 0 @@ -93,7 +94,10 @@ self._page = self.findParentOfType('GFPage') self._page._entryList.append(self) + if not self.__grid_link: + self.__grid_link = self.findParentOfType('GFGrid') + # ------------------------------------------------------------------------- def _is_navigable_ (self, mode): @@ -142,8 +146,60 @@ self._form._event_focus_changed(self, index - self._visibleIndex) + # ------------------------------------------------------------------------- + def _event_line_up(self): + """ + The user has pressed the cursor up key in an entry which doesn't + otherwise handle that key. + + If this object is part of a grid, move up one record. + """ + + if self.__grid_link: + self.__grid_link.line_up() + # ------------------------------------------------------------------------- + + def _event_line_down(self): + """ + The user has pressed the cursor down key in an entry which doesn't + otherwise handle that key. + + If this object is part of a grid, move down one record. + """ + + if self.__grid_link: + self.__grid_link.line_down() + + # ------------------------------------------------------------------------- + + def _event_page_up(self): + """ + The user has pressed the page up key in an entry which doesn't + otherwise handle that key. + + If this object is part of a grid, move up one screen page. + """ + + if self.__grid_link: + self.__grid_link.page_up() + + # ------------------------------------------------------------------------- + + def _event_page_down(self): + """ + The user has pressed the page down key in an entry which doesn't + otherwise handle that key. + + If this object is part of a grid, move down one screen page. + """ + + if self.__grid_link: + self.__grid_link.page_down() + + + # ------------------------------------------------------------------------- # Number of rows of this widgets has changed # ------------------------------------------------------------------------- Modified: trunk/gnue-forms/src/uidrivers/qt3/widgets/entry.py =================================================================== --- trunk/gnue-forms/src/uidrivers/qt3/widgets/entry.py 2009-10-27 07:34:59 UTC (rev 10011) +++ trunk/gnue-forms/src/uidrivers/qt3/widgets/entry.py 2009-10-27 16:00:31 UTC (rev 10012) @@ -366,14 +366,20 @@ keycode = event.key() state = event.state() + # Handle cursor up/down and page up/down. + if state == 0: + if keycode == qt.Qt.Key_Up: + self.ui_widget._gfObject._event_line_up() + elif keycode == qt.Qt.Key_Down: + self.ui_widget._gfObject._event_line_down() + elif keycode == qt.Qt.Key_Prior: + self.ui_widget._gfObject._event_page_up() + elif keycode == qt.Qt.Key_Next: + self.ui_widget._gfObject._event_page_down() + # We will ask the Key-Mapper for a command only for Tab- and # Return-Keys. Everything else should be handled by the widget - if keycode in [qt.Qt.Key_Up, qt.Qt.Key_Down]: - is_cmd = state == 0 - else: - is_cmd = keycode in [qt.Qt.Key_Tab, qt.Qt.Key_Return] - - if is_cmd: + if keycode in [qt.Qt.Key_Tab, qt.Qt.Key_Return]: (command, args) = GFKeyMapper.KeyMapper.getEvent(keycode, state & qt.QKeyEvent.ShiftButton > 0, state & qt.QKeyEvent.ControlButton > 0, Modified: trunk/gnue-forms/src/uidrivers/qt4/widgets/entry.py =================================================================== --- trunk/gnue-forms/src/uidrivers/qt4/widgets/entry.py 2009-10-27 07:34:59 UTC (rev 10011) +++ trunk/gnue-forms/src/uidrivers/qt4/widgets/entry.py 2009-10-27 16:00:31 UTC (rev 10012) @@ -330,16 +330,30 @@ # Not sure why, but the int is important or "&" will fail... state = int(event.modifiers()) - (command, args) = GFKeyMapper.KeyMapper.getEvent(keycode, + # Handle cursor up/down and page up/down. + if state == 0: + if keycode == qt.Qt.Key_Up: + self.ui_widget._gfObject._event_line_up() + elif keycode == qt.Qt.Key_Down: + self.ui_widget._gfObject._event_line_down() + elif keycode == qt.Qt.Key_Prior: + self.ui_widget._gfObject._event_page_up() + elif keycode == qt.Qt.Key_Next: + self.ui_widget._gfObject._event_page_down() + + # We will ask the Key-Mapper for a command only for Tab- and + # Return-Keys. Everything else should be handled by the widget + if keycode in [qt.Qt.Key_Tab, qt.Qt.Key_Return]: + (command, args) = GFKeyMapper.KeyMapper.getEvent(keycode, state & qt.Qt.SHIFT > 0, state & qt.Qt.CTRL > 0, state & qt.Qt.ALT > 0) - if command: - if command == 'NEWLINE': - self.ui_widget._request(command, text = '\n') - else: - self.ui_widget._request(command, triggerName = args) + if command: + if command == 'NEWLINE': + self.ui_widget._request(command, text = '\n') + else: + self.ui_widget._request(command, triggerName = args) else: # TODO: is there another way to find the qt widget class which Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py =================================================================== --- trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py 2009-10-27 07:34:59 UTC (rev 10011) +++ trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py 2009-10-27 16:00:31 UTC (rev 10012) @@ -111,10 +111,9 @@ self.__border = self._uiDriver.control_border('default') ctrl = wx.TextCtrl(parent, -1, size=csize, style=xFlags) + ctrl.Bind(wx.EVT_TEXT, self.__on_text_changed) ctrl.Bind(wx.EVT_CHAR, self.__on_keypress) - ctrl.Bind(wx.EVT_TEXT, self.__on_text_changed) ctrl.Bind(wx.EVT_KEY_DOWN, self.__on_key_down) - ctrl.Bind(wx.EVT_SET_FOCUS, self.__on_set_focus) return [self.__add_entry_label(parent), ctrl] @@ -367,22 +366,33 @@ def __on_keypress(self, event): keycode = event.GetKeyCode() + control = event.GetEventObject() # Treat enter of the numeric keypad the same way as normal enter key if keycode == wx.WXK_NUMPAD_ENTER: keycode = wx.WXK_RETURN - is_cmd = keycode in [wx.WXK_TAB, wx.WXK_RETURN, wx.WXK_UP, wx.WXK_DOWN] + # Let multiline entries handle return/up/down/pgup/pgdown themselves. + if isinstance(control, wx.TextCtrl) and control.IsMultiLine(): + if keycode in (wx.WXK_RETURN, wx.WXK_UP, wx.WXK_DOWN, + wx.WXK_PAGEUP, wx.WXK_PAGEDOWN): + event.Skip() + return + + # Handle cursor up/down and page up/down. + if not (event.ShiftDown() or event.CmdDown() or event.AltDown()): + if keycode == wx.WXK_UP: + self._gfObject._event_line_up() + elif keycode == wx.WXK_DOWN: + self._gfObject._event_line_down() + elif keycode == wx.WXK_PAGEUP: + self._gfObject._event_page_up() + elif keycode == wx.WXK_PAGEDOWN: + self._gfObject._event_page_down() + command = None - # Prevent up- and down-keys for multiline text controls from being - # interpreted as record-navigation-keys. - wxctrl = event.GetEventObject() - if isinstance(wxctrl, wx.TextCtrl) and wxctrl.IsMultiLine() \ - and (keycode in [wx.WXK_RETURN, wx.WXK_UP, wx.WXK_DOWN]): - is_cmd = False - - if is_cmd: + if keycode in [wx.WXK_TAB, wx.WXK_RETURN]: (command, args) = GFKeyMapper.KeyMapper.getEvent(keycode, event.ShiftDown(), event.CmdDown(), _______________________________________________ commit-gnue mailing list commit-gnue@gnu.org http://lists.gnu.org/mailman/listinfo/commit-gnue