aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--h-client/hclient.py139
-rw-r--r--h-client/hlibrary.py40
2 files changed, 154 insertions, 25 deletions
diff --git a/h-client/hclient.py b/h-client/hclient.py
index c154579..d645833 100644
--- a/h-client/hclient.py
+++ b/h-client/hclient.py
@@ -194,19 +194,93 @@ class hclient:
#set the node
def setNode(self,widget):
+ self.client.logout()
+ self.updateStatus()
+ self.printErrors()
self.client.setNode(self.serverEntry.get_text())
- #close the window for preferences
+ #close the preferences window
def closePref(self,widget):
self.prefWindow.destroy()
+ #login to the server
+ def login(self,widget):
+ self.client.login(self.usernameEntry.get_text(),self.passwordEntry.get_text())
+ self.updateStatus()
+ self.printErrors()
+ self.loginWindow.destroy()
+
+ #logout to the server
+ def logout(self,widget):
+ self.client.logout()
+ self.updateStatus()
+ self.printErrors()
+
+ #close the login window
+ def closeLoginWindow(self,widget):
+ self.loginWindow.destroy()
+
+ #start the login window
+ def openLoginWindow(self,widget):
+
+ #window for preferences
+ self.loginWindow = gtk.Window(gtk.WINDOW_TOPLEVEL)
+ self.loginWindow.set_title("preferences")
+ #self.prefWindow.set_size_request(300, -1)
+
+ vbox = gtk.VBox(False, 0)
+
+ self.loginWindow.add(vbox)
+
+ table = gtk.Table(2, 2, True)
+ table.set_border_width(10)
+
+ label = gtk.Label("<b>login to the server</b>")
+ label.set_use_markup(True)
+
+ vbox.pack_start(label, False, True, 0)
+
+ vbox.pack_start(table, False, True, 0)
+
+ ### username
+ usernameLabel = gtk.Label("username:")
+ #add the label
+ table.attach(usernameLabel, 0, 1, 0, 1)
+
+ self.usernameEntry = gtk.Entry()
+ #add the input to the table
+ table.attach(self.usernameEntry, 1, 2, 0, 1)
+
+ ### password
+ passwordLabel = gtk.Label("password:")
+ #add the label
+ table.attach(passwordLabel, 0, 1, 1, 2)
+
+ self.passwordEntry = gtk.Entry()
+ self.passwordEntry.set_visibility(False)
+
+ #add the input to the table
+ table.attach(self.passwordEntry, 1, 2, 1, 2)
+
+ hbox = gtk.HBox(False, 0)
+ hbox.set_border_width(10)
+ applyButton = gtk.Button(stock=gtk.STOCK_APPLY)
+ closeButton = gtk.Button(stock=gtk.STOCK_CLOSE)
+ applyButton.connect("clicked", self.login)
+ closeButton.connect("clicked", self.closeLoginWindow)
+ hbox.pack_end(applyButton, False, True, 0)
+ hbox.pack_end(closeButton, False, True, 3)
+ vbox.pack_start(hbox, False, True, 0)
- #start the window for preferences
+ self.loginWindow.show_all()
+
+
+ #start the preferences window
def openPrefWindow(self,widget):
#window for preferences
self.prefWindow = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.prefWindow.set_title("preferences")
- self.prefWindow.set_size_request(300, -1)
+ #self.prefWindow.set_size_request(300, -1)
vbox = gtk.VBox(False, 0)
@@ -215,14 +289,13 @@ class hclient:
table = gtk.Table(1, 2, True)
table.set_border_width(10)
- vbox.pack_start(table, False, True, 10)
+ vbox.pack_start(table, False, True, 0)
### server
serverLabel = gtk.Label("Server URL:")
#add the label
table.attach(serverLabel, 0, 1, 0, 1)
- #model name input
self.serverEntry = gtk.Entry()
self.serverEntry.set_text(self.client.getNode())
#add the input to the table
@@ -236,7 +309,7 @@ class hclient:
closeButton.connect("clicked", self.closePref)
hbox.pack_end(applyButton, False, True, 0)
hbox.pack_end(closeButton, False, True, 3)
- vbox.pack_start(hbox, False, True, 10)
+ vbox.pack_start(hbox, False, True, 0)
#applyButton.connect("clicked", self.applyChanges)
self.prefWindow.show_all()
@@ -268,6 +341,23 @@ class hclient:
self.errorBar.show_all()
self.client.errors = []
+
+ #check if the user is logged
+ #hide or show the login/logout buttons
+ def updateStatus(self):
+ if self.client.isLogged():
+ self.loginButton.hide()
+ self.logoutButton.show()
+ info = self.client.getUserInfo()
+ if info != False:
+ self.statusLabel.set_markup("<i>hello</i> <b>"+info['username']+"</b>, <i>you are logged in</i>")
+ else:
+ self.printErrors()
+ else:
+ self.loginButton.show()
+ self.logoutButton.hide()
+ self.statusLabel.set_markup("<i>you are not logged in</i>")
+
#another callback
def delete_event(self, widget, event, data=None):
@@ -277,7 +367,7 @@ class hclient:
def __init__(self):
#start the client object
- self.client = Client()
+ self.client = Client('h-source')
self.client.createDevices()
# Create the main window
@@ -389,6 +479,27 @@ class hclient:
## build the right window ##
+ #right top
+ rthbox = gtk.HBox(False, 0)
+ rthbox.set_border_width(5)
+ #login button
+ self.loginButton = gtk.Button("Login")
+ self.loginButton.set_sensitive(True)
+ self.loginButton.connect("clicked", self.openLoginWindow)
+ rthbox.pack_start(self.loginButton, False, True, 0)
+
+ #login button
+ self.logoutButton = gtk.Button("Logout")
+ self.logoutButton.set_sensitive(True)
+ self.logoutButton.connect("clicked", self.logout)
+ rthbox.pack_start(self.logoutButton, False, True, 0)
+
+ #status label
+ self.statusLabel = gtk.Label("")
+ self.statusLabel.set_use_markup(True)
+ rthbox.pack_end(self.statusLabel, False, True, 0)
+
+
self.rightTable = gtk.Table(8, 2, True)
#create the entries
@@ -558,7 +669,15 @@ class hclient:
rFrame = gtk.Frame()
rFrame.add(rhbox)
rFrame.set_border_width(5)
- self.centerWindow.pack_start(rFrame, True, True, 0)
+
+ rvbox = gtk.VBox(False, 0)
+
+ rvbox.pack_start(rthbox, True, True, 0)
+ rvbox.pack_start(rFrame, True, True, 0)
+
+
+
+ self.centerWindow.pack_start(rvbox, True, True, 0)
#self.rframe.add(self.rightWindow)
#self.rframe.set_border_width(30)
@@ -567,7 +686,9 @@ class hclient:
self.bottomWindow.show_all()
self.leftWindow.show()
self.window.show()
- self.synchronize(None);
+ self.synchronize(None)
+ self.updateStatus()
+ #self.logoutButton.hide()
def main():
gtk.main()
diff --git a/h-client/hlibrary.py b/h-client/hlibrary.py
index 3205fbd..79679b7 100644
--- a/h-client/hlibrary.py
+++ b/h-client/hlibrary.py
@@ -373,7 +373,7 @@ class Client:
}
}
- def __init__(self,url = 'http://www.h-node.com'):
+ def __init__(self,url = ''):
self.request = Mycurl(url)
def getNode(self):
@@ -430,27 +430,35 @@ class Client:
#get info about the user logged
def getUserInfo(self):
- self.request.perform('users/info/en')
- xmldoc = minidom.parseString(self.request.contents)
- status = xmldoc.getElementsByTagName("status")[0].childNodes[0].data
-
- username = ''
- token = ''
- groups = ''
-
- if status == 'logged':
- username = xmldoc.getElementsByTagName("username")[0].childNodes[0].data
- token = xmldoc.getElementsByTagName("token")[0].childNodes[0].data
- groups = xmldoc.getElementsByTagName("groups")[0].childNodes[0].data
+ result = self.request.perform('users/info/en')
+
+ if result:
+ xmldoc = minidom.parseString(self.request.contents)
+ status = xmldoc.getElementsByTagName("status")[0].childNodes[0].data
+
+ username = ''
+ token = ''
+ groups = ''
+
+ if status == 'logged':
+ username = xmldoc.getElementsByTagName("username")[0].childNodes[0].data
+ token = xmldoc.getElementsByTagName("token")[0].childNodes[0].data
+ groups = xmldoc.getElementsByTagName("groups")[0].childNodes[0].data
+
+ return {'status':status,'username':username,'token':token,'groups':groups}
- return {'status':status,'username':username,'token':token,'groups':groups}
+ else:
+ self._status = False
+ self.errors.append("unable to connect to server")
+ return False
#return True if the user is logged, else return False
def isLogged(self):
info = self.getUserInfo()
- if info['status'] == 'logged':
- return True
+ if info != False:
+ if info['status'] == 'logged':
+ return True
return False