[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r8779 - trunk/gnue-forms/src/uidrivers/qt3/widgets
From: |
johannes |
Subject: |
[gnue] r8779 - trunk/gnue-forms/src/uidrivers/qt3/widgets |
Date: |
Fri, 13 Oct 2006 03:37:48 -0500 (CDT) |
Author: johannes
Date: 2006-10-13 03:37:47 -0500 (Fri, 13 Oct 2006)
New Revision: 8779
Modified:
trunk/gnue-forms/src/uidrivers/qt3/widgets/entry.py
Log:
Added Dropdown widgets
Modified: trunk/gnue-forms/src/uidrivers/qt3/widgets/entry.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt3/widgets/entry.py 2006-10-13 07:28:15 UTC
(rev 8778)
+++ trunk/gnue-forms/src/uidrivers/qt3/widgets/entry.py 2006-10-13 08:37:47 UTC
(rev 8779)
@@ -90,8 +90,14 @@
result = CheckBox(parent, self)
return (None, result)
+ # -------------------------------------------------------------------------
+ def __build_dropdown(self, parent):
+ result = ComboBox(parent, self)
+ return (None, result)
+
+
# -------------------------------------------------------------------------
# Enable/disable this entry
# -------------------------------------------------------------------------
@@ -116,8 +122,6 @@
method = getattr(widget, '_ui_set_value_', None)
if method:
method(value)
- else:
- widget.setText(value)
# -------------------------------------------------------------------------
@@ -149,7 +153,7 @@
if isinstance(widget, MultiLineEdit):
widget.setSelectedArea(0, selection1, 0, selection2)
- else:
+ elif hasattr(widget, 'setSelection'):
widget.setSelection(selection1, selection2-selection1)
@@ -243,6 +247,15 @@
if password:
self.setEchoMode(qt.QLineEdit.Password)
+ # -------------------------------------------------------------------------
+ # UI-Slots
+ # -------------------------------------------------------------------------
+
+ def _ui_set_value_(self, value):
+
+ self.setText(value)
+
+
# =============================================================================
# Multiline text entry widget
# =============================================================================
@@ -255,13 +268,30 @@
self.setTextFormat(qt.Qt.PlainText)
+ # -------------------------------------------------------------------------
+ # UI slots
+ # -------------------------------------------------------------------------
+ def _ui_set_value_(self, value):
+
+ # TODO: check for newlines (and paragraph handling)
+ self.setText(value)
+
+
+
# =============================================================================
# Checkbox (TriState)
# =============================================================================
class CheckBox(BaseEntry, qt.QCheckBox):
+ """
+ Implementation of a Tri-State-Checkbox
+ """
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
def __init__(self, parent, ui_widget):
qt.QCheckBox.__init__(self, parent)
@@ -270,7 +300,22 @@
self.connect(self, qt.SIGNAL('toggled(bool)'), self.__on_toggled)
+
+ # -------------------------------------------------------------------------
+ # Event-Handler
+ # -------------------------------------------------------------------------
+
+ def __on_toggled(self, state):
+
+ self.ui_widget._request('TOGGLECHKBOX')
+
+
+ # -------------------------------------------------------------------------
+ # UI-Slots
+ # -------------------------------------------------------------------------
+
def _ui_set_value_(self, value):
+
if value is None:
self.setState(qt.QButton.NoChange)
elif value:
@@ -278,11 +323,145 @@
else:
self.setState(qt.QButton.Off)
- def __on_toggled(self, state):
- self.ui_widget._request('TOGGLECHKBOX')
+# =============================================================================
+# Base class for widgets having a set of allowed values
+# =============================================================================
+class ChoiceEntry(BaseEntry):
+ """
+ """
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__(self, ui_widget, qt_class):
+
+ BaseEntry.__init__(self, ui_widget, qt_class)
+
+ self.ui_widget = ui_widget
+ self.qt_class = qt_class
+ self.__last_choices = None
+
+ # -------------------------------------------------------------------------
+ # Check the list of choices against the bound field
+ # -------------------------------------------------------------------------
+
+ def update_choices(self):
+ """
+ Check wether an update of the available choices is needed.
+ """
+ field = self.ui_widget._gfObject._field
+ if self.__last_choices != field._allowedValues:
+ self._freeze_()
+ try:
+ choices = field._allowedValuesReverse.keys()
+ choices.sort()
+
+ self._clear_()
+
+ for dsc in choices:
+ self._append_(field._allowedValuesReverse[dsc], dsc)
+
+ self.__last_choices = field._allowedValues
+
+ finally:
+ self._thaw_()
+
+ # -------------------------------------------------------------------------
+ # Virtual methods
+ # -------------------------------------------------------------------------
+
+ def _freeze_(self):
+ """
+ Descendants can override this method to freeze widget updates while
+ changing the choices
+ """
+ pass
+
+ # -------------------------------------------------------------------------
+
+ def _thaw_(self):
+ """
+ Descendants can override this method to enable widget update after
+ changing the choices
+ """
+ pass
+
+ # -------------------------------------------------------------------------
+
+ def _clear_(self):
+ """
+ Descendants must implement this method to clear it's list of choices
+ """
+ raise NotImplementedError
+
+ # -------------------------------------------------------------------------
+
+ def _append_(self, key, description):
+ """
+ Descendants must implement this method to add an item to the widget
+
+ @param key: the key of the item to be added
+ @param description: the full text to be shown in the widget
+ """
+ raise NotImplementedError
+
+
+
# =============================================================================
+# Dropdown widgets
+# =============================================================================
+
+class ComboBox(ChoiceEntry, qt.QComboBox):
+ """
+ Dropdown widgets
+ """
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__(self, parent, ui_widget):
+
+ qt.QComboBox.__init__(self, True, parent)
+ ChoiceEntry.__init__(self, ui_widget, qt.QComboBox)
+ self.update_choices()
+
+ self.connect(self, qt.SIGNAL('activated(int)'), self.__on_activated)
+
+
+ # -------------------------------------------------------------------------
+ # Event-Handler
+ # -------------------------------------------------------------------------
+
+ def __on_activated(self, item_index):
+ self.ui_widget._request('REPLACEVALUE',
+ text=unicode(self.currentText()))
+
+
+ # -------------------------------------------------------------------------
+ # Implementation of virtual methods
+ # -------------------------------------------------------------------------
+
+ def _clear_(self):
+ self.clear()
+
+ # -------------------------------------------------------------------------
+
+ def _append_(self, key, description):
+ self.insertItem(description)
+
+ # -------------------------------------------------------------------------
+
+ def _ui_set_value_(self, value):
+ self.update_choices()
+ self.setCurrentText(value)
+
+
+
+# =============================================================================
# Keymapper configuration: Translate from QT to our virtual keystrokes
# =============================================================================
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r8779 - trunk/gnue-forms/src/uidrivers/qt3/widgets,
johannes <=