commit-gnue
[Top][All Lists]
Advanced

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

gnue/forms/src/uidrivers/gtk2 UILoginHandler.py


From: Jan Ischebeck
Subject: gnue/forms/src/uidrivers/gtk2 UILoginHandler.py
Date: Sun, 01 Jun 2003 13:02:38 -0400

CVSROOT:        /cvsroot/gnue
Module name:    gnue
Changes by:     Jan Ischebeck <address@hidden>  03/06/01 13:02:38

Modified files:
        forms/src/uidrivers/gtk2: UILoginHandler.py 

Log message:
        closes ticket #183 and make UILoginHandler usable

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/forms/src/uidrivers/gtk2/UILoginHandler.py.diff?tr1=1.1&tr2=1.2&r1=text&r2=text

Patches:
Index: gnue/forms/src/uidrivers/gtk2/UILoginHandler.py
diff -c gnue/forms/src/uidrivers/gtk2/UILoginHandler.py:1.1 
gnue/forms/src/uidrivers/gtk2/UILoginHandler.py:1.2
*** gnue/forms/src/uidrivers/gtk2/UILoginHandler.py:1.1 Sat May 17 10:46:04 2003
--- gnue/forms/src/uidrivers/gtk2/UILoginHandler.py     Sun Jun  1 13:02:37 2003
***************
*** 19,25 ****
  # Copyright 2000-2003 Free Software Foundation
  #
  # FILE:
! # UILoginHandler.py
  #
  # DESCRIPTION:
  # Part of the gtk2 based user interface driver for GNUe forms.
--- 19,25 ----
  # Copyright 2000-2003 Free Software Foundation
  #
  # FILE:
! # gtk2/UILoginHandler.py
  #
  # DESCRIPTION:
  # Part of the gtk2 based user interface driver for GNUe forms.
***************
*** 30,36 ****
  import string
  import os.path
  
! from gtk import *
  
  from gnue.common.datasources import GLoginHandler
  from gnue.common.apps import GConfig
--- 30,36 ----
  import string
  import os.path
  
! import gtk
  
  from gnue.common.datasources import GLoginHandler
  from gnue.common.apps import GConfig
***************
*** 45,403 ****
  ##
  #####################################################################
  
- #
- # UILoginHandler
- #
- 
- 
- class UILoginHandler(GLoginHandler.LoginHandler):
-   def __init__(self):
-     global loginWindow
-     loginWindow=gtk.Window()
-     loginWindow.set_title(_("LOGIN WINDOW"))
-     loginWindow.set_border_width(8)
-     #$loginWindow.connect('destroy', lambda win: gtk.main_quit())
-     self.dlg = None
- 
- 
-   def getLogin(self, loginData, errortext=None):#"Invalid username/password"):
-     if 1: # TODO: This is left here to prevent me from having to unindent 
this code
-           # TODO: Since the UI stuff is currently being gutted I'm not 
wasting the time
-           # TODO: to do the right thing
-       if len(loginData[1]):
-         loginMesg = _('Login required for\n"%s"') % (loginData[1])
-       else:
-         loginMesg = _('Login required for %s') % (loginData[0])
-       self.dlg = gtk.Dialog(_("GNU Enterprise: Login to %s") % loginData[0], 
loginWindow,
-         gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT,
-         (_("_LOGIN"), gtk.RESPONSE_OK,_("_CANCEL"), gtk.RESPONSE_CANCEL))
- 
-       table1 = gtk.Table(len(loginData[2])+10, 6) # row, column
-       table1.set_row_spacings(4)
-       table1.set_col_spacings(4)
-       bmp = gtk.Image()
-       if os.path.isabs(gConfigForms('loginPNG')):
-         imageFile = gConfigForms('loginPNG')
-       else:
-         imageFile = images_dir+gConfigForms('loginPNG')
- 
-       bmp.set_from_file(imageFile)
- 
-       messageField = gtk.Label(str(loginMesg))
-       # left, right, top, bottom
-       table1.attach_defaults(bmp,1,3,0,1)
-       table1.attach_defaults(messageField,1,3,2,3)
- 
-       self.textEntryList = []
-       labelList = []
- 
-       xSpacing = 0
-       ySpacing = 0
-       fieldLabelWidth = 0
- 
-       raghav=gtk.Entry()
-       raghav.set_visibility(0)
- 
-       for prompt in loginData[2]:
-         s = gtk.Label('%s:' % prompt[1])
-         s.set_use_underline(gtk.TRUE)
-         labelList.append(s)
-         if prompt[2]:
-           t = gtk.Entry()
-           t.set_visibility(0)
-         else:
-           t = gtk.Entry()
- 
-         myID = len(self.textEntryList)
-         self.textEntryList.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()
- 
- 
-       #$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, str(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
- 
-       num_rows=len(loginData[2])
-       # Move the fields and labels into position
-       for i in range(0, len(self.textEntryList)):
-        table1.attach_defaults(labelList[i],1,2,i+3,i+4)
-        table1.attach_defaults(self.textEntryList[i],2,3,i+3,i+4)
- 
-       if errortext:
-         errorField = gtk.Label(str(errortext))
-         t = len(self.textEntryList)
-         table1.attach_defaults(errorField,1,3,t+4,t+5)
- 
-        #$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))
-       #$loginWindow.show_all()
-       #$gtk.main()
-       self.dlg.vbox.pack_start(table1, gtk.TRUE, gtk.TRUE, 0)
-       self.dlg.set_position(1)  #for center
-       self.dlg.show_all()
- 
-       response=self.dlg.run()
-       if response==gtk.RESPONSE_OK:
-         self.loginCompleted(1)
-       else:
-         self.loginCompleted(0)
-         raise GLoginHandler.UserCanceledLogin
- 
-     # To close this window when 'Login' is clicked
-     self.destroyLoginDialog()
-     rv = {}
-     for i in range(0, len(loginData[2])):
-       rv[loginData[2][i][0]] = self.textEntryList[i].get_text()
- 
-     return rv
- 
-   #
-   # Login is completed, for whatever reason
-   #
-   def loginCompleted(self, successful):
-     self._completed = successful
-     #$print "inside login completed"
-     GDebug.printMesg(1, "inside login completed")
-     #$self.dlg.EndModal(1)
- 
-   #
-   # Called when user clicks "login"
-   #
-   #$def loginButtonEventTrap(self, event):
-     #$self.loginCompleted(1)
-     #self.destroyLoginDialog() #this does not work
- 
-   #
-   # 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 wxWindows dialogs
-   #
-   def destroyLoginDialog(self):
-     #$print "inside destroy login dialog"
-     GDebug.printMesg(1, "inside destroy login dialog")
-     self.dlg.destroy()
-     loginWindow.destroy()
-     #$self.dlg.Destroy()
- 
- #
- # UILoginHandler
- #
  class UILoginHandler(GLoginHandler.LoginHandler):
    def __init__(self):
-     #self._wxapp = getWxApp()
      self.dlg = None
  
    # Hack for McMillan packaging on win32
    def getDummyLogin(self):
!     self.dlg = wxDialog(NULL, -1,'dummy')
!     self.destroyLoginDialog()
      
!   def getLogin(self, loginData, errortext=None):#"Invalid username/password"):
!     return
!     if 1: # TODO: This is left here to prevent me from having to unindent 
this code
!           # TODO: Since the UI stuff is currently being gutted I'm not 
wasting the time
!           # TODO: to do the right thing
!       if len(loginData[1]):
!         loginMesg = _('Login required for\n"%s"') % (loginData[1])
!       else:
!         loginMesg = _('Login required for %s') % (loginData[0])
! 
!       self.dlg = wxDialog(NULL, -1, _("GNU Enterprise: Login to %s") % 
loginData[0])
!       self.dlg.SetAutoLayout(true)
! 
!       if os.path.isabs(gConfigForms('loginPNG')):
!         imageFile = gConfigForms('loginPNG')
!       else:
!         imageFile = images_dir+gConfigForms('loginPNG')
!       bmp = wxImage(imageFile, wxBITMAP_TYPE_PNG).ConvertToBitmap()
! 
!       messageField = WrappedStaticText(self.dlg, -1, str(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, '%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, str(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]] = self.textctrlList[i].GetValue()
  
      return rv
  
--- 45,141 ----
  ##
  #####################################################################
  
  class UILoginHandler(GLoginHandler.LoginHandler):
    def __init__(self):
      self.dlg = None
  
    # Hack for McMillan packaging on win32
+   # TODO: do we need that?
    def getDummyLogin(self):
!     pass
! 
!   def getLogin(self, loginData, errortext=None):
      
!     if len(loginData[1]):
!       loginMesg = _('Login required for\n"%s"') % (loginData[1])
!     else:
!       loginMesg = _('Login required for %s') % (loginData[0])
!       
!     self.dlg = gtk.Dialog(_("GNU Enterprise: Login to %s") % loginData[0],
!                           None, gtk.DIALOG_MODAL,
!                           (_("_LOGIN"), gtk.RESPONSE_OK,
!                            _("_CANCEL"), gtk.RESPONSE_CANCEL))
!     
!     table1 = gtk.Table(len(loginData[2])+10, 6) # row, column
!     table1.set_row_spacings(4)
!     table1.set_col_spacings(4)
!     
!     bmp = gtk.Image()
!     
!     if os.path.isabs(gConfigForms('loginPNG')):
!       imageFile = gConfigForms('loginPNG')
!     else:
!       imageFile = images_dir+gConfigForms('loginPNG')
!       
!     bmp.set_from_file(imageFile)
!     table1.attach_defaults(bmp,1,3,0,1)
!     
!     messageField = gtk.Label(str(loginMesg))
!     table1.attach_defaults(messageField,1,3,2,3)
!     
!     self.textEntryList = []
!     labelList = []
  
!     for prompt in loginData[2]:
!         
!       # Build label
!       s = gtk.Label('%s:' % prompt[1])
!       s.set_use_underline(gtk.TRUE)
!       labelList.append(s)
! 
!       # Build entry fields
!       t = gtk.Entry()
! 
!       # set visibility to 0 for password fields
!       if prompt[2]:
!         t.set_visibility(0)
!         
!       myID = len(self.textEntryList)
!       self.textEntryList.append(t)
!       t.connect("key-press-event", self.keyPressHandler, myID)
! 
!     num_rows=len(loginData[2])
!       
!     # Add labels and entry fields to layout
! 
!     for i in range(0, len(self.textEntryList)):
!       table1.attach_defaults(labelList[i],1,2,i+3,i+4)
!       table1.attach_defaults(self.textEntryList[i],2,3,i+3,i+4)
! 
!     if errortext:
!       errorField = gtk.Label(str(errortext))
!       t = len(self.textEntryList)
!       table1.attach_defaults(errorField,1,3,t+4,t+5)
! 
!     # focus first entry
!     self.textEntryList[0].grab_focus()
! 
!     self.dlg.vbox.pack_start(table1, gtk.TRUE, gtk.TRUE, 0)
!     self.dlg.set_position(1)  #for center
!     self.dlg.show_all()
! 
!     response=self.dlg.run()
!       
!     if response==gtk.RESPONSE_OK:
!       self.loginCompleted(1)
!     else:
!       self.loginCompleted(0)
        raise GLoginHandler.UserCanceledLogin
  
+     # get loginData
      rv = {}
      for i in range(0, len(loginData[2])):
!       rv[loginData[2][i][0]] = self.textEntryList[i].get_text()
  
      return rv
  
***************
*** 406,481 ****
    #
    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 wxWindows 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("")
! 
--- 144,166 ----
    #
    def loginCompleted(self, successful):
      self._completed = successful
  
    #
!   # Called when user presses a key
!   #     -- interupts event chain, if ENTER was pressed
    #
!   def keyPressHandler(self, widget, event, myID):
!     if event.type!=gtk.gdk.KEY_PRESS:
!       return
! 
!     # Check if ENTER is pressed:
!     if event.keyval == gtk.keysyms.Return and \
!        not event.state:
! 
!       try:
!         # move to next Entry in List
!         self.textEntryList[myID+1].grab_focus()
!       except IndexError:
!         # for the last event in the list, trigger OK button
!         self.dlg.response(gtk.RESPONSE_OK)
!         self.dlg.destroy()




reply via email to

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