import gtk import gtk.glade import pickle import Core from config_window import * from new_grid_window import * from label_manager import * from grid import * class WinMain: def __init__(self,core): print("WinMain::init()") self.uitree=gtk.glade.XML(Core.Core.RSRC_PATH+"/winmain.glade") self.core=core self.winmain=self.uitree.get_widget("winMain") self.winmain.connect("destroy",self.OnDestroy) for device in gtk.gdk.devices_list(): print "Device: "+device.name+":"+str(device.mode) if device.name=="Logitech USB Optical Mouse": device.set_mode(gtk.gdk.MODE_SCREEN) device.set_axis_use(0,gtk.gdk.AXIS_IGNORE) device.set_axis_use(1,gtk.gdk.AXIS_IGNORE) device.set_source(gtk.gdk.SOURCE_CURSOR) self.winmain.set_extension_events(gtk.gdk.EXTENSION_EVENTS_ALL) gtk.gdk.event_handler_set(self.OnTest) btnnew=self.uitree.get_widget("btnNew") btnnew.connect("clicked",self.OnBtnNewClicked) btnopen = self.uitree.get_widget("btnOpen") btnopen.connect("clicked",self.OnBtnOpenClicked) btnsave = self.uitree.get_widget("btnSave") btnsave.connect("clicked",self.OnBtnSaveClicked) btnsetup = self.uitree.get_widget("btnSetup") btnsetup.connect("clicked",self.OnBtnSetupClicked) self.winmain.set_title("Amic (%s)"%self.core.version) self.winmain.show() self.vbox=self.uitree.get_widget("vbox1") self.label_manager=Label_Manager(self.core) #self.label_manager.add_grid(Grid(self.core,"grid 2",3,7)) self.vbox.pack_start(self.label_manager,True,True,0) self.opened_files=[] # gtk.main() def OnTest(self,event): if event.type==gtk.gdk.BUTTON_PRESS: print "Mouse click from " + str(event.device.name) gtk.main_do_event(event) def OnDestroy(self,data): # print("WinMain::destroy()") gtk.main_quit() def OnBtnNewClicked(self,data): # print("BtnNew::click") self.new_grid_window=New_Grid_Window(self,self.core) def OnBtnOpenClicked(self,data): # print("BtnOpen::click") dialog = gtk.FileChooserDialog("Open..", None, gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)) dialog.set_default_response(gtk.RESPONSE_OK) filter = gtk.FileFilter() filter.set_name("Grids") filter.add_pattern("*.grid") dialog.add_filter(filter) filter = gtk.FileFilter() filter.set_name("All files") filter.add_pattern("*") dialog.add_filter(filter) response = dialog.run() if response == gtk.RESPONSE_OK: text=dialog.get_filename() + ' opened' file_name=dialog.get_filename() # self.statusBar.push(data,text) # self.file = open(self.text2, 'rw') # self.fileopened = True # self.buffer=gtk.TextBuffer() # self.buffer.set_text(self.file.read()) # self.textviewer.set_buffer(self.buffer) # self.file_saved=False found=False if len(self.opened_files)>0: for item in self.opened_files: id,fname=item if fname==file_name: found=True if not found: self.opened_files.append((self.core.id_counter,file_name)) file=open(file_name, 'rb') grid=pickle.load(file) file.close() self.label_manager.add_grid(Grid(self.core,grid.name,grid.rows,grid.cols,self.core.id_counter,grid.button_list)) self.label_manager.grid_list[self.label_manager.get_current_page()].selection_manager.running=True self.label_manager.grid_list[self.label_manager.get_current_page()].is_an_opened_file=True #self.label_manager.update_manager(self.core.id_counter) self.core.id_counter+=1 else: print "File already opened" else: self.opened_files.append((self.core.id_counter,file_name)) file=open(file_name, 'rb') grid=pickle.load(file) file.close() self.label_manager.add_grid(Grid(self.core,grid.name,grid.rows,grid.cols,self.core.id_counter,grid.button_list)) self.label_manager.grid_list[self.label_manager.get_current_page()].selection_manager.running=True self.label_manager.grid_list[self.label_manager.get_current_page()].is_an_opened_file=True #self.label_manager.update_manager() self.core.id_counter+=1 # print self.opened_files dialog.destroy() elif response == gtk.RESPONSE_CANCEL: dialog.destroy() # openfilemenu def open_grid(self,path,id): found=False if len(self.opened_files)>0: for item in self.opened_files: id,fname=item if fname==path: found=True if not found: self.opened_files.append((self.core.id_counter,path)) file=open(path, 'rb') grid=pickle.load(file) file.close() self.label_manager.add_grid(Grid(self.core,grid.name,grid.rows,grid.cols,self.core.id_counter,grid.button_list,id)) self.label_manager.grid_list[len(self.label_manager.grid_list)-1].selection_manager.running=True self.label_manager.grid_list[len(self.label_manager.grid_list)-1].is_an_opened_file=True self.core.id_counter+=1 # self.label_manager.update_manager() else: print "File already opened" for item in self.opened_files: id,fname=item if fname==path: print fname print id self.label_manager.set_current_page(id) #print self.opened_files #def opengrid def OnBtnSaveClicked(self,data): #print("BtnSave::click") self.label_manager.grid_list[self.label_manager.get_current_page()].dump() def OnBtnSetupClicked(self,data): # print("BtnSetup::click") if self.label_manager.get_n_pages() > 0: self.label_manager.grid_list[self.label_manager.get_current_page()].selection_manager.running=False if self.label_manager.get_n_pages() > 0: self.conf_window=Config_Window(self.core.conf_manager,self.core.joy,self) else:self.conf_window=Config_Window(self.core.conf_manager,self.core.joy)