import pygtk pygtk.require('2.0') import gtk import gtk.glade import gobject import math from joy_manager import * from configuration_manager import * from WinMain import * import Core class Config_Window: def __init__(self,cfg_manager,joy,winmain=None): self.glade = gtk.glade.XML(Core.Core.RSRC_PATH+"/glade_configure_joystick.glade") self.window=self.glade.get_widget("win_config_joystick") self.window.show() self.window.connect("destroy", self.window_hide) self.window.set_modal(True) self.cfg_manager=cfg_manager self.combo_joysticks=self.glade.get_widget("combo_joysticks") self.joy=joy self.accept_button=self.glade.get_widget("button1") self.cancel_button=self.glade.get_widget("button2") self.list_trigger=[] self.list_checkbox=[] self.button_checkbox=None self.joy_init=False self.winmain=winmain store = gtk.ListStore(gobject.TYPE_STRING) for item in self.joy.get_joy_list(): id,name,axes,buttons=item store.append(["%s"%(name)]) # Temporal entry to test combo box as we don't have two joysticks #store.append(["NULL joystick - JUST TESTING"]) self.combo_joysticks.set_model(store) self.combo_joysticks.set_active(0) self.combo_joysticks.connect("changed",self.update_menus) self.vbox1=self.glade.get_widget("vbox1") self.first_time=True for item in self.joy.get_joy_list(): id,name,axes,buttons=item if name==self.cfg_manager.joy_name: self.joy.init_joy(id) self.joy_init=True if not self.joy_init: self.joy.init_joy(0) self.update_menus() #gtk.main() #def __init__ def update_joy_data(self): list = self.joy.get_all_axes() id=0 for item in self.progressbar_list: 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 return True # returns true because it is needed for the timeout to repeat itself # def update_progressbars def update_menus(self,data=None): #print "#" #print "> %s "%self.combo_joysticks.get_active_text() # init code for the new joystick should be here # it is now hardcoded to be just joy[0] # ---------------------------------------------- ^^^^^^^^^ self.list_checkbox=[] self.joy.quit_joy() self.joy.init_joy(self.combo_joysticks.get_active()) if not self.first_time: self.vbox1.remove(self.vbox) hbox_list=[] self.progressbar_list=[] for item in range(self.joy.axes): tmp_hbox=gtk.HBox(False,3) tmp_hbox.show() tmp_label=gtk.Label("Axis %s"%item) 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.list_checkbox.append(tmp_checkbutton) hbox_list.append(tmp_hbox) self.buttons_label=gtk.Label("Buttons (any of them) ") self.buttons_label.show() self.buttons_checkbutton=gtk.CheckButton() self.buttons_checkbutton.show() tmp_hbox=gtk.HBox(False,2) tmp_hbox.show() tmp_hbox.pack_start(self.buttons_label,True,True,0) tmp_hbox.pack_start(self.buttons_checkbutton,True,True,0) self.button_list=[] hbox_list.append(tmp_hbox) tmp_hbox=gtk.HBox(False,self.joy.buttons) tmp_hbox.show() for item in range(self.joy.buttons): tmp_label=gtk.Label("[%s] OFF"%(item)) tmp_label.show() self.button_list.append(tmp_label) tmp_hbox.pack_start(tmp_label,True,True,0) hbox_list.append(tmp_hbox) self.vbox = gtk.VBox(True, len(hbox_list)) self.vbox.show() for item in hbox_list: self.vbox.pack_start(item,True,True,0) self.vbox1.pack_start(self.vbox,True,True,0) self.hbox2=self.glade.get_widget("hbox2") self.vbox1.reorder_child(self.hbox2,6) self.maintimer = gobject.timeout_add(50, self.update_joy_data) self.style=self.progressbar_list[0].get_modifier_style() self.first_time=False if self.combo_joysticks.get_active_text()==self.cfg_manager.joy_name: for item in self.cfg_manager.list_triggers: type,id=item if type=="axis": self.list_checkbox[id].set_active(True) if type=="buttons": self.buttons_checkbutton.set_active(True) #self.accept_button.connect("clicked",self.cfg_manager.update_variables,self.combo_joysticks.get_active_text(),self.list_trigger) self.accept_button.connect("clicked",self.update_variables) self.cancel_button.connect("clicked",self.window_hide) #def update_menus def window_hide(self,widget,data=None): if self.winmain!=None: self.winmain.label_manager.grid_list[self.winmain.label_manager.get_current_page()].selection_manager.running=True self.window.hide() #def window_hide def update_variables(self,widget, data=None): #print "## Debug ##" counter=0 list_enabled=[] for item in self.list_checkbox: # print ("## Check button for Axis %s is %s" % (counter,("disabled","enabled")[item.get_active()])) counter+=1 if item.get_active(): list_enabled.append(("axis",counter-1)) #print ("## Check button for Buttons is %s" %("disabled","enabled")[self.buttons_checkbutton.get_active()]) if self.buttons_checkbutton.get_active(): list_enabled.append(("buttons","all")) #print list_enabled #def update_variables(self,widget,name,list): self.cfg_manager.update_variables(self.combo_joysticks.get_active_text(),list_enabled) if self.winmain!=None: self.winmain.label_manager.grid_list[self.winmain.label_manager.get_current_page()].selection_manager.running=True self.window.hide() # def update_variables def destroy(self, widget, data=None): print "closing conf window..." #def destroy #class config_window if __name__ =="__main__": cfg_mngr=Configuration_Manager() cfg_mngr.load_cfg_file() joy=Joy() app=Config_Window(cfg_mngr,joy) gtk.main()