[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r9330 - in trunk/gnue-forms/src/uidrivers: . qt4 qt4/widgets
From: |
jcater |
Subject: |
[gnue] r9330 - in trunk/gnue-forms/src/uidrivers: . qt4 qt4/widgets |
Date: |
Fri, 26 Jan 2007 02:00:26 -0600 (CST) |
Author: jcater
Date: 2007-01-26 02:00:24 -0600 (Fri, 26 Jan 2007)
New Revision: 9330
Added:
trunk/gnue-forms/src/uidrivers/qt4/
trunk/gnue-forms/src/uidrivers/qt4/MenuBar.py
trunk/gnue-forms/src/uidrivers/qt4/QTApp.py
trunk/gnue-forms/src/uidrivers/qt4/ToolBar.py
trunk/gnue-forms/src/uidrivers/qt4/UILoginHandler.py
trunk/gnue-forms/src/uidrivers/qt4/UIdriver.py
trunk/gnue-forms/src/uidrivers/qt4/__init__.py
trunk/gnue-forms/src/uidrivers/qt4/dialogs.py
trunk/gnue-forms/src/uidrivers/qt4/widgets/
trunk/gnue-forms/src/uidrivers/qt4/widgets/__init__.py
trunk/gnue-forms/src/uidrivers/qt4/widgets/_base.py
trunk/gnue-forms/src/uidrivers/qt4/widgets/box.py
trunk/gnue-forms/src/uidrivers/qt4/widgets/button.py
trunk/gnue-forms/src/uidrivers/qt4/widgets/entry.py
trunk/gnue-forms/src/uidrivers/qt4/widgets/form.py
trunk/gnue-forms/src/uidrivers/qt4/widgets/grid.py
trunk/gnue-forms/src/uidrivers/qt4/widgets/gridline.py
trunk/gnue-forms/src/uidrivers/qt4/widgets/hbox.py
trunk/gnue-forms/src/uidrivers/qt4/widgets/image.py
trunk/gnue-forms/src/uidrivers/qt4/widgets/label.py
trunk/gnue-forms/src/uidrivers/qt4/widgets/page.py
trunk/gnue-forms/src/uidrivers/qt4/widgets/scrollbar.py
trunk/gnue-forms/src/uidrivers/qt4/widgets/vbox.py
Log:
copy of qt3 driver into qt4
Added: trunk/gnue-forms/src/uidrivers/qt4/MenuBar.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt4/MenuBar.py 2007-01-26 06:47:06 UTC
(rev 9329)
+++ trunk/gnue-forms/src/uidrivers/qt4/MenuBar.py 2007-01-26 08:00:24 UTC
(rev 9330)
@@ -0,0 +1,136 @@
+# GNU Enterprise Forms - QT3 UI driver - MenuBar
+#
+# Copyright 2001-2007 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
+# 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.
+#
+# $Id$
+"""
+Menu bar
+"""
+
+import qt
+from gnue.forms.uidrivers._commonGuiToolkit import MenuBar as _Base
+
+_ICON_CACHE = {}
+
+# =============================================================================
+# Implementation of the menu bar for qt3
+# =============================================================================
+
+class MenuBar(_Base.MenuBar):
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def init(self):
+ self.menubar = self.container.menuBar()
+ self.__idmap = {}
+ return self.menubar
+
+ # -------------------------------------------------------------------------
+ # Add a sub menu
+ # -------------------------------------------------------------------------
+
+ def addMenu(self, name, parent):
+ """
+ Add antoher menu to the given parent menu or menubar
+
+ @param name: name of the menu
+ @param parent: parent menu or menubar to append the new menu to
+
+ @result: newly created menu
+ """
+
+ menu = qt.QPopupMenu(parent)
+ parent.insertItem(name, menu)
+ qt.QObject.connect(menu, qt.SIGNAL('activated(int)'),
+ self.__item_selected)
+ return menu
+
+
+ # -------------------------------------------------------------------------
+ # Add an action
+ # -------------------------------------------------------------------------
+
+ def addAction(self, name, parent, userAction):
+ """
+ Add a new menu item to a given menu.
+
+ @param name: name of the menu item
+ @param parent: menu to add this new item to
+ @param userAction: userAction instance representing the new menu item
+
+ @returns: the newly created menu item
+ """
+
+ iconloc = userAction.getIconLocation(size="16x16")
+ label = name
+
+ # Set the action icon if available
+ if iconloc:
+ icon = _ICON_CACHE.setdefault(iconloc,
+ qt.QIconSet(qt.QPixmap(iconloc)))
+ mid = parent.insertItem(icon, label)
+ else:
+ mid = parent.insertItem(label)
+
+ hotkey = userAction.getHotKeyText({'PAGEDOWN': 'PgDown'})
+ if hotkey:
+ parent.setAccel(qt.QKeySequence(hotkey), mid)
+
+ parent.setWhatsThis(mid, userAction.description or '')
+
+ self.__idmap[mid] = userAction
+
+ return (parent, mid)
+
+ # -------------------------------------------------------------------------
+ # Add a separator
+ # -------------------------------------------------------------------------
+
+ def addSeparator(self, parent):
+ parent.insertSeparator()
+
+
+ # -------------------------------------------------------------------------
+ # Enable a menu item
+ # -------------------------------------------------------------------------
+
+ def enableItem(self, item):
+ parent, mid = item
+ parent.setItemEnabled(mid, True)
+
+
+ # -------------------------------------------------------------------------
+ # Disable a menu item
+ # -------------------------------------------------------------------------
+
+ def disableItem(self, item):
+ parent, mid = item
+ parent.setItemEnabled(mid, False)
+
+
+ # -------------------------------------------------------------------------
+ # A menu item was selected
+ # -------------------------------------------------------------------------
+
+ def __item_selected(self, itemid):
+
+ self._fire(self.__idmap[itemid])
Property changes on: trunk/gnue-forms/src/uidrivers/qt4/MenuBar.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: trunk/gnue-forms/src/uidrivers/qt4/QTApp.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt4/QTApp.py 2007-01-26 06:47:06 UTC (rev
9329)
+++ trunk/gnue-forms/src/uidrivers/qt4/QTApp.py 2007-01-26 08:00:24 UTC (rev
9330)
@@ -0,0 +1,80 @@
+# GNU Enterprise Forms - QT 3 UI driver - Application object
+#
+# Copyright 2001-2007 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
+# 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.
+#
+# $Id$
+
+import sys
+import qt
+
+from gnue.common.apps import GDebug
+
+__QtApp = None
+
+# -----------------------------------------------------------------------------
+# get the global application object
+# -----------------------------------------------------------------------------
+
+def getQtApp():
+ """
+ Get the global qt application instance or (if none has been created) build
+ a new one
+ """
+ global __QtApp
+
+ if not __QtApp:
+ assert gDebug(6,"QtApp initializing")
+ __QtApp = GFqtApp()
+
+ return __QtApp
+
+
+# =============================================================================
+# QT Application
+# =============================================================================
+
+class GFqtApp(qt.QApplication):
+ """
+ The QT Application object as used by GNUe Forms
+ """
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__(self):
+
+ self.__started = False
+ qt.QApplication.__init__(self, sys.argv)
+ self.connect(self, qt.SIGNAL('lastWindowClosed()'), self.quit)
+
+
+ # -------------------------------------------------------------------------
+ # Start the main loop
+ # -------------------------------------------------------------------------
+
+ def start(self):
+ """
+ Start the applications main loop, but do it only once !
+ """
+
+ if not self.__started:
+ self.__started = True
+ self.exec_loop()
Property changes on: trunk/gnue-forms/src/uidrivers/qt4/QTApp.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: trunk/gnue-forms/src/uidrivers/qt4/ToolBar.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt4/ToolBar.py 2007-01-26 06:47:06 UTC
(rev 9329)
+++ trunk/gnue-forms/src/uidrivers/qt4/ToolBar.py 2007-01-26 08:00:24 UTC
(rev 9330)
@@ -0,0 +1,163 @@
+# GNU Enterprise Forms - QT3 UI driver - ToolBar
+#
+# Copyright 2001-2007 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
+# 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.
+#
+# $Id$
+
+import qt
+
+from gnue.forms.uidrivers._commonGuiToolkit import ToolBar as _Base
+
+__all__ = ['ToolBar']
+
+_ICON_CACHE = {}
+
+# =============================================================================
+# ToolBar widget
+# =============================================================================
+
+class ToolBar(_Base.ToolBar):
+ """
+ Implementation of the QT3 tool bar
+ """
+
+ # -------------------------------------------------------------------------
+ # Initialize the toolbar
+ # -------------------------------------------------------------------------
+
+ def init(self):
+ """
+ Create a new tool bar
+ @returns: the QToolBar instance
+ """
+
+ self.toolbar = qt.QToolBar(u_("Forms Toolbar"), self.container)
+ self.toolbar.show()
+ return self.toolbar
+
+
+ # -------------------------------------------------------------------------
+ # Add a menu item (action)
+ # -------------------------------------------------------------------------
+
+ def addAction(self, name, userAction):
+ """
+ Add an action to the toolbar
+
+ @param name: name of the action
+ @param userAction: userAction instance representing the action to add
+ """
+
+ action = Action(self, name, userAction)
+ return action
+
+
+ # -------------------------------------------------------------------------
+ # Add a separator
+ # -------------------------------------------------------------------------
+
+ def addSeparator(self):
+ self.toolbar.addSeparator()
+
+
+ # -------------------------------------------------------------------------
+ # Enable a menu item
+ # -------------------------------------------------------------------------
+
+ def enableItem(self, item):
+ item.setEnabled(True)
+
+ # -------------------------------------------------------------------------
+ # Disable a menu item
+ # -------------------------------------------------------------------------
+
+ def disableItem(self, item):
+ item.setEnabled(False)
+
+ # -------------------------------------------------------------------------
+ # Set a toggle action to 'on'
+ # -------------------------------------------------------------------------
+
+ def startingItem(self, item):
+ item.setOn(True)
+
+ # -------------------------------------------------------------------------
+ # Set a toggle action to 'off'
+ # -------------------------------------------------------------------------
+
+ def endingItem(self, item):
+ item.setOn(False)
+
+
+# =============================================================================
+# Action
+# =============================================================================
+
+class Action(qt.QAction):
+ """
+ Implementation of an action used within a toolbar
+ """
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__(self, parent, name, user_action):
+
+ qt.QAction.__init__(self, parent.toolbar)
+
+ self.parent = parent
+ self.user_action = user_action
+
+ iconloc = user_action.getIconLocation(size="24x24")
+
+ # Set the action icon if available
+ if iconloc:
+ icon = _ICON_CACHE.setdefault(iconloc,
+ qt.QIconSet(qt.QPixmap(iconloc)))
+ self.setIconSet(icon)
+ else:
+ print u_("** WARNING: Cannot add '%s' to toolbar; no icon") \
+ % user_action.event
+
+ self.setText(name)
+ if user_action.canToggle:
+ self.setToggleAction(True)
+
+ self.setToolTip(user_action.description or '')
+
+ self.connect(self, qt.SIGNAL('activated()'), self.__activated)
+
+ self.addTo(parent.toolbar)
+
+ # -------------------------------------------------------------------------
+ # String representation
+ # -------------------------------------------------------------------------
+
+ def __repr__(self):
+ return "<Action %s (%s)>" % (self.user_action.event,
+ self.user_action.canToggle)
+
+ # -------------------------------------------------------------------------
+ # Slot Implementations
+ # -------------------------------------------------------------------------
+
+ def __activated(self):
+ self.parent._fire(self.user_action, False)
Property changes on: trunk/gnue-forms/src/uidrivers/qt4/ToolBar.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: trunk/gnue-forms/src/uidrivers/qt4/UILoginHandler.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt4/UILoginHandler.py 2007-01-26
06:47:06 UTC (rev 9329)
+++ trunk/gnue-forms/src/uidrivers/qt4/UILoginHandler.py 2007-01-26
08:00:24 UTC (rev 9330)
@@ -0,0 +1,76 @@
+# GNU Enterprise Forms - QT 3 UI Driver - Login Handler
+#
+# Copyright 2001-2007 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
+# 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.
+#
+# $Id$
+
+import os.path
+
+from gnue.common.datasources import GLoginHandler
+from gnue.common.apps import GConfig, i18n
+from gnue.forms.uidrivers.qt3 import dialogs, QTApp
+
+
+# =============================================================================
+# This class implements a login handler for QT3
+# =============================================================================
+
+class UILoginHandler(GLoginHandler.LoginHandler):
+ """
+ Implementation of a LoginHandler for QT3
+ """
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__(self):
+
+ # Make sure to have an application instance available
+ self.app = QTApp.getQtApp()
+
+
+ # -------------------------------------------------------------------------
+ # Override virtual methods
+ # -------------------------------------------------------------------------
+
+ def _askLogin_(self, title, fields):
+
+ lfields = fields [:]
+ if lfields [0][2] != 'image':
+ imageFile = gConfigForms('loginPNG')
+ if not os.path.exists (imageFile):
+ imageFile = os.path.join (os.path.normpath ( \
+ GConfig.getInstalledBase ('forms_images',
'common_images')),
+ gConfigForms ('loginPNG'))
+
+ if os.path.exists (imageFile):
+ lfields.insert (0, (None, imageFile, 'image', None, None, []))
+
+ dialog = dialogs.InputDialog(title, lfields)
+
+ try:
+ dialog.exec_loop()
+ result = dialog.inputData
+
+ finally:
+ del dialog
+
+ return result
Property changes on: trunk/gnue-forms/src/uidrivers/qt4/UILoginHandler.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: trunk/gnue-forms/src/uidrivers/qt4/UIdriver.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt4/UIdriver.py 2007-01-26 06:47:06 UTC
(rev 9329)
+++ trunk/gnue-forms/src/uidrivers/qt4/UIdriver.py 2007-01-26 08:00:24 UTC
(rev 9330)
@@ -0,0 +1,187 @@
+# GNU Enterprise Forms - QT UI Driver - User Interface
+#
+# Copyright 2001-2007 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
+# 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.
+#
+# $Id$
+"""
+A pyQT based user interface driver for GNUe forms.
+"""
+
+import os.path
+
+from gnue.forms.uidrivers._base import Exceptions
+
+try:
+ import qt
+
+except ImportError:
+ raise Exceptions.DriverNotSupported, \
+ u_("The GNUe-Forms QT3 driver requires PyQT 3.x.")
+
+from gnue.common.apps import GConfig
+from gnue.forms.uidrivers._commonGuiToolkit import UIdriver as commonToolkit
+from gnue.forms.uidrivers.qt3.QTApp import *
+from gnue.forms.uidrivers.qt3 import dialogs
+
+
+# =============================================================================
+# Splash Screen
+# =============================================================================
+
+class UISplashScreen(qt.QMainWindow):
+ """
+ Splash screen window
+ """
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__(self):
+
+ 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 = qt.QLabel('', self)
+ image.setPixmap(qt.QPixmap(picture))
+
+ self.setCentralWidget(image)
+ self.show()
+ getQtApp().processEvents()
+
+
+
+# =============================================================================
+# This class implements the User Interface for QT3
+# =============================================================================
+
+class GFUserInterface(commonToolkit.GFUserInterface):
+
+ __rearrange_boxes__ = True
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__(self, eventHandler, name="Undefined", disableSplash=None,
+ parentContainer=None, moduleName=None):
+
+ commonToolkit.GFUserInterface.__init__(self, eventHandler, name,
+ 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
+
+ self.name = "QT3"
+
+ self._disabledColour = None
+ self._qtapp = getQtApp()
+
+ if not self._disableSplash:
+ self.__splash = UISplashScreen()
+ else:
+ self.__splash = None
+
+
+
+ # -------------------------------------------------------------------------
+ # Start the application's main loop
+ # -------------------------------------------------------------------------
+
+ def mainLoop(self):
+ """
+ Start the main loop of the current application instance
+ """
+
+ assert gEnter(6)
+
+ self._qtapp.start()
+
+ assert gLeave(6)
+
+
+ # -------------------------------------------------------------------------
+ # Hide splash screen
+ # -------------------------------------------------------------------------
+
+ def hide_splash(self):
+ """
+ Hide the splash screen (if available)
+ """
+
+ if self.__splash:
+ try:
+ self.__splash.close()
+ self._qtapp.processEvents()
+ finally:
+ self.__splash = None
+
+
+ # -------------------------------------------------------------------------
+ # Show a simple error message
+ # -------------------------------------------------------------------------
+
+ def _ui_show_error_(self, message):
+
+ self.hide_splash()
+ qt.QMessageBox.critical(None, "GNU Enterprise", message)
+
+
+ # -------------------------------------------------------------------------
+ # Show Exception dialog
+ # -------------------------------------------------------------------------
+
+ def _ui_show_exception_(self, group, name, message, detail):
+
+ self.hide_splash()
+ dlg = dialogs.ExceptionDialog(group, name, message, detail)
+ dlg.exec_loop()
+
+ # -------------------------------------------------------------------------
+ # Create and run an input dialog
+ # -------------------------------------------------------------------------
+
+ def _getInput(self, title, fields, cancel=True):
+
+ dlg = dialogs.InputDialog(title, fields, cancel)
+ dlg.exec_loop()
+ return dlg.inputData
+
+
+ # -------------------------------------------------------------------------
+ # Exit the application
+ # -------------------------------------------------------------------------
+
+ def _ui_exit_(self):
+
+ assert gEnter(6)
+
+ for child in self._children:
+ child.main_window._closing_ = True
+ child.main_window.close()
+
+ assert gLeave(6)
Property changes on: trunk/gnue-forms/src/uidrivers/qt4/UIdriver.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: trunk/gnue-forms/src/uidrivers/qt4/__init__.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt4/__init__.py 2007-01-26 06:47:06 UTC
(rev 9329)
+++ trunk/gnue-forms/src/uidrivers/qt4/__init__.py 2007-01-26 08:00:24 UTC
(rev 9330)
@@ -0,0 +1,2 @@
+from UIdriver import *
+from UILoginHandler import *
Property changes on: trunk/gnue-forms/src/uidrivers/qt4/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: trunk/gnue-forms/src/uidrivers/qt4/dialogs.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt4/dialogs.py 2007-01-26 06:47:06 UTC
(rev 9329)
+++ trunk/gnue-forms/src/uidrivers/qt4/dialogs.py 2007-01-26 08:00:24 UTC
(rev 9330)
@@ -0,0 +1,655 @@
+# GNU Enterprise Forms - QT3 UI Driver - UI specific dialogs
+#
+# Copyright 2001-2007 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
+# 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.
+#
+# $Id$
+"""
+Implementation of some common dialogs for the QT3 driver
+"""
+
+import qt
+
+from gnue.forms import VERSION
+
+__all__ = ['ExceptionDialog', 'InputDialog', 'AboutBox']
+
+# =============================================================================
+# Exception display dialog
+# =============================================================================
+
+class ExceptionDialog(qt.QDialog):
+ """
+ Dialog for displaying exceptions. The traceback of the exception is
+ available via a detail button.
+ """
+
+ _TITLE = {'system' : u_("GNUe Internal System Error"),
+ 'admin' : u_("GNUe Unexpected Error"),
+ 'application': u_("GNUe Application Error")}
+
+ _FORMAT = {
+ 'system': u_("An unexpected internal error has occured:\n%s.\n"
+ "This means you have found a bug in GNU Enterprise. "
+ "Please report it to address@hidden"),
+ 'admin': u_("An unexpected error has occured:\n%s.\n"
+ "Please contact your system administrator."),
+ 'application': u_("An unexpected error has occured:\n%s.\n"
+ "Please contact your system administrator.")}
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__ (self, group, name, message, detail):
+
+ qt.QDialog.__init__(self)
+
+ self.vbox = qt.QVBoxLayout(self)
+ self.vbox.setMargin(4)
+
+ hbox = qt.QHBoxLayout()
+ hbox.setMargin(5)
+ self.vbox.addLayout(hbox, 0)
+
+ pxm = qt.QMessageBox.standardIcon(qt.QMessageBox.Critical)
+ self.icon = qt.QLabel('', self)
+ self.icon.setPixmap(pxm)
+ hbox.addWidget(self.icon, 0)
+
+ self.msg = qt.QLabel(self._FORMAT.get(group) % message, self)
+ hbox.addWidget(self.msg, 1)
+
+ self.ext = qt.QMultiLineEdit(self)
+ self.ext.setText(detail)
+ self.ext.setReadOnly(True)
+
+ self._ext_visible = False
+ self.setExtension(self.ext)
+ self.setOrientation(qt.Qt.Vertical)
+
+ sep = qt.QFrame(self) # separatorline
+ sep.setFrameStyle(qt.QFrame.HLine | qt.QFrame.Sunken)
+ self.vbox.addWidget(sep, 0)
+
+ bbox = qt.QHBoxLayout()
+ bbox.addStretch(1)
+
+ self.cbtn = qt.QPushButton(u_("Close"), self)
+ self.connect(self.cbtn, qt.SIGNAL('clicked()'),
+ self.reject)
+ bbox.addWidget(self.cbtn, 0)
+
+ self.det = qt.QPushButton(u_(">> Detail"), self)
+ self.connect(self.det, qt.SIGNAL('clicked()'),
+ self.__toggle_detail)
+ bbox.addWidget(self.det, 0)
+
+ self.vbox.addLayout(bbox, 0)
+
+ self.setCaption(self._TITLE.get(group, u'Error'))
+
+ # -------------------------------------------------------------------------
+
+ def __toggle_detail(self):
+
+ view = not self._ext_visible
+ self._ext_visible = view
+ if view:
+ self.det.setText (u_('<< Detail'))
+ else:
+ self.det.setText (u_('>> Detail'))
+
+ self.showExtension(view)
+
+
+# =============================================================================
+# AboutDialog
+# =============================================================================
+
+class AboutBox(qt.QDialog):
+ """
+ Displays an about dialog for the current application
+ """
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__(self, parent, name, version, author, descr, icon):
+ """
+ @param parent: QT widget to be the parent of the dialog
+ @param name: name of the application
+ @param version: version of the application
+ @param author: author of the application
+ @param description: text describing the form
+ @param icon: path to the appication's icon
+ """
+
+ qt.QDialog.__init__(self, parent)
+
+ current = self.font()
+ small = qt.QFont(current.family(), current.pointSize()-1)
+ bold = qt.QFont(current.family(), current.pointSize(), qt.QFont.Bold)
+
+ self.setCaption(u_("About %s") % name)
+
+ vbox = qt.QVBoxLayout(self)
+ vbox.setMargin(12)
+
+ if icon:
+ label = qt.QLabel(self)
+ label.setPixmap(qt.QPixmap(icon))
+ vbox.addWidget(label, 0, qt.Qt.AlignHCenter)
+
+ label = qt.QLabel(name, self)
+ label.setFont(bold)
+ vbox.addWidget(label, 0, qt.Qt.AlignHCenter)
+
+ if version:
+ label = qt.QLabel(u_("Version: %s") % version, self)
+ label.setFont(small)
+ vbox.addWidget(label, 0, qt.Qt.AlignHCenter)
+
+ if author:
+ label = qt.QLabel(author, self)
+ vbox.addWidget(label, 0, qt.Qt.AlignHCenter)
+
+ if descr:
+ label = qt.QLabel(descr, self)
+ vbox.addWidget(label, 1, qt.Qt.AlignHCenter | qt.Qt.WordBreak)
+
+ sep = qt.QFrame(self, "separatorline")
+ sep.setFrameStyle(qt.QFrame.HLine | qt.QFrame.Sunken)
+ vbox.addWidget(sep, 0)
+
+ label = qt.QLabel("GNU Enterprise Forms", self)
+ label.setFont(bold)
+ vbox.addWidget(label, 0, qt.Qt.AlignHCenter)
+
+ vers = "Version %s / %s %s" % (VERSION, 'QT', qt.qVersion())
+ label = qt.QLabel(vers, self)
+ label.setFont(small)
+ vbox.addWidget(label, 0, qt.Qt.AlignHCenter)
+
+ hbox = qt.QHBoxLayout()
+ hbox.setMargin(4)
+ hbox.addStretch(1)
+
+ ok = qt.QPushButton(u_("Ok"), self)
+ self.connect(ok, qt.SIGNAL('clicked()'), self.accept)
+ hbox.addWidget(ok, 0)
+
+ hbox.addStretch(1)
+
+ vbox.addLayout(hbox)
+
+
+
+# =============================================================================
+# LineEdit widget for InputDialog
+# =============================================================================
+
+class IDLineEdit(qt.QLineEdit):
+ """
+ LineEdit control for InputDialogs which automatically updates the input
+ data dictionary on changes of the text.
+
+ Signals:
+
+ on_enter(QWidget): Emitted when the Enter/Return key was hit
+ """
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__(self, name, default, elements, password, ddict, parent):
+
+ qt.QLineEdit.__init__(self, default or '', parent, str(name))
+
+ if password:
+ self.setEchoMode(qt.QLineEdit.Password)
+
+ if elements and elements [0][0]:
+ qt.QToolTip.add(self, elements[0][0])
+
+ self.ddict = ddict
+ self.ddict[name] = default or ''
+
+ self.connect(self, qt.SIGNAL('textChanged(const QString &)'),
+ self.__on_text_change)
+ self.connect(self, qt.SIGNAL('returnPressed()'),
+ self.__on_return_pressed)
+
+ # -------------------------------------------------------------------------
+ # Event Slots
+ # -------------------------------------------------------------------------
+
+ def __on_text_change(self, text):
+ self.ddict[self.name()] = unicode(text)
+
+ # -------------------------------------------------------------------------
+
+ def __on_return_pressed(self):
+ self.emit(qt.PYSIGNAL('on_enter(QWidget)'), (self,))
+
+
+# =============================================================================
+# Combobox Widget for InputDialog
+# =============================================================================
+
+class IDComboBox(qt.QComboBox):
+ """
+ A ComboBox Widget for InputDialogs.
+
+ Such a ComboBox automatically manages the allowed values as defined by the
+ input data dictionary.
+
+ Signals:
+
+ on_enter(QWidget): Emitted when Enter/Return-Key was hit
+ update_depending(QWidget, int): Emitted when a value has been selected.
+ The int argument is the index of the selected value.
+ """
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__(self, name, master, allowed, default, tip, ddict, parent):
+
+ qt.QComboBox.__init__(self, False, parent, str(name))
+
+ self.ddict = ddict
+ self._master = master
+ self._allowed = allowed
+ self._default = default
+ self._keys = []
+
+ if tip:
+ qt.QToolTip.add(self, tip)
+
+ self.connect(self, qt.SIGNAL('activated(int)'), self.__on_selected)
+
+ self.update_widget()
+
+
+ # -------------------------------------------------------------------------
+ # Rebuild the contents of the combobox
+ # -------------------------------------------------------------------------
+
+ def update_widget(self):
+ """
+ Reset the allowed values of the ComboBox depending on the master-value
+ or (if no master is available) the predefined allowed values.
+ """
+
+ name = self.name()
+ self.clear()
+
+ if self._master:
+ values = self._allowed.get(self.ddict.get(self._master), {})
+ else:
+ values = self._allowed
+
+ if values:
+ self._keys = []
+ for (k, v) in values.items():
+ self._keys.append(k)
+ self.insertItem(v)
+
+ if self._default in values:
+ self.setCurrentItem(self._keys.index(self._default))
+ self.ddict[name] = self._default
+ else:
+ self.ddict[name] = self._keys[0]
+ self.setCurrentItem(0)
+
+ else:
+ if name in self.ddict:
+ del self.ddict[name]
+
+ self.setEnabled(len(values) > 0)
+
+
+ # -------------------------------------------------------------------------
+ # Event-Handlers
+ # -------------------------------------------------------------------------
+
+ def keyPressEvent(self, event):
+ """
+ If the Enter- or Return-Key is pressed the KeyEvent is consumed and an
+ on_enter signal is emitted.
+ """
+ if event.key() in [qt.Qt.Key_Return, qt.Qt.Key_Enter]:
+ self.emit(qt.PYSIGNAL('on_enter(QWidget)'), (self,))
+ else:
+ qt.QComboBox.keyPressEvent(self, event)
+
+
+ # -------------------------------------------------------------------------
+ # Slots
+ # -------------------------------------------------------------------------
+
+ def __on_selected(self, index):
+
+ new = self._keys[index]
+ self.ddict[self.name()] = new
+ self.emit(qt.PYSIGNAL('update_depending(QWidget, int)'), (self,index))
+
+
+
+# =============================================================================
+# Class implementing a versatile input dialog
+# =============================================================================
+
+class InputDialog (qt.QDialog):
+ """
+ Dialog class prompting the user for a given number of fields. These field
+ definitions are specified as follows:
+
+ A field definition is a tuple having these elements:
+ - fieldlabel: This text will be used as label in the left column
+ - fieldname: This is the key in the result-dictionary to contain the value
+ entered by the user
+ - fieldtype: Currently these types are supported:
+ - label: The contents of 'fieldlabel' as static text
+ - warning: The contents of 'fieldlabel' as static text, formatted as
+ warning
+ - string: A text entry control
+ - password: A text entry control with obscured characters
+ - dropdown: Foreach element given in 'elements' a separate ComboBox
+ control will be created, where each one has it's own dictionary of
+ allowed values. If a value is selected in one control, all others
+ are synchronized to represent the same key-value.
+ - default: Default value to use
+ - masterfield: Used for 'dropdowns'. This item specifies another field
+ definition acting as master field. If this master field is changed, the
+ allowedValues of this dropdown will be changed accordingly. If a
+ masterfield is specified the 'allowedValues' dictionaries are built
+ like {master1: {key: value, key: value, ...}, master2: {key: value,
+ ...}}
+ - elements: sequence of input element tuples (label, allowedValues). This
+ is used for dropdowns only. 'label' will be used as ToolTip for the
+ control and 'allowedValues' gives a dictionary with all valid keys to
+ be selected in the dropdown.
+
+ @return: If closed by 'Ok' the result is a dictionary with all values
+ entered by the user, where the "fieldname"s will be used as keys. If
+ the user has not selected a value from a dropdown (i.e. it has no
+ values to select) there will be no such key in the result dictionary.
+ If the dialog is canceled ('Cancel'-Button) the result will be None.
+ """
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__ (self, title, fields, cancel = True):
+ """
+ Create a new input dialog
+
+ @param title: Dialog title
+ @param fields: sequence of field definition tuples
+ @param cancel: If True add a Cancel button to the dialog
+ """
+
+ qt.QDialog.__init__ (self)
+
+ self.setCaption(title)
+ self.setIcon(qt.QMessageBox.standardIcon(qt.QMessageBox.Question))
+
+ self.top_sizer = qt.QVBoxLayout(self)
+ self.top_sizer.setMargin(8)
+
+ self.grid = qt.QGridLayout()
+ bbox = qt.QHBoxLayout()
+ bbox.addStretch(1)
+
+ self.top_sizer.addLayout(self.grid)
+
+ sep = qt.QFrame(self, "separatorline")
+ sep.setFrameStyle(qt.QFrame.HLine | qt.QFrame.Sunken)
+ self.top_sizer.addWidget(sep)
+
+ self.top_sizer.addLayout(bbox)
+
+ cancel = qt.QPushButton(u_('Cancel'), self)
+ cancel.setDefault(False)
+ cancel.setAutoDefault(False)
+ self.connect(cancel, qt.SIGNAL('clicked()'), self.reject)
+ bbox.addWidget(cancel)
+
+ ok = qt.QPushButton(u_('Ok'), self)
+ ok.setDefault(False)
+ ok.setAutoDefault(False)
+ self.connect(ok, qt.SIGNAL('clicked()'), qt.SLOT('accept()'))
+ bbox.addWidget(ok)
+
+ self.inputData = {}
+ self.__dropdowns = {}
+ self.__entries = []
+
+ row = 0
+ for (label, name, fieldtype, default, master, elements) in fields:
+ ftp = fieldtype.lower()
+
+ if ftp in ['label', 'warning']:
+ self.__addText(row, label, ftp == 'warning')
+
+ elif ftp == 'image':
+ self.__addImage(row, name)
+
+ elif ftp in ['string', 'password']:
+ self.__addString(row, label, name, default, elements, ftp !=
+ 'string')
+
+ elif ftp == 'dropdown':
+ self.__addChoice(row, label, name, default, master, elements)
+
+ row += 1
+
+ if self.__entries:
+ self.__focus(self.__entries[0])
+
+
+ # -------------------------------------------------------------------------
+ # If the dialog is dismissed, clear the input data
+ # -------------------------------------------------------------------------
+
+ def reject(self):
+ """
+ Cancel the dialog and clear the input data dictionary
+ """
+
+ self.inputData = None
+ qt.QDialog.reject(self)
+
+
+ # -------------------------------------------------------------------------
+ # Add a centered, static label or warning
+ # -------------------------------------------------------------------------
+
+ def __addText(self, row, label, warning=False):
+
+ text = qt.QLabel(label, self)
+ text.setAlignment(qt.Qt.AlignHCenter)
+ self.grid.addMultiCellWidget(text, row, row, 0, 1)
+
+ if warning:
+ text.setPaletteForegroundColor(qt.QColor('red'))
+
+
+ # -------------------------------------------------------------------------
+ # Add a text control for a string or a password
+ # -------------------------------------------------------------------------
+
+ def __addString(self, row, label, name, default, elements, pwd=False):
+
+ text = qt.QLabel(label, self)
+ self.grid.addWidget(text, row, 0)
+
+ entry = IDLineEdit(name, default, elements, pwd, self.inputData, self)
+ self.grid.addWidget(entry, row, 1)
+
+ self.connect(entry, qt.PYSIGNAL('on_enter(QWidget)'),
+ self.__on_enter)
+
+ self.__entries.append(entry)
+
+
+ # -------------------------------------------------------------------------
+ # Add a series of dropdowns into a single row
+ # -------------------------------------------------------------------------
+
+ def __addChoice(self, row, label, name, default, master, elements):
+
+ text = qt.QLabel(label, self)
+ self.grid.addWidget(text, row, 0)
+
+ hbox = qt.QHBoxLayout()
+ self.grid.addLayout(hbox, row, 1)
+
+ perMaster = self.__dropdowns.setdefault(master, {})
+ perRow = perMaster.setdefault(name, [])
+
+ border = 0
+ for (tip, allowedValues) in elements:
+ widget = IDComboBox(name, master, allowedValues, default, tip,
+ self.inputData, self)
+ self.connect(widget, qt.PYSIGNAL('update_depending(QWidget, int)'),
+ self.__update_depending)
+ self.connect(widget, qt.PYSIGNAL('on_enter(QWidget)'),
+ self.__on_enter)
+
+ perRow.append(widget)
+
+ hbox.addWidget(widget)
+ self.__entries.append(widget)
+
+
+ # -------------------------------------------------------------------------
+ # Add a centered image to the dialog
+ # -------------------------------------------------------------------------
+
+ def __addImage (self, row, imageURL):
+
+ image = qt.QLabel('', self)
+ image.setAlignment(qt.Qt.AlignHCenter)
+ image.setPixmap(qt.QPixmap(imageURL))
+ self.grid.addMultiCellWidget(image, row, row, 0, 1)
+
+
+ # -------------------------------------------------------------------------
+ # If <Enter> is pressed within a text control, move the focus
+ # -------------------------------------------------------------------------
+
+ def __on_enter(self, entry):
+
+ next = None
+ start = self.__entries.index(entry)+1
+ if start < len(self.__entries):
+ for i in range(start, len(self.__entries)):
+ if self.__entries[i].isEnabled():
+ next = self.__entries[i]
+ break
+
+ if next is not None:
+ self.__focus(next)
+ else:
+ self.accept()
+
+ # -------------------------------------------------------------------------
+ # Focus a given widget
+ # -------------------------------------------------------------------------
+
+ def __focus(self, widget):
+ widget.setFocus()
+
+ if isinstance(widget, qt.QLineEdit):
+ widget.selectAll()
+
+ # -------------------------------------------------------------------------
+ # Update all depending combo boxes
+ # -------------------------------------------------------------------------
+
+ def __update_depending(self, widget, index):
+
+ for item in self.__dropdowns[widget._master][widget.name()]:
+ item.setCurrentItem(index)
+
+ master = widget.name()
+
+ if master in self.__dropdowns:
+ for name in self.__dropdowns[master].keys():
+ drops = self.__dropdowns[master][name]
+ for i in drops:
+ i.update_widget()
+
+
+# =============================================================================
+# Module Self Test
+# =============================================================================
+
+if __name__ == '__main__':
+ import sys
+
+ cname = {'c1': 'demoa', 'c2': 'demob'}
+ ckey = {'c1': 'ck-A' , 'c2': 'ck-B'}
+
+ wija = {'c1': {'04': '2004', '05': '2005'},
+ 'c2': {'24': '2024', '25': '2025', '26': '2026'}}
+
+ codes = {'24': {'241': 'c-24-1', '242': 'c-24-2'},
+ '25': {'251': 'c-25-1'}}
+
+ fields = [('Foo!', '/home/johannes/gnue/share/gnue/images/gnue.png',
'image',
+ None, None, []),
+ ('Username', u'_username', 'string', None, None, \
+ [('Name of the user', None)]),
+ ('Password', u'_password', 'password', 'foo', None, [('yeah',1)]),
+ ('Foobar', u'_foobar', 'dropdown', 'frob', None, \
+ [('single', {'trash': 'Da Trash', 'frob': 'Frob'})]),
+ ('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', u'_depp', 'label', 'furz', None, []),
+ ('Das ist jetzt ein Fehler', None, 'warning', None, None, []),
+
+ ('Firma', u'company', 'dropdown', 'c1', None,
+ [('Name', cname), ('Code', ckey)]),
+ ('Wirtschaftsjahr', u'wija', 'dropdown', '05', 'company',
+ [('Jahr', wija)]),
+ ('Codes', u'codes', 'dropdown', None, 'wija',
+ [('Code', codes)])
+ ]
+
+ app = qt.QApplication( sys.argv )
+ app.connect(app, qt.SIGNAL("lastWindowClosed()"), app, qt.SLOT("quit()"))
+
+ dialog = InputDialog ('Foobar', fields)
+ try:
+ dialog.show()
+ print "Result:", dialog.inputData
+
+ finally:
+ app.quit()
+
+ app.exec_loop()
Property changes on: trunk/gnue-forms/src/uidrivers/qt4/dialogs.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: trunk/gnue-forms/src/uidrivers/qt4/widgets/__init__.py
===================================================================
Property changes on: trunk/gnue-forms/src/uidrivers/qt4/widgets/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: trunk/gnue-forms/src/uidrivers/qt4/widgets/_base.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt4/widgets/_base.py 2007-01-26 06:47:06 UTC
(rev 9329)
+++ trunk/gnue-forms/src/uidrivers/qt4/widgets/_base.py 2007-01-26 08:00:24 UTC
(rev 9330)
@@ -0,0 +1,145 @@
+# GNU Enterprise Forms - QT3 UI Driver - Basic UI widget
+#
+# Copyright 2001-2007 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
+# 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.
+#
+# $Id$
+
+import qt
+
+from gnue.forms.uidrivers._base.widgets._base import UIWidget
+
+__all__ = ['UIHelper']
+
+# =============================================================================
+# Base class for all qt3 UI widgets
+# =============================================================================
+
+class UIHelper(UIWidget):
+ """
+ Implements the common behaviour of qt3 UI widgets
+ """
+
+ growable = False
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__(self, event):
+
+ UIWidget.__init__(self, event)
+
+ self.widget = None
+ self.label = None
+
+
+ # -------------------------------------------------------------------------
+ # Focus handling
+ # -------------------------------------------------------------------------
+
+ def _ui_set_focus_(self, index):
+
+ widget = self.widgets[index]
+ if widget:
+ widget.setFocus()
+
+ # -------------------------------------------------------------------------
+
+ def _ui_focus_in_(self, index):
+
+ widget = self.widgets[index]
+ if self.in_grid and widget._gnue_label_:
+ label = widget._gnue_label_
+ widget.show()
+ label.hide()
+
+
+ # -------------------------------------------------------------------------
+
+ def _ui_focus_out_(self, index):
+
+ widget = self.widgets[index]
+ if self.in_grid and widget._gnue_label_:
+ label = widget._gnue_label_
+ label.show()
+ widget.hide()
+
+
+
+# =============================================================================
+# Base class for H/V-Boxes in a managed layout
+# =============================================================================
+
+class ManagedBox(UIHelper):
+ """
+ """
+
+ growable = True
+ _vertical_ = True
+ _entry_pos = 0
+ last_item = 0
+
+ # -------------------------------------------------------------------------
+ # Create the widget
+ # -------------------------------------------------------------------------
+
+ def _create_widget_(self, event, spacer):
+ """
+ """
+
+ self._container = self.widget = qt.QGroupBox(event.container)
+ if self._gfObject.label is not None:
+ self._container.setTitle(self._gfObject.label)
+
+ self._container.setInsideMargin(6)
+
+ if self._vertical_:
+ self.sizer = qt.QGridLayout(1, 2, 2)
+ else:
+ self.sizer = qt.QGridLayout(2, 1, 2)
+
+ self._entry_pos = self.__need_both() and 2 or 1
+
+ if self._vertical_:
+ self.sizer.setColStretch(self._entry_pos - 1, 1)
+ else:
+ self.sizer.setRowStretch(self._entry_pos - 1, 1)
+
+ self._container.layout().addLayout(self.sizer)
+ self.getParent().add_widgets(self, 0)
+
+ self.last_item = 0
+
+
+ # -------------------------------------------------------------------------
+ # Does this box need both columns or rows ?
+ # -------------------------------------------------------------------------
+
+ def __need_both(self):
+
+ result = False
+
+ for item in self._children:
+ if (item._gfObject._type in ['GFEntry', 'GFImage']) and \
+ item._gfObject.label:
+ result = True
+ break
+
+ return result
Property changes on: trunk/gnue-forms/src/uidrivers/qt4/widgets/_base.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: trunk/gnue-forms/src/uidrivers/qt4/widgets/box.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt4/widgets/box.py 2007-01-26 06:47:06 UTC
(rev 9329)
+++ trunk/gnue-forms/src/uidrivers/qt4/widgets/box.py 2007-01-26 08:00:24 UTC
(rev 9330)
@@ -0,0 +1,91 @@
+# GNU Enterprise Forms - QT3 UI Driver - Box widgets
+#
+# Copyright 2001-2007 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
+# 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.
+#
+# $Id$
+
+import qt
+
+from gnue.forms.uidrivers.qt3.widgets._base import UIHelper
+
+__all__ = ['UIBox']
+
+# =============================================================================
+# The Box Widget
+# =============================================================================
+
+class UIBox(UIHelper):
+ """
+ Implementation of the box tag
+ """
+
+ # -------------------------------------------------------------------------
+ # Create the widget
+ # -------------------------------------------------------------------------
+
+ def _create_widget_(self, event, spacer):
+ """
+ Create the QGroupBox and add it to the owner
+
+ @param event: the creation event instance
+ """
+
+ self._container = qt.QGroupBox(self._gfObject.label, event.container)
+ self._container.setInsideMargin(6)
+ self.widget = self._container
+
+ self.sizer = qt.QGridLayout(self.chr_h, self.chr_w, 2)
+ self._container.layout().addLayout(self.sizer)
+
+ self.getParent().add_widgets(self, 0)
+
+ return self._container
+
+
+ # -------------------------------------------------------------------------
+ # Add child widgets (qt) to the layout
+ # -------------------------------------------------------------------------
+
+ def add_widgets(self, ui_widget, spacer):
+ """
+ Add a given UI-widget to the QGridLayout of the box
+
+ @param ui_widget: UI widget to add
+ @param spacer: not used for boxes
+ """
+
+ item = ui_widget.widget
+
+ self.sizer.addMultiCellWidget(item, ui_widget.chr_y,
+ ui_widget.chr_y + ui_widget.chr_h - 1, ui_widget.chr_x,
+ ui_widget.chr_x + ui_widget.chr_w - 1)
+
+
+
+
+# =============================================================================
+# Configuration
+# =============================================================================
+
+configuration = {
+ 'baseClass': UIBox,
+ 'provides' : 'GFBox',
+ 'container': 0,
+}
Property changes on: trunk/gnue-forms/src/uidrivers/qt4/widgets/box.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: trunk/gnue-forms/src/uidrivers/qt4/widgets/button.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt4/widgets/button.py 2007-01-26
06:47:06 UTC (rev 9329)
+++ trunk/gnue-forms/src/uidrivers/qt4/widgets/button.py 2007-01-26
08:00:24 UTC (rev 9330)
@@ -0,0 +1,121 @@
+# GNU Enterprise Forms - QT3 UI driver - Buttons
+#
+# Copyright 2001-2007 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
+# 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.
+#
+# $Id$
+
+import qt
+
+from gnue.forms.uidrivers.qt3.widgets._base import UIHelper
+
+__all__ = ['UIButton']
+
+# =============================================================================
+# Implementation of the <button> tag
+# =============================================================================
+
+class UIButton(UIHelper):
+ """
+ Implementation of the <button> tag
+ """
+
+ # -------------------------------------------------------------------------
+ # Create the button widget
+ # -------------------------------------------------------------------------
+
+ def _create_widget_(self, event, spacer):
+ """
+ Create the button widget
+ """
+
+ owner = self.getParent()
+ if self.in_grid:
+ parent = owner._get_cell(self, spacer)
+ else:
+ parent = event.container
+
+ self.widget = Button(parent, self)
+
+ if self.in_grid:
+ self.widget._gnue_label_ = None
+
+ owner.add_widgets(self, spacer)
+
+ return self.widget
+
+
+ # -------------------------------------------------------------------------
+ # Enable/disable this button
+ # -------------------------------------------------------------------------
+
+ def _ui_enable_(self, index):
+ self.widgets[index].setEnabled(True)
+
+ # -------------------------------------------------------------------------
+
+ def _ui_disable_(self, index):
+ self.widgets[index].setEnabled(False)
+
+
+# =============================================================================
+# QT Button class
+# =============================================================================
+
+class Button(qt.QPushButton):
+ """
+ Descendant of a qt.QPushButton which implements the clicked event to fire
+ the corresponding even of the GFButton instance
+ """
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ 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):
+
+ # 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()
+
+
+# =============================================================================
+# Configuration
+# =============================================================================
+
+configuration = {
+ 'baseClass': UIButton,
+ 'provides' : 'GFButton',
+ 'container': 0,
+}
Property changes on: trunk/gnue-forms/src/uidrivers/qt4/widgets/button.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: trunk/gnue-forms/src/uidrivers/qt4/widgets/entry.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt4/widgets/entry.py 2007-01-26 06:47:06 UTC
(rev 9329)
+++ trunk/gnue-forms/src/uidrivers/qt4/widgets/entry.py 2007-01-26 08:00:24 UTC
(rev 9330)
@@ -0,0 +1,830 @@
+# GNU Enterprise Forms - QT3 UI driver - Entry widgets
+#
+# Copyright 2001-2007 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
+# 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.
+#
+# $Id$
+"""
+Entry widget
+"""
+
+import qt
+
+from gnue.forms.input import GFKeyMapper
+from gnue.forms.input.GFKeyMapper import vk
+from gnue.forms.uidrivers.qt3.widgets._base import UIHelper
+
+# =============================================================================
+# Interface class for entry widgets
+# =============================================================================
+
+class UIEntry(UIHelper):
+ """
+ """
+
+ def _create_widget_(self, event, spacer):
+
+ style = self._gfObject.style.lower()
+ self._block_change_ = False
+ owner = self.getParent()
+
+ if self.in_grid:
+ parent = owner._get_cell(self, spacer)
+ else:
+ 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)
+
+ if self.in_grid:
+ self.widget._gnue_label_ = self.label
+
+ owner.add_widgets(self, spacer)
+
+ return self.widget
+
+ # -------------------------------------------------------------------------
+ # Create the variouse entry widgets
+ # -------------------------------------------------------------------------
+
+ def __build_default(self, parent, password=False, multiline=False):
+
+ label = self.__add_entry_label(parent)
+ if multiline:
+ self.growable = True
+ return [label, MultiLineEdit(parent, self)]
+ else:
+ return [label, 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 = Label(parent, self)
+ return [self.__add_entry_label(parent), ctrl]
+
+ # -------------------------------------------------------------------------
+
+ def __build_checkbox(self, parent):
+
+ result = CheckBox(parent, self)
+ return [None, result]
+
+ # -------------------------------------------------------------------------
+
+ def __build_dropdown(self, parent):
+
+ result = ComboBox(parent, self)
+ return [self.__add_entry_label(parent), result]
+
+ # -------------------------------------------------------------------------
+
+ def __build_listbox(self, parent):
+
+ self.growable = True
+ result = ListBox(parent, self)
+ return [self.__add_entry_label(parent), result]
+
+
+ # -------------------------------------------------------------------------
+ # Create a label for a given entry
+ # -------------------------------------------------------------------------
+
+ def __add_entry_label(self, parent):
+
+ if self.in_grid:
+ result = GridLabel(parent, self)
+
+ elif self._gfObject.label:
+ result = qt.QLabel(self._gfObject.label, parent)
+ else:
+ result = None
+
+ return result
+
+
+ # -------------------------------------------------------------------------
+ # Enable/disable this entry
+ # -------------------------------------------------------------------------
+
+ def _ui_enable_(self, index):
+ self.widgets[index].setEnabled(True)
+
+ # -------------------------------------------------------------------------
+
+ def _ui_disable_(self, index):
+ self.widgets[index].setEnabled(False)
+
+
+ # -------------------------------------------------------------------------
+ # Set "editable" status for this widget
+ # -------------------------------------------------------------------------
+
+ def _ui_set_editable_(self, index, editable):
+
+ # TODO: grey out entry, disallow changes if possible.
+ pass
+
+
+ # -------------------------------------------------------------------------
+ # Set value and cursor position
+ # -------------------------------------------------------------------------
+
+ def _ui_set_value_(self, index, value):
+ """
+ This function sets the value of a widget.
+ """
+
+ widget = self.widgets[index]
+
+ self._block_change_ = True
+ try:
+ method = getattr(widget, '_ui_set_value_', None)
+ if method:
+ method(value)
+ finally:
+ if self.in_grid and widget._gnue_label_:
+ if isinstance(widget._gnue_label_, qt.QLabel):
+ widget._gnue_label_.setText(value)
+
+ self._block_change_ = False
+
+ # -------------------------------------------------------------------------
+
+ 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]
+ method = getattr(widget, '_ui_set_cursor_position_', None)
+ if method:
+ method(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]
+
+ method = getattr(widget, '_ui_set_selected_area_', None)
+ if method:
+ method(selection1, selection2)
+
+ # -------------------------------------------------------------------------
+ # Clipboard and selection
+ # -------------------------------------------------------------------------
+
+ def _ui_cut_(self, index):
+
+ widget = self.widgets[index]
+ if hasattr(widget, '_ui_cut_'):
+ widget._ui_cut_()
+
+ # -------------------------------------------------------------------------
+
+ def _ui_copy_(self, index):
+
+ widget = self.widgets[index]
+ if hasattr(widget, '_ui_copy_'):
+ widget._ui_copy_()
+
+ # -------------------------------------------------------------------------
+
+ def _ui_paste_(self, index):
+
+ widget = self.widgets[index]
+ if hasattr(widget, '_ui_paste_'):
+ widget._ui_paste_()
+
+ # -------------------------------------------------------------------------
+
+ def _ui_select_all_(self, index):
+
+ widget = self.widgets[index]
+ if hasattr(widget, '_ui_select_all_'):
+ widget._ui_select_all_()
+
+ # -------------------------------------------------------------------------
+
+ def _ui_set_choices_(self, index, choices):
+
+ widget = self.widgets[index]
+ if hasattr(widget, '_ui_set_choices_'):
+ widget._ui_set_choices_(choices)
+
+
+# =============================================================================
+# 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
+ self.lookup = self
+ self._keypress_ = False
+
+
+ # -------------------------------------------------------------------------
+ # 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)
+
+ # -------------------------------------------------------------------------
+
+ def _ui_cut_(self):
+
+ if hasattr(self, 'cut'):
+ self.cut()
+
+ # -------------------------------------------------------------------------
+
+ def _ui_copy_(self):
+
+ if hasattr(self, 'copy'):
+ self.copy()
+
+ # -------------------------------------------------------------------------
+
+ def _ui_paste_(self):
+
+ if hasattr(self, 'paste'):
+ self.paste()
+
+ # -------------------------------------------------------------------------
+
+ def _ui_select_all_(self):
+
+ if hasattr(self, 'selectAll'):
+ self.selectAll()
+
+
+ # -------------------------------------------------------------------------
+ # 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 > 0,
+ state & qt.QKeyEvent.ControlButton > 0,
+ state & qt.QKeyEvent.AltButton > 0)
+
+ if command:
+ if command == 'NEWLINE':
+ self.ui_widget._request(command, text = '\n')
+ else:
+ self.ui_widget._request(command, triggerName = args)
+
+ 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)
+
+
+ # -------------------------------------------------------------------------
+ # Keep the GF-Focus in sync
+ # -------------------------------------------------------------------------
+
+ def focusInEvent(self, event):
+ """
+ Keep the GF-Focus in sync with the QT3-focus
+ """
+
+ self._block_focus = True
+ self.ui_widget._gfObject._event_set_focus(self.ui_widget.widgets.index(
+ self.lookup))
+ self._block_focus = False
+
+ self.qt_class.focusInEvent(self, event)
+
+
+# =============================================================================
+# Label widgets
+# =============================================================================
+
+class Label(BaseEntry, qt.QLabel):
+ """
+ Label widgets
+ """
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__(self, parent, ui_widget):
+ qt.QLabel.__init__(self, parent)
+ BaseEntry.__init__(self, ui_widget, qt.QLineEdit)
+
+ # -------------------------------------------------------------------------
+ # UI-Slots
+ # -------------------------------------------------------------------------
+
+ def _ui_set_value_(self, value):
+
+ self.setText(value)
+
+# =============================================================================
+# GridLabel
+# =============================================================================
+
+class GridLabel(qt.QLabel):
+ """
+ Implements a Label widget used within grid controls which is capable of
+ activating the corresponding entry widget on a mouse click.
+ """
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__(self, parent, ui_widget):
+
+ self.ui_widget = ui_widget
+ qt.QLabel.__init__(self, parent)
+
+
+ # -------------------------------------------------------------------------
+ # Event-handler
+ # -------------------------------------------------------------------------
+
+ def mousePressEvent(self, event):
+
+ # Find the widget this label belongs to
+ for (index, item) in enumerate(self.ui_widget.widgets):
+ if item._gnue_label_ == self:
+ if item.isEnabled():
+ # This replaces the label with the actual entry and sets
+ # the focus on the entry
+ self.ui_widget._gfObject.set_focus(index)
+ self.ui_widget._ui_set_focus_(index)
+
+ break
+
+
+# =============================================================================
+# 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)
+
+ self.connect(self, qt.SIGNAL('textChanged(const QString &)'),
+ self.__on_text_changed)
+
+ if password:
+ self.setEchoMode(qt.QLineEdit.Password)
+
+
+ # -------------------------------------------------------------------------
+ # Qt-Signals
+ # -------------------------------------------------------------------------
+
+ def __on_text_changed(self, value):
+
+ if not self.ui_widget._block_change_:
+ self.ui_widget._request('REPLACEVALUE', text=unicode(value),
+ position=self.cursorPosition())
+
+
+ # -------------------------------------------------------------------------
+ # 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())
+ self.ui_widget._request('SELECTWITHMOUSE', position1=left,
+ position2=right)
+ else:
+ self.ui_widget._request('CURSORMOVE', position=left)
+
+
+ # -------------------------------------------------------------------------
+ # UI-Slots
+ # -------------------------------------------------------------------------
+
+ def _ui_set_value_(self, value):
+
+ self.setText(value)
+
+
+
+# =============================================================================
+# 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)
+
+ self.__last_para = 0
+ self.__last_pos = 0
+
+ self.setTextFormat(qt.Qt.PlainText)
+
+ self.connect(self, qt.SIGNAL('textChanged()'),
+ self.__on_text_changed)
+ self.connect(self, qt.SIGNAL('cursorPositionChanged(int, int)'),
+ self.__on_cursor_changed)
+
+ # -------------------------------------------------------------------------
+ # UI slots
+ # -------------------------------------------------------------------------
+
+ def _ui_set_value_(self, value):
+
+ self.setText(value)
+
+ # -------------------------------------------------------------------------
+
+ def _ui_set_cursor_position_(self, position):
+
+ (para, offset) = self.__position_to_qt(position)
+ self.setCursorPosition(para, offset)
+
+ # -------------------------------------------------------------------------
+
+ def _ui_set_selected_area_(self, selection1, selection2):
+
+ (para1, offs1) = self.__position_to_qt(selection1)
+ (para2, offs2) = self.__position_to_qt(selection2)
+
+ self.setSelection(para1, offs1, para2, offs2)
+
+
+ # -------------------------------------------------------------------------
+ # Qt-Signals
+ # -------------------------------------------------------------------------
+
+ def __on_text_changed(self):
+
+ # FIXME: This signal is fired twice when a selection get's replaced by
+ # a new text. By doing this and the lack of a working
+ # getCursorPosition() replacing selected text does not work properly.
+ if not self.ui_widget._block_change_:
+ self.ui_widget._request('REPLACEVALUE', text=unicode(self.text()),
+ position=self.__qt_to_position() + 1)
+
+ # -------------------------------------------------------------------------
+
+ def __on_cursor_changed(self, para, pos):
+
+ # pyQT has a broken getCursorPosition(), so we have no chance to find
+ # out where the cursor is currently located. That's the reason for
+ # doing it this way.
+ self.__last_para = para
+ self.__last_pos = pos
+
+
+ # -------------------------------------------------------------------------
+ # Map a QT position into a GF position
+ # -------------------------------------------------------------------------
+
+ def __qt_to_position(self):
+
+ result = self.__last_pos + self.__last_para
+ for i in range(self.__last_para):
+ result += self.paragraphLength(i)
+
+ return result
+
+
+ # -------------------------------------------------------------------------
+ # Map a GF position into a QT position
+ # -------------------------------------------------------------------------
+
+ def __position_to_qt(self, position):
+
+ val = unicode(self.text())[:position]
+ para = val.count('\n')
+ offset = position
+ if para > 0:
+ offset = len(val.split('\n')[-1])
+
+ return (para, offset)
+
+
+# =============================================================================
+# Checkbox (TriState)
+# =============================================================================
+
+class CheckBox(BaseEntry, qt.QCheckBox):
+ """
+ Implementation of a Tri-State-Checkbox
+ """
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__(self, parent, ui_widget):
+
+ qt.QCheckBox.__init__(self, ui_widget._gfObject.label, parent)
+ BaseEntry.__init__(self, ui_widget, qt.QCheckBox)
+ self.setTristate(True)
+ # We have to set both TabFocus and ClickFocus for this widget,
+ # otherwise the checkbox won't request the focus-change on clicking
+ # into it using the mouse. This is needed to enable the GFInstance to
+ # process the TOGGLECHKBOX request
+ self.setFocusPolicy(qt.QWidget.StrongFocus)
+
+ self._blocked_ = False
+ self.connect(self, qt.SIGNAL('toggled(bool)'), self.__on_toggled)
+
+
+ # -------------------------------------------------------------------------
+ # Event-Handler
+ # -------------------------------------------------------------------------
+
+ def __on_toggled(self, state):
+
+ if not self._blocked_:
+ self.ui_widget._request('TOGGLECHKBOX')
+
+ # -------------------------------------------------------------------------
+ # UI-Slots
+ # -------------------------------------------------------------------------
+
+ def _ui_set_value_(self, value):
+
+ self._blocked_ = True
+ try:
+ if value is None:
+ self.setState(qt.QButton.NoChange)
+ elif value:
+ self.setState(qt.QButton.On)
+ else:
+ self.setState(qt.QButton.Off)
+
+ finally:
+ self._blocked_ = False
+
+
+# =============================================================================
+# 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
+
+ # -------------------------------------------------------------------------
+ # Implementation of virtual methods
+ # -------------------------------------------------------------------------
+
+ def _ui_set_choices_(self, choices):
+ self.clear()
+
+ for item in choices:
+ self.insertItem(item)
+
+
+# =============================================================================
+# 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.setDuplicatesEnabled(False)
+
+ self.__lineEdit = LineEdit(parent, ui_widget)
+ self.__lineEdit.lookup = self
+ self.setLineEdit(self.__lineEdit)
+
+ 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 _ui_set_value_(self, value):
+
+ 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)
+
+ # -------------------------------------------------------------------------
+
+ def _ui_cut_(self):
+
+ self.lineEdit().cut()
+
+ # -------------------------------------------------------------------------
+
+ def _ui_copy_(self):
+
+ self.lineEdit().copy()
+
+ # -------------------------------------------------------------------------
+
+ def _ui_paste_(self):
+
+ self.lineEdit().paste()
+
+ # -------------------------------------------------------------------------
+
+ def _ui_select_all_(self):
+
+ self.lineEdit().selectAll()
+
+
+# =============================================================================
+# Listbox widgets
+# =============================================================================
+
+class ListBox(ChoiceEntry, qt.QListBox):
+ """
+ Listbox widgets
+ """
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__(self, parent, ui_widget):
+
+ qt.QListBox.__init__(self, parent)
+ ChoiceEntry.__init__(self, ui_widget, qt.QListBox)
+
+ self.connect(self, qt.SIGNAL('highlighted(int)'),
self.__on_highlighted)
+
+
+ # -------------------------------------------------------------------------
+ # Event-Handler
+ # -------------------------------------------------------------------------
+
+ def __on_highlighted(self, index):
+ self.ui_widget._request('REPLACEVALUE',
+ text=unicode(self.currentText()))
+
+ # -------------------------------------------------------------------------
+
+ def _ui_set_value_(self, value):
+
+ self.setCurrentItem(self.findItem(value))
+
+
+
+
+# =============================================================================
+# Keymapper configuration: Translate from QT to our virtual keystrokes
+# =============================================================================
+
+qtKeyTranslations = {
+ vk.A : qt.Qt.Key_A, vk.C : qt.Qt.Key_C,
+ vk.V : qt.Qt.Key_V, vk.X : qt.Qt.Key_X,
+ 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.RETURN : qt.Qt.Key_Return, vk.BACKSPACE : qt.Qt.Key_Backspace }
+
+GFKeyMapper.KeyMapper.setUIKeyMap(qtKeyTranslations)
+
+
+# =============================================================================
+# Configuration
+# =============================================================================
+
+configuration = {
+ 'baseClass': UIEntry,
+ 'provides' : 'GFEntry',
+ 'container': False,
+}
Property changes on: trunk/gnue-forms/src/uidrivers/qt4/widgets/entry.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: trunk/gnue-forms/src/uidrivers/qt4/widgets/form.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt4/widgets/form.py 2007-01-26 06:47:06 UTC
(rev 9329)
+++ trunk/gnue-forms/src/uidrivers/qt4/widgets/form.py 2007-01-26 08:00:24 UTC
(rev 9330)
@@ -0,0 +1,443 @@
+# GNU Enterprise Forms - QT3 driver - Form widget
+#
+# Copyright 2001-2007 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
+# 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.
+#
+# $Id$
+"""
+Implementation of the UI layer for the <form> and <dialog> tag
+"""
+
+import qt
+import os
+
+from gnue.common.apps import GConfig
+from gnue.forms.uidrivers.qt3 import dialogs, QTApp
+from gnue.forms.uidrivers.qt3.MenuBar import MenuBar
+from gnue.forms.uidrivers.qt3.ToolBar import ToolBar
+from gnue.forms.uidrivers.qt3.widgets._base import UIHelper
+
+# =============================================================================
+# The form
+# =============================================================================
+
+class UIForm(UIHelper):
+ """
+ Implementation of the <form> and <dialog> tag
+ """
+
+ _TAB_STYLE = {'left': qt.QTabWidget.Top,
+ 'top' : qt.QTabWidget.Top,
+ 'right': qt.QTabWidget.Bottom,
+ 'bottom': qt.QTabWidget.Bottom}
+
+ _MBOX_KIND = {'Info' : {'style': qt.QMessageBox.information,
+ 'title': u_("Information"),
+ 'btns' : [qt.QMessageBox.Ok]},
+ 'Warning' : {'style': qt.QMessageBox.warning,
+ 'title': u_("Warning"),
+ 'btns' : [qt.QMessageBox.Ok]},
+ 'Question': {'style': qt.QMessageBox.question,
+ 'title': u_("Question"),
+ 'btns' : [qt.QMessageBox.Yes,
+ qt.QMessageBox.No]},
+ 'Error' : {'style': qt.QMessageBox.critical,
+ 'title': u_("Error"),
+ 'btns' : [qt.QMessageBox.Ok]}}
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__(self, event):
+
+ UIHelper.__init__(self, event)
+
+ self.pages = []
+ self.main_window = None
+
+ self._form = None
+ self.__status_bar = None
+ self.__status_fields = []
+ self.sizing_enabled = False
+
+
+ # -------------------------------------------------------------------------
+ # Create a new window object
+ # -------------------------------------------------------------------------
+
+ def _create_widget_(self, event, spacer):
+
+ if self._form.style != 'dialog':
+ self.main_window = self._uiDriver._parentContainer
+ if not self.main_window:
+ self.main_window = MainWindow(self)
+ else:
+ self.main_window = Dialog(self)
+
+ self.main_window.setCaption(self._form.title)
+
+ self.main_widget = qt.QWidget(self.main_window)
+ if self._form.style != 'dialog':
+ self.main_window.setCentralWidget(self.main_widget)
+
+ base_sizer = qt.QVBoxLayout(self.main_widget)
+ base_sizer.setMargin(6)
+ base_sizer.setResizeMode(qt.QLayout.Minimum)
+
+ if self._form.style != 'dialog':
+ if not self._form._features['GUI:STATUSBAR:SUPPRESS']:
+ self.__status_bar = self.main_window.statusBar()
+ self.__setup_status_bar()
+
+ if not self._form._features['GUI:MENUBAR:SUPPRESS']:
+ MenuBar(self._uiDriver, self.main_window, self._form)
+
+ if not self._form._features['GUI:TOOLBAR:SUPPRESS']:
+ tlb = ToolBar(self._uiDriver, self.main_window, self._form)
+
+ if self._form._layout.tabbed != 'none':
+ self._container = qt.QTabWidget(self.main_widget)
+ self._container.setTabPosition( \
+ self._TAB_STYLE[self._form._layout.tabbed])
+ base_sizer.addWidget(self._container)
+ self._container.connect(self._container,
+ qt.SIGNAL('currentChanged(QWidget*)'), self.__on_page_changed)
+ 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
+ # -------------------------------------------------------------------------
+
+ def show(self):
+ """
+ Show the form or dialog modeless
+ """
+
+ self.sizing_enabled = True
+ self.main_window.show()
+ self._uiDriver.hide_splash()
+
+
+ # -------------------------------------------------------------------------
+ # Show the form/dialog modal
+ # -------------------------------------------------------------------------
+
+ def show_modal(self):
+ """
+ Show the dialog modal. This seems only possible for QDialog instances.
+ """
+
+ self._uiDriver.hide_splash()
+ self.sizing_enabled = True
+ if isinstance(self.main_window, qt.QDialog):
+ self.main_window.setModal(True)
+ self.main_window.exec_loop()
+ else:
+ self.main_window.show()
+
+
+ # -------------------------------------------------------------------------
+ # Show a given page
+ # -------------------------------------------------------------------------
+
+ def show_page(self, page_index):
+ """
+ Show a given <page> in the current container
+
+ @param page_index: the zero-based index of the page to show
+ """
+
+ if isinstance(self._container, qt.QTabWidget):
+ self._container.blockSignals(True)
+ try:
+ self._container.setCurrentPage(page_index)
+ finally:
+ self._container.blockSignals(False)
+ else:
+ self.main_window.setUpdatesEnabled(False)
+ try:
+ for (index, page) in enumerate(self.pages):
+ if index == page_index:
+ page.show()
+ else:
+ page.hide()
+ finally:
+ self.main_window.setUpdatesEnabled(True)
+ self.main_window.repaint()
+
+ # -------------------------------------------------------------------------
+ # Populate the status bar
+ # -------------------------------------------------------------------------
+
+ def __setup_status_bar(self):
+
+ self.__status_bar.setSizeGripEnabled(True)
+
+ for i in [-1, 50, 50, 75, 75]:
+ widget = qt.QLabel(self.__status_bar)
+ self.__status_fields.append(widget)
+ if i > -1:
+ widget.setMinimumWidth(75)
+ stretch = 0
+ else:
+ stretch = 1
+ self.__status_bar.addWidget(widget, stretch, True)
+
+ # -------------------------------------------------------------------------
+ # Event-handler
+ # -------------------------------------------------------------------------
+
+ def __on_page_changed(self, widget):
+ index = self._container.indexOf(widget)
+ self._container.blockSignals(True)
+ try:
+ self._form._event_page_changed(index)
+ finally:
+ self._container.blockSignals(False)
+
+
+
+ # -------------------------------------------------------------------------
+ # User feedback functions
+ # -------------------------------------------------------------------------
+
+ def _ui_begin_wait_(self):
+ """
+ Display the hourglass cursor on all windows of the application.
+ """
+ self.main_window.setCursor(qt.QCursor(qt.Qt.WaitCursor))
+
+ # -------------------------------------------------------------------------
+
+ def _ui_end_wait_(self):
+ """
+ Display the normal mouse cursor on all windows of the application.
+ """
+ self.main_window.setCursor(qt.QCursor(qt.Qt.ArrowCursor))
+
+ # -------------------------------------------------------------------------
+
+ def _ui_beep_(self):
+ """
+ Ring the system bell
+ """
+ QTApp.getQtApp().beep()
+
+ # -------------------------------------------------------------------------
+
+ def _ui_update_status_(self, tip, record_status, insert_status,
+ record_number, record_count, page_number, page_count):
+ """
+ Update the apropriate section of the status bar with the given
+ information.
+
+ @param tip: message to be shown in the first section
+ @param record_status: message for the second section
+ @param insert_status: message for the third section
+ @param record_number: number of the current record
+ @param record_count: number of available records. Together with
+ record_number this will be set into the 4th section
+ @param page_number: number of the current page
+ @param page_count: number of available pages. Together with the
+ page_number this will be set into the 5th section
+ """
+
+ if not self.__status_bar:
+ return
+
+ if tip:
+ self.__status_fields[0].setText(tip)
+
+ if record_status is not None:
+ self.__status_fields[1].setText(record_status)
+
+ if insert_status is not None:
+ self.__status_fields[2].setText(insert_status)
+
+ if record_number and record_count:
+ self.__status_fields[3].setText(
+ "%s/%s" % (record_number, record_count))
+
+ if page_number and page_count:
+ self.__status_fields[4].setText(
+ "%s/%s" % (page_number, page_count))
+
+ # -------------------------------------------------------------------------
+
+ def _ui_goto_page_(self, page):
+ """
+ Change to container to show the requested page
+
+ @param page: UIPage instance to show
+ """
+
+ self.show_page(page.page_index)
+
+ # -------------------------------------------------------------------------
+
+ def _ui_show_message_(self, message, kind, title, cancel):
+ """
+ This function creates a message box of a given kind and returns True,
+ False or None depending on the button pressed.
+
+ @param message: the text of the messagebox
+ @param kind: type of the message box.
+ Valid types are 'Info', 'Warning', 'Question', 'Error'
+ @param title: title of the message box
+ @param cancel: If True a cancel button will be added to the dialog
+
+ @return: True if the Ok-, Close-, or Yes-button was pressed, False if
+ the No-button was pressed or None if the Cancel-button was pressed.
+ """
+
+ 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 = self._MBOX_KIND[kind]['title']
+
+ 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
+
+ # -------------------------------------------------------------------------
+
+ def _ui_show_about_(self, name, version, author, description):
+ """
+ Show the about box describing the current application
+ """
+ idir = GConfig.getInstalledBase('forms_images', 'common_images')
+ icon = os.path.join(idir, 'gnue-icon.png')
+
+ dlg = dialogs.AboutBox(self.main_window, name, version, author,
+ description, icon)
+ dlg.exec_loop()
+
+ # -------------------------------------------------------------------------
+
+ def _ui_close_(self):
+ """
+ Close the window (acutally only hide it)
+ """
+ self.sizing_enabled = False
+ self.main_window.hide()
+
+# =============================================================================
+# Window class
+# =============================================================================
+
+class MainWindow(qt.QMainWindow):
+ """
+ A forms main window
+ """
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__(self, ui_form):
+
+ self.ui_form = ui_form
+ self._closing_ = False
+ qt.QMainWindow.__init__(self)
+
+
+ # -------------------------------------------------------------------------
+ # Close of a form
+ # -------------------------------------------------------------------------
+
+ def close(self, *args):
+ """
+ Only close the form if @I{_closing_} is set to True, otherwise pass the
+ close request back to the bound GFForm instance.
+ """
+
+ if self._closing_:
+ return qt.QMainWindow.close(self, *args)
+ else:
+ self.ui_form._form.close()
+ return False
+
+
+# =============================================================================
+# A dialog type form
+# =============================================================================
+
+class Dialog(qt.QDialog):
+ """
+ Qt-Widget for dialog style forms
+ """
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__(self, ui_form):
+
+ self.ui_form = ui_form
+ self._closing_ = False
+ qt.QDialog.__init__(self)
+
+
+ # -------------------------------------------------------------------------
+ # Close a dialog
+ # -------------------------------------------------------------------------
+
+ def close(self, *args):
+ """
+ Only close the form if @I{_closing_} is set to True, otherwise pass the
+ close request back to the bound GFForm instance.
+ """
+
+ if self._closing_:
+ return qt.QDialog.close(self, *args)
+ else:
+ self.ui_form._form.close()
+ return False
+
+
+# =============================================================================
+# Configuration
+# =============================================================================
+
+configuration = {
+ 'baseClass': UIForm,
+ 'provides': 'GFForm',
+ 'container': 1
+}
Property changes on: trunk/gnue-forms/src/uidrivers/qt4/widgets/form.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: trunk/gnue-forms/src/uidrivers/qt4/widgets/grid.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt4/widgets/grid.py 2007-01-26 06:47:06 UTC
(rev 9329)
+++ trunk/gnue-forms/src/uidrivers/qt4/widgets/grid.py 2007-01-26 08:00:24 UTC
(rev 9330)
@@ -0,0 +1,267 @@
+# GNU Enterprise Forms - QT3 UI driver - Grid Widgets
+#
+# Copyright 2001-2007 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
+# 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.
+#
+# $Id$
+
+import qt
+
+from gnue.forms.uidrivers.qt3.widgets import _base
+
+__all__ = ['UIGrid']
+
+# =============================================================================
+# Interface implementation for a grid widget
+# =============================================================================
+
+class UIGrid(_base.UIHelper):
+ """
+ The visual container for the grid control.
+ """
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__(self, event):
+
+ _base.UIHelper.__init__(self, event)
+ self.__max = 0
+ self.__visible = 0
+ self.growable = True
+
+
+ # -------------------------------------------------------------------------
+ # Create a wx box widget
+ # -------------------------------------------------------------------------
+
+ def _create_widget_ (self, event, spacer):
+ """
+ Create the QWidget for the grid control and add it to the owner.
+ The spacer is ignored for <grid> tags.
+
+ @param event: the creation-event instance carrying information like
+ container (parent-widget)
+ @param spacer: not used for grid tags
+
+ @returns: the QLayout instance used for adding the rows
+ """
+ parent = event.container
+
+ self.widget = qt.QFrame(parent)
+
+ hbox = qt.QHBoxLayout(self.widget, 2)
+
+ self._container = ResizeContainer(self.widget, self)
+ self.scroll = qt.QScrollBar(qt.Qt.Vertical, self.widget)
+
+ hbox.addWidget(self._container, 1)
+ hbox.addWidget(self.scroll, 0)
+
+ self.rowsizer = qt.QGridLayout(self._container)
+
+ self.__max = self._gfObject.rows
+ self.__visible = self.__max
+
+ self.__build_header()
+
+ self.getParent().add_widgets(self, spacer)
+
+ return None
+
+
+ # -------------------------------------------------------------------------
+ # Build the first row of the grid (the header)
+ # -------------------------------------------------------------------------
+
+ def __build_header(self):
+
+ cols = {}
+ linenum = 0
+ for line in self._gfObject.findChildrenOfType('GFGridLine', True,
True):
+ index = 0
+ for item in line._children:
+ span = int(getattr(item, 'Sizer__span', 1))
+ cols.setdefault(index, []).append(getattr(item, 'label', None))
+ index += span
+ linenum += 1
+
+ colnum = cols.keys()
+ colnum.sort()
+
+ for clx in colnum:
+ self.rowsizer.setColStretch(clx, 1)
+
+ pnl = qt.QFrame(self._container)
+ vbx = qt.QVBoxLayout(pnl)
+
+ for label in cols[clx]:
+ stc = qt.QLabel(label, pnl)
+ vbx.addWidget(stc)
+
+ self.rowsizer.addMultiCellWidget(pnl, 0, 0, clx, clx)
+
+
+ # -------------------------------------------------------------------------
+ # Get the row-number of a concrete gridline in the GridBagSizer
+ # -------------------------------------------------------------------------
+
+ def _get_row(self, line, record):
+ """
+ Get the row number of a concrete gridline in the QGridLayout
+ @param line: the UIGridLine instance we're interested in
+ @param record: the spacer (rel. record-number) of the line in question
+ @returns: the row within the QGridLayout
+ """
+
+ return len(self._children) * record + self._children.index(line) + 1
+
+
+ # -------------------------------------------------------------------------
+ # Adjust scrollbar if the current record has changed
+ # -------------------------------------------------------------------------
+
+ def _ui_adjust_scrollbar_(self, position, size, count):
+ """
+ Adjust the thumb-position and the number of rows of the scrollbar
+ """
+ self.scroll.setMaxValue(count)
+ self.scroll.setPageStep(size)
+ self.scroll.setValue(position)
+
+
+ # -------------------------------------------------------------------------
+ # Add or remove records from the grid
+ # -------------------------------------------------------------------------
+
+ def update_records(self, num_recs):
+
+ if num_recs > self.__visible:
+ self.__add_new_records(num_recs - self.__visible)
+ self._gfObject._event_rows_changed(self.__visible)
+ else:
+ self.__hide_records(self.__visible - num_recs)
+ self._gfObject._event_rows_changed(self.__visible)
+
+
+ # -------------------------------------------------------------------------
+ # Add new records to the grid (after resizing it)
+ # -------------------------------------------------------------------------
+
+ def __add_new_records(self, num_recs):
+
+ for index in range(num_recs):
+ record = self.__visible + index
+
+ if record >= self.__max:
+ self.walk(self.__child_add_walker, record)
+ self.__change_visibility(record, True)
+ self.__max += 1
+ else:
+ self.__change_visibility(record, True)
+
+ self.__visible += num_recs
+
+ self._uiForm.main_window.updateGeometry()
+
+
+ # -------------------------------------------------------------------------
+ # Create all child-widgets
+ # -------------------------------------------------------------------------
+
+ def __child_add_walker(self, item, spacer):
+
+ if item == self:
+ return
+
+ widget = item.create_widget(item._creationEvent, spacer)
+ item.widgets.append(widget)
+
+
+ # -------------------------------------------------------------------------
+ # Show or hide grid lines
+ # -------------------------------------------------------------------------
+
+ def __change_visibility(self, record, state):
+
+ grid = self._container.layout()
+
+ for item in self._children:
+ for panel in item._columns[record]:
+ if state:
+ panel.show()
+ else:
+ panel.hide()
+
+
+ # -------------------------------------------------------------------------
+ # Hide a given number of records
+ # -------------------------------------------------------------------------
+
+ def __hide_records(self, num_recs):
+
+ for index in range(num_recs):
+ self.__change_visibility(self.__visible-1, False)
+ self.__visible -= 1
+
+ self._uiForm.main_window.updateGeometry()
+
+
+# =============================================================================
+# Qt class implementing the grid-container
+# =============================================================================
+
+class ResizeContainer(qt.QWidget):
+ def __init__(self, parent, ui_grid):
+ qt.QWidget.__init__(self, parent)
+ self.ui_grid = ui_grid
+
+ def resizeEvent(self, event):
+ qt.QWidget.resizeEvent(self, event)
+
+ if not self.ui_grid._uiForm.sizing_enabled:
+ return
+
+ saved = self.ui_grid._uiForm.sizing_enabled
+ self.ui_grid._uiForm.sizing_enabled = False
+ try:
+ header = self.layout().cellGeometry(0, 0)
+ rech = 0
+ for item in self.ui_grid._children:
+ rech += max([panel.layout().minimumSize().height() \
+ for panel in item._columns[0]])
+ available = self.size().height() - header.height()
+ num_recs = available / rech
+
+ self.ui_grid.update_records(num_recs)
+
+ finally:
+ self.ui_grid._uiForm.sizing_enabled = saved
+
+
+# =============================================================================
+# Configuration data
+# =============================================================================
+
+configuration = {
+ 'baseClass': UIGrid,
+ 'provides' : 'GFGrid',
+ 'container': 1
+}
Property changes on: trunk/gnue-forms/src/uidrivers/qt4/widgets/grid.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: trunk/gnue-forms/src/uidrivers/qt4/widgets/gridline.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt4/widgets/gridline.py 2007-01-26
06:47:06 UTC (rev 9329)
+++ trunk/gnue-forms/src/uidrivers/qt4/widgets/gridline.py 2007-01-26
08:00:24 UTC (rev 9330)
@@ -0,0 +1,164 @@
+# GNU Enterprise Forms - QT3 UI Driver - GridLine widget
+#
+# Copyright 2001-2007 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
+# 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.
+#
+# $Id$
+"""
+Implementation of a <gridline>. A gridline is a logical line within a <grid>
+and defines the controls building up the line.
+"""
+
+import qt
+
+from gnue.forms.uidrivers.qt3.widgets import _base
+
+__all__ = ['UIGridLine']
+
+# =============================================================================
+# Interface implementation for a grid line widget
+# =============================================================================
+
+class UIGridLine (_base.UIHelper):
+ """
+ Collection of controls building a given line in a grid.
+
+ @ivar _columns: a dictionary which holds a sequence of QFrame instances
+ per spacer. Each of these panels will get the parent widget for the
+ control located in that cell.
+ """
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__(self, event):
+
+ _base.UIHelper.__init__(self, event)
+ self._columns = {}
+
+
+ # -------------------------------------------------------------------------
+ # Create the line widget
+ # -------------------------------------------------------------------------
+
+ def _create_widget_ (self, event, spacer):
+ """
+ Prepare the columns (cells) for the girdline and add it to the owner.
+ """
+
+ parent = event.container
+ self.__prepare_columns(parent, spacer)
+ self._container = parent
+
+ return None
+
+
+ # -------------------------------------------------------------------------
+ # Prepare the cells for this gridline
+ # -------------------------------------------------------------------------
+
+ def __prepare_columns(self, parent, spacer):
+
+ owner = self.getParent()
+ sizer = parent.layout()
+ row = owner._get_row(self, spacer)
+
+ offset = 0
+ for child in self._children:
+ panel = qt.QWidget(parent)
+ hbx = qt.QHBoxLayout(panel)
+
+ if not spacer % 2:
+ name = 'grid_color_even'
+ else:
+ name = 'grid_color_odd'
+
+ color = self.__load_color_from_string(gConfigForms(name))
+ panel.setPaletteBackgroundColor(color)
+
+ self._columns.setdefault(spacer, []).append(panel)
+
+ sizer.addMultiCellWidget(panel, row, row, offset, offset +
+ child.span)
+ offset += child.span
+
+
+ # -------------------------------------------------------------------------
+ # Load the given colorname form the database or parse it as hex-rgb-string
+ # -------------------------------------------------------------------------
+
+ def __load_color_from_string(self, value):
+
+ result = qt.QColor(value)
+ if not result.isValid():
+ (red, green, blue) = value[:2], value[2:4], value[4:6]
+ result = qt.QColor(int(red, 16), int(green, 16), int(blue, 16))
+
+ return result
+
+
+ # -------------------------------------------------------------------------
+ # Add an UI widget to the Grid container
+ # -------------------------------------------------------------------------
+
+ def add_widgets(self, ui_widget, spacer):
+ """
+ Add a given UI widget to the gridline.
+
+ @param ui_widget: widget to add to the page
+ @param spacer: the row-index (relative record number) to add the
widget
+ """
+
+ panel = self._get_cell(ui_widget, spacer)
+ sizer = panel.layout()
+
+ if ui_widget.label:
+ sizer.addWidget(ui_widget.label)
+ sizer.addWidget(ui_widget.widget)
+
+ if ui_widget.label:
+ ui_widget.widget.hide()
+
+
+ # -------------------------------------------------------------------------
+ # Get the cell-parent for a given child-control
+ # -------------------------------------------------------------------------
+
+ def _get_cell(self, ui_widget, spacer):
+ """
+ Return the wx.Panel instance (acting as parent widget) for a given
+ UI-Widget.
+
+ @param ui_widget: the UIWidget to get the cell parent for
+ @param spacer: the spacer of the row to get the cell parent for
+ """
+ index = self._children.index(ui_widget)
+ return self._columns[spacer][index]
+
+
+# =============================================================================
+# Configuration data
+# =============================================================================
+
+configuration = {
+ 'baseClass': UIGridLine,
+ 'provides' : 'GFGridLine',
+ 'container': 1
+}
Property changes on: trunk/gnue-forms/src/uidrivers/qt4/widgets/gridline.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: trunk/gnue-forms/src/uidrivers/qt4/widgets/hbox.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt4/widgets/hbox.py 2007-01-26 06:47:06 UTC
(rev 9329)
+++ trunk/gnue-forms/src/uidrivers/qt4/widgets/hbox.py 2007-01-26 08:00:24 UTC
(rev 9330)
@@ -0,0 +1,86 @@
+# GNU Enterprise Forms - QT3 UI driver - VBox widgets
+#
+# Copyright 2001-2007 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
+# 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.
+#
+# $Id$
+
+import qt
+
+from gnue.forms.uidrivers.qt3.widgets._base import ManagedBox
+
+__all__ = ['UIHBox']
+
+# =============================================================================
+# Interface implementation for a box widget
+# =============================================================================
+
+class UIHBox(ManagedBox):
+ """
+ Implementation of the <hbox> tag
+ """
+
+ _vertical_ = False
+
+ # -------------------------------------------------------------------------
+ # Add an item to the box
+ # -------------------------------------------------------------------------
+
+ def add_widgets(self, ui_widget, spacer):
+ """
+ Add a given UI widget to the horizontal box
+
+ @param ui_widget: the widget to be added
+ @param spacer: not used for boxes
+ """
+
+ both = isinstance(ui_widget, ManagedBox)
+ add = False
+
+ if ui_widget.label:
+ add = True
+ self.sizer.addMultiCellWidget(ui_widget.label, 0, 0,
+ self.last_item, self.last_item)
+
+ if ui_widget.widget:
+ add = True
+
+ span = 0
+ if both and not ui_widget.label:
+ span = 1
+
+ row = self._entry_pos - 1
+ self.sizer.addMultiCellWidget(ui_widget.widget, row, row+span,
+ self.last_item, self.last_item)
+
+ if add and ui_widget.growable:
+ self.sizer.setColStretch(self.last_item, ui_widget.stretch)
+
+ self.last_item += int(add)
+
+
+# =============================================================================
+# Configuration
+# =============================================================================
+
+configuration = {
+ 'baseClass': UIHBox,
+ 'provides' : 'GFHBox',
+ 'container': 0
+}
Property changes on: trunk/gnue-forms/src/uidrivers/qt4/widgets/hbox.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: trunk/gnue-forms/src/uidrivers/qt4/widgets/image.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt4/widgets/image.py 2007-01-26 06:47:06 UTC
(rev 9329)
+++ trunk/gnue-forms/src/uidrivers/qt4/widgets/image.py 2007-01-26 08:00:24 UTC
(rev 9330)
@@ -0,0 +1,170 @@
+# GNU Enterprise Forms - QT3 UI driver - Image widget
+#
+# Copyright 2001-2007 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
+# 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.
+#
+# $Id$
+
+import qt
+import cStringIO
+
+try:
+ from PIL import Image as PILImage
+
+except:
+ PILImage = None
+
+from gnue.common.definitions import GParser
+from gnue.forms.uidrivers.qt3.widgets import _base
+
+# =============================================================================
+# Exceptions
+# =============================================================================
+
+class MissingSizeError(GParser.MarkupError):
+ """ Image has no size given """
+ def __init__(self, image):
+ msg = u_("Image '%(name)s' is missing one of Sizer:width or "
+ "Sizer:height") % {'name': image.name}
+ GParser.MarkupError.__init__(self, msg, image._url, image._lineNumber)
+
+
+# =============================================================================
+# Wrap an UI layer around a wx image
+# =============================================================================
+
+class UIImage (_base.UIHelper):
+ """
+ Creates a single instance of an image.
+ """
+
+ # ------------------------------------------------------------------------
+ # Create an image widget
+ # ------------------------------------------------------------------------
+
+ def _create_widget_ (self, event, spacer):
+ """
+ Creates a new StaticBitmap widget.
+ """
+
+ parent = event.container
+
+ (min_w, min_h) = self.get_default_size()
+ self.widget = qt.QScrollView(parent)
+ self.widget.setMinimumSize(min_w, min_h)
+
+ image = qt.QLabel(self.widget)
+ self.widget.addChild(image)
+
+ self.getParent().add_widgets(self, spacer)
+
+ return image
+
+
+ # -------------------------------------------------------------------------
+ # Get the default size for the image
+ # -------------------------------------------------------------------------
+
+ def get_default_size(self):
+
+ if self.managed:
+ width = int(getattr(self._gfObject, 'Sizer__width', -1))
+ height = int(getattr(self._gfObject, 'Sizer__height', -1))
+ if width == -1 or height == -1:
+ raise MissingSizeError(self._gfObject)
+ else:
+ width = self._uiDriver.cell_width * self.chr_w
+ height = self._uiDriver.cell_height * self.chr_h
+
+ return (width, height)
+
+
+ # -------------------------------------------------------------------------
+ # Set "editable" status for this widget
+ # -------------------------------------------------------------------------
+
+ def _ui_set_editable_(self, index, editable):
+
+ pass
+
+
+ # ------------------------------------------------------------------------
+ # Set the widget's PIL
+ # ------------------------------------------------------------------------
+
+ def _ui_set_value_(self, index, value):
+ """
+ Loads an image.
+ """
+
+ if PILImage is None:
+ return
+
+ widget = self.widgets [index]
+ scrx, scry = self.get_default_size()
+ imgx, imgy = value.size
+
+ scalex = scaley = 1
+
+ fit = self._gfObject.fit
+
+ if fit == "auto":
+ if float (scrx) / imgx < float (scry) / imgy:
+ fit = "width"
+ else:
+ fit = "height"
+
+ if fit == "width":
+ scalex = scaley = float (scrx) / imgx
+
+ elif fit == "height":
+ scalex = scaley = float (scry) / imgy
+
+ elif fit == "both":
+ scalex = float (scrx) / imgx
+ scaley = float (scry) / imgy
+ else:
+ self.widget.resizeContents(imgx, imgy)
+
+ if scalex != 1 or scaley != 1:
+ value = value.resize ((abs(int(imgx * scalex)),
+ abs(int(imgy * scaley))), PILImage.BICUBIC)
+
+ # Convert the PIL Image to a QPixmap
+ # TODO: find a better way than using StringIO
+ # Note: the PIL 1.1.6 release contains ImageQT
+ # which allows direct convertion into qt4
+ # compatible objects via ImageQt.ImageQt(PILimage)
+ #
+ f = cStringIO.StringIO()
+ value.save(f, 'PNG')
+ pxm = qt.QPixmap()
+ pxm.loadFromData(f.getvalue())
+ widget.setPixmap(pxm)
+ pxmSize = pxm.size()
+
+# =============================================================================
+# Configuration data
+# =============================================================================
+
+configuration = {
+ 'baseClass': UIImage,
+ 'provides' : 'GFImage',
+ 'container': 0,
+}
Property changes on: trunk/gnue-forms/src/uidrivers/qt4/widgets/image.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: trunk/gnue-forms/src/uidrivers/qt4/widgets/label.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt4/widgets/label.py 2007-01-26 06:47:06 UTC
(rev 9329)
+++ trunk/gnue-forms/src/uidrivers/qt4/widgets/label.py 2007-01-26 08:00:24 UTC
(rev 9330)
@@ -0,0 +1,63 @@
+# GNU Enterprise Forms - QT3 UI driver - Label widgets
+#
+# Copyright 2001-2007 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
+# 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.
+#
+# $Id$
+
+import qt
+
+from gnue.forms.uidrivers.qt3.widgets._base import UIHelper
+
+_alignment = {
+ 'left' : qt.Qt.AlignLeft | qt.Qt.AlignVCenter,
+ 'center': qt.Qt.AlignHCenter | qt.Qt.AlignVCenter,
+ 'right' : qt.Qt.AlignRight | qt.Qt.AlignVCenter}
+
+# =============================================================================
+# UI Label widget
+# =============================================================================
+
+class UILabel(UIHelper):
+ """
+ """
+
+ # -------------------------------------------------------------------------
+ # Create the widget
+ # -------------------------------------------------------------------------
+
+ def _create_widget_(self, event, spacer):
+
+ self.widget = qt.QLabel(self._gfObject.text, event.container)
+ self.widget.setAlignment(_alignment[self._gfObject.alignment])
+
+ self.getParent().add_widgets(self, spacer)
+
+ return self.widget
+
+
+# =============================================================================
+# Configuration
+# =============================================================================
+
+configuration = {
+ 'baseClass': UILabel,
+ 'provides' : 'GFLabel',
+ 'container': 0,
+}
Property changes on: trunk/gnue-forms/src/uidrivers/qt4/widgets/label.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: trunk/gnue-forms/src/uidrivers/qt4/widgets/page.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt4/widgets/page.py 2007-01-26 06:47:06 UTC
(rev 9329)
+++ trunk/gnue-forms/src/uidrivers/qt4/widgets/page.py 2007-01-26 08:00:24 UTC
(rev 9330)
@@ -0,0 +1,108 @@
+# GNU Enterprise Forms - QT3 driver - Page widget
+#
+# Copyright 2001-2007 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
+# 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.
+#
+# $Id$
+
+import qt
+
+from _base import UIHelper
+
+# =============================================================================
+# UIPage implements a <page> tag
+# =============================================================================
+
+class UIPage(UIHelper):
+ """
+ Implmenetation of the page tag
+
+ @ivar page_index: zero-based index of the page within the form's
+ page-container (which is either a notebook or a panel).
+ """
+
+ page_index = 0
+
+ # -------------------------------------------------------------------------
+ # Create a new page widget
+ # -------------------------------------------------------------------------
+
+ def _create_widget_(self, event, spacer):
+ """
+ Create the page widget and add it to the page-container. The spacer is
+ ignored for page tags.
+
+ @returns: the QWidget instance which is the parent for all child
+ widgets of this page. It has already a QLayout descendant set.
+ """
+
+ self.page_index = len(self._uiForm.pages)
+
+ parent = event.container
+
+ self._container = qt.QWidget(parent)
+ if self.managed:
+ page_sizer = qt.QVBoxLayout(self._container)
+ else:
+ w = getattr(self._form._layout, 'Char__width', -1)
+ h = getattr(self._form._layout, 'Char__height', -1)
+ page_sizer = qt.QGridLayout(self._container, h, w, 2, 2)
+
+ if isinstance(parent, qt.QTabWidget):
+ title = "%s" % (self._gfObject.caption or self._gfObject.name)
+ parent.addTab(self._container, title)
+ else:
+ parent.layout().addWidget(self._container)
+
+ self._uiForm.pages.append(self._container)
+
+ return self._container
+
+
+ # -------------------------------------------------------------------------
+ # Add an UI widget to the page
+ # -------------------------------------------------------------------------
+
+ def add_widgets(self, ui_widget, spacer):
+ """
+ Add an UI widget to the page
+
+ @param ui_widget: UI widget to be added
+ @param spacer: not used for pages
+ """
+
+ item = ui_widget.widget
+ sizer = self._container.layout()
+
+ if self.managed:
+ sizer.addWidget(item)
+ else:
+ sizer.addMultiCellWidget(item, ui_widget.chr_y, ui_widget.chr_y +
+ ui_widget.chr_h - 1, ui_widget.chr_x, ui_widget.chr_x +
+ ui_widget.chr_w - 1)
+
+# =============================================================================
+# Configuration
+# =============================================================================
+
+configuration = {
+ 'baseClass': UIPage,
+ 'provides' : 'GFPage',
+ 'container': 1
+}
Property changes on: trunk/gnue-forms/src/uidrivers/qt4/widgets/page.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: trunk/gnue-forms/src/uidrivers/qt4/widgets/scrollbar.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt4/widgets/scrollbar.py 2007-01-26
06:47:06 UTC (rev 9329)
+++ trunk/gnue-forms/src/uidrivers/qt4/widgets/scrollbar.py 2007-01-26
08:00:24 UTC (rev 9330)
@@ -0,0 +1,81 @@
+# GNU Enterprise Forms - QT3 UI driver - ScrollBar widgets
+#
+# Copyright 2001-2007 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
+# 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.
+#
+# $Id$
+
+import qt
+
+from gnue.forms.uidrivers.qt3.widgets._base import UIHelper
+
+# =============================================================================
+# The scrollbar widget
+# =============================================================================
+
+class UIScrollBar(UIHelper):
+ """
+ Implementation of the <scrollbar> tag
+ """
+
+ # -------------------------------------------------------------------------
+ # Create a new widget
+ # -------------------------------------------------------------------------
+
+ def _create_widget_(self, event, spacer):
+
+ parent = event.container
+
+ self.widget = qt.QScrollBar(qt.Qt.Vertical, parent)
+ self.getParent().add_widgets(self, spacer)
+
+ self.widget.connect(self.widget, qt.SIGNAL('valueChanged(int)'),
+ self.__on_value_changed)
+
+ return self.widget
+
+
+ # -------------------------------------------------------------------------
+ # Handle changes of the current value
+ # -------------------------------------------------------------------------
+
+ def __on_value_changed(self, value):
+
+ self._gfObject._event_scrollToRecord(value)
+
+
+ # -------------------------------------------------------------------------
+ # Adjust the scrollbar to a new position
+ # -------------------------------------------------------------------------
+
+ def _ui_adjust_scrollbar_(self, position, size, count):
+
+ self.widget.setMaxValue(count)
+ self.widget.setPageStep(size)
+ self.widget.setValue(position)
+
+# =============================================================================
+# Configuration
+# =============================================================================
+
+configuration = {
+ 'baseClass': UIScrollBar,
+ 'provides' : 'GFScrollBar',
+ 'container': 0,
+}
Property changes on: trunk/gnue-forms/src/uidrivers/qt4/widgets/scrollbar.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: trunk/gnue-forms/src/uidrivers/qt4/widgets/vbox.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt4/widgets/vbox.py 2007-01-26 06:47:06 UTC
(rev 9329)
+++ trunk/gnue-forms/src/uidrivers/qt4/widgets/vbox.py 2007-01-26 08:00:24 UTC
(rev 9330)
@@ -0,0 +1,90 @@
+# GNU Enterprise Forms - QT3 UI driver - VBox widgets
+#
+# Copyright 2001-2007 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
+# 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.
+#
+# $Id$
+
+import qt
+
+from gnue.forms.uidrivers.qt3.widgets._base import ManagedBox
+
+__all__ = ['UIVBox']
+
+# =============================================================================
+# Interface implementation for a box widget
+# =============================================================================
+
+class UIVBox(ManagedBox):
+ """
+ Implementation of the <vbox> tag
+ """
+
+ # -------------------------------------------------------------------------
+ # Add an item to the box
+ # -------------------------------------------------------------------------
+
+ def add_widgets(self, ui_widget, spacer):
+ """
+ Add a given UI widget to the vertical box. The following widgets span
+ both columns: vbox, hbox, grid and checkboxes
+
+ @param ui_widget: widget to add
+ @param spacer: not used for boxes
+ """
+
+ both = isinstance(ui_widget, ManagedBox) or \
+ isinstance(ui_widget.widget, qt.QCheckBox)
+ add = False
+
+ if ui_widget.label:
+ add = True
+ self.sizer.addMultiCellWidget(ui_widget.label, self.last_item,
+ self.last_item, 0, 0, qt.Qt.AlignLeft | qt.Qt.AlignTop)
+
+ if ui_widget.widget:
+ add = True
+
+ span = 0
+ row = self.last_item
+ left = self._entry_pos - 1
+ right = left + span
+
+ if both and not ui_widget.label:
+ left = 0
+ span = 1
+
+ self.sizer.addMultiCellWidget(ui_widget.widget, row, row, left,
+ right)
+
+ if add and ui_widget.growable:
+ self.sizer.setRowStretch(self.last_item, ui_widget.stretch)
+
+ self.last_item += int(add)
+
+
+# =============================================================================
+# Configuration
+# =============================================================================
+
+configuration = {
+ 'baseClass': UIVBox,
+ 'provides' : 'GFVBox',
+ 'container': 0
+}
Property changes on: trunk/gnue-forms/src/uidrivers/qt4/widgets/vbox.py
___________________________________________________________________
Name: svn:keywords
+ Id
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r9330 - in trunk/gnue-forms/src/uidrivers: . qt4 qt4/widgets,
jcater <=