aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Gallo <tonicucoz@gmail.com>2011-03-24 01:31:00 +0000
committerAntonio Gallo <tonicucoz@gmail.com>2011-03-24 01:31:00 +0000
commit558ef7dfa6e741177b476f7c26b6b615382edeae (patch)
tree77a9de4b1fd1e064bdf9feab80db177485ae463a
parenta2b68340b1cc18cd67d5608078cdfed191a69548 (diff)
h-client:added toolbar and apply button
-rw-r--r--h-client/hclient.py205
-rw-r--r--h-client/hlibrary.py15
2 files changed, 176 insertions, 44 deletions
diff --git a/h-client/hclient.py b/h-client/hclient.py
index 949a7ba..8b3a463 100644
--- a/h-client/hclient.py
+++ b/h-client/hclient.py
@@ -51,44 +51,90 @@ class hclient:
#the device that has to be displaced in the right window
currentDevice = ''
+ #get the active text from a combo
+ #combo: the gtk combo instance
+ #default: default value if the active index < 0
+ def getActive(self, combo, default = 'not-specified'):
+ model = combo.get_model()
+ active = combo.get_active()
+ if active < 0:
+ return default
+ else:
+ return model[active][0]
+
+ #update the current device object by taking the values from the entries
+ def applyChanges(self,widget):
+ self.currentDevice.setModel(self.modelNameEntry.get_text())
+
+ self.currentDevice.setYear(self.getActive(self.commYearCombo))
+
+ self.currentDevice.setInterface(self.getActive(self.interfaceCombo))
+
+ self.currentDevice.setDistributions([])
+ self.currentDevice.addDistributions(self.distributionEntry.get_text())
+
+ self.currentDevice.setKernel(self.kernelEntry.get_text())
+
+ self.currentDevice.setHowItWorks(self.getActive(self.howItWorksCombo))
+
+ self.currentDevice.setDriver(self.driverEntry.get_text())
+
+ descriptionBuffer = self.descriptionText.get_buffer()
+ startiter, enditer = descriptionBuffer.get_bounds()
+ self.currentDevice.setDescription(descriptionBuffer.get_text(startiter, enditer))
+
+
#set the device that has to be displaced in the right window
- def setCurrentDevice(self, selection):
+ def setEntries(self, selection):
model, path = selection.get_selected()
if path:
#get the code:
code = model.get_value(path, 1)
- #set the current device
- self.currentDevice = code
- #get the device
+
if code in self.client.devices:
+
+ #set the current device
+ self.currentDevice = self.client.devices[code][0]
+ #get the device
+
device = self.client.devices[code][0]
#set the model entry
- self.setModelEntry(device)
+ self.setModelEntry()
#set the vendorid:productid entry
- self.setVendorIdProductIDCode(device)
- #set the commercialization year
- self.setCommYearEntry(device)
- #set the interface
- self.setInterfaceEntry(device)
+ 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()
+
+ #make sensitive the apply button
+ self.applyButton.set_sensitive(True)
#set the model name entry
- #device: a device object (a subclass of Device - see hlibrary.py)
- def setModelEntry(self,device):
- self.modelNameEntry.set_text(device.getModel())
+ def setModelEntry(self):
+ self.modelNameEntry.set_text(self.currentDevice.getModel())
#set the vendorid:productid entry
- #device: a device object (a subclass of Device - see hlibrary.py)
- def setVendorIdProductIDCode(self,device):
- self.vendorIdProductIdEntry.set_text(device.getVendorId() + ':' + device.getProductId())
+ def setVendorIdProductIDCode(self):
+ self.vendorIdProductIdEntry.set_text(self.currentDevice.getVendorId() + ':' + self.currentDevice.getProductId())
#set the year of commercialization
- #device: a device object (a subclass of Device - see hlibrary.py)
- def setCommYearEntry(self,device):
- if device.getYear() in self._years:
- index = self._years.index(device.getYear())
+ def setCommYearEntry(self):
+ if self.currentDevice.getYear() in self._years:
+ index = self._years.index(self.currentDevice.getYear())
else:
index = 0
@@ -96,20 +142,55 @@ class hclient:
#set the interface
- #device: a device object (a subclass of Device - see hlibrary.py)
- def setInterfaceEntry(self,device):
+ def setInterfaceEntry(self):
self.interfaceCombo.get_model().clear()
- for interface in device.getInterfaces():
+ for interface in self.currentDevice.getInterfaces():
self.interfaceCombo.append_text(interface)
- if device.getInterface() in device.getInterfaces():
- index = device.getInterfaces().index(device.getInterface())
+ if self.currentDevice.getInterface() in self.currentDevice.getInterfaces():
+ index = self.currentDevice.getInterfaces().index(self.currentDevice.getInterface())
else:
index = 0
self.interfaceCombo.set_active(index)
+
+
+ #set the distribution entry
+ def setDistributionEntry(self):
+ self.distributionEntry.set_text(self.currentDevice.createDistroEntry())
+
+
+ #set the kernel libre entry
+ def setKernelEntry(self):
+ self.kernelEntry.set_text(self.currentDevice.getKernel())
+
+
+ #set the howItWorks entry
+ def setHowItWorksEntry(self):
+ self.howItWorksCombo.get_model().clear()
+ for option in self.currentDevice.getHowItWorksOptions():
+ self.howItWorksCombo.append_text(option)
+
+ if self.currentDevice.getHowItWorks() in self.currentDevice.getHowItWorksOptions():
+ index = self.currentDevice.getHowItWorksOptions().index(self.currentDevice.getHowItWorks())
+ else:
+ index = 0
+
+ self.howItWorksCombo.set_active(index)
+
+ #set the driver entry
+ def setDriverEntry(self):
+ self.driverEntry.set_text(self.currentDevice.getDriver())
+
+
+ #set the description entry
+ def setDescriptionEntry(self):
+ textbuffer = gtk.TextBuffer(table=None)
+ textbuffer.set_text(self.currentDevice.getDescription())
+ self.descriptionText.set_buffer(textbuffer)
+
- # another callback
+ #another callback
def delete_event(self, widget, event, data=None):
gtk.main_quit()
return False
@@ -135,15 +216,43 @@ class hclient:
self.window.connect("delete_event", self.delete_event)
# Sets the border width of the window.
- self.window.set_border_width(3)
+ self.window.set_border_width(0)
+ vbox = gtk.VBox(False, 0)
+
self.centerWindow = gtk.HBox(False, 0)
+
+
+ ## build the toolbar ##
+ toolbar = gtk.Toolbar()
+ toolbar.set_tooltips(True)
+ #toolbar.set_style(gtk.TOOLBAR_BOTH)
+
+ pref = gtk.ToolButton(gtk.STOCK_PREFERENCES)
+ pref.set_tooltip_text('Preferences')
+ #sync = gtk.ToolButton(None,'Synchronize')
+ #sync.set_tooltip_text('Synchronize with the server: this will override your entries')
+ info = gtk.ToolButton(gtk.STOCK_INFO)
+ info.set_tooltip_text('Information')
+
+ toolbar.insert(pref, 0)
+ #toolbar.insert(sync, 1)
+ toolbar.insert(info, 1)
+ toolbar.show_all()
+
#add the bottom box
- self.window.add(self.centerWindow)
+ self.window.add(vbox)
- ## build the left window ##
+ vbox.pack_start(toolbar, True, True, 0)
+
+ vbox.pack_start(self.centerWindow, True, True, 0)
+ vbox.show()
+
+
+ ## build the left window ##
+
#start the left vertical box
self.leftWindow = gtk.VBox(False, 0)
#self.leftWindow.set_border_width(5)
@@ -160,13 +269,13 @@ class hclient:
self.tree = gtk.TreeView()
- languages = gtk.TreeViewColumn()
- languages.set_title("Your PCI and USB devices")
+ devices = gtk.TreeViewColumn()
+ devices.set_title("Your PCI and USB devices")
cell = gtk.CellRendererText()
- languages.pack_start(cell, True)
- languages.add_attribute(cell, "text", 0)
-
+ devices.pack_start(cell, False)
+ devices.add_attribute(cell, "text", 0)
+
self.treestore = gtk.TreeStore(str,str)
it = self.treestore.append(None, ["PCI Devices",""])
@@ -176,18 +285,20 @@ class hclient:
self.treestore.append(it, [dev[0].getType(),key])
selection = self.tree.get_selection()
- selection.connect('changed', self.setCurrentDevice)
+ selection.connect('changed', self.setEntries)
- self.tree.append_column(languages)
+ self.tree.append_column(devices)
self.tree.set_model(self.treestore)
-
+
self.leftWindow.pack_start(self.tree, False, True, 0)
self.leftWindow.show_all()
#self.lframe.add(self.leftWindow)
+ ## build the right window ##
+
self.rightTable = gtk.Table(8, 2, True)
#create the entries
@@ -277,14 +388,14 @@ class hclient:
###how it works
#how it works label
- self.howItWorksLabel = gtk.Label("How does it work?")
+ self.howItWorksLabel = gtk.Label("Does it work?")
#add the label
self.rightTable.attach(self.howItWorksLabel, 0, 1, 6, 7)
- self.howItWorksLabelCombo = gtk.combo_box_new_text()
+ self.howItWorksCombo = gtk.combo_box_new_text()
#add the combo to the table
- self.rightTable.attach(self.howItWorksLabelCombo, 1, 2, 6, 7)
+ self.rightTable.attach(self.howItWorksCombo, 1, 2, 6, 7)
### driver
@@ -307,7 +418,7 @@ class hclient:
sw = gtk.ScrolledWindow()
sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
- self.descriptionText = textview = gtk.TextView()
+ self.descriptionText = gtk.TextView()
self.descriptionText.set_wrap_mode(gtk.WRAP_CHAR)
sw.add(self.descriptionText)
@@ -319,12 +430,22 @@ class hclient:
self.rightTable.show_all()
+ #apply and submit buttons
+ hboxBelowEntries = gtk.VBox(False, 0)
+ self.applyButton = gtk.Button(stock=gtk.STOCK_APPLY)
+ self.applyButton.set_sensitive(False)
+ self.applyButton.connect("clicked", self.applyChanges)
+
+ hboxBelowEntries.pack_start(self.applyButton, False, True, 0)
+ hboxBelowEntries.show_all()
+
#start the left vertical box
self.rightWindow = gtk.VBox(False, 0)
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()
self.rightWindow.show_all()
@@ -345,4 +466,4 @@ def main():
if __name__ == "__main__":
Client = hclient()
- main()
+ main() \ No newline at end of file
diff --git a/h-client/hlibrary.py b/h-client/hlibrary.py
index 393de7e..a9e93dd 100644
--- a/h-client/hlibrary.py
+++ b/h-client/hlibrary.py
@@ -29,6 +29,7 @@ from xml.dom import minidom
class Device(object):
+ #from codename to h-source distro code
_distrosTable = {
'deltah' : 'gnewsense_2_3',
'metad' : 'gnewsense_3_0',
@@ -37,6 +38,9 @@ class Device(object):
'slaine' : 'trisquel_4_5'
}
+ #list of options for the howItWorks entry
+ _howItWorksOptions = ['yes','no']
+
#_allowedDistros = {
#'blag_90001' : 'BLAG 90001',
#'blag_120000' : 'BLAG 120000',
@@ -55,6 +59,7 @@ class Device(object):
#'venenux_0_8_2' : 'VENENUX-EC 0.8.2'
#}
+ #list of interfaces
_interfaces = []
_status = True
@@ -92,7 +97,7 @@ class Device(object):
string = string.replace("&"+entity+";",unichr(code))
return string.encode('utf-8')
- #get the distro h-source allowed code from the distro codename
+ #get the h-source distro code from the codename
def getDistroCode(self,codenameString):
codenames = self._distrosTable.keys()
for codename in codenames:
@@ -100,6 +105,7 @@ class Device(object):
return self._distrosTable[codename]
return ''
+ #create the distribution entry
def createDistroEntry(self):
cleanDistros = []
for distro in self._distributions:
@@ -121,12 +127,13 @@ class Device(object):
self._distributions.append(distroName)
#add many distributions
- #distroList: comma separated list of distros
+ #distroList: comma separated list of distros (type: string)
def addDistributions(self,distroList):
distros = distroList.split(',')
for distro in distros:
self.addDistribution(distro)
+ #get the h-source distro code of the user
def userDistribution(self):
if not os.system('cat /etc/*-release | grep CODENAME > tmp/temp'):
f = open('tmp/temp','r')
@@ -137,6 +144,9 @@ class Device(object):
self._status = False
self.errors.append('tmp folder not writable')
+ def getHowItWorksOptions(self):
+ return self._howItWorksOptions
+
def getInterfaces(self):
return self._interfaces
@@ -225,6 +235,7 @@ class Videocard(Device):
self._type = 'videocard'
self._howItWorks = 'does_not_work'
self._interfaces = ['not-specified','PCI','AGP','PCI-E','ISA','MCA','VLB']
+ self._howItWorksOptions = ['works_with_3D','works_without_3D','does_not_work']
def setPost(self):
super(Videocard, self).setPost()