[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue/forms/src/uidrivers/qt UILoginHandler.py
From: |
Jason Cater |
Subject: |
gnue/forms/src/uidrivers/qt UILoginHandler.py |
Date: |
Wed, 05 Mar 2003 23:13:09 -0500 |
CVSROOT: /cvsroot/gnue
Module name: gnue
Changes by: Jason Cater <address@hidden> 03/03/05 23:13:08
Modified files:
forms/src/uidrivers/qt: UILoginHandler.py
Log message:
usable, but not very pretty login handler
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/forms/src/uidrivers/qt/UILoginHandler.py.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
Patches:
Index: gnue/forms/src/uidrivers/qt/UILoginHandler.py
diff -c gnue/forms/src/uidrivers/qt/UILoginHandler.py:1.1
gnue/forms/src/uidrivers/qt/UILoginHandler.py:1.2
*** gnue/forms/src/uidrivers/qt/UILoginHandler.py:1.1 Fri Feb 21 01:30:50 2003
--- gnue/forms/src/uidrivers/qt/UILoginHandler.py Wed Mar 5 23:13:08 2003
***************
*** 53,62 ****
#
class UILoginHandler(GLoginHandler.LoginHandler):
def __init__(self):
! self._wxapp = getQtApp()
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
--- 53,62 ----
#
class UILoginHandler(GLoginHandler.LoginHandler):
def __init__(self):
! self._qtapp = getQtApp()
self.dlg = None
! def getLogin(self, loginData, errortext=None):
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
***************
*** 65,137 ****
else:
loginMesg = _('Login required for %s') % (loginData[0])
! self.dlg = wxDialog(NULL, -1, _("GNU Enterprise: Login to %s") %
loginData[0])
! self.dlg.SetAutoLayout(true)
! bmp = wxImage(images_dir+gConfigForms('smallPNG'),
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
--- 65,140 ----
else:
loginMesg = _('Login required for %s') % (loginData[0])
! self.dlg = QDialog(None, _("GNU Enterprise: Login to %s") %
loginData[0], 1)
! self.dlg.setCaption ( _("GNU Enterprise: Login to %s") % loginData[0])
! bmp = QPixmap(images_dir+gConfigForms('smallPNG'))
! messageField = WrappedStaticText(self.dlg, str(loginMesg), 300)
self.textctrlList = []
labelList = []
! dlgWidth = max(bmp.width(), messageField.width()+20)
! dlgHeight = bmp.height() + messageField.height() + 80
xSpacing = 0
ySpacing = 0
fieldLabelWidth = 0
for prompt in loginData[2]:
! s = QLabel('%s:' % prompt[1], self.dlg)
labelList.append(s)
+ t = QLineEdit(self.dlg)
+ t.setFixedWidth(150)
if prompt[2]:
! t.setEchoMode(QLineEdit.Password)
myID = len(self.textctrlList)
self.textctrlList.append(t)
! ## EVT_CHAR(t, LoginFieldHandler(self, myID).loginFieldEventTrap)
fieldLabelWidth = max(fieldLabelWidth,
! s.width() + t.width() + 10)
dlgWidth = max(dlgWidth, \
! s.width() + t.width() + 20)
! xSpacing = max(xSpacing, s.width())
! ySpacing = max(ySpacing, s.height())
! ySpacing = max(ySpacing, t.height())
!
!
! ## loginId = wxNewId()
! ## cancelId = wxNewId()
!
! loginButton = QPushButton(self.dlg)
! loginButton.setText(_('Login'))
! loginButton.show()
! cancelButton = QPushButton(self.dlg)
! cancelButton.setText(_('Cancel'))
! cancelButton.show()
!
! QObject.connect(loginButton, SIGNAL("clicked()"),
! self.loginButtonEventTrap)
! QObject.connect(loginButton, SIGNAL("clicked()"),
! self.loginCancelEventTrap)
!
! dlgWidth = max(dlgWidth, loginButton.width() +
! cancelButton.width() + 6) + 20
! dlgHeight += max(loginButton.height(),
! cancelButton.height()) - 6
if errortext:
! errorField = WrappedStaticText(self.dlg, str(errortext), 300)
! ## errorField.SetForegroundColour(wxColour(223,0,0))
! dlgWidth = max(dlgWidth, errorField.width()+10)
! dlgHeight += errorField.height() + 6
! firstY = bmp.height() + messageField.height() + 50
lastY = firstY
xSpacing += 10 # Add whitespace between widgets
ySpacing += 6 # Add whitespace between widgets
***************
*** 141,199 ****
# 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
#
# Login is completed, for whatever reason
--- 144,200 ----
# Move the fields and labels into position
for i in range(0, len(self.textctrlList)):
dlgHeight = dlgHeight + ySpacing
! labelList[i].move(xPos, lastY)
! self.textctrlList[i].move(xPos + xSpacing, lastY)
lastY = lastY + ySpacing
+ self.textctrlList[i].show()
if errortext:
! errorField.move(
! dlgWidth/2 - errorField.width()/2,
! lastY+3)
# Set the focus to the first text entry field
! ## self.textctrlList[0].SetFocus()
# Create and position the logo
! img = QLabel(self.dlg)
! img.setFrameRect(QRect(dlgWidth-bmp.width()/2, 12, bmp.width(),
bmp.height()))
! img.setPixmap(bmp)
!
! img.show()
# Move the various widgets into position
! messageField.move(
! dlgWidth/2 - messageField.width()/2,
! 30 + bmp.height())
!
! cancelButton.move(
! dlgWidth - 10 - cancelButton.width(),
! dlgHeight - 10 - max(loginButton.height(),
! cancelButton.height()))
! print "Cancel Button %s,%s" % (cancelButton.x(),cancelButton.y())
! loginButton.move(
! dlgWidth - 16 - cancelButton.width() - \
! loginButton.width(),
! dlgHeight - 10 - max(loginButton.height(),
! cancelButton.height()))
self.loginButton = loginButton
! self.dlg.setFixedSize(dlgWidth, dlgHeight)
! # If user cancels, this will be set to 0
! completed = self.dlg.exec_loop()
! if completed == QDialog.Rejected:
! raise GLoginHandler.UserCanceledLogin
! rv = {}
! for i in range(0, len(loginData[2])):
! rv[loginData[2][i][0]] = self.textctrlList[i].text()
! return rv
#
# Login is completed, for whatever reason
***************
*** 205,265 ****
#
# 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(QLabel):
! def __init__(self, parent, id, label, width, *args, **params):
! ## QLabel.__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:
--- 206,242 ----
#
# Called when user clicks "login"
#
! def loginButtonEventTrap(self):
! self.dlg.accept()
#
# Called when user clicks "cancel"
#
! def loginCancelEventTrap(self):
! self.dlg.reject()
#
# TODO: This is a hack required because windows
# TODO: seems to have issues with wxWindows dialogs
#
def destroyLoginDialog(self):
! self.dlg.hide()
+
+
class WrappedStaticText(QLabel):
! def __init__(self, parent, label, width, *args, **params):
! QLabel.__init__(self, label, parent, *args, **params)
+ ## QLabel.setFixedWidth(width)
textSoFar = ""
thisLine = ""
for part in string.split(label,'\n'):
for word in string.split(part):
! self.setText(thisLine + word)
! if self.width() > width:
textSoFar += thisLine + " \n"
thisLine = word + " "
else:
***************
*** 269,275 ****
thisLine = ""
if len(textSoFar):
! self.SetLabel(string.replace(textSoFar,' \n','\n')[:-1])
else:
! self.SetLabel("")
--- 246,252 ----
thisLine = ""
if len(textSoFar):
! self.setText(string.replace(textSoFar,' \n','\n')[:-1])
else:
! self.setText("")
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- gnue/forms/src/uidrivers/qt UILoginHandler.py,
Jason Cater <=