commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnue] r8811 - trunk/gnue-forms/src/uidrivers/qt3/widgets


From: johannes
Subject: [gnue] r8811 - trunk/gnue-forms/src/uidrivers/qt3/widgets
Date: Tue, 17 Oct 2006 08:00:48 -0500 (CDT)

Author: johannes
Date: 2006-10-17 08:00:47 -0500 (Tue, 17 Oct 2006)
New Revision: 8811

Modified:
   trunk/gnue-forms/src/uidrivers/qt3/widgets/entry.py
Log:
Focus-Handling and cursor positioning


Modified: trunk/gnue-forms/src/uidrivers/qt3/widgets/entry.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt3/widgets/entry.py 2006-10-17 10:11:19 UTC 
(rev 8810)
+++ trunk/gnue-forms/src/uidrivers/qt3/widgets/entry.py 2006-10-17 13:00:47 UTC 
(rev 8811)
@@ -141,10 +141,9 @@
         """
 
         widget = self.widgets[index]
-        if isinstance(widget, MultiLineEdit):
-            widget.setCursorPosition(0, position)
-        elif hasattr(widget, 'setCursorPosition'):
-            widget.setCursorPosition(position)
+        method = getattr(widget, '_ui_set_cursor_position_', None)
+        if method:
+            method(position)
 
     # -------------------------------------------------------------------------
 
@@ -158,10 +157,9 @@
         """
         widget = self.widgets[index]
 
-        if isinstance(widget, MultiLineEdit):
-            widget.setSelectedArea(0, selection1, 0, selection2)
-        elif hasattr(widget, 'setSelection'):
-            widget.setSelection(selection1, selection2-selection1)
+        method = getattr(widget, '_ui_set_selected_area_', None)
+        if method:
+            method(selection1, selection2)
 
 
 # =============================================================================
@@ -177,9 +175,27 @@
     def __init__(self, ui_widget, qt_class):
         self.ui_widget = ui_widget
         self.qt_class = qt_class
+        self.lookup = self
 
 
     # -------------------------------------------------------------------------
+    # User-Feedback methods
+    # -------------------------------------------------------------------------
+
+    def _ui_set_cursor_position_(self, position):
+
+        if hasattr(self, 'setCursorPosition'):
+            self.setCursorPosition(position)
+
+    # -------------------------------------------------------------------------
+
+    def _ui_set_selected_area_(self, selection1, selection2):
+
+        if hasattr(self, 'setSelection'):
+            self.setSelection(selection1, selection2-selection1)
+
+
+    # -------------------------------------------------------------------------
     # Event-Handler
     # -------------------------------------------------------------------------
 
@@ -223,7 +239,7 @@
         gf_object = self.ui_widget._gfObject
         do_focus = gf_object._form._currentEntry != gf_object
 
-        count = self.ui_widget.widgets.index(self)
+        count = self.ui_widget.widgets.index(self.lookup)
         adjust = count - gf_object._visibleIndex
 
         if do_focus or adjust:
@@ -232,6 +248,10 @@
         self.qt_class.focusInEvent(self, event)
 
 
+    # -------------------------------------------------------------------------
+    # The real focus worker
+    # -------------------------------------------------------------------------
+
     def __focus_worker(self, change_focus, adjust):
 
         if change_focus:
@@ -245,8 +265,6 @@
             self.ui_widget._request('JUMPRECORD', data=adjust)
 
 
-
-
 # =============================================================================
 # LineEdit widgets
 # =============================================================================
@@ -267,7 +285,30 @@
         if password:
             self.setEchoMode(qt.QLineEdit.Password)
 
+
     # -------------------------------------------------------------------------
+    # Release of a mouse button
+    # -------------------------------------------------------------------------
+
+    def mouseReleaseEvent(self, event):
+        """
+        After releasing the left mouse button, make sure to update the
+        insertion point on the GF layer.
+        """
+
+        self.qt_class.mouseReleaseEvent(self, event)
+
+        if event.button() == qt.Qt.LeftButton:
+            left = self.cursorPosition()
+            if self.hasSelectedText():
+                right = left + len(self.selectedText()) - 1
+                self.ui_widget._request('SELECTWITHMOUSE', position1=left,
+                        position2=right)
+            else:
+                self.ui_widget._request('CURSORMOVE', position=left)
+
+
+    # -------------------------------------------------------------------------
     # UI-Slots
     # -------------------------------------------------------------------------
 
@@ -297,8 +338,22 @@
         # TODO: check for newlines (and paragraph handling)
         self.setText(value)
 
+    # -------------------------------------------------------------------------
 
+    def _ui_set_cursor_position_(self, position):
 
+        # TODO: what about other paragraphs ?
+        self.setCursorPosition(0, position)
+
+    # -------------------------------------------------------------------------
+
+    def _ui_set_selected_area_(self, selection1, selection2):
+
+        self.setSelectedArea(0, selection1, 0, selection2)
+
+
+
+
 # =============================================================================
 # Checkbox (TriState)
 # =============================================================================
@@ -453,6 +508,13 @@
 
         qt.QComboBox.__init__(self, True, parent)
         ChoiceEntry.__init__(self, ui_widget, qt.QComboBox)
+
+        self.setDuplicatesEnabled(False)
+
+        self.__lineEdit = LineEdit(parent, ui_widget)
+        self.__lineEdit.lookup = self
+        self.setLineEdit(self.__lineEdit)
+
         self.update_choices()
 
         self.connect(self, qt.SIGNAL('activated(int)'), self.__on_activated)
@@ -485,7 +547,19 @@
         self.update_choices()
         self.setCurrentText(value)
 
+    # -------------------------------------------------------------------------
 
+    def _ui_set_cursor_position_(self, position):
+
+        self.lineEdit().setCursorPosition(position)
+
+    # -------------------------------------------------------------------------
+
+    def _ui_set_selected_area_(self, position1, position2):
+
+        self.lineEdit().setSelection(position1, position2-position1)
+
+
 # =============================================================================
 # Listbox widgets
 # =============================================================================





reply via email to

[Prev in Thread] Current Thread [Next in Thread]