[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r7518 - in trunk/gnue-forms/src/uidrivers: gtk2 wx
From: |
johannes |
Subject: |
[gnue] r7518 - in trunk/gnue-forms/src/uidrivers: gtk2 wx |
Date: |
Wed, 4 May 2005 07:57:49 -0500 (CDT) |
Author: johannes
Date: 2005-05-04 07:57:48 -0500 (Wed, 04 May 2005)
New Revision: 7518
Modified:
trunk/gnue-forms/src/uidrivers/gtk2/UILoginHandler.py
trunk/gnue-forms/src/uidrivers/gtk2/dialogs.py
trunk/gnue-forms/src/uidrivers/wx/UILoginHandler.py
trunk/gnue-forms/src/uidrivers/wx/dialogs.py
Log:
Implement new concept of GLoginHandler
Modified: trunk/gnue-forms/src/uidrivers/gtk2/UILoginHandler.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/gtk2/UILoginHandler.py 2005-05-04
12:55:46 UTC (rev 7517)
+++ trunk/gnue-forms/src/uidrivers/gtk2/UILoginHandler.py 2005-05-04
12:57:48 UTC (rev 7518)
@@ -21,12 +21,11 @@
#
# $Id$
-import gtk
import os.path
-import types
-from gnue.common.apps import GConfig, i18n
+from gnue.common.apps import GConfig
from gnue.common.datasources import GLoginHandler
+from gnue.forms.uidrivers.gtk2 import dialogs
# =============================================================================
# This class implements a login handler for GTK2
@@ -35,113 +34,27 @@
class UILoginHandler (GLoginHandler.LoginHandler):
# ---------------------------------------------------------------------------
- # Get input for all fields listed in loginData
+ # Create an instance of an InputDialog and return it's result
# ---------------------------------------------------------------------------
- def getLogin (self, loginData, error = None):
- (connection, description, fields) = loginData
+ def _askLogin (self, title, fields):
- self.dialog = gtk.Dialog (u_("GNU Enterprise: Login to %s") % connection,
- None, gtk.DIALOG_MODAL,
- (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
- gtk.STOCK_OK , gtk.RESPONSE_OK))
-
- try:
- self.dialog.set_border_width (10)
-
+ 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'))
- bmp = gtk.Image ()
- bmp.set_from_file (imageFile)
- self.dialog.vbox.pack_start (bmp)
- bmp.show ()
+ if os.path.exists (imageFile):
+ lfields.insert (0, (None, imageFile, 'image', None, None, []))
- text = u_('Login required for %(newline)s"%(description)s"') \
- % {'newline': len (description) and '\n' or '',
- 'description': description or connection}
- label = gtk.Label (text)
- label.set_line_wrap (True)
- label.set_justify (gtk.JUSTIFY_CENTER)
- self.dialog.vbox.pack_start (label, True, True, 20)
- label.show ()
+ dlg = dialogs.InputDialog (title, lfields)
- table = gtk.Table (len (fields), 2)
- self.textEntries = []
+ try:
+ dlg.run ()
+ return dlg.inputData
- for ix in range (len (fields)):
- item = fields [ix]
- text = "%s" % item [1]
- if isinstance (text, types.StringType):
- text = unicode (text, i18n.encoding)
- label = gtk.Label (text)
- label.set_alignment (0, label.get_alignment () [1])
- table.attach (label, 0, 1, ix, ix + 1)
- label.show ()
-
- entry = gtk.Entry ()
- if item [2]:
- entry.set_visibility (0)
- table.attach (entry, 1, 2, ix, ix + 1)
- entry.connect ('key-press-event', self._keypress, ix + 1)
- entry.show ()
-
- self.textEntries.append (entry)
-
- table.show ()
- self.dialog.vbox.pack_start (table, True, True, 10)
-
- # Add an error text if given
- if error is not None:
- if isinstance (error, types.StringType):
- error = unicode (error, i18n.encoding)
- label = gtk.Label (error)
- label.set_line_wrap (True)
- label.modify_fg (gtk.STATE_NORMAL, gtk.gdk.color_parse ('red'))
- self.dialog.vbox.pack_start (label, True, True, 10)
- label.show ()
-
- # focus first entry
- self.textEntries [0].grab_focus ()
-
- self.dialog.set_position (1) # for center
- self.dialog.show_all ()
-
- result = self.dialog.run ()
- self._completed = result == gtk.RESPONSE_OK
- if not self._completed:
- raise GLoginHandler.UserCanceledLogin
-
- result = {}
- for ix in range (len (fields)):
- text = unicode (self.textEntries [ix].get_text (), 'utf-8')
- result [fields [ix][0]] = text
-
finally:
- self.dialog.destroy ()
-
- return result
-
-
- # ---------------------------------------------------------------------------
- # Keypress handler for moving the focus on enter-keys
- # ---------------------------------------------------------------------------
-
- def _keypress (self, widget, event, data):
- if event.type != gtk.gdk.KEY_PRESS:
- return
-
- if event.keyval == gtk.keysyms.Return and not event.state:
- if data < len (self.textEntries):
- self.textEntries [data].grab_focus ()
- else:
- self.dialog.response (gtk.RESPONSE_OK)
-
-
- # Hack for McMillan packaging on win32
- # TODO: do we need that?
- def getDummyLogin (self):
- pass
+ dlg.destroy ()
Modified: trunk/gnue-forms/src/uidrivers/gtk2/dialogs.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/gtk2/dialogs.py 2005-05-04 12:55:46 UTC
(rev 7517)
+++ trunk/gnue-forms/src/uidrivers/gtk2/dialogs.py 2005-05-04 12:57:48 UTC
(rev 7518)
@@ -258,9 +258,11 @@
def __add_text (self, row, label, isWarning = False):
gLabel = gtk.Label (label)
+ gLabel.set_justify (gtk.JUSTIFY_CENTER)
+
if isWarning:
attr = pango.AttrList ()
- attr.insert (pango.AttrForeground (65535, 0, 0, 0, len (label)))
+ attr.insert (pango.AttrForeground (65535, 0, 0, 0, -1))
gLabel.set_attributes (attr)
self.table.attach (gLabel, 0, 2, row, row + 1)
@@ -517,7 +519,8 @@
('Wirtschaftsjahr', 'wija', 'dropdown', '05', 'company',
[('Jahr', wija)]),
('Codes', 'codes', 'dropdown', None, 'wija',
- [('Code', codes)])]
+ [('Code', codes)]),
+ (u"Dre\xf6ksau 'bl\xf6sepp'", None, 'warning', None, None, [])]
#fields = [('Username', '_username', 'string', 'foobar', None, []),
Modified: trunk/gnue-forms/src/uidrivers/wx/UILoginHandler.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx/UILoginHandler.py 2005-05-04 12:55:46 UTC
(rev 7517)
+++ trunk/gnue-forms/src/uidrivers/wx/UILoginHandler.py 2005-05-04 12:57:48 UTC
(rev 7518)
@@ -1,6 +1,9 @@
+# GNU Enterprise Forms - wx UI Driver - Login Handler
#
-# This file is part of GNU Enterprise.
+# Copyright 2001-2005 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,277 +19,55 @@
# write to the Free Software Foundation, Inc., 59 Temple Place
# - Suite 330, Boston, MA 02111-1307, USA.
#
-# Copyright 2000-2005 Free Software Foundation
-#
-# FILE:
-# UIwxpython.py
-#
-# DESCRIPTION:
-# A wxPython based user interface driver for GNUe forms.
-#
-# NOTES:
-#
+# $Id: $
-import string
import os.path
-from wxPython.wx import *
-
from gnue.common.datasources import GLoginHandler
from gnue.common.apps import GConfig, i18n
+from gnue.forms.uidrivers.wx import dialogs
+
from GFwxApp import *
-from common import wxEncode, wxDecode
-# Shortcut
-images_dir = GConfig.getInstalledBase('forms_images','common_images') + '/'
+# =============================================================================
+# This class implements a login handler for GTK2
+# =============================================================================
+class UILoginHandler (GLoginHandler.LoginHandler):
-#####################################################################
-##
-## Login Support
-##
-## Everything below this point is in support of the wx drivers
-## UILoginHandler
-##
-#####################################################################
+ # ---------------------------------------------------------------------------
+ # Constructor
+ # ---------------------------------------------------------------------------
-#
-# UILoginHandler
-#
-class UILoginHandler(GLoginHandler.LoginHandler):
- def __init__(self):
- self._wxapp = getWxApp()
- self.dlg = None
+ def __init__ (self):
- # Hack for McMillan packaging on win32
- def getDummyLogin(self):
- self.dlg = wxDialog(NULL, -1,'dummy')
- self.destroyLoginDialog()
-
+ self._wxapp = getWxApp ()
+
+
# ---------------------------------------------------------------------------
- # Get input for all fields listed in loginData
+ # Prompt for all fields
# ---------------------------------------------------------------------------
- def getLogin (self, loginData, errortext = None):
+ def _askLogin (self, title, fields):
"""
"""
- if len (loginData [1]):
- loginMesg = wxEncode (u_('Login required for\n"%s"') % loginData [1])
- else:
- loginMesg = wxEncode (u_('Login required for %s') % loginData [0])
+ 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'))
- self.dlg = wxDialog (NULL, -1,
- wxEncode (u_("GNU Enterprise: Login to %s") % loginData [0]))
- self.dlg.SetAutoLayout (True)
+ if os.path.exists (imageFile):
+ lfields.insert (0, (None, imageFile, 'image', None, None, []))
- if os.path.isabs (gConfigForms ('loginPNG')):
- imageFile = gConfigForms ('loginPNG')
- else:
- imageFile = images_dir + gConfigForms ('loginPNG')
+ dialog = dialogs.InputDialog (title, lfields)
+
+ try:
+ dialog.ShowModal ()
+ return dialog.inputData
- bmp = wxImage (imageFile, wxBITMAP_TYPE_PNG).ConvertToBitmap ()
-
- messageField = WrappedStaticText (self.dlg, -1, loginMesg, 300,
- style = wxALIGN_CENTER)
-
- self.textctrlList = []
- labelList = []
-
- dlgWidth = max (bmp.GetWidth (), messageField.GetSize ().GetWidth () + 20)
- dlgHeight = bmp.GetHeight () + messageField.GetSize ().GetHeight () + 80
-
- xSpacing = 0
- ySpacing = 0
- fieldLabelWidth = 0
-
- for prompt in loginData [2]:
- s = wxStaticText (self.dlg, -1, wxEncode ('%s:' % prompt [1]))
-
- labelList.append (s)
- if prompt[2]:
- t = wxTextCtrl (self.dlg, -1, "", wxPoint (1, 1), wxSize (150, 20),
- style = wxTE_PASSWORD | wxTE_PROCESS_ENTER)
- else:
- t = wxTextCtrl (self.dlg, -1, "", wxPoint (1, 1), wxSize (150, 20),
- style = wxTE_PROCESS_ENTER)
-
- myID = len (self.textctrlList)
- self.textctrlList.append (t)
- EVT_CHAR (t, LoginFieldHandler (self, myID).loginFieldEventTrap)
-
- fieldLabelWidth = max (fieldLabelWidth,
- s.GetSize ().GetWidth () + t.GetSize ().GetWidth () + 10)
-
- dlgWidth = max (dlgWidth, \
- s.GetSize ().GetWidth () + t.GetSize ().GetWidth () + 20)
-
- xSpacing = max (xSpacing, s.GetSize ().GetWidth ())
- ySpacing = max (ySpacing, s.GetSize ().GetHeight ())
- ySpacing = max (ySpacing, t.GetSize ().GetHeight ())
-
- loginId = wxNewId ()
- cancelId = wxNewId ()
-
- loginButton = wxButton (self.dlg, loginId, _('Login'))
- cancelButton = wxButton (self.dlg, cancelId, _('Cancel'))
-
- EVT_BUTTON (self.dlg, loginId, self.loginButtonEventTrap)
- EVT_BUTTON (self.dlg, cancelId, self.loginCancelEventTrap)
-
- dlgWidth = max (dlgWidth, loginButton.GetSize ().GetWidth () +
- cancelButton.GetSize ().GetWidth () + 6) + 20
-
- dlgHeight += max (loginButton.GetSize ().GetHeight (),
- cancelButton.GetSize ().GetHeight ()) - 6
-
- if errortext:
- errorField = WrappedStaticText (self.dlg, -1, wxEncode (errortext),
- 300, style = wxALIGN_CENTER)
- errorField.SetForegroundColour (wxColour (223, 0, 0))
-
- dlgWidth = max (dlgWidth, errorField.GetSize ().width + 10)
- dlgHeight += errorField.GetSize ().height + 6
-
-
- firstY = bmp.GetHeight () + messageField.GetSize ().GetHeight () + 50
- lastY = firstY
- xSpacing += 10 # Add whitespace between widgets
- ySpacing += 6 # Add whitespace between widgets
- xPos = dlgWidth / 2 - fieldLabelWidth / 2
-
- # Move the fields and labels into position
- for i in range (0, len (self.textctrlList)):
- dlgHeight = dlgHeight + ySpacing
- labelList [i].SetPosition (wxPoint (xPos, lastY))
- self.textctrlList[i].SetPosition (wxPoint (xPos + xSpacing, lastY))
- lastY = lastY + ySpacing
-
- if errortext:
- errorField.SetPosition (
- wxPoint (dlgWidth / 2 - errorField.GetSize ().width / 2, lastY + 3))
-
- # Set the focus to the first text entry field
- self.textctrlList [0].SetFocus ()
-
- # Create and position the logo
- wxStaticBitmap (self.dlg, -1, bmp,
- wxPoint ( (dlgWidth - bmp.GetWidth ()) / 2, 12),
- wxSize (bmp.GetWidth (), bmp.GetHeight ()))
-
- # Move the various widgets into position
- messageField.SetPosition (
- wxPoint (dlgWidth / 2 - messageField.GetSize ().GetWidth () / 2,
- 30 + bmp.GetHeight ()))
-
- cancelButton.SetPosition (
- wxPoint (dlgWidth - 10 - cancelButton.GetSize ().GetWidth (),
- dlgHeight - 10 - max (loginButton.GetSize ().GetHeight (),
- cancelButton.GetSize ().GetHeight ())))
- loginButton.SetPosition (
- wxPoint (dlgWidth - 16 - cancelButton.GetSize ().GetWidth () - \
- loginButton.GetSize ().GetWidth (),
- dlgHeight - 10 - max (loginButton.GetSize ().GetHeight (),
- cancelButton.GetSize ().GetHeight ())))
-
- self.loginButton = loginButton
-
- self.dlg.SetSize (wxSize (dlgWidth, dlgHeight))
-
- self.dlg.Refresh ()
- self.dlg.Fit ()
- self.dlg.Raise ()
- self.dlg.CenterOnScreen ()
-
- # If user cancels, this will be set to 0
- self._completed = 0
- self.dlg.ShowModal ()
-
- if not self._completed:
- raise GLoginHandler.UserCanceledLogin
-
- rv = {}
- for i in range (0, len (loginData [2])):
- rv [loginData [2] [i] [0]] = wxDecode (self.textctrlList [i].GetValue ())
-
- return rv
-
-
- #
- # Login is completed, for whatever reason
- #
- def loginCompleted(self, successful):
- self._completed = successful
- self.dlg.EndModal(1)
-
- #
- # Called when user clicks "login"
- #
- def loginButtonEventTrap(self, event):
- self.loginCompleted(1)
-
- #
- # Called when user clicks "cancel"
- #
- def loginCancelEventTrap(self, event):
- self.loginCompleted(0)
-
- #
- # TODO: This is a hack required because windows
- # TODO: seems to have issues with wxWidgets dialogs
- #
- def destroyLoginDialog(self):
- self.dlg.Destroy()
-
-#
-# LoginFieldHandler
-#
-# Used by the login handler
-# enables the user to press return and have it jump to the next box
-#
-class LoginFieldHandler:
- def __init__(self, app, seq):
- self.app = app
- self.seq = seq
-
- def loginFieldEventTrap(self, event):
- if event.KeyCode() in (WXK_RETURN, WXK_TAB):
- if self.seq < len(self.app.textctrlList) - 1:
- self.app.textctrlList[self.seq+1].SetFocus()
- else:
- if event.KeyCode() == WXK_TAB:
- if event.ShiftDown():
- self.app.textctrlList[self.seq-1].SetFocus()
- else:
- self.app.loginButton.SetFocus()
- else:
- self.app.loginCompleted(1)
- else:
- event.Skip()
-
-
-
-class WrappedStaticText(wxStaticText):
- def __init__(self, parent, id, label, width, *args, **params):
- wxStaticText.__init__(self, parent, id, "bah!", *args, **params)
-
-
- textSoFar = ""
- thisLine = ""
- for part in string.split(label,'\n'):
- for word in string.split(part):
- self.SetLabel(thisLine + word)
- if self.GetSize().width > width:
- textSoFar += thisLine + " \n"
- thisLine = word + " "
- else:
- thisLine += word + " "
-
- textSoFar += thisLine + " \n"
- thisLine = ""
-
- if len(textSoFar):
- self.SetLabel(string.replace(textSoFar,' \n','\n')[:-1])
- else:
- self.SetLabel("")
-
+ finally:
+ dialog.Destroy ()
Modified: trunk/gnue-forms/src/uidrivers/wx/dialogs.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx/dialogs.py 2005-05-04 12:55:46 UTC
(rev 7517)
+++ trunk/gnue-forms/src/uidrivers/wx/dialogs.py 2005-05-04 12:57:48 UTC
(rev 7518)
@@ -237,7 +237,7 @@
def __add_text (self, label, warning = False):
- text = wxStaticText (self, -1, label)
+ text = wxStaticText (self, -1, label, style = wxALIGN_CENTER)
if warning:
text.SetForegroundColour (wxRED)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r7518 - in trunk/gnue-forms/src/uidrivers: gtk2 wx,
johannes <=