import pygtk pygtk.require('2.0') import gtk import gtk.glade class Custom_Label(gtk.HBox): def __init__(self,name,parent_grid): super(Custom_Label, self).__init__(False,2) # initializing gtk.Label self.show() self.notebook=None self.parent_grid=parent_grid self.label=gtk.Label(name) self.label.show() self.pack_start(self.label,True,True,0) self.button=gtk.Button() self.button.show() image=gtk.Image() image.set_from_stock(gtk.STOCK_CLOSE,gtk.ICON_SIZE_MENU) self.button.set_image(image) self.pack_start(self.button,True,True,0) self.button.connect("clicked",self.close_tab) self.debug=False #def __init__ def close_tab(self,widget,data=None): closed_id=self.parent_grid.id to_update_list=[] to_update_opened=[] to_update_parents=[] counter=0 grid_to_erase=[] if self.debug: print "" # print "Closing Grid.ID[%s]"%self.parent_grid.id print "# Grid info:" print "# ID: %s"%self.parent_grid.id print "# Name: %s"%self.parent_grid.name print "# Rows: %s"%self.parent_grid.rows print "# Cols: %s"%self.parent_grid.cols print "# Opened File: %s"%self.parent_grid.is_an_opened_file print "# Child of Grid ID: %s"%self.parent_grid.parent_grid print "# Number of buttons: %s"%len(self.parent_grid.button_list) print "# Selection Manager is %s"%("disabled","enabled")[self.parent_grid.selection_manager.running] print "" print "## Grid List:" for item in self.parent_grid.core.winmain.label_manager.grid_list: if item.id < self.parent_grid.id: if self.debug: print "## grid.id[%s] is safe to be left alone"%item.id if item.id ==self.parent_grid.id: if self.debug: print "## grid.id[%s] - This is the one to erase"%item.id grid_to_erase.append(item.id) if self.debug: print "##### adding it to the TO_ERASE list... %s"%grid_to_erase if item.id > self.parent_grid.id: if self.debug: print "## grid.id[%s] needs to be updated"%item.id to_update_list.append(item.id) if self.debug: print "##### adding it to the TO_UPDATE list... %s"%to_update_list for item in self.parent_grid.core.winmain.label_manager.grid_list: for id_to_erase in grid_to_erase: if item.parent_grid==id_to_erase: print "Grid ID[%s] has Grid[%s] as its parent"%(item.id,id_to_erase) grid_to_erase.append(item.id) if self.debug: print "" print "### Deleting Grid from list:" print "### Delete list %s"%grid_to_erase print "### List before:" for item in self.parent_grid.core.winmain.label_manager.grid_list: print "#### grid.id[%s]"%item.id counter=0 tmp_list=[] found=False counter2=0 for item in self.parent_grid.core.winmain.label_manager.grid_list: item.selection_manager.running=False for id_to_erase in grid_to_erase: if item.id==id_to_erase: found=True if self.debug: print "#### Found grid.id[%s]"%item.id if counter2==0: tmp=item.id counter2+=1 else: tmp=item.id-1 self.parent_grid.core.winmain.label_manager.remove_page(tmp) self.parent_grid.core.id_counter-=1 if item.is_an_opened_file: tmp_list2=[] for file in self.parent_grid.core.winmain.opened_files: id,fname=file if item.id==id: print "Closing file %s..."%fname else: tmp_list2.append(file) self.parent_grid.core.winmain.opened_files=tmp_list2 if not found: tmp_list.append(item) found=False self.parent_grid.core.winmain.label_manager.grid_list=tmp_list if len(self.parent_grid.core.winmain.label_manager.grid_list)>0: self.parent_grid.core.winmain.label_manager.grid_list[self.parent_grid.core.winmain.label_manager.get_current_page()].selection_manager.running=True if self.debug: print "### List after:" for item in self.parent_grid.core.winmain.label_manager.grid_list: print "#### grid.id[%s]"%item.id print "" print "### Updating parent-child links" print "### To Update list: %s"%to_update_list print "### parent.ids:" for item in self.parent_grid.core.winmain.label_manager.grid_list: print "#### grid.parent[%s]"%item.parent_grid tmp_list=[] for item in self.parent_grid.core.winmain.label_manager.grid_list: for id_to_update in to_update_list: if id_to_update==item.parent_grid: item.parent_grid-=1 tmp_list.append(item) self.parent_grid.core.winmain.label_manager.grid_list=tmp_list if self.debug: print "### parent.ids after:" for item in self.parent_grid.core.winmain.label_manager.grid_list: print "#### grid.parent[%s]"%item.parent_grid if self.debug: print "" print "#### Updating IDs:" print "#### List of IDs to update:" for item in to_update_list: print "##### grid.id[%s]"%item print "### List before update:" for item in self.parent_grid.core.winmain.label_manager.grid_list: print "#### grid.id[%s]"%item.id tmp_list=[] for item in self.parent_grid.core.winmain.label_manager.grid_list: for id_to_update in to_update_list: if item.id==id_to_update: item.id-=1 tmp_list.append(item) self.parent_grid.core.winmain.label_manager.grid_list=tmp_list if self.debug: print "### List after update:" for item in self.parent_grid.core.winmain.label_manager.grid_list: print "#### grid.id[%s]"%item.id #def close_tab def destroy(self,widget,data=None): gtk.main_quit() #class Custom_Label