commit-gnue
[Top][All Lists]
Advanced

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

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


From: johannes
Subject: [gnue] r8770 - in trunk/gnue-forms/src/uidrivers/qt3: . widgets
Date: Thu, 12 Oct 2006 07:34:47 -0500 (CDT)

Author: johannes
Date: 2006-10-12 07:34:46 -0500 (Thu, 12 Oct 2006)
New Revision: 8770

Modified:
   trunk/gnue-forms/src/uidrivers/qt3/UIdriver.py
   trunk/gnue-forms/src/uidrivers/qt3/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/qt3/widgets/form.py
Log:
Added Buttons, started with entries


Modified: trunk/gnue-forms/src/uidrivers/qt3/UIdriver.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt3/UIdriver.py      2006-10-12 12:27:04 UTC 
(rev 8769)
+++ trunk/gnue-forms/src/uidrivers/qt3/UIdriver.py      2006-10-12 12:34:46 UTC 
(rev 8770)
@@ -24,37 +24,31 @@
 A pyQT based user interface driver for GNUe forms.
 """
 
-import sys
 import os.path
 
 from gnue.forms.uidrivers._base import Exceptions
 
 try:
-  from qt import *
+    import qt
+
 except ImportError:
-  raise Exceptions.DriverNotSupported, \
-          _("The GNUe-Forms QT3 driver requires PyQT.")
+    raise Exceptions.DriverNotSupported, \
+            u_("The GNUe-Forms QT3 driver requires PyQT.")
 
-from gnue.common import events
 from gnue.common.apps import GConfig
-from gnue.common.utils.TextUtils import lineWrap
-
-from gnue.forms import VERSION
-from gnue.forms.GFForm import *
 from gnue.forms.uidrivers._commonGuiToolkit import UIdriver as commonToolkit
-
 from gnue.forms.uidrivers.qt3.QTApp import *
-from gnue.forms.uidrivers.qt3.widgets._base  import *
-from gnue.forms.uidrivers.qt3.common import _eventObjToQtWindow, 
setWidgetBaseFont
-from common import *
-
 from gnue.forms.uidrivers.qt3 import dialogs
 
+
 # =============================================================================
 # Splash Screen
 # =============================================================================
 
-class UISplashScreen(QMainWindow):
+class UISplashScreen(qt.QMainWindow):
+    """
+    Splash screen window
+    """
 
     # -------------------------------------------------------------------------
     # Constructor
@@ -62,16 +56,16 @@
 
     def __init__(self):
 
-        QMainWindow.__init__(self, None, 'GNUeSplash', Qt.WStyle_Splash |
-                Qt.WStyle_StaysOnTop)
+        qt.QMainWindow.__init__(self, None, 'GNUeSplash', qt.Qt.WStyle_Splash |
+                qt.Qt.WStyle_StaysOnTop)
 
         idir = GConfig.getInstalledBase('forms_images', 'common_images')
         picture = gConfigForms ('splashScreenPNG')
         if not os.path.isabs(picture):
             picture = os.path.join (idir, picture)
 
-        image = QLabel('', self)
-        image.setPixmap(QPixmap(picture))
+        image = qt.QLabel('', self)
+        image.setPixmap(qt.QPixmap(picture))
 
         self.setCentralWidget(image)
         self.show()
@@ -96,7 +90,11 @@
                               disableSplash, parentContainer, moduleName)
         self.__splash = None
 
+        # We don't need these values for this ui driver
+        self.textWidth = self.widgetWidth = -1
+        self.textHeight = self.widgetHeight = -1
 
+
     # -------------------------------------------------------------------------
     # Initialize user interface
     # -------------------------------------------------------------------------
@@ -112,41 +110,8 @@
 
         self._disabledColour = None
         self._qtapp = getQtApp()
-        fdb = QFontDatabase()
 
-        font = QFont("Courier 10 Pitch", int(gConfigForms('pointSize')))
-        font.setFixedPitch(True)
 
-        font.setPointSize(int(gConfigForms('pointSize')))
-        setWidgetBaseFont(font)
-
-
-        fm = QFontMetrics(font)
-        # TODO: Making some assumptions here!!
-        maxWidth=0
-        checkchars = string.printable
-        for letter in checkchars:
-            width = fm.width("W")
-            maxWidth = max(maxWidth,width)
-
-        print "Max Width = ", maxWidth, fm.width("i")
-        #maxWidth=fm.width("W")
-        maxHeight = fm.height()
-        maxDescent = fm.descent()
-        maxLeading = fm.leading()
-
-        # The pixel width of text inside a widget
-        self.textWidth = int(maxWidth+maxLeading)
-    
-        # The pixel height of text inside a widget
-        self.textHeight = int(maxHeight+maxDescent)
-    
-        # The pixel width of a 1 char widget (for things like buttons)
-        self.widgetWidth = self.textWidth
-    
-        # The pixel height of a 1 char widget (for things like buttons)
-        self.widgetHeight = self.textHeight + 4
-
     # -------------------------------------------------------------------------
     # Start the application's main loop
     # -------------------------------------------------------------------------
@@ -200,7 +165,7 @@
     def _ui_show_error_(self, message):
 
         self.hide_splash()
-        QMessageBox.critical(None, "GNU Enterprise", message)
+        qt.QMessageBox.critical(None, "GNU Enterprise", message)
 
 
     # -------------------------------------------------------------------------

Modified: trunk/gnue-forms/src/uidrivers/qt3/widgets/_base.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt3/widgets/_base.py 2006-10-12 12:27:04 UTC 
(rev 8769)
+++ trunk/gnue-forms/src/uidrivers/qt3/widgets/_base.py 2006-10-12 12:34:46 UTC 
(rev 8770)
@@ -25,6 +25,7 @@
 
 from gnue.forms.uidrivers._base.widgets._base import UIWidget
 
+__all__ = ['UIHelper']
 
 # =============================================================================
 # Base class for all qt3 UI widgets 
@@ -32,6 +33,7 @@
 
 class UIHelper(UIWidget):
     """
+    Implements the common behaviour of qt3 UI widgets
     """
 
     # -------------------------------------------------------------------------
@@ -45,7 +47,11 @@
 
         @param index: the index of the qt widget to set the focus to
         """
-        self.widgets[index].setFocus()
+        widget = self.widgets[index]
+        if widget:
+            widget.setFocus()
+        else:
+            print "** MISSING widget?", self._gfObject.name, index
 
 
     # -------------------------------------------------------------------------

Modified: trunk/gnue-forms/src/uidrivers/qt3/widgets/button.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt3/widgets/button.py        2006-10-12 
12:27:04 UTC (rev 8769)
+++ trunk/gnue-forms/src/uidrivers/qt3/widgets/button.py        2006-10-12 
12:34:46 UTC (rev 8770)
@@ -1,6 +1,9 @@
+# GNU Enterprise Forms - QT3 UI driver - Buttons
 #
-# This file is part of GNU Enterprise.
+# Copyright 2001-2006 Free Software Foundation
 #
+# 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
@@ -16,82 +19,99 @@
 # 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:
-# A QT-based user interface driver for GNUe forms.
-#
-# NOTES:
-#
-from qt import *
+# $Id$
 
-from gnue.common import events
-from gnue.forms.uidrivers.qt3.common import uiBaseEvtHandler as _Base
-from gnue.forms.uidrivers.qt3.common import _eventObjToQtWindow
+import qt
+
 from gnue.forms.uidrivers.qt3.widgets._base import UIHelper
 
-#
-# UIButton
-#
-# Widget set specific function that creates a single instance of a button
-#
+__all__ = ['UIButton']
+
+# =============================================================================
+# Implementation of the <button> tag
+# =============================================================================
+
 class UIButton(UIHelper):
-  def _create_widget(self, event, spacer):
-    object = event.object
+    """
+    Implementation of the <button> tag
+    """
 
-    # Create a button..
-    newWidget = _Button(event, self)
+    # -------------------------------------------------------------------------
+    # Create the button widget
+    # -------------------------------------------------------------------------
 
-    # .. set the label text..
-    newWidget.setText(object.label)
+    def _create_widget_(self, event, spacer):
+        """
+        Create the button widget
+        """
 
-    # .. the examples had this, so we do to ..  :)
-    newWidget.setAutoDefault(1)
+        parent = event.container
 
-    # ..and move it to it's proper place
-    newWidget.setGeometry(object.Char__x*event.widgetWidth,
-                          
(object.Char__y+spacer+(spacer*object._gap))*event.widgetHeight,
-                          self.itemWidth,self.itemHeight)
+        self.widget = Button(parent, self)
+        self.getParent().add_widgets(self, spacer)
 
-    # Attach the events to our button, and we can all go home...
-    if event.initialize:
-      self._eventHandler = event.eventHandler
-      QObject.connect(newWidget, SIGNAL("clicked()"), self.buttonHandler)
-      #QObject.connect(newWidget, PYSIGNAL("sigClicked"), self.buttonHandler)
+        return self.widget
 
 
-    return newWidget
+    # -------------------------------------------------------------------------
+    # Enable/disable this button
+    # -------------------------------------------------------------------------
 
-  #
-  #
-  def buttonHandler(self):
-    self._gfObject._event_fire()
+    def _ui_enable_(self, index):
+        self.widgets[index].setEnabled(True)
 
+    # -------------------------------------------------------------------------
 
-  # -------------------------------------------------------------------------
-  # Enable/disable this button
-  # -------------------------------------------------------------------------
+    def _ui_disable_(self, index):
+        self.widgets[index].setEnabled(False)
 
-  def _ui_enable_(self, index):
-      self.widgets[index].setEnabled(True)
 
-  # -------------------------------------------------------------------------
+# =============================================================================
+# QT Button class 
+# =============================================================================
 
-  def _ui_disable_(self, index):
-      self.widgets[index].setEnabled(False)
+class Button(qt.QPushButton):
+    """
+    Descendant of a qt.QPushButton which implements the clicked event to fire
+    the corresponding even of the GFButton instance
+    """
 
+    # -------------------------------------------------------------------------
+    # Constructor
+    # -------------------------------------------------------------------------
 
-class _Button(_Base, QPushButton):
-  def __init__(self, event, *args):
-    QPushButton.__init__(self, event.container,'button%s' % id(self))
-    _Base.__init__(self, event, qtClass=QPushButton, *args)
+    def __init__(self, parent, ui_widget):
 
+        qt.QPushButton.__init__(self, ui_widget._gfObject.label, parent)
 
+        self.connect(self, qt.SIGNAL('clicked()'), self.__on_clicked)
+        self.ui_widget = ui_widget
+
+    # -------------------------------------------------------------------------
+    # Slot implementations
+    # -------------------------------------------------------------------------
+
+    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)
+
+        self.ui_widget._gfObject._event_fire()
+
+
+# =============================================================================
+# Configuration
+# =============================================================================
+
 configuration = {
-    'baseClass'  : UIButton,
-    'provides'   : 'GFButton',
-    'container'  : 0,
-    }
+  'baseClass': UIButton,
+  'provides' : 'GFButton',
+  'container': 0,
+}

Modified: trunk/gnue-forms/src/uidrivers/qt3/widgets/entry.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt3/widgets/entry.py 2006-10-12 12:27:04 UTC 
(rev 8769)
+++ trunk/gnue-forms/src/uidrivers/qt3/widgets/entry.py 2006-10-12 12:34:46 UTC 
(rev 8770)
@@ -26,6 +26,8 @@
 
 import qt
 
+from gnue.forms.input import GFKeyMapper
+from gnue.forms.input.GFKeyMapper import vk
 from gnue.forms.uidrivers.qt3.widgets._base import UIHelper
 
 # =============================================================================
@@ -40,13 +42,50 @@
 
         style = self._gfObject.style.lower()
 
-        self.widget = qt.QLineEdit(event.container)
+        parent = event.container
+        func = getattr(self, '_UIEntry__build_%s' % style, None)
+        if func:
+            (self.label, self.widget) = func(parent)
+        else:
+            (self.label, self.widget) = self.__build_default(parent)
+
         self.getParent().add_widgets(self, spacer)
 
         return self.widget
 
+    # -------------------------------------------------------------------------
+    # Create the variouse entry widgets
+    # -------------------------------------------------------------------------
 
+    def __build_default(self, parent, password=False, multiline=False):
+
+        if multiline:
+            return (None, MultiLineEdit(parent, self))
+        else:
+            return (None, LineEdit(parent, self, password))
+
     # -------------------------------------------------------------------------
+
+    def __build_password(self, parent):
+
+        return self.__build_default(parent, True)
+
+    # -------------------------------------------------------------------------
+
+    def __build_multiline(self, parent):
+
+        return self.__build_default(parent, False, True)
+
+    # -------------------------------------------------------------------------
+
+    def __build_label(self, parent):
+
+        ctrl = qt.QLabel(parent)
+        return (None, ctrl)
+
+
+
+    # -------------------------------------------------------------------------
     # Enable/disable this entry
     # -------------------------------------------------------------------------
 
@@ -68,13 +107,147 @@
         widget = self.widgets[index]
         widget.setText(value)
 
+    # -------------------------------------------------------------------------
 
+    def _ui_set_cursor_position_(self, index, position):
+        """
+        Set the cursor position to the given location inside a capable widget.
 
+        @param position: new position of the insertion point
+        @param index: index of the widget to be changed (if rows > 0)
+        """
+
+        widget = self.widgets[index]
+        widget.setCursorPosition(position)
+
+
 # =============================================================================
+# Base class for entry widgets
+# =============================================================================
+
+class BaseEntry(object):
+
+    # -------------------------------------------------------------------------
+    # Constructor
+    # -------------------------------------------------------------------------
+
+    def __init__(self, ui_widget, qt_class):
+        self.ui_widget = ui_widget
+        self.qt_class = qt_class
+
+    # -------------------------------------------------------------------------
+    # Event-Handler
+    # -------------------------------------------------------------------------
+
+    def keyPressEvent(self, event):
+        """
+        Handle key press events by searching for an apropriate command.  If no
+        command was found a keypress event is fired on the bound UI widget.
+        """
+
+        keycode = event.key()
+        state = event.state()
+
+        (command, args) = GFKeyMapper.KeyMapper.getEvent(keycode,
+                state & qt.QKeyEvent.ShiftButton,
+                state & qt.QKeyEvent.ControlButton,
+                state & qt.QKeyEvent.AltButton)
+
+        if command:
+            if command == 'NEWLINE':
+                self.ui_widget._request(command, text = '\n')
+            else:
+                self.ui_widget._request(command, triggerName = args)
+
+        elif len(event.text()):
+            self.ui_widget._keypress(unicode(event.text()))
+        else:
+            # TODO: is there another way to find the qt widget class which is
+            # implemented by the class of this Mixin ?
+            self.qt_class.keyPressEvent(self, event)
+
+    # -------------------------------------------------------------------------
+
+    def mousePressEvent(self, event):
+        """
+        """
+
+        gf_object = self.ui_widget._gfObject
+
+        count = self.ui_widget.widgets.index(self)
+        adjust = count - gf_object._visibleIndex
+        do_focus = gf_object._form._currentEntry != gf_object
+        
+        if do_focus:
+            self.ui_widget._request('FOCUS', data = self.ui_widget._gfObject)
+
+        if adjust:
+            self.ui_widget._request('JUMPRECORD', data = adjust)
+
+        if not do_focus:
+            self.qt_class.mousePressEvent(self, event)
+
+
+
+# =============================================================================
+# LineEdit widgets
+# =============================================================================
+
+class LineEdit(BaseEntry, qt.QLineEdit):
+    """
+    Single line text entry widget
+    """
+
+    # -------------------------------------------------------------------------
+    # Constructor
+    # -------------------------------------------------------------------------
+
+    def __init__(self, parent, ui_widget, password=False):
+        qt.QLineEdit.__init__(self, parent)
+        BaseEntry.__init__(self, ui_widget, qt.QLineEdit)
+
+        if password:
+            self.setEchoMode(qt.QLineEdit.Password)
+
+# =============================================================================
+# Multiline text entry widget
+# =============================================================================
+
+class MultiLineEdit(BaseEntry, qt.QTextEdit):
+
+    def __init__(self, parent, ui_widget):
+        qt.QLineEdit.__init__(self, parent)
+        BaseEntry.__init__(self, ui_widget, qt.QTextEdit)
+
+
+# =============================================================================
+# Keymapper configuration: Translate from QT to our virtual keystrokes
+# =============================================================================
+
+qtKeyTranslations = {
+    vk.F1     : qt.Qt.Key_F1,        vk.F2        : qt.Qt.Key_F2,
+    vk.F3     : qt.Qt.Key_F3,        vk.F4        : qt.Qt.Key_F4,
+    vk.F5     : qt.Qt.Key_F5,        vk.F6        : qt.Qt.Key_F6,
+    vk.F7     : qt.Qt.Key_F7,        vk.F8        : qt.Qt.Key_F8,
+    vk.F9     : qt.Qt.Key_F9,        vk.F10       : qt.Qt.Key_F10,
+    vk.F11    : qt.Qt.Key_F11,       vk.F12       : qt.Qt.Key_F12,
+    vk.INSERT : qt.Qt.Key_Insert,    vk.DELETE    : qt.Qt.Key_Delete,
+    vk.HOME   : qt.Qt.Key_Home,      vk.END       : qt.Qt.Key_End,
+    vk.PAGEUP : qt.Qt.Key_Prior,     vk.PAGEDOWN  : qt.Qt.Key_Next,
+    vk.UP     : qt.Qt.Key_Up,        vk.DOWN      : qt.Qt.Key_Down,
+    vk.LEFT   : qt.Qt.Key_Left,      vk.RIGHT     : qt.Qt.Key_Right,
+    vk.TAB    : qt.Qt.Key_Tab,
+    vk.ENTER  : qt.Qt.Key_Return,    vk.BACKSPACE : qt.Qt.Key_Backspace }
+
+GFKeyMapper.KeyMapper.setUIKeyMap(qtKeyTranslations)
+
+
+# =============================================================================
 # Configuration
 # =============================================================================
 
 configuration = {
   'baseClass': UIEntry,
-  'provides' : 'GFEntry', 'container': False,
+  'provides' : 'GFEntry',
+  'container': False,
 }

Modified: trunk/gnue-forms/src/uidrivers/qt3/widgets/form.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt3/widgets/form.py  2006-10-12 12:27:04 UTC 
(rev 8769)
+++ trunk/gnue-forms/src/uidrivers/qt3/widgets/form.py  2006-10-12 12:34:46 UTC 
(rev 8770)
@@ -109,8 +109,15 @@
         else:
             self._container = self.main_widget
 
+        fmet = self.main_window.fontMetrics()
+
+        self._uiDriver.cell_height = fmet.height()
+        text = "".join([chr(i) for i in range(48, 127)])
+        self._uiDriver.cell_width = fmet.width(text) / len(text) + 1
+
         return self.main_window
 
+
     # -------------------------------------------------------------------------
     # Show the form/dialog
     # -------------------------------------------------------------------------





reply via email to

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