import pygtk pygtk.require('2.0') import gtk import gtk.glade import gobject import locale import gettext import math from net.Lliurex.Amic.JoyManager import * from net.Lliurex.Amic.Configuration import * from net.Lliurex.Amic.Resources import * locale.textdomain("lliurex-amic") gettext.textdomain("lliurex-amic") _=gettext.gettext rsrc_path=get_rsrc() class Preferences: def __init__(self): self.glade_path=rsrc_path+"/preferences.glade" self.conf_file="/etc/lliurex-amic/pref.conf" self.button_press_pixbuf=gtk.gdk.pixbuf_new_from_file(rsrc_path+"/button-press.png") self.button_release_pixbuf=gtk.gdk.pixbuf_new_from_file(rsrc_path+"/button-released.png") print "__INIT__" self.glade = gtk.glade.XML(self.glade_path) self.window=self.glade.get_widget("win") self.window.show() self.window.connect("destroy", self.kill) self.cancelButton=self.glade.get_widget("cancelButton") self.acceptButton=self.glade.get_widget("acceptButton") self.buttonListVBox=self.glade.get_widget("buttonListvbox") self.joyCombobox=self.glade.get_widget("joyCombobox") self.msgLabel=self.glade.get_widget("msgLabel") self.miceCombobox=self.glade.get_widget("miceCombobox") self.scaleThreshold=self.glade.get_widget("scaleThreshold") self.spinScanPeriod=self.glade.get_widget("spinScanPeriod") self.imgtestarea=self.glade.get_widget("imgtestarea") self.cancelButton.connect("clicked",self.cancelButtonAction) self.acceptButton.connect("clicked",self.acceptButtonAction) self.configuration=Configuration(self.conf_file) self.scaleThreshold.set_value(self.configuration.threshold) self.spinScanPeriod.set_value(self.configuration.scanperiod) self.joy=Joy() joy_list=[] joy_list=self.joy.get_joy_list() store = gtk.ListStore(gobject.TYPE_STRING) found_id=0 self.found=False for item in self.joy.get_joy_list(): id,name,axes,buttons=item print "Joystick: " + name if name==self.configuration.joy_name: found_id=id self.found=True store.append(["%s"%(name)]) # Temporal entry to test combo box as we don't have two joysticks #store.append(["NULL joystick - JUST TESTING"]) self.variable_vbox=None self.joyCombobox.set_model(store) self.joyCombobox.connect("changed",self.update_menus) self.joyCombobox.set_active(found_id) store2 = gtk.ListStore(gobject.TYPE_STRING) found_id=0 count=0 for device in gtk.gdk.devices_list(): #print "Device: "+device.name+":"+str(device.mode) if device.name!="Virtual core XTEST pointer" and device.name!="Macintosh mouse button emulation" and device.name!="Core Pointer": store2.append(["%s"%device.name]) if device.name==self.configuration.mouse: print "Mouse: " + device.name found_id=count count+=1 self.miceCombobox.set_model(store2) self.miceCombobox.set_active(found_id) self.first_time=True #def __init__ def update_menus(self,data=None): self.progressbar_list=[] self.checkbox_list=[] self.button_list=[] #self.joy.quit_joy() #print self.joyCombobox.get_active() self.joy.init_joy(self.joyCombobox.get_active()) hbox_list=[] for id in range(self.joy.axes): tmp_hbox=gtk.HBox(False,3) tmp_hbox.show() tmp_label=gtk.Label(_("Axis")+" %s:"%id) tmp_label.show() tmp_hbox.pack_start(tmp_label,True,True,0) tmp_progressbar=gtk.ProgressBar() tmp_progressbar.show() tmp_hbox.pack_start(tmp_progressbar,True,True,0) self.progressbar_list.append(tmp_progressbar) tmp_checkbutton=gtk.CheckButton() tmp_checkbutton.show() tmp_hbox.pack_start(tmp_checkbutton,True,True,0) self.checkbox_list.append(tmp_checkbutton) tmp_hbox.show_all() hbox_list.append(tmp_hbox) tmp_label=gtk.Label(_("Buttons: (Any of them)")) tmp_label.show() self.buttons_checkbutton=gtk.CheckButton() self.buttons_checkbutton.show() tmp_hbox=gtk.HBox(True,2) tmp_hbox.show() tmp_hbox.pack_start(tmp_label,True,True,0) tmp_hbox.pack_start(self.buttons_checkbutton,True,True,0) hbox_list.append(tmp_hbox) hbox_buttons=gtk.HBox(False,self.joy.buttons) hbox_buttons.show() for id in range(self.joy.buttons): button_hbox=gtk.HBox(True,2) button_hbox.show() tmp_label=gtk.Label("[%s]"%id) tmp_label.show() tmp_icon=gtk.Image() tmp_icon.show() tmp_icon.set_from_pixbuf(self.button_release_pixbuf) button_hbox.pack_start(tmp_label,False,False,0) button_hbox.pack_start(tmp_icon,False,False,0) #self.button_list.append(tmp_label) self.button_list.append(tmp_icon) #hbox_buttons.pack_start(tmp_label,True,True,0) hbox_buttons.pack_start(button_hbox,True,True,0) hbox_list.append(hbox_buttons) #self.buttonListVBox.pack_start(hbox_) if self.variable_vbox!=None: self.buttonListVBox.remove(self.variable_vbox) self.variable_vbox=gtk.VBox(False,len(hbox_list)) self.variable_vbox.show() for hbox_item in range(len(hbox_list)): self.variable_vbox.pack_start(hbox_list[hbox_item]) self.buttonListVBox.pack_start(self.variable_vbox,False,False,0) self.maintimer = gobject.timeout_add(50, self.update_joy_data) if self.joyCombobox.get_active_text()==self.configuration.joy_name: #self.msgLabel.set_text(self.configuration.axes) list=self.configuration.axes.split(',') count=0 for tmp_checkbox in self.checkbox_list: for id in range(len(list)): if count==int(list[id]): tmp_checkbox.set_active(True) count+=1 if self.configuration.buttons: self.buttons_checkbutton.set_active(True) #def update_menus def update_joy_data(self): list = self.joy.get_all_axes() id=0 for item in self.progressbar_list: if math.fabs(list[id]) > self.scaleThreshold.get_value(): item.modify_bg(gtk.STATE_NORMAL,gtk.gdk.Color(0xFFFF,0,0,0)) else: item.modify_bg(gtk.STATE_NORMAL,gtk.gdk.Color(0x9999,0x9999,0x9999,0)) item.set_fraction(math.fabs(list[id])) id+=1 list = self.joy.get_all_buttons() id=0 """ for item in self.button_list: if list[id]: item.set_text("[%s] ON"%(id)) else: item.set_text("[%s] OFF"%(id)) id+=1 """ for item in self.button_list: if list[id]: item.set_from_pixbuf(self.button_press_pixbuf) else: item.set_from_pixbuf(self.button_release_pixbuf) id+=1 return True # returns true because it is needed for the timeout to repeat itself # def update_joy_data def cancelButtonAction(self,widget, data=None): print "Cancel Button" exit() #def cancelButtonAction def imgareaPress(self,widget,event): print "click" def acceptButtonAction(self,widget, data=None): print "Accept Button!" self.configuration.joy_name=self.joyCombobox.get_active_text() self.configuration.mouse=self.miceCombobox.get_active_text() if "buttons_checkbutton" in dir(self): self.configuration.buttons=self.buttons_checkbutton.get_active() else: print "No checkbuttons found!!!" axes_list="" count=0 for checkbox in self.checkbox_list: if checkbox.get_active(): axes_list=axes_list+"%s,"%count count+=1 axes_list=axes_list.rstrip(',') self.configuration.axes=axes_list self.configuration.threshold=self.scaleThreshold.get_value() self.configuration.scanperiod=self.spinScanPeriod.get_value() self.configuration.save() self.msgLabel.set_text("Configuration file saved in /etc/lliurex-amic/pref.conf") #def acceptButtonAction def run(self): gtk.main() #def run def kill(self,data=None): gtk.main_quit() #def killl #class preferences