]> git.zarvox.org Git - wp3.git/commitdiff
Attempt to implement a modular interface for WP3 in python with PyQt.
authorDrew Fisher <drew.m.fisher@gmail.com>
Sun, 21 Jun 2009 08:20:20 +0000 (01:20 -0700)
committerDrew Fisher <drew.m.fisher@gmail.com>
Sun, 21 Jun 2009 08:20:20 +0000 (01:20 -0700)
Partial port of wizard (MainFrame) from WP2 to PyQt4.  Addition of LDAP
lookup by NetID for new users.  Perhaps the New Person Wizard should
be modal?

Code actually looks up user by NetID in LDAP and prints the fields that
we plan to actually use for the whitepages.

donestep.py [new file with mode: 0644]
ldapsearcher.py [new file with mode: 0644]
ldapstep.py [new file with mode: 0644]
netidstep.py [new file with mode: 0644]
newpersonwizard.py [new file with mode: 0644]

diff --git a/donestep.py b/donestep.py
new file mode 100644 (file)
index 0000000..e52e2de
--- /dev/null
@@ -0,0 +1,11 @@
+from PyQt4 import QtCore
+from PyQt4.QtGui import *
+
+class DoneStep(QWidget):
+       def __init__(self, parent=None):
+               QWidget.__init__(self,parent)
+               self.title = QLabel("<center><h2>Thanks for submitting your info to the Whitepages!</h2></center>")
+               self.grid = QGridLayout()
+               self.grid.addWidget(self.title,0,0,1,1)
+               self.setLayout(self.grid)
+               self.data = {}
diff --git a/ldapsearcher.py b/ldapsearcher.py
new file mode 100644 (file)
index 0000000..cac4ac5
--- /dev/null
@@ -0,0 +1,51 @@
+import ldap
+
+class LDAPSearcher():
+       def __init__(self):
+               server = "operator.tamu.edu"
+               who = ""
+               cred = ""
+               self.l = ldap.open(server)
+               self.l.simple_bind_s(who, cred)
+               #print "bound successfully"
+
+       def lookup(self,username=""):
+               base = ""
+               scope = ldap.SCOPE_SUBTREE
+               filter = "tamuEduPersonNetID=" + username
+               retrieve_attributes = ["sn", "givenName", "mail", "major", "classification"]
+               count = 0
+               result_set = []
+               timeout = 0
+               toreturn = {}
+               #print "searching"
+               result_id = self.l.search(base, scope, filter, retrieve_attributes)
+               while 1:
+                       result_type, result_data = self.l.result(result_id, timeout)
+                       if (result_data == []):
+                               break
+                       else:
+                               if result_type == ldap.RES_SEARCH_ENTRY:
+                                       result_set.append(result_data)
+               if len(result_set) == 0:
+               #       print "No matching NetID"
+                       return {}
+               toreturn["netid"] = username
+               for i in range(len(result_set)):
+                       for entry in result_set[i]:
+                               for attr in retrieve_attributes:
+                                       try:
+                                               if entry[1][attr][0] == "":
+                                                       continue;
+               #                               print attr,"=",entry[1][attr][0]
+                                               toreturn[attr] = entry[1][attr][0]
+                                       except:
+                                               pass
+               #print result_set
+               return toreturn
+
+if __name__ == "__main__":
+       a = LDAPSearcher()
+       print a.lookup("drew.m.fisher")
+
+
diff --git a/ldapstep.py b/ldapstep.py
new file mode 100644 (file)
index 0000000..0de4740
--- /dev/null
@@ -0,0 +1,23 @@
+from PyQt4 import QtCore
+from PyQt4.QtGui import *
+
+from ldapsearcher import LDAPSearcher
+
+class LDAPStep(QWidget):
+       def __init__(self, parent=None):
+               QWidget.__init__(self,parent)
+               self.title = QLabel("<center><h2>Looking you up in LDAP...</h2></center>")
+               self.grid = QGridLayout()
+               self.grid.addWidget(self.title,0,0,1,1)
+               self.setLayout(self.grid)
+               self.ldap = LDAPSearcher()
+               self.data = {}
+       
+       def lookup(self, netid=""):
+               self.data = self.ldap.lookup(netid)
+               print self.data
+               self.emit(QtCore.SIGNAL("ready()"))
+               self.emit(QtCore.SIGNAL("submit()"))
+               # Later we'll actually do something with this data
+
+
diff --git a/netidstep.py b/netidstep.py
new file mode 100644 (file)
index 0000000..bbe9131
--- /dev/null
@@ -0,0 +1,29 @@
+from PyQt4 import QtCore
+from PyQt4.QtGui import *
+
+class NetIDStep(QWidget):
+       def __init__(self, parent=None):
+               QWidget.__init__(self,parent)
+               self.title = QLabel("<h1>Whitepages v3</h1><h2>Collecting contact information for the dorm</h2>")
+               self.instructions = QLabel("&Enter your NetID:")
+               self.netid = QLineEdit()
+               self.grid = QGridLayout()
+               self.grid.addWidget(self.title,0,0,1,2)
+               self.grid.addWidget(self.instructions,1,0,1,1)
+               self.grid.addWidget(self.netid,1,1,1,1)
+               self.setLayout(self.grid)
+               QtCore.QObject.connect(self.netid, QtCore.SIGNAL('textChanged(QString)'), self.textchanged)
+               QtCore.QObject.connect(self.netid, QtCore.SIGNAL('returnPressed()'), self.submit)
+       def textchanged(self):
+               if len(str(self.netid.text())) != 0:
+                       self.emit( QtCore.SIGNAL('ready()'))
+               else:
+                       self.emit( QtCore.SIGNAL('notReady()'))
+               print "text changed"
+       def submit(self):
+               self.emit( QtCore.SIGNAL('submit()'))
+       def reset(self):
+               self.netid.clear()
+       def getNetID(self):
+               return str(self.netid.text())
+
diff --git a/newpersonwizard.py b/newpersonwizard.py
new file mode 100644 (file)
index 0000000..1aa15a2
--- /dev/null
@@ -0,0 +1,84 @@
+from PyQt4 import QtCore
+from PyQt4.QtGui import *
+
+from netidstep import NetIDStep
+from ldapstep import LDAPStep
+from donestep import DoneStep
+
+class NewPersonWizard(QWidget):
+       def __init__(self, parent=None):
+               QWidget.__init__(self, parent)
+               self.setWindowTitle("Whitepages v3")
+               self.steps = []
+               self.currentstep = 0
+               # Here you create the steps, in order
+               # TODO: determine if steps should have a single interface, or if MainWindow should 
+               # track each by unique name.  Right now we do the first.
+               # I think the latter is better, because then we can keep exactly one copy of the data around
+               # - inside the step that it refers to.
+               self.netidstep = NetIDStep()
+               self.lstep = LDAPStep()
+               self.donestep = DoneStep()
+               self.steps.append( self.netidstep )
+               self.steps.append( self.lstep )
+               self.steps.append( self.donestep )
+               self.next_button = QPushButton("&Next")
+               self.next_button.setEnabled(False)
+               self.prev_button = QPushButton("&Previous")
+               self.prev_button.setEnabled(False)
+               self.layout = QGridLayout()
+               for s in self.steps:
+                       QtCore.QObject.connect( s, QtCore.SIGNAL('notReady()'), self.next_disabled)
+                       QtCore.QObject.connect( s, QtCore.SIGNAL('ready()'), self.next_enabled)
+                       QtCore.QObject.connect( s, QtCore.SIGNAL('submit()'), self.next)
+                       self.layout.addWidget(s,0,0,2,2)
+                       s.hide()
+               self.layout.addWidget(self.prev_button,2,0,1,1)
+               self.layout.addWidget(self.next_button,2,1,1,1)
+               self.setLayout(self.layout)
+               self.resize(400,300)
+               self.show()
+               self.steps[0].show()
+               QtCore.QObject.connect( self.prev_button, QtCore.SIGNAL('clicked()'), self.prev)
+               QtCore.QObject.connect( self.next_button, QtCore.SIGNAL('clicked()'), self.next)
+
+       def next(self):
+               if not self.next_button.isEnabled():
+                       print "Can't advance yet."
+                       return
+               if  self.currentstep + 1 < len(self.steps) :
+                       self.steps[self.currentstep].hide()
+                       self.currentstep = self.currentstep + 1
+                       self.steps[self.currentstep].show()
+               self.prev_button.setEnabled(True)
+               self.next_button.setEnabled(False)
+               # Perform special actions if particular step
+               if isinstance(self.steps[self.currentstep],LDAPStep):
+                       self.lstep.lookup(self.netidstep.getNetID())
+               print "Next selected"
+
+       def prev(self):
+               if not self.prev_button.isEnabled():
+                       print "Can't go back."
+                       return
+               if self.currentstep > 0:
+                       self.steps[self.currentstep].hide()
+                       self.currentstep = self.currentstep - 1
+                       self.steps[self.currentstep].show()
+               self.next_button.setEnabled(True)
+               self.prev_button.setEnabled( self.currentstep != 0)
+               print "Prev selected"
+       def next_enabled(self):
+               self.next_button.setEnabled(True)
+       def next_disabled(self):
+               self.next_button.setEnabled(False)
+       def reset(self):
+               for s in self.steps:
+                       s.reset()
+
+
+if __name__ == "__main__":
+       app = QApplication([""])
+       widget = NewPersonWizard()
+       app.exec_()
+