commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r8771 - in trunk/gnue-forms/src/uidrivers/qt3: . widgets


From: johannes
Subject: [gnue] r8771 - in trunk/gnue-forms/src/uidrivers/qt3: . widgets
Date: Thu, 12 Oct 2006 08:50:49 -0500 (CDT)

Author: johannes
Date: 2006-10-12 08:50:48 -0500 (Thu, 12 Oct 2006)
New Revision: 8771

Modified:
   trunk/gnue-forms/src/uidrivers/qt3/dialogs.py
   trunk/gnue-forms/src/uidrivers/qt3/widgets/_base.py
   trunk/gnue-forms/src/uidrivers/qt3/widgets/entry.py
   trunk/gnue-forms/src/uidrivers/qt3/widgets/form.py
Log:
Fixed inputDialogs (widget names might not be unicode), fixed 
_ui_show_message_, added checkbox


Modified: trunk/gnue-forms/src/uidrivers/qt3/dialogs.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt3/dialogs.py       2006-10-12 12:34:46 UTC 
(rev 8770)
+++ trunk/gnue-forms/src/uidrivers/qt3/dialogs.py       2006-10-12 13:50:48 UTC 
(rev 8771)
@@ -136,7 +136,7 @@
 
     def __init__(self, name, default, elements, password, ddict, parent):
 
-        qt.QLineEdit.__init__(self, default or '', parent, name)
+        qt.QLineEdit.__init__(self, default or '', parent, str(name))
 
         if password:
             self.setEchoMode(qt.QLineEdit.Password)
@@ -189,7 +189,7 @@
 
     def __init__(self, name, master, allowed, default, tip, ddict, parent):
 
-        qt.QComboBox.__init__(self, False, parent, name)
+        qt.QComboBox.__init__(self, False, parent, str(name))
 
         self.ddict = ddict
         self._master  = master
@@ -535,22 +535,22 @@
 
     fields = [('Foo!', '/home/johannes/gnue/share/gnue/images/gnue.png', 
'image',
              None, None, []),
-            ('Username', '_username', 'string', None, None, \
+            ('Username', u'_username', 'string', None, None, \
               [('Name of the user', None)]),
-            ('Password', '_password', 'password', 'foo', None, [('yeah',1)]),
-            ('Foobar', '_foobar', 'dropdown', 'frob', None, \
+            ('Password', u'_password', 'password', 'foo', None, [('yeah',1)]),
+            ('Foobar', u'_foobar', 'dropdown', 'frob', None, \
                 [('single', {'trash': 'Da Trash', 'frob': 'Frob'})]),
-            ('Multi', '_multi', 'dropdown', '100', None, \
+            ('Multi', u'_multi', 'dropdown', '100', None, \
                 [('name', {'50': 'A 50', '100': 'B 100', '9': 'C 9'}),
                 ('sepp', {'50': 'se 50', '100': 'se 100', '9': 'se 9'})]),
-            ('Noe', '_depp', 'label', 'furz', None, []),
+            ('Noe', u'_depp', 'label', 'furz', None, []),
             ('Das ist jetzt ein Fehler', None, 'warning', None, None, []),
 
-            ('Firma', 'company', 'dropdown', 'c1', None,
+            ('Firma', u'company', 'dropdown', 'c1', None,
                 [('Name', cname), ('Code', ckey)]),
-            ('Wirtschaftsjahr', 'wija', 'dropdown', '05', 'company',
+            ('Wirtschaftsjahr', u'wija', 'dropdown', '05', 'company',
                 [('Jahr', wija)]),
-            ('Codes', 'codes', 'dropdown', None, 'wija',
+            ('Codes', u'codes', 'dropdown', None, 'wija',
                 [('Code', codes)])
                 ]
 

Modified: trunk/gnue-forms/src/uidrivers/qt3/widgets/_base.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt3/widgets/_base.py 2006-10-12 12:34:46 UTC 
(rev 8770)
+++ trunk/gnue-forms/src/uidrivers/qt3/widgets/_base.py 2006-10-12 13:50:48 UTC 
(rev 8771)
@@ -67,39 +67,3 @@
         @param index: the index of the qt widget to kill the focus for
         """
         pass
-
-
-    def _ui_set_value_(self, index, value):
-        # These must be here or dropdown style controls
-        # will get events they shouldn't and break.
-        widget = self.widgets[index]
-
-        # Check if foreign key changed
-        object = self._uiDriver._IdToGFObj[id(widget)]
-        try:
-          if object.style == "dropdown" and \
-              not object._field._allowedValues == widget._origAllowedValues:
-            widget._origAllowedValues = object._field._allowedValues
-            widget.clear()
-            for value in object._field._allowedValuesDescr:
-              widget.insertString(value)
-        except AttributeError:
-          pass
-
-        if object.style == "checkbox":
-          widget.setChecked(value)
-        else:
-          widget.setText(value)
-
-
-    def _ui_set_cursor_position_(self, index, position):
-        try:
-          self.widgets[index].set_cursor_position(position)
-        except AttributeError:
-          pass  # For label-style entries
-
-    def _ui_set_selected_area_(self, index, selection1, selection2):
-        try:
-          self.widgets[index].setSelection(selection1, selection2-selection1)
-        except (AttributeError, TypeError):
-          pass  # For label-style & dropdown entries

Modified: trunk/gnue-forms/src/uidrivers/qt3/widgets/entry.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt3/widgets/entry.py 2006-10-12 12:34:46 UTC 
(rev 8770)
+++ trunk/gnue-forms/src/uidrivers/qt3/widgets/entry.py 2006-10-12 13:50:48 UTC 
(rev 8771)
@@ -83,8 +83,15 @@
         ctrl = qt.QLabel(parent)
         return (None, ctrl)
 
+    # -------------------------------------------------------------------------
 
+    def __build_checkbox(self, parent):
+        
+        result = CheckBox(parent, self)
+        return (None, result)
 
+
+
     # -------------------------------------------------------------------------
     # Enable/disable this entry
     # -------------------------------------------------------------------------
@@ -105,8 +112,13 @@
         """
 
         widget = self.widgets[index]
-        widget.setText(value)
 
+        method = getattr(widget, '_ui_set_value_', None)
+        if method:
+            method(value)
+        else:
+            widget.setText(value)
+
     # -------------------------------------------------------------------------
 
     def _ui_set_cursor_position_(self, index, position):
@@ -118,9 +130,29 @@
         """
 
         widget = self.widgets[index]
-        widget.setCursorPosition(position)
+        if isinstance(widget, MultiLineEdit):
+            widget.setCursorPosition(0, position)
+        elif hasattr(widget, 'setCursorPosition'):
+            widget.setCursorPosition(position)
 
+    # -------------------------------------------------------------------------
 
+    def _ui_set_selected_area_(self, index, selection1, selection2):
+        """
+        Sets the selection start/end inside a capable widget.
+
+        @param selection1: start position of the selection
+        @param selection2: end position of the selection
+        @param index: index of the widget to be changed
+        """
+        widget = self.widgets[index]
+
+        if isinstance(widget, MultiLineEdit):
+            widget.setSelectedArea(0, selection1, 0, selection2)
+        else:
+            widget.setSelection(selection1, selection2-selection1)
+
+
 # =============================================================================
 # Base class for entry widgets
 # =============================================================================
@@ -135,6 +167,7 @@
         self.ui_widget = ui_widget
         self.qt_class = qt_class
 
+
     # -------------------------------------------------------------------------
     # Event-Handler
     # -------------------------------------------------------------------------
@@ -149,9 +182,9 @@
         state = event.state()
 
         (command, args) = GFKeyMapper.KeyMapper.getEvent(keycode,
-                state & qt.QKeyEvent.ShiftButton,
-                state & qt.QKeyEvent.ControlButton,
-                state & qt.QKeyEvent.AltButton)
+                state & qt.QKeyEvent.ShiftButton > 0,
+                state & qt.QKeyEvent.ControlButton > 0,
+                state & qt.QKeyEvent.AltButton > 0)
 
         if command:
             if command == 'NEWLINE':
@@ -186,6 +219,7 @@
 
         if not do_focus:
             self.qt_class.mousePressEvent(self, event)
+            # TODO: update the insertion point after moving the cursor
 
 
 
@@ -219,8 +253,36 @@
         qt.QLineEdit.__init__(self, parent)
         BaseEntry.__init__(self, ui_widget, qt.QTextEdit)
 
+        self.setTextFormat(qt.Qt.PlainText)
 
+
 # =============================================================================
+# Checkbox (TriState)
+# =============================================================================
+
+class CheckBox(BaseEntry, qt.QCheckBox):
+
+    def __init__(self, parent, ui_widget):
+
+        qt.QCheckBox.__init__(self, parent)
+        BaseEntry.__init__(self, ui_widget, qt.QCheckBox)
+        self.setTristate(True)
+
+        self.connect(self, qt.SIGNAL('toggled(bool)'), self.__on_toggled)
+
+    def _ui_set_value_(self, value):
+        if value is None:
+            self.setState(qt.QButton.NoChange)
+        elif value:
+            self.setState(qt.QButton.On)
+        else:
+            self.setState(qt.QButton.Off)
+
+    def __on_toggled(self, state):
+        self.ui_widget._request('TOGGLECHKBOX')
+
+
+# =============================================================================
 # Keymapper configuration: Translate from QT to our virtual keystrokes
 # =============================================================================
 

Modified: trunk/gnue-forms/src/uidrivers/qt3/widgets/form.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt3/widgets/form.py  2006-10-12 12:34:46 UTC 
(rev 8770)
+++ trunk/gnue-forms/src/uidrivers/qt3/widgets/form.py  2006-10-12 13:50:48 UTC 
(rev 8771)
@@ -36,6 +36,7 @@
 
 class UIForm(UIHelper):
     """
+    Implementation of the <form> and <dialog> tag
     """
 
     _TAB_STYLE = {'left': qt.QTabWidget.Top,
@@ -44,13 +45,18 @@
                   'bottom': qt.QTabWidget.Bottom}
 
     _MBOX_KIND = {'Info'    : {'style': qt.QMessageBox.information,
-                               'title': u_("Information")},
+                               'title': u_("Information"),
+                               'btns' : [qt.QMessageBox.Ok]},
                   'Warning' : {'style': qt.QMessageBox.warning,
-                               'title': u_("Warning")},
+                               'title': u_("Warning"),
+                               'btns' : [qt.QMessageBox.Ok]},
                   'Question': {'style': qt.QMessageBox.question,
-                               'title': u_("Question")},
+                               'title': u_("Question"),
+                               'btns' : [qt.QMessageBox.Yes,
+                                         qt.QMessageBox.No]},
                   'Error'   : {'style': qt.QMessageBox.critical,
-                               'title': u_("Error")}}
+                               'title': u_("Error"),
+                               'btns' : [qt.QMessageBox.Ok]}}
 
     # -------------------------------------------------------------------------
     # Constructor
@@ -284,12 +290,24 @@
             the No-button was pressed or None if the Cancel-button was pressed.
         """
 
-        boxClass = _MBOX_KIND[kind]['style']
+        boxClass = self._MBOX_KIND[kind]['style']
+        buttons = self._MBOX_KIND[kind]['btns'][:]
+        if cancel:
+            buttons.append(qt.QMessageBox.Cancel)
 
+        while len(buttons) < 3:
+            buttons.append(qt.QMessageBox.NoButton)
+
         if title is None:
-            title = _MBOX_KIND[kind]['title']
+            title = self._MBOX_KIND[kind]['title']
 
-        result = boxClass(None, title, message)
+        result = boxClass(None, title, message, *buttons)
+        if result in [qt.QMessageBox.Cancel, qt.QMessageBox.NoButton]:
+            return None
+        elif result in [qt.QMessageBox.Ok, qt.QMessageBox.Yes]:
+            return True
+        else:
+            return False
 
     # -------------------------------------------------------------------------
 





reply via email to

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