[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r8856 - in trunk/gnue-forms/src: . GFObjects uidrivers/gtk2/widge
From: |
reinhard |
Subject: |
[gnue] r8856 - in trunk/gnue-forms/src: . GFObjects uidrivers/gtk2/widgets uidrivers/qt3 uidrivers/qt3/widgets uidrivers/win32/widgets uidrivers/wx uidrivers/wx26/widgets |
Date: |
Wed, 18 Oct 2006 15:26:26 -0500 (CDT) |
Author: reinhard
Date: 2006-10-18 15:26:25 -0500 (Wed, 18 Oct 2006)
New Revision: 8856
Removed:
trunk/gnue-forms/src/uidrivers/qt3/common.py
Modified:
trunk/gnue-forms/src/GFForm.py
trunk/gnue-forms/src/GFInstance.py
trunk/gnue-forms/src/GFObjects/GFTabStop.py
trunk/gnue-forms/src/uidrivers/gtk2/widgets/_base.py
trunk/gnue-forms/src/uidrivers/qt3/widgets/button.py
trunk/gnue-forms/src/uidrivers/qt3/widgets/entry.py
trunk/gnue-forms/src/uidrivers/win32/widgets/_base.py
trunk/gnue-forms/src/uidrivers/wx/common.py
trunk/gnue-forms/src/uidrivers/wx26/widgets/button.py
trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py
Log:
More direct way of setting the focus on GF layer if the user selects another
widget with the mouse.
Modified: trunk/gnue-forms/src/GFForm.py
===================================================================
--- trunk/gnue-forms/src/GFForm.py 2006-10-18 18:21:05 UTC (rev 8855)
+++ trunk/gnue-forms/src/GFForm.py 2006-10-18 20:26:25 UTC (rev 8856)
@@ -316,6 +316,35 @@
# UI events (called from UIForm)
# -------------------------------------------------------------------------
+ def _event_focus_changed(self, target, row_offset):
+ """
+ Notify the form that the user has moved the focus with a mouse click.
+
+ This method makes sure that the logical focus follows the physical
+ focus.
+
+ In case the current focus widget vetoes the focus loss, this method
+ beats the focus back to the old widget.
+ """
+
+ try:
+ self.endEditing()
+ try:
+ self.move_focus(target, row_offset)
+ finally:
+ self.beginEditing()
+ except:
+ # Old focus entry has invalid value: beat the UI focus back, so we
+ # are captured until the value is corrected.
+ # FIXME: if there is a way (on some UIs) to veto the focus change
+ # on UI layer, this should be the prefered method
+ self._currentEntry.ui_focus_in()
+ if hasattr(self._currentEntry, '_displayHandler'):
+ self._currentEntry._displayHandler.generateRefreshEvent()
+ raise
+
+ # -------------------------------------------------------------------------
+
def _event_page_changed(self, page_number):
"""
Notify the form that the user has switched to a different page.
@@ -1039,11 +1068,6 @@
@param row_offset: number of rows to jump up or down in new widget
"""
- # cannot change focus to same entry
- if widget == self._currentEntry:
- assert gDebug(5, "Current entry did not change from %s" % widget)
- return
-
assert gDebug(5, "Change focus: %s->%s" % (self._currentEntry, widget))
new_block = widget.get_block()
Modified: trunk/gnue-forms/src/GFInstance.py
===================================================================
--- trunk/gnue-forms/src/GFInstance.py 2006-10-18 18:21:05 UTC (rev 8855)
+++ trunk/gnue-forms/src/GFInstance.py 2006-10-18 20:26:25 UTC (rev 8856)
@@ -81,10 +81,6 @@
# First, all events are passed to the focus widget
'__before__' : self.__beforeEvent,
- # events not related to menu, toolbar, or hotkeys
- 'requestFOCUS' : self.changeFocus,
- 'requestJUMPRECORD' : self.__execute_jumpRecord,
-
# Focus-related events
'requestENTER' : self.__execute_nextEntry,
'requestNEXTENTRY' : self.__execute_nextEntry,
@@ -426,40 +422,6 @@
# ---------------------------------------------------------------------------
- # Change the focus to an entry object
- # ---------------------------------------------------------------------------
-
- def changeFocus(self, event):
- """
- Change the focus to the entry object requested by the event source
- """
-
- if event.data == event._form._currentEntry:
- return True
-
- if event.data._type in ['GFEntry', 'GFImage', 'GFButton']:
- if not event.data.is_navigable (event._form.getCurrentMode ()):
- return False
-
- try:
- event._form.endEditing()
- try:
- event._form.move_focus(event.data, 0)
- finally:
- event._form.beginEditing()
-
- return True
-
- except:
- # Old focus entry has invalid value: beat the UI focus back, so we are
- # captured until the value is corrected.
- event._form._currentEntry.ui_focus_in()
- if hasattr(event._form._currentEntry, '_displayHandler'):
- event._form._currentEntry._displayHandler.generateRefreshEvent()
- raise
-
-
- # ---------------------------------------------------------------------------
# Focus movement
# ---------------------------------------------------------------------------
@@ -558,12 +520,6 @@
# ---------------------------------------------------------------------------
- def __execute_jumpRecord(self, event):
-
- event._form.jump_records(event.data)
-
- # ---------------------------------------------------------------------------
-
def __execute_jumpRowsUp(self, event):
if event._form._currentEntry._rows > 1:
Modified: trunk/gnue-forms/src/GFObjects/GFTabStop.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFTabStop.py 2006-10-18 18:21:05 UTC (rev
8855)
+++ trunk/gnue-forms/src/GFObjects/GFTabStop.py 2006-10-18 20:26:25 UTC (rev
8856)
@@ -114,6 +114,35 @@
# -------------------------------------------------------------------------
+ # UI events (called from UIEntry/UIButton)
+ # -------------------------------------------------------------------------
+
+ def _event_set_focus(self, index):
+ """
+ Notify the object that the user has set the focus to this object with a
+ mouse click.
+
+ This method makes sure that the logical focus follows the physical
+ focus.
+
+ In case the current focus widget vetoes the focus loss, this method
+ beats the focus back to the old widget.
+
+ In fact, this method only calls L{GFForm.GFForm._event_focus_changed}
+ with a target of this object.
+ """
+
+ # Most UIs issue a set_focus event also when the focus moves from
+ # another window to this one. We don't need to do anything in this
+ # case.
+ if self._form.get_focus_object() is self \
+ and index == self._visibleIndex:
+ return
+
+ self._form._event_focus_changed(self, index - self._visibleIndex)
+
+
+ # -------------------------------------------------------------------------
# Number of rows of this widgets has changed
# -------------------------------------------------------------------------
Modified: trunk/gnue-forms/src/uidrivers/gtk2/widgets/_base.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/gtk2/widgets/_base.py 2006-10-18
18:21:05 UTC (rev 8855)
+++ trunk/gnue-forms/src/uidrivers/gtk2/widgets/_base.py 2006-10-18
20:26:25 UTC (rev 8856)
@@ -113,7 +113,6 @@
if lookupWidget is None:
lookupWidget = widget
- # assert gDebug (6, "ADD FOCUSHANDLER %s (%s)" % (widget, lookupWidget))
method = after and widget.connect_after or widget.connect
widget._focusHandler = method ('focus-in-event', self.__focusInHandler,
lookupWidget)
@@ -124,31 +123,10 @@
# ---------------------------------------------------------------------------
def __focusInHandler (self, widget, event, lookupWidget):
- """
- This function handles 'focus-in-event' signals by creating an immediate
- call to 'requestFOCUS'. If the focused widget needs a jump to another
- record an additional 'requestJUMPRECORD' event will be fired.
- """
- assert gDebug (6, "FOCUS-IN-EVENT: %s for %s" % (widget, lookupWidget))
+ assert gDebug (6, "focus-in-event: %s for %s" % (widget, lookupWidget))
gfObject = self._uiDriver._WidgetToGFObj [lookupWidget]
- _formRef = gfObject._form
-
- if _formRef._currentEntry == gfObject and \
- self.widgets.index (lookupWidget) == gfObject._visibleIndex:
- assert gDebug (6, "SKIPPING since we already have the focus!")
- return False
-
- if _formRef._currentEntry != gfObject:
- action = events.Event ('requestFOCUS', gfObject, _form = _formRef)
- self._eventHandler (action)
-
- adjust = self.widgets.index (lookupWidget) - gfObject._visibleIndex
- if adjust:
- assert gDebug (6, "Adjusting record to %s" % adjust)
- action = events.Event ('requestJUMPRECORD', adjust, _form = _formRef)
- self._eventHandler (action)
-
+ gfObject._event_set_focus(self.widgets.index(lookupWidget))
return False
Deleted: trunk/gnue-forms/src/uidrivers/qt3/common.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt3/common.py 2006-10-18 18:21:05 UTC
(rev 8855)
+++ trunk/gnue-forms/src/uidrivers/qt3/common.py 2006-10-18 20:26:25 UTC
(rev 8856)
@@ -1,204 +0,0 @@
-#
-# This file is part of GNU Enterprise.
-#
-# GNU Enterprise is free software; you can redistribute it
-# and/or modify it under the terms of the GNU General Public
-# License as published by the Free Software Foundation; either
-# version 2, or (at your option) any later version.
-#
-# GNU Enterprise is distributed in the hope that it will be
-# useful, but WITHOUT ANY WARRANTY; without even the implied
-# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-# PURPOSE. See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public
-# License along with program; see the file COPYING. If not,
-# write to the Free Software Foundation, Inc., 59 Temple Place
-# - Suite 330, Boston, MA 02111-1307, USA.
-#
-# Copyright 2000-2006 Free Software Foundation
-#
-# FILE:
-# UIqt.py
-#
-# DESCRIPTION:
-"""
-Common routines for the QT driver
-"""
-# NOTES:
-#
-
-import string
-from qt import *
-from gnue.common import events
-
-# Finishing creation of dictionary for language font encodings
-encodings = {
-#FIX# 'iso8859-1': wxFONTENCODING_ISO8859_1,
-#FIX# 'iso8859-2': wxFONTENCODING_ISO8859_2,
-#FIX# 'iso8859-3': wxFONTENCODING_ISO8859_3,
-#FIX# 'iso8859-4': wxFONTENCODING_ISO8859_4,
-#FIX# 'iso8859-5': wxFONTENCODING_ISO8859_5,
-#FIX# 'iso8859-6': wxFONTENCODING_ISO8859_6,
-#FIX# 'iso8859-7': wxFONTENCODING_ISO8859_7,
-#FIX# 'iso8859-8': wxFONTENCODING_ISO8859_8,
-#FIX# 'iso8859-9': wxFONTENCODING_ISO8859_9,
-#FIX# 'iso8859-10': wxFONTENCODING_ISO8859_10,
-#FIX# 'iso8859-11': wxFONTENCODING_ISO8859_11,
-#FIX# 'iso8859-12': wxFONTENCODING_ISO8859_12,
-#FIX# 'iso8859-13': wxFONTENCODING_ISO8859_13,
-#FIX# 'iso8859-14': wxFONTENCODING_ISO8859_14,
-#FIX# 'iso8859-15': wxFONTENCODING_ISO8859_15,
-#FIX# 'koi8': wxFONTENCODING_KOI8,
-#FIX# 'koi8-r': wxFONTENCODING_KOI8,
-#FIX# 'cp1250': wxFONTENCODING_CP1250,
-#FIX# 'cp1251': wxFONTENCODING_CP1251,
-#FIX# 'cp1252': wxFONTENCODING_CP1252
- '':''
- }
-
-
-
-# TODO: get rid of this call
-def _eventObjToQtWindow(event):
- return event
-
-
-#
-# Little global helper routine to set font according to options
-#
-# TODO: Not completed
-#
-def initFont(widget, affectsLayout=1):
- global _font
- widget.setFont(_font)
-
-def setWidgetBaseFont(font):
- global _font
- _font = font
-
-
-#####################################################################
-##
-## Basic Event Processing
-##
-#####################################################################
-
-def _setDefaultEventHandlers(newWidget, eventHandler, initialize, uiDriver):
- return
-## if initialize:
-## uiBaseEvtHandler(newWidget, eventHandler, uiDriver)
-
-
-##
-##
-##
-class uiBaseEvtHandler:
- def __init__(self, event, uiwidget, qtClass=None):
- self._eventHandler = event.eventHandler
- self._uiwidget = uiwidget
- self._qtClass = qtClass
- self.setFocusPolicy(QWidget.NoFocus)
-
- #
- # Over-ride events
- #
- def keyPressEvent(self, event):
- action = None
-
- uiwidget = self._uiwidget
- gfObject = uiwidget._gfObject
-
- keycode = event.key()
- state = event.state()
- shifted = state & QKeyEvent.ShiftButton
- control = state & QKeyEvent.ControlButton
- alt = state & QKeyEvent.AltButton
-
- # Get the event to process from the KeyMapper
- command, args = GFKeyMapper.KeyMapper.getEvent( keycode, shifted, control,
alt)
-
- if command:
- action = events.Event('request%s' % command, arguments=args)
-
- elif not (control or alt):
- char = "%s" % event.text()
- if char:
- action = events.Event('requestKEYPRESS',
- char, text=char, code=keycode)
-
- if action:
- # Add the object's _form to the outgoing event
- # rather than every event in the function
- action.__dict__.update({'_form':gfObject._form})
- self._eventHandler(action)
-
- #
- # Over-ride events
- #
- def mousePressEvent(self, event):
- uiwidget = self._uiwidget
- gfObject = uiwidget._gfObject
-
- if not self.hasFocus():
- # Request Focus
- self._eventHandler('requestFOCUS',gfObject,_form=gfObject._form)
- count = uiwidget._uiDriver._IdToUIObj[id(self)].widgets.index(self)
- self._eventHandler('requestJUMPRECORD',count -
gfObject._visibleIndex,_form=gfObject._form)
-
- if self._qtClass:
- self._qtClass.mousePressEvent(self, event)
- try:
- self.__cursor = self.cursorPosition()
- selected, start, end = self.getSelection()
- self._eventHandler('requestCURSORMOVE',
- position=self.cursorPosition(),
- _form=gfObject._form)
- if selected:
- self._eventHandler('requestSELECTWITHMOUSE',
- position1=start,
- position2=end,
- _form=gfObject._form)
- except AttributeError:
- pass # Not everything has a cursorPosition()
-
-
- def _selectionChanged(self):
- uiwidget = self._uiwidget
- gfObject = uiwidget._gfObject
- selected, start, end = self.getSelection()
- if selected:
- self._eventHandler('requestSELECTWITHMOUSE',
- position1=start,
- position2=end,
- _form=gfObject._form)
-
-
-
-#####################################################################
-##
-## Keymapper Support
-##
-#####################################################################
-from gnue.forms.input import GFKeyMapper
-from gnue.forms.input.GFKeyMapper import vk
-
-# Translate from QT keystrokes to our virtual keystrokes
-qtKeyTranslations = {
- vk.F1 : Qt.Key_F1, vk.F2 : Qt.Key_F2,
- vk.F3 : Qt.Key_F3, vk.F4 : Qt.Key_F4,
- vk.F5 : Qt.Key_F5, vk.F6 : Qt.Key_F6,
- vk.F7 : Qt.Key_F7, vk.F8 : Qt.Key_F8,
- vk.F9 : Qt.Key_F9, vk.F10 : Qt.Key_F10,
- vk.F11 : Qt.Key_F11, vk.F12 : Qt.Key_F12,
- vk.INSERT : Qt.Key_Insert, vk.DELETE : Qt.Key_Delete,
- vk.HOME : Qt.Key_Home, vk.END : Qt.Key_End,
- vk.PAGEUP : Qt.Key_Prior, vk.PAGEDOWN : Qt.Key_Next,
- vk.UP : Qt.Key_Up, vk.DOWN : Qt.Key_Down,
- vk.LEFT : Qt.Key_Left, vk.RIGHT : Qt.Key_Right,
- vk.TAB : Qt.Key_Tab,
- vk.ENTER : Qt.Key_Return, vk.BACKSPACE : Qt.Key_Backspace }
-
-GFKeyMapper.KeyMapper.setUIKeyMap(qtKeyTranslations)
-
-
Modified: trunk/gnue-forms/src/uidrivers/qt3/widgets/button.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt3/widgets/button.py 2006-10-18
18:21:05 UTC (rev 8855)
+++ trunk/gnue-forms/src/uidrivers/qt3/widgets/button.py 2006-10-18
20:26:25 UTC (rev 8856)
@@ -93,16 +93,12 @@
def __on_clicked(self):
- gfo = self.ui_widget._gfObject
- count = self.ui_widget.widgets.index(self)
- adjust = count - gfo._visibleIndex
-
- if self.ui_widget._form._currentEntry != gfo:
- self.ui_widget._request('FOCUS', data=gfo)
-
- if adjust:
- self.ui_widget._request('JUMPRECORD', data=adjust)
-
+ # FIXME: _event_set_focus only needed if the button was not focussed
+ # before anyway. Maybe use focusInEvent like for entries?
+ # Does the GF focus move to this button correctly if it is only
+ # focussed with the mouse but not clicked?
+ self.ui_widget._gfObject._event_set_focus(self.ui_widget.widgets.index(
+ self))
self.ui_widget._gfObject._event_fire()
Modified: trunk/gnue-forms/src/uidrivers/qt3/widgets/entry.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt3/widgets/entry.py 2006-10-18 18:21:05 UTC
(rev 8855)
+++ trunk/gnue-forms/src/uidrivers/qt3/widgets/entry.py 2006-10-18 20:26:25 UTC
(rev 8856)
@@ -322,35 +322,14 @@
Keep the GF-Focus in sync with the QT3-focus
"""
- gf_object = self.ui_widget._gfObject
- do_focus = gf_object._form._currentEntry != gf_object
+ self._block_focus = True
+ self.ui_widget._gfObject._event_set_focus(self.ui_widget.widgets.index(
+ self.lookup))
+ self._block_focus = False
- count = self.ui_widget.widgets.index(self.lookup)
- adjust = count - gf_object._visibleIndex
-
- if do_focus or adjust:
- self.__focus_worker(do_focus, adjust)
-
self.qt_class.focusInEvent(self, event)
- # -------------------------------------------------------------------------
- # The real focus worker
- # -------------------------------------------------------------------------
-
- def __focus_worker(self, change_focus, adjust):
-
- if change_focus:
- try:
- self._block_focus = True
- self.ui_widget._request('FOCUS', data=self.ui_widget._gfObject)
- finally:
- self._block_focus = False
-
- if adjust:
- self.ui_widget._request('JUMPRECORD', data=adjust)
-
-
# =============================================================================
# Label widgets
# =============================================================================
Modified: trunk/gnue-forms/src/uidrivers/win32/widgets/_base.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/widgets/_base.py 2006-10-18
18:21:05 UTC (rev 8855)
+++ trunk/gnue-forms/src/uidrivers/win32/widgets/_base.py 2006-10-18
20:26:25 UTC (rev 8856)
@@ -99,13 +99,11 @@
# edit control part of the combo box eventhandler
def _wndproc1(self, hwnd, msg, wParam, lParam):
if msg == win32con.WM_LBUTTONDOWN:
+ # TODO: only needed if this widget doesn't have the focus yet
gfObject = self._uiDriver._IdToGFObj[self._id]
uiObject = self._uiDriver._IdToUIObj[self._id]
+ gfObject._event_set_focus(uiObject.widgets.index(self))
- uiObject._eventHandler('requestFOCUS',gfObject,_form=gfObject._form)
- count = uiObject.widgets.index(self)
- uiObject._eventHandler('requestJUMPRECORD',count -
gfObject._visibleIndex,_form=gfObject._form)
-
elif msg == win32con.WM_KEYDOWN:
keycode = wParam
self._AutoComplete = True
@@ -145,10 +143,9 @@
uiObject = self._uiDriver._IdToUIObj[self._id]
if 1: #not self.hasFocus():
- # Request Focus
- uiObject._eventHandler('requestFOCUS',gfObject,_form=gfObject._form)
- count = uiObject.widgets.index(self)
- uiObject._eventHandler('requestJUMPRECORD',count -
gfObject._visibleIndex,_form=gfObject._form)
+ # Request Focus
+ # TODO: only needed if this widget doesn't have the focus yet
+ gfObject._event_set_focus(uiObject.widgets.index(self))
if gfObject._type == 'GFButton':
self.SetFocus()
Modified: trunk/gnue-forms/src/uidrivers/wx/common.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx/common.py 2006-10-18 18:21:05 UTC (rev
8855)
+++ trunk/gnue-forms/src/uidrivers/wx/common.py 2006-10-18 20:26:25 UTC (rev
8856)
@@ -194,8 +194,7 @@
count = self._uiDriver._IdToUIObj[id].widgets.index(screenWidget)
if event.GetTimestamp():
- self._eventProcessor('requestFOCUS',gfObject,_form=gfObject._form)
- self._eventProcessor('requestJUMPRECORD',count -
gfObject._visibleIndex,_form=gfObject._form)
+ gfObject._event_set_focus(count)
if isinstance(screenWidget,wxTextCtrl):
event.SetTimestamp(0)
Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/button.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/button.py 2006-10-18
18:21:05 UTC (rev 8855)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/button.py 2006-10-18
20:26:25 UTC (rev 8856)
@@ -104,15 +104,7 @@
def __on_set_focus (self, event):
lookup = event.GetEventObject()
- count = self.widgets.index(lookup)
- adjust = count - self._gfObject._visibleIndex
-
- if self._form._currentEntry != self._gfObject:
- self._request('FOCUS', data=self._gfObject)
-
- if adjust:
- self._request('JUMPRECORD', data=adjust)
-
+ self._gfObject._event_set_focus(self.widgets.index(lookup))
event.Skip()
Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py 2006-10-18
18:21:05 UTC (rev 8855)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py 2006-10-18
20:26:25 UTC (rev 8856)
@@ -250,22 +250,11 @@
def __on_set_focus(self, event):
- do_focus = (self._gfObject._form._currentEntry != self._gfObject)
-
- # adjust the record number if necessary
+ # Let the GF focus follow
lookup = event.GetEventObject()
if 'wxMac' in wx.PlatformInfo and self._gfObject.style == 'dropdown':
lookup = lookup.GetParent()
-
- count = self.widgets.index(lookup)
- adjust = count - self._gfObject._visibleIndex
-
- if do_focus:
- self._request('FOCUS', data=self._gfObject)
-
- if adjust:
- self._request('JUMPRECORD', data=adjust)
-
+ self._gfObject._event_set_focus(self.widgets.index(lookup))
event.Skip()
# -------------------------------------------------------------------------
@@ -443,15 +432,6 @@
# -------------------------------------------------------------------------
- # On lose of the focus we un-select ComboBox-Entries
- # -------------------------------------------------------------------------
-
- def _ui_lose_focus_(self, index):
-
- _base.UIHelper._ui_lose_focus_(self, index)
-
-
- # -------------------------------------------------------------------------
# Set the value of a widget
# -------------------------------------------------------------------------
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r8856 - in trunk/gnue-forms/src: . GFObjects uidrivers/gtk2/widgets uidrivers/qt3 uidrivers/qt3/widgets uidrivers/win32/widgets uidrivers/wx uidrivers/wx26/widgets,
reinhard <=