def make_widget(self): t = Container.make_widget(self) self.tabs = UITabs(t, self) self.tabs.pack(side='top', fill='x') self.main = Frame(t) self.main.pack(side='top', fill='both') return t
def __init__(self, top=None, tab=None, flist=None): self.flist = flist TOPLEVEL = self.TOPLEVEL = top self.CLOSE_FRAME = None self.active_frame = tab TOPLEVEL.protocol("WM_DELETE_WINDOW", self.closetoplevel) self.tabframes = {} # map tabid -> tabframe self.nexttabid = 1 tab_bar = self.tab_bar = UITabs(self.TOPLEVEL, self) tabmanagerlist.add(self)
class TabbedContainer(Container, UITabsObserver): def __init__(self, flist): Container.__init__(self, flist) self.containers = {} # map tab to container self.active = None self.w.bind('<Activate>', lambda e: self._activate()) self.w.bind('<FocusIn>', lambda e: self._activate()) def add_component(self, component): id = self.tabs.add(title='Shell***') self.containers[id] = component.top def make_widget(self): t = Container.make_widget(self) self.tabs = UITabs(t, self) self.tabs.pack(side='top', fill='x') self.main = Frame(t) self.main.pack(side='top', fill='both') return t def move_to_front(self, component): Container.move_to_front(self, component) tabid = self.get_tabid(component.top) self.tabs.select(tabid) def handle_addtab(self, tabs): self.flist.new() def remove(self, container): tabid = self.get_tabid(container) if tabid is not None: if container == self.active: self.tab_deselected(self.tabs, tabid) self.active = None self.component = None del(self.containers[tabid]) self.tabs.remove(tabid) if len(self.containers) == 0: self._close() def _activate(self): # Called when we get moved to the front self.flist.tab_container = self def _close(self): "Close button on window - try to close all tabs" # loop through all dirty containers, if nobody aborts, we're good # to close the whole window for t, c in self.containers.items(): if c.component is not None and not c.component.get_saved(): # NOTE: while maybesave() does move the tab to the front, # because of deferred drawing plus the 'after_idle' in # our tab_selected routine, the changes don't appear # onscreen immediately. # # This is normally not a problem, but because this may # be immediately followed by a modal dialog call which # blocks the update events, we ensure everything is # onscreen before calling maybesave() self.move_to_front(c.component) self.w.update() self.w.update_idletasks() if c.component.maybesave() == 'cancel': return # user aborted the close for t, c in self.containers.items(): if c.component is not None: c.component.close(without_save=True) # already asked self.w.destroy() self.w = None self.component = None if self.flist: self.flist.delete_container(self) def handle_closetab(self, tabs, tabid): self.containers[tabid]._close() def tab_deselected(self, tabs, tabid): if len(self.containers) == 0: return self.w.pack_propagate(False) self.containers[tabid].w.pack_forget() self.w['menu'] = None def setup_statusbar(self): if self.statusbar is None: self.create_statusbar() def get_tabid(self, container): for t in self.containers: if self.containers[t] == container: return t return None def container_title_changed(self, container): tabid = self.get_tabid(container) if tabid is not None: self.tabs.set_title(tabid, container.short_title) if container.title is not None: self.tabs.set_tooltip(tabid, container.title) self.tabs.set_dirty(tabid, not container.saved) if container == self.active: self.w.wm_title(container.title if container.title else container.short_title) self.w.wm_iconname(container.short_title) self.flist.filenames_changed() # to update window list def tab_selected(self, tabs, tabid): self.w.after_idle(lambda: self._tab_selected(tabid)) def _tab_selected(self, tabid): if self.active != self.containers[tabid]: self.active = self.containers[tabid] self.component = self.active.component self.active.w.pack(side='top', fill='both') self.w['menu'] = self.active.menubar self.statusbar.observe(self.active.component) self.container_title_changed(self.active) self.w.pack_propagate(True)
class TabbedContainer(Container, UITabsObserver): def __init__(self, flist): Container.__init__(self, flist) self.containers = {} # map tab to container self.active = None self.w.bind('<Activate>', lambda e: self._activate()) self.w.bind('<FocusIn>', lambda e: self._activate()) def add_component(self, component): id = self.tabs.add(title='Shell***') self.containers[id] = component.top def make_widget(self): t = Container.make_widget(self) self.tabs = UITabs(t, self) self.tabs.pack(side='top', fill='x') self.main = Frame(t) self.main.pack(side='top', fill='both') return t def move_to_front(self, component): Container.move_to_front(self, component) tabid = self.get_tabid(component.top) self.tabs.select(tabid) def handle_addtab(self, tabs): self.flist.new() def remove(self, container): tabid = self.get_tabid(container) if tabid is not None: if container == self.active: self.tab_deselected(self.tabs, tabid) self.active = None self.component = None del (self.containers[tabid]) self.tabs.remove(tabid) if len(self.containers) == 0: self._close() def _activate(self): # Called when we get moved to the front self.flist.tab_container = self def _close(self): "Close button on window - try to close all tabs" # loop through all dirty containers, if nobody aborts, we're good # to close the whole window for t, c in self.containers.items(): if c.component is not None and not c.component.get_saved(): # NOTE: while maybesave() does move the tab to the front, # because of deferred drawing plus the 'after_idle' in # our tab_selected routine, the changes don't appear # onscreen immediately. # # This is normally not a problem, but because this may # be immediately followed by a modal dialog call which # blocks the update events, we ensure everything is # onscreen before calling maybesave() self.move_to_front(c.component) self.w.update() self.w.update_idletasks() if c.component.maybesave() == 'cancel': return # user aborted the close for t, c in self.containers.items(): if c.component is not None: c.component.close(without_save=True) # already asked self.w.destroy() self.w = None self.component = None if self.flist: self.flist.delete_container(self) def handle_closetab(self, tabs, tabid): self.containers[tabid]._close() def tab_deselected(self, tabs, tabid): if len(self.containers) == 0: return self.w.pack_propagate(False) self.containers[tabid].w.pack_forget() self.w['menu'] = None def setup_statusbar(self): if self.statusbar is None: self.create_statusbar() def get_tabid(self, container): for t in self.containers: if self.containers[t] == container: return t return None def container_title_changed(self, container): tabid = self.get_tabid(container) if tabid is not None: self.tabs.set_title(tabid, container.short_title) if container.title is not None: self.tabs.set_tooltip(tabid, container.title) self.tabs.set_dirty(tabid, not container.saved) if container == self.active: self.w.wm_title( container.title if container.title else container.short_title) self.w.wm_iconname(container.short_title) self.flist.filenames_changed() # to update window list def tab_selected(self, tabs, tabid): self.w.after_idle(lambda: self._tab_selected(tabid)) def _tab_selected(self, tabid): if self.active != self.containers[tabid]: self.active = self.containers[tabid] self.component = self.active.component self.active.w.pack(side='top', fill='both') self.w['menu'] = self.active.menubar self.statusbar.observe(self.active.component) self.container_title_changed(self.active) self.w.pack_propagate(True)