From 0e2f0ad8b748e10ba19315cfeeae6ac6654ffb75 Mon Sep 17 00:00:00 2001 From: Antonio Gallo Date: Thu, 14 Apr 2011 00:33:49 +0000 Subject: h-client:implemented a feature to help the user to select the distro --- h-client/hclient.py | 162 ++++++++++++++++++++++++++++++++++++++------------- h-client/hlibrary.py | 43 ++++++++------ 2 files changed, 146 insertions(+), 59 deletions(-) diff --git a/h-client/hclient.py b/h-client/hclient.py index 9a22bb2..1dc6135 100644 --- a/h-client/hclient.py +++ b/h-client/hclient.py @@ -214,6 +214,7 @@ class hclient: self.client.setNode(self.serverEntry.get_text()) self.updateStatus() self.synchronize(None) + self.prefWindow.destroy() #close the preferences window def closePref(self,widget): @@ -269,10 +270,7 @@ class hclient: def closeLicenseNoticeWindow(self,widget): self.licenseNoticeWindow.destroy() - #close the info window - def closeInfoWindowWindow(self,widget): - self.infoWindow.destroy() - + #open the dialog with the software info def openInfoWindow(self,widget): about = gtk.AboutDialog() about.set_program_name("h-node client") @@ -284,57 +282,132 @@ class hclient: about.run() about.destroy() - #start the window containing the license notice - def openLicenseNoticeWindow(self,widget): - #window for preferences - self.licenseNoticeWindow = gtk.Window(gtk.WINDOW_TOPLEVEL) - self.licenseNoticeWindow.set_title("license notice") - self.licenseNoticeWindow.set_position(gtk.WIN_POS_CENTER) - self.licenseNoticeWindow.set_icon_from_file("img/icon.png") - self.licenseNoticeWindow.set_size_request(300, -1) + #close the window containing the list of allowed distribusions + def closeDistroHelperWindow(self,widget): + self.distroHelperWindow.destroy() - vbox = gtk.VBox(False, 0) - vbox.set_border_width(10) - self.licenseNoticeWindow.add(vbox) - - result = self.client.getLicenseNotice(); - #print result - ##if result + #update the distribution entry + def setDistributions(self,widget): + self.currentDevice.setDistributions(self._tempDistributions) + self.distributionEntry.set_text(self.currentDevice.createDistroEntry()) + self.distroHelperWindow.destroy() - #description input - sw = gtk.ScrolledWindow() - #sw.set_shadow_type(gtk.SHADOW_ETCHED_IN) - sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_NEVER) + #add a distrocode to the self._tempDistributions property + def addTempDistribution(self,widget,data): + if widget.get_active(): + self._tempDistributions.append(data) + else: + try: + del self._tempDistributions[self._tempDistributions.index(data)] + except: + pass + + #print self._tempDistributions - noticeText = gtk.TextView() - #noticeText.set_decorated(False) - noticeText.set_editable(False) - #noticeText.modify_base(gtk.STATE_NORMAL, gtk.gdk.Color(50,100,150) ) - noticeText.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse("#a3a3a3") ) - noticeText.set_wrap_mode(gtk.WRAP_CHAR) + #window containing the list of allowed distribusions + def openDistroHelperWindow(self,widget,data,a = None,b = None): + + #used to temporarily save the list of distributions from the distribution entry or from the distribution checkButtons + self._tempDistributions = [] + + self.distroHelperWindow = gtk.Window(gtk.WINDOW_TOPLEVEL) + self.distroHelperWindow.set_title("choose the distribution") + self.distroHelperWindow.set_position(gtk.WIN_POS_CENTER) + self.distroHelperWindow.set_icon_from_file("img/icon.png") + self.distroHelperWindow.set_size_request(300, -1) + self.distroHelperWindow.set_transient_for(self.window) + self.distroHelperWindow.set_modal(True) - textbuffer = gtk.TextBuffer(table=None) - textbuffer.set_text(result) - noticeText.set_buffer(textbuffer) + self.vboxCh = gtk.VBox(False, 0) + self.vboxCh.set_border_width(10) + self.distroHelperWindow.add(self.vboxCh) - sw.add(noticeText) - #sw.show() - #sw.show_all() + #fill the self._tempDistributions list with the distros already contained inside the distribution entry + checkedDistros = self.distributionEntry.get_text().split(',') + + for distro in checkedDistros: + if distro != '' and self.client.distroIsAllowed(distro.lstrip().rstrip()): + self._tempDistributions.append(distro.lstrip().rstrip()) - vbox.pack_start(sw, False, True, 5) + #create and pack the checkButtons + for distroCode,distroLabel in self.client.allowedDistros.iteritems(): + chbutton = gtk.CheckButton(distroLabel) + if distroCode in self._tempDistributions: + chbutton.set_active(True) + chbutton.connect("clicked", self.addTempDistribution,distroCode) + self.vboxCh.pack_start(chbutton, True, True, 2) hbox = gtk.HBox(False, 0) hbox.set_border_width(10) applyButton = gtk.Button(stock=gtk.STOCK_APPLY) closeButton = gtk.Button(stock=gtk.STOCK_CANCEL) - applyButton.connect("clicked", self.submit) - closeButton.connect("clicked", self.closeLicenseNoticeWindow) + applyButton.connect("clicked", self.setDistributions) + closeButton.connect("clicked", self.closeDistroHelperWindow) hbox.pack_end(applyButton, False, True, 0) hbox.pack_end(closeButton, False, True, 3) - vbox.pack_start(hbox, False, True, 0) + self.vboxCh.pack_start(hbox, False, True, 0) + + self.distroHelperWindow.show_all() - self.licenseNoticeWindow.show_all() + #start the window containing the license notice + def openLicenseNoticeWindow(self,widget): + result = self.client.getLicenseNotice(); + + if result: + #window for preferences + self.licenseNoticeWindow = gtk.Window(gtk.WINDOW_TOPLEVEL) + self.licenseNoticeWindow.set_title("license notice") + self.licenseNoticeWindow.set_position(gtk.WIN_POS_CENTER) + self.licenseNoticeWindow.set_icon_from_file("img/icon.png") + self.licenseNoticeWindow.set_size_request(300, -1) + self.licenseNoticeWindow.set_transient_for(self.window) + self.licenseNoticeWindow.set_modal(True) + + vbox = gtk.VBox(False, 0) + vbox.set_border_width(10) + self.licenseNoticeWindow.add(vbox) + + + #print result + ##if result + + #description input + sw = gtk.ScrolledWindow() + #sw.set_shadow_type(gtk.SHADOW_ETCHED_IN) + sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_NEVER) + + noticeText = gtk.TextView() + #noticeText.set_decorated(False) + noticeText.set_editable(False) + #noticeText.modify_base(gtk.STATE_NORMAL, gtk.gdk.Color(50,100,150) ) + noticeText.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse("#a3a3a3") ) + + noticeText.set_wrap_mode(gtk.WRAP_CHAR) + + textbuffer = gtk.TextBuffer(table=None) + textbuffer.set_text(result) + noticeText.set_buffer(textbuffer) + + sw.add(noticeText) + #sw.show() + #sw.show_all() + + vbox.pack_start(sw, False, True, 5) + + hbox = gtk.HBox(False, 0) + hbox.set_border_width(10) + applyButton = gtk.Button(stock=gtk.STOCK_APPLY) + closeButton = gtk.Button(stock=gtk.STOCK_CANCEL) + applyButton.connect("clicked", self.submit) + closeButton.connect("clicked", self.closeLicenseNoticeWindow) + hbox.pack_end(applyButton, False, True, 0) + hbox.pack_end(closeButton, False, True, 3) + vbox.pack_start(hbox, False, True, 0) + + self.licenseNoticeWindow.show_all() + else: + self.printErrors() #start the login window @@ -346,6 +419,8 @@ class hclient: self.loginWindow.set_position(gtk.WIN_POS_CENTER) self.loginWindow.set_icon_from_file("img/icon.png") self.loginWindow.set_size_request(300, -1) + self.loginWindow.set_transient_for(self.window) + self.loginWindow.set_modal(True) self.window.connect("delete_event", self.delete_event_login) @@ -408,6 +483,8 @@ class hclient: self.prefWindow.set_position(gtk.WIN_POS_CENTER) self.prefWindow.set_icon_from_file("img/icon.png") self.prefWindow.set_size_request(300, -1) + self.prefWindow.set_transient_for(self.window) + self.prefWindow.set_modal(True) vbox = gtk.VBox(False, 0) @@ -723,13 +800,16 @@ class hclient: ### distribution #distribution label - self.distributionLabel = gtk.Label("Distribution:") + self.distributionLabel = gtk.Label("Distribution used: ") self.distributionLabel.set_alignment(0.95,0.5) #add the label self.rightTable.attach(self.distributionLabel, 0, 1, 4, 5) #distribution input self.distributionEntry = gtk.Entry() + self.distributionEntry.connect("button-press-event", self.openDistroHelperWindow) + + #add the input self.rightTable.attach(self.distributionEntry, 1, 2, 4, 5) diff --git a/h-client/hlibrary.py b/h-client/hlibrary.py index c86c66c..c55fb4a 100644 --- a/h-client/hlibrary.py +++ b/h-client/hlibrary.py @@ -41,24 +41,6 @@ class Device(object): #list of options for the howItWorks entry _howItWorksOptions = ['yes','no'] - #_allowedDistros = { - #'blag_90001' : 'BLAG 90001', - #'blag_120000' : 'BLAG 120000', - #'dragora_1_1' : 'Dragora 1.1', - #'dragora_2_0' : 'Dragora 2.0 Ardi', - #'dynebolic_2_5_2' : 'Dynebolic 2.5.2 DHORUBA', - #'gnewsense_2_3' : 'gNewSense 2.3 Deltah', - #'gnewsense_3_0' : 'gNewSense 3.0 Metad', - #'musix_2_0' : 'Musix GNU+Linux 2.0 R0', - #'trisquel_3_5' : 'Trisquel 3.5 Awen', - #'trisquel_4_0' : 'Trisquel 4.0 Taranis', - #'trisquel_4_5' : 'Trisquel 4.5 Slaine', - #'ututo_xs_2009' : 'UTUTO XS 2009', - #'ututo_xs_2010' : 'UTUTO XS 2010', - #'venenux_0_8' : 'VENENUX 0.8', - #'venenux_0_8_2' : 'VENENUX-EC 0.8.2' - #} - #allowed years of commercialization _years = [ 'not-specified', @@ -361,6 +343,24 @@ class Mycurl: class Client: + allowedDistros = { + 'blag_90001' : 'BLAG 90001', + 'blag_120000' : 'BLAG 120000', + 'dragora_1_1' : 'Dragora 1.1', + 'dragora_2_0' : 'Dragora 2.0 Ardi', + 'dynebolic_2_5_2' : 'Dynebolic 2.5.2 DHORUBA', + 'gnewsense_2_3' : 'gNewSense 2.3 Deltah', + 'gnewsense_3_0' : 'gNewSense 3.0 Metad', + 'musix_2_0' : 'Musix GNU+Linux 2.0 R0', + 'trisquel_3_5' : 'Trisquel 3.5 Awen', + 'trisquel_4_0' : 'Trisquel 4.0 Taranis', + 'trisquel_4_5' : 'Trisquel 4.5 Slaine', + 'ututo_xs_2009' : 'UTUTO XS 2009', + 'ututo_xs_2010' : 'UTUTO XS 2010', + 'venenux_0_8' : 'VENENUX 0.8', + 'venenux_0_8_2' : 'VENENUX-EC 0.8.2' + } + devices = {} _status = True @@ -384,6 +384,13 @@ class Client: def __init__(self,url = ''): self.request = Mycurl(url) + #check if a distro code is allowed or not + def distroIsAllowed(self,distroCode): + allowedDistroCodes = self.allowedDistros.keys() + if distroCode in allowedDistroCodes: + return True + return False + def getNode(self): return self.request.getDomain() -- cgit v1.2.3