From efd2c8034502bc1b17da3ce6cb42172829e3f04a Mon Sep 17 00:00:00 2001 From: Antonio Gallo Date: Sat, 26 Mar 2011 11:40:06 +0000 Subject: improved GUI, alert when the server is not reachable --- h-client/hclient.py | 74 +++++++++++++++++++------------- h-client/hlibrary.py | 118 ++++++++++++++++++++++++++++++++++----------------- 2 files changed, 122 insertions(+), 70 deletions(-) diff --git a/h-client/hclient.py b/h-client/hclient.py index f0198b2..709165a 100644 --- a/h-client/hclient.py +++ b/h-client/hclient.py @@ -87,27 +87,32 @@ class hclient: self.applyButton.set_sensitive(True) self.resetButton.set_sensitive(True) + else: + + self.currentDevice = None + #set the pyGTK device entries def setEntries(self): - #set the model entry - self.setModelEntry() - #set the vendorid:productid entry - self.setVendorIdProductIDCode() - #set the commercialization year entry - self.setCommYearEntry() - #set the interface entry - self.setInterfaceEntry() - #set the distribution entry - self.setDistributionEntry() - #set the kernel entry - self.setKernelEntry() - #set the howItWorks entry - self.setHowItWorksEntry() - #set the driver entry - self.setDriverEntry() - #set the description entry - self.setDescriptionEntry() + if self.currentDevice != None: + #set the model entry + self.setModelEntry() + #set the vendorid:productid entry + self.setVendorIdProductIDCode() + #set the commercialization year entry + self.setCommYearEntry() + #set the interface entry + self.setInterfaceEntry() + #set the distribution entry + self.setDistributionEntry() + #set the kernel entry + self.setKernelEntry() + #set the howItWorks entry + self.setHowItWorksEntry() + #set the driver entry + self.setDriverEntry() + #set the description entry + self.setDescriptionEntry() #set the model name entry @@ -235,6 +240,7 @@ class hclient: def synchronize(self,widget): self.client.sync() + print self.client.errors self.setEntries() @@ -277,7 +283,7 @@ class hclient: pref.set_tooltip_text('Preferences') pref.connect("clicked", self.openPrefWindow) sync = gtk.ToolButton(gtk.STOCK_REFRESH) - sync.set_tooltip_text('Synchronize with the server: this will override the entries or your devices') + sync.set_tooltip_text('Synchronize with the server: this will override the entries of your devices') sync.connect("clicked", self.synchronize) info = gtk.ToolButton(gtk.STOCK_INFO) info.set_tooltip_text('Information') @@ -310,11 +316,6 @@ class hclient: self.tree = gtk.TreeView() self.tree.set_headers_visible(False) - #treeFrame = gtk.Frame() - #treeFrame.set_border_width(5) - ##treeFrame.add(self.tree) - #treeFrame.show_all() - devices = gtk.TreeViewColumn("Your PCI and USB devices") cell = gtk.CellRendererText() @@ -338,7 +339,7 @@ class hclient: self.tree.set_model(self.treestore) treesw = gtk.ScrolledWindow() - treesw.set_size_request(50,400) + treesw.set_size_request(50,431) treesw.set_shadow_type(gtk.SHADOW_ETCHED_IN) treesw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) treesw.add(self.tree) @@ -359,6 +360,7 @@ class hclient: ### model #model name label self.modelNameLabel = gtk.Label("Model name:") + self.modelNameLabel.set_alignment(0.95,0.5) #add the label self.rightTable.attach(self.modelNameLabel, 0, 1, 0, 1) @@ -371,6 +373,7 @@ class hclient: ### vendorid:productid #vendorid:productid label self.vendorIdProductIdLabel = gtk.Label("VendorID:productID code:") + self.vendorIdProductIdLabel.set_alignment(0.95,0.5) #add the label self.rightTable.attach(self.vendorIdProductIdLabel, 0, 1, 1, 2) @@ -385,6 +388,7 @@ class hclient: ###year of commercialization #year of commercialization label self.commYearLabel = gtk.Label("Year of commercialization:") + self.commYearLabel.set_alignment(0.95,0.5) #add the label self.rightTable.attach(self.commYearLabel, 0, 1, 2, 3) @@ -397,6 +401,7 @@ class hclient: ###interface #interface label self.interfaceLabel = gtk.Label("Interface:") + self.interfaceLabel.set_alignment(0.95,0.5) #add the label self.rightTable.attach(self.interfaceLabel, 0, 1, 3, 4) @@ -413,6 +418,7 @@ class hclient: ### distribution #distribution label self.distributionLabel = gtk.Label("Distribution:") + self.distributionLabel.set_alignment(0.95,0.5) #add the label self.rightTable.attach(self.distributionLabel, 0, 1, 4, 5) @@ -425,6 +431,7 @@ class hclient: ### kernel #kernel label self.kernelLabel = gtk.Label("Kernel libre version:") + self.kernelLabel.set_alignment(0.95,0.5) #add the label self.rightTable.attach(self.kernelLabel, 0, 1, 5, 6) @@ -437,6 +444,7 @@ class hclient: ###how it works #how it works label self.howItWorksLabel = gtk.Label("Does it work?") + self.howItWorksLabel.set_alignment(0.95,0.5) #add the label self.rightTable.attach(self.howItWorksLabel, 0, 1, 6, 7) @@ -449,6 +457,7 @@ class hclient: ### driver #driver label self.driverLabel = gtk.Label("Free driver used:") + self.driverLabel.set_alignment(0.95,0.5) #add the label self.rightTable.attach(self.driverLabel, 0, 1, 7, 8) @@ -497,18 +506,23 @@ class hclient: #start the left vertical box self.rightWindow = gtk.VBox(False, 0) - self.rightWindow.pack_start(self.rightTable, False, True, 5) + self.rightWindow.pack_start(self.rightTable, False, True, 10) self.rightWindow.pack_start(self.descriptionLabel, False, True, 3) self.rightWindow.pack_start(sw, False, True, 0) self.rightWindow.pack_start(hboxBelowEntries, False, True, 10) - self.rightWindow.show_all() - - self.centerWindow.pack_start(self.rightWindow, True, True, 5) + #self.rightWindow.show_all() + + rhbox = gtk.HBox(False, 0) + rhbox.pack_start(self.rightWindow, True, True, 5) + rFrame = gtk.Frame() + rFrame.add(rhbox) + rFrame.set_border_width(5) + self.centerWindow.pack_start(rFrame, True, True, 0) #self.rframe.add(self.rightWindow) #self.rframe.set_border_width(30) - self.centerWindow.show() + self.centerWindow.show_all() self.leftWindow.show() self.window.show() diff --git a/h-client/hlibrary.py b/h-client/hlibrary.py index c08239f..415b04b 100644 --- a/h-client/hlibrary.py +++ b/h-client/hlibrary.py @@ -304,6 +304,9 @@ class Mycurl: self.contents = '' self.setDomain(domain) + def getStatus(self): + return self._status + def setDomain(self,domain): self.domain = domain #check if the trailing slash is present @@ -320,6 +323,7 @@ class Mycurl: def body_callback(self, buf): self.contents = self.contents + buf + #perform the HTTP request def perform(self,requestUri = ''): self.url = self.domain + requestUri; @@ -332,8 +336,15 @@ class Mycurl: if self._post != None: c.setopt(c.POSTFIELDS, urllib.urlencode(self._post)) c.setopt(c.WRITEFUNCTION, self.body_callback) + c.perform() + + result = False + if c.getinfo(c.HTTP_CODE) == 200: + result = True + c.close() + return result class Client: @@ -496,47 +507,74 @@ class Client: #syncronize with the xml database def sync(self): - #loop the found devices - for key,dev in self.devices.iteritems(): - #find the class - Class = dev[1] - vendorid_productid = key[2:] - #find the controller - controller = self.getController(Class) - - #perform an http request - self.request.contents = '' - self.request.perform('download/' + controller + '/en') - - #parse the xml database - xmldoc = minidom.parseString(self.request.contents) - devices = xmldoc.getElementsByTagName("device") - for device in devices: - - code = device.getElementsByTagName("vendorid_productid")[0] - if code.hasChildNodes(): - if (code.childNodes[0].data == vendorid_productid): - - modelName = device.getElementsByTagName("model_name")[0].childNodes[0].data.encode('utf-8') - interface = device.getElementsByTagName("interface")[0].childNodes[0].data.encode('utf-8') - distribution = device.getElementsByTagName("distribution")[0].childNodes[0].data.encode('utf-8') - idDevice = device.getElementsByTagName("id")[0].childNodes[0].data.encode('utf-8') - works = device.getElementsByTagName("it_works")[0].childNodes[0].data.encode('utf-8') - year = device.getElementsByTagName("year")[0].childNodes[0].data.encode('utf-8') - - if device.getElementsByTagName("description")[0].hasChildNodes(): - description = device.getElementsByTagName("description")[0].childNodes[0].data.encode('utf-8') - dev[0].setDescription(description) - - #print modelName - dev[0].setModel(modelName) - dev[0].setInterface(interface) - dev[0].addDistributions(distribution) - dev[0].setHowItWorks(works) - dev[0].setYear(year) - dev[2] = 'update' - dev[3] = idDevice + #perform an http request + self.request.contents = '' + + result = self.request.perform('download/all/en') + + if result: + + #loop the found devices + for key,dev in self.devices.iteritems(): + #find the class + #Class = dev[1] + vendorid_productid = key[2:] + #find the controller + #controller = self.getController(Class) + + ##perform an http request + #self.request.contents = '' + + #result = self.request.perform('download/' + controller + '/en') + + #parse the xml database + xmldoc = minidom.parseString(self.request.contents) + devices = xmldoc.getElementsByTagName("device") + for device in devices: + + #check it is not a notebook + deviceType = device.getElementsByTagName("type")[0].childNodes[0].data.encode('utf-8') + + if deviceType != 'notebook': + code = device.getElementsByTagName("vendorid_productid")[0] + if code.hasChildNodes(): + if (code.childNodes[0].data == vendorid_productid): + + modelName = device.getElementsByTagName("model_name")[0].childNodes[0].data.encode('utf-8') + interface = device.getElementsByTagName("interface")[0].childNodes[0].data.encode('utf-8') + distribution = device.getElementsByTagName("distribution")[0].childNodes[0].data.encode('utf-8') + idDevice = device.getElementsByTagName("id")[0].childNodes[0].data.encode('utf-8') + works = device.getElementsByTagName("it_works")[0].childNodes[0].data.encode('utf-8') + year = device.getElementsByTagName("year")[0].childNodes[0].data.encode('utf-8') + + if device.getElementsByTagName("description")[0].hasChildNodes(): + description = device.getElementsByTagName("description")[0].childNodes[0].data.encode('utf-8') + dev[0].setDescription(description) + + if device.getElementsByTagName("kernel_libre")[0].hasChildNodes(): + kernel_libre = device.getElementsByTagName("kernel_libre")[0].childNodes[0].data.encode('utf-8') + dev[0].setKernel(kernel_libre) + + #driverNode = device.getElementsByTagName("driver")[0] + #if driverNode: + #if driverNode.hasChildNodes(): + #driver = driverNode.childNodes[0].data.encode('utf-8') + #dev[0].setDriver(driver) + + + #print modelName + dev[0].setModel(modelName) + dev[0].setInterface(interface) + dev[0].addDistributions(distribution) + dev[0].setHowItWorks(works) + dev[0].setYear(year) + dev[2] = 'update' + dev[3] = idDevice + else: + self._status = False + self.errors.append("couldn't connect to host") + def submit(self): for key,dev in self.devices.iteritems(): dev[0].setPost() -- cgit v1.2.3