[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
r6014 - in trunk/gnue-forms/src: . uidrivers/_base uidrivers/gtk2
From: |
johannes |
Subject: |
r6014 - in trunk/gnue-forms/src: . uidrivers/_base uidrivers/gtk2 |
Date: |
Wed, 21 Jul 2004 14:04:52 -0500 (CDT) |
Author: johannes
Date: 2004-07-21 14:04:51 -0500 (Wed, 21 Jul 2004)
New Revision: 6014
Modified:
trunk/gnue-forms/src/GFForm.py
trunk/gnue-forms/src/GFInstance.py
trunk/gnue-forms/src/uidrivers/_base/UIdriver.py
trunk/gnue-forms/src/uidrivers/gtk2/MenuBar.py
trunk/gnue-forms/src/uidrivers/gtk2/ToolBar.py
trunk/gnue-forms/src/uidrivers/gtk2/UIdriver.py
Log:
messageBox takes strings as box-type and returns True, False or None.
Modified: trunk/gnue-forms/src/GFForm.py
===================================================================
--- trunk/gnue-forms/src/GFForm.py 2004-07-21 17:52:51 UTC (rev 6013)
+++ trunk/gnue-forms/src/GFForm.py 2004-07-21 19:04:51 UTC (rev 6014)
@@ -42,7 +42,6 @@
from gnue.common.datasources import ConnectionTriggerObj
from gnue.forms.GFObjects import *
from gnue.forms import GFParser
-from gnue.forms.uidrivers._base import UIdriver as BaseDriver
# Defines which objects are "Tab Stops"
@@ -169,7 +168,6 @@
'GUI:STATUSBAR:SUPPRESS': False,
}
- self.__updateTriggerNs ()
self._in_trigger_lock = False
#
@@ -1094,19 +1092,3 @@
def triggerActivateTrigger(self,name):
self.processTrigger(name)
-
-
- # ---------------------------------------------------------------------------
- # Update the trigger namespace with some UI-driver constants
- # ---------------------------------------------------------------------------
-
- def __updateTriggerNs (self):
- """
- This function adds message-box-constants to the trigger namespace. Use the
- MBOX_* constants to define the type of message box to be displayed. All
- RESPONSE_* constants are the return values.
- """
- for k in ['MBOX_INFO', 'MBOX_WARNING', 'MBOX_ERROR', 'MBOX_QUESTION',
- 'RESPONSE_OK', 'RESPONSE_CLOSE', 'RESPONSE_CANCEL',
- 'RESPONSE_YES', 'RESPONSE_NO']:
- self._triggerns [k] = getattr (BaseDriver, k)
Modified: trunk/gnue-forms/src/GFInstance.py
===================================================================
--- trunk/gnue-forms/src/GFInstance.py 2004-07-21 17:52:51 UTC (rev 6013)
+++ trunk/gnue-forms/src/GFInstance.py 2004-07-21 19:04:51 UTC (rev 6014)
@@ -40,7 +40,6 @@
from gnue.forms.GFParser import loadFile
from gnue.forms import VERSION
from gnue.forms import GFKeyMapper
-from gnue.forms.uidrivers._base import UIdriver as BaseDriver
from gnue.common.apps import GDebug
from gnue.common.datasources import GDataObjects, GConnections
from gnue.common import events
@@ -479,7 +478,7 @@
# then the proxied event should set this to the
# message text
if event.__errortext__:
- self.displayMessageBox (event.__errortext__, BaseDriver.MBOX_ERROR)
+ self.displayMessageBox (event.__errortext__, 'Error')
def nextEntry(self, event):
"""
@@ -679,7 +678,7 @@
message = event._form.jumpRecord(count)
if message:
- self.displayMessageBox (message, BaseDriver.MBOX_ERROR)
+ self.displayMessageBox (message, 'Error')
return
@@ -766,7 +765,7 @@
if not event._form.isSaved():
self.displayMessageBox (_("Data not saved. Save changes or clear "
- "the form to proceed."), BaseDriver.MBOX_ERROR)
+ "the form to proceed."), 'Error')
event._form.refreshUIEvents()
else:
event._form.processTrigger('On-Exit')
@@ -774,7 +773,7 @@
_('Current data is saved'),
_formName=event._form.name)
except AbortRequest, t:
- self.displayMessageBox (t, BaseDriver.MBOX_WARNING)
+ self.displayMessageBox (t, 'Warning')
event._form.refreshUIEvents()
#
@@ -833,7 +832,7 @@
#
# Displays a generic message box
#
- def displayMessageBox (self, message = '', kind = BaseDriver.MBOX_INFO,
+ def displayMessageBox (self, message = '', kind = 'Info',
cancel = False, caption = 'GNUe Message', title = 'Information'):
parameters = {
'caption': caption,
@@ -841,8 +840,7 @@
'title' : title
}
if hasattr (self._uiinstance, 'messageBox'):
- res = self._uiinstance.messageBox (message, kind, title, cancel)
- return res
+ return self._uiinstance.messageBox (message, kind, title, cancel)
else:
self.activateForm ('_messageBox', parameters, modal = 1)
Modified: trunk/gnue-forms/src/uidrivers/_base/UIdriver.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/_base/UIdriver.py 2004-07-21 17:52:51 UTC
(rev 6013)
+++ trunk/gnue-forms/src/uidrivers/_base/UIdriver.py 2004-07-21 19:04:51 UTC
(rev 6014)
@@ -63,10 +63,7 @@
except ImportError:
return 'default'
-MBOX_INFO = 0
-MBOX_WARNING = 1
-MBOX_QUESTION = 2
-MBOX_ERROR = 3
+MBOX_TYPES = ['Info', 'Warning', 'Question', 'Error']
RESPONSE_OK = 0
RESPONSE_CLOSE = 1
Modified: trunk/gnue-forms/src/uidrivers/gtk2/MenuBar.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/gtk2/MenuBar.py 2004-07-21 17:52:51 UTC
(rev 6013)
+++ trunk/gnue-forms/src/uidrivers/gtk2/MenuBar.py 2004-07-21 19:04:51 UTC
(rev 6014)
@@ -1,6 +1,9 @@
+# GNU Enterprise Forms - GTK UI Driver - Menubar widget
#
-# This file is part of GNU Enterprise.
+# Copyright 2001-2004 Free Software Foundation
#
+# This file is part of GNU Enterprise
+#
# GNU Enterprise is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation; either
@@ -16,27 +19,26 @@
# write to the Free Software Foundation, Inc., 59 Temple Place
# - Suite 330, Boston, MA 02111-1307, USA.
#
-# Copyright 2000-2004 Free Software Foundation
-#
-# FILE:
-# gtk2/MenuBar.py
-#
-# DESCRIPTION:
-# A generic UIdriver base for common message-based GUI toolkits.
-#
-# NOTES:
-#
+# $Id: $
-import string
import gtk
-from gnue.forms.uidrivers._commonGuiToolkit.MenuBar import MenuBar as
_BaseMenuBar
+
+from gnue.forms.uidrivers._commonGuiToolkit.MenuBar import MenuBar as Base
+
-class MenuBar(_BaseMenuBar):
+# =============================================================================
+# This class implements the menu bar widget for GTK
+# =============================================================================
+class MenuBar (Base):
+
+ # ---------------------------------------------------------------------------
# Create the menu
- def init(self):
- self.menu = gtk.MenuBar()
- self.container.content_table.attach(self.menu,
+ # ---------------------------------------------------------------------------
+
+ def init (self):
+ self.menu = gtk.MenuBar ()
+ self.container.content_table.attach (self.menu,
# X direction Y direction
0, 1, 0, 1,
gtk.EXPAND | gtk.FILL, 0,
@@ -44,62 +46,94 @@
self.menu.show ()
return self.menu
- def correctLabel(self,label):
+
+ # ---------------------------------------------------------------------------
+ # Make sure to have a correct label
+ # ---------------------------------------------------------------------------
+
+ def correctLabel (self, label):
# TODO: remove decode step, when gettext translations are send
# in unicode instead of local encoding
- return string.replace(unicode(label,gConfigForms('textEncoding')),'&','_')
+ return string.replace (unicode (label, gConfigForms ('textEncoding')),
+ '&', '_')
+ # ---------------------------------------------------------------------------
# Add a (sub)menu
- def addMenu(self, name, parent):
- menuitem = gtk.MenuItem(self.correctLabel(name))
- menu=gtk.Menu()
- menuitem.set_submenu(menu)
- parent.add(menuitem)
+ # ---------------------------------------------------------------------------
+
+ def addMenu (self, name, parent):
+ menuitem = gtk.MenuItem (self.correctLabel (name))
+ menu = gtk.Menu ()
+ menuitem.set_submenu (menu)
+ parent.add (menuitem)
return menu
+
+ # ---------------------------------------------------------------------------
# Add a menu item (action)
- def addAction(self, name, parent, userAction):
- label = name
- hotkey = userAction.getHotKeyText()
- iconloc = userAction.getIconLocation(size="16x16")
+ # ---------------------------------------------------------------------------
- # TODO: fix display of hotkey
+ def addAction (self, name, parent, userAction):
+ label = name
+ hotkey = userAction.getHotKeyText ()
+ iconloc = userAction.getIconLocation (size = "16x16")
+
+ # TODO: do we need an accelerator group ? AccelLabel doesn't work ...
if hotkey:
- label += '\t %s' % hotkey
+ label = "%s\t%s" % (label, hotkey)
- item = gtk.ImageMenuItem(self.correctLabel(label)) #,
userAction.description or '')
- parent.add(item)
+ item = gtk.ImageMenuItem (self.correctLabel (label))
- event = 'request' + userAction.event
- item.connect('activate',lambda event, l=self.driver, e=event, f=self.form:\
- l.dispatchEvent(e,_form=f))
+ parent.add (item)
+ item.connect ('activate', self._menuHandler, userAction)
+
# Set the action icon if available
if iconloc:
- try:
- # TODO: Check if caching works, or if we have to cache pixmaps
- # Some caching logic for faster second/third forms
- icon = _cachedIcons[iconloc]
- except KeyError:
- icon = gtk.Image()
- icon.set_from_file(iconloc)
- _cachedIcons[iconloc] = icon
- item.set_image(icon)
+ if _cachedIcons.has_key (iconloc):
+ icon = _cachedIcons [iconloc]
+ else:
+ icon = gtk.Image ()
+ icon.set_from_file (iconloc)
+ _cachedIcons [iconloc] = icon
+ item.set_image (icon)
+
return item
+
+
+ # ---------------------------------------------------------------------------
+ # Handle the activate-signal of menu items
+ # ---------------------------------------------------------------------------
+
+ def _menuHandler (self, menuItem, userAction):
+ event = "request%s" % userAction.event
+ self.driver.dispatchEvent (event, _form = self.form)
+
+ # ---------------------------------------------------------------------------
# Add a separator
- def addSeparator(self, parent):
- item = gtk.SeparatorMenuItem()
- parent.add(item)
+ # ---------------------------------------------------------------------------
+
+ def addSeparator (self, parent):
+ item = gtk.SeparatorMenuItem ()
+ parent.add (item)
+
+ # ---------------------------------------------------------------------------
# Enable a menu item
- def enableItem(self, item):
- item.set_sensitive(1)
+ # ---------------------------------------------------------------------------
+
+ def enableItem (self, item):
+ item.set_sensitive (1)
+
+ # ---------------------------------------------------------------------------
# Disable a menu item
- def disableItem(self, item):
- item.set_sensitive(0)
+ # ---------------------------------------------------------------------------
+
+ def disableItem (self, item):
+ item.set_sensitive (0)
_cachedIcons = {}
Modified: trunk/gnue-forms/src/uidrivers/gtk2/ToolBar.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/gtk2/ToolBar.py 2004-07-21 17:52:51 UTC
(rev 6013)
+++ trunk/gnue-forms/src/uidrivers/gtk2/ToolBar.py 2004-07-21 19:04:51 UTC
(rev 6014)
@@ -65,7 +65,7 @@
GDebug.printMesg (1, "TOOL: add action %s, %s" % \
(repr (name), repr (userAction.description)))
- label = name.encode ('utf-8')
+ label = name
toolTip = unicode (userAction.description, i18n.encoding)
iconloc = userAction.getIconLocation (size = "24x24")
@@ -81,8 +81,6 @@
icon.set_from_file (iconloc)
_cachedIcons [iconloc] = icon
- event = 'request%s' % userAction.event
-
if userAction.canToggle:
button = self.toolbar.append_element (gtk.TOOLBAR_CHILD_TOGGLEBUTTON,
None, label, toolTip, None, icon, self._toggleEvent, userAction)
Modified: trunk/gnue-forms/src/uidrivers/gtk2/UIdriver.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/gtk2/UIdriver.py 2004-07-21 17:52:51 UTC
(rev 6013)
+++ trunk/gnue-forms/src/uidrivers/gtk2/UIdriver.py 2004-07-21 19:04:51 UTC
(rev 6014)
@@ -73,20 +73,20 @@
_WidgetToGFObj = {}
_WidgetToUIObj = {}
- _MBOX_KIND = {BaseDriver.MBOX_INFO : {'type' : gtk.MESSAGE_INFO,
- 'buttons': gtk.BUTTONS_CLOSE},
- BaseDriver.MBOX_WARNING : {'type' : gtk.MESSAGE_WARNING,
- 'buttons': gtk.BUTTONS_CLOSE},
- BaseDriver.MBOX_QUESTION: {'type' : gtk.MESSAGE_QUESTION,
- 'buttons': gtk.BUTTONS_YES_NO},
- BaseDriver.MBOX_ERROR : {'type' : gtk.MESSAGE_ERROR,
- 'buttons': gtk.BUTTONS_CLOSE}}
+ _MBOX_KIND = {'Info' : {'type' : gtk.MESSAGE_INFO,
+ 'buttons': gtk.BUTTONS_CLOSE},
+ 'Warning' : {'type' : gtk.MESSAGE_WARNING,
+ 'buttons': gtk.BUTTONS_CLOSE},
+ 'Question': {'type' : gtk.MESSAGE_QUESTION,
+ 'buttons': gtk.BUTTONS_YES_NO},
+ 'Error' : {'type' : gtk.MESSAGE_ERROR,
+ 'buttons': gtk.BUTTONS_CLOSE}}
- _RESPONSE = {gtk.RESPONSE_OK : BaseDriver.RESPONSE_OK,
- gtk.RESPONSE_CLOSE : BaseDriver.RESPONSE_CLOSE,
- gtk.RESPONSE_CANCEL: BaseDriver.RESPONSE_CANCEL,
- gtk.RESPONSE_YES : BaseDriver.RESPONSE_YES,
- gtk.RESPONSE_NO : BaseDriver.RESPONSE_NO}
+ _RESPONSE = {gtk.RESPONSE_OK : True,
+ gtk.RESPONSE_CLOSE : True,
+ gtk.RESPONSE_YES : True,
+ gtk.RESPONSE_NO : False,
+ gtk.RESPONSE_CANCEL: None }
# ---------------------------------------------------------------------------
# Initialize user interface
@@ -269,11 +269,19 @@
# create a modal message box
# ---------------------------------------------------------------------------
- def messageBox (self, message, kind, title = None, cancel = False):
+ def messageBox (self, message, kind = 'Info', title = None, cancel = False):
"""
+ 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.
"""
- mbRec = self._MBOX_KIND.get (kind, self._MBOX_KIND [BaseDriver.MBOX_INFO])
-
+ mbRec = self._MBOX_KIND.get (kind)
dialog = gtk.MessageDialog (parent = None, flags = gtk.DIALOG_MODAL,
type = mbRec ['type'], buttons = mbRec ['buttons'],
message_format = message)
@@ -282,6 +290,7 @@
if isinstance (title, types.StringType):
title = unicode (title, i18n.encoding)
dialog.set_title (title)
+
cButtons = [gtk.BUTTONS_CANCEL, gtk.BUTTONS_OK_CANCEL]
if cancel and not mbRec ['buttons'] in cButtons:
dialog.add_button (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- r6014 - in trunk/gnue-forms/src: . uidrivers/_base uidrivers/gtk2,
johannes <=