import pygtk import gtk import gtk.glade import gnomevfs import net.Lliurex.JClic import net.Lliurex.JClic.Settings class Setup: def __init__(self,setup): self.icon_library = gtk.gdk.pixbuf_new_from_file("/usr/share/pixmaps/lliurex-recursos/jclicdb.png") self.icon_folder = self.load_icon("folder") self.uiTree = gtk.glade.XML("/usr/share/lliurex-recursos/glade/setup_ui.glade") self.winSetup = self.uiTree.get_widget("winSetup") self.btnAccept = self.uiTree.get_widget("btnAccept") self.btnAccept.connect("clicked",self.OnBtnAcceptClicked) self.btnCancel = self.uiTree.get_widget("btnCancel") self.btnCancel.connect("clicked",self.OnBtnCancelClicked) self.treeLibraries = self.uiTree.get_widget("treeLibraries") #pixbuf caption id self.treeStore= gtk.TreeStore(gtk.gdk.Pixbuf,str,str) colPix = gtk.TreeViewColumn("") colText = gtk.TreeViewColumn("name") self.treeLibraries.append_column(colPix) self.treeLibraries.append_column(colText) cell = gtk.CellRendererPixbuf() colPix.pack_start(cell, True) colPix.add_attribute(cell, 'pixbuf', 0) cell = gtk.CellRendererText() colText.pack_start(cell, True) colText.add_attribute(cell, 'text', 1) self.setup = setup for lib in setup.get_libraries(): iter=self.treeStore.append(None,[self.icon_library,lib.name,"library"]) self.put_node(lib,"main",iter) self.treeLibraries.set_model(self.treeStore) self.treeLibraries.expand_all() print "loading setup window" if not self.setup.lib_path==None: tmp = self.setup.lib_path.split(".") root = self.treeStore.get_iter_root() while not root==None: value = self.treeStore.get_value(root,1) if value==tmp[0]: print "Found Library:",value path=self.treeStore.get_path(self.lookup(self.treeStore.iter_children(root),tmp[1])) print "path: ",path self.treeLibraries.set_cursor(path) break root=self.treeStore.iter_next(root) def lookup(self,iter,id): if iter==None: return None value = self.treeStore.get_value(iter,2) balue = self.treeStore.get_value(iter,1) print "lookup ",balue, " ",value if value==id: return iter piter = self.lookup(self.treeStore.iter_next(iter),id) if not piter==None: return piter return self.lookup(self.treeStore.iter_children(iter),id) def put_node(self,lib,id,iter): for activity in lib.activities: if id==activity.value: piter=self.treeStore.append(iter,[self.icon_folder,activity.caption,activity.value]) for child in activity.children: self.put_node(lib,child,piter) # ************************************ # Loads an icon given its gnome keyname # ************************************ def load_icon(self,name,size = 48): theme = gtk.icon_theme_get_default() idata = theme.load_icon(name, size, 0) return idata def show(self): self.winSetup.show() def OnBtnCancelClicked(self,event): self.winSetup.hide() def OnBtnAcceptClicked(self,event): model,iter=self.treeLibraries.get_selection().get_selected() value = model.get_value(iter,2) while not iter==None: root = iter iter = model.iter_parent(iter) rvalue = model.get_value(root,1) print "Selected path:",rvalue," : ",value #ToDo # set new path #self.setup.sync_dir(rvalue + "." + value) self.setup.set_lib_path(rvalue + "." + value) self.winSetup.hide()