def __init__(self, ctx): super(Session, self).__init__(False, 2) if self.session_orientation == gtk.ORIENTATION_HORIZONTAL: self.paneds = [HMultiPaned()] else: self.paneds = [VMultiPaned()] self.paned_nb = gtk.Notebook() self.paned_nb.set_show_tabs(False) self.paned_nb.set_show_border(False) self.paned_nb.append_page(self.paneds[0], gtk.Label('Main')) self.pages = ['Main'] self.perspectives = [] self.container_cbs = [] self.editor_cbs = [] self.packet = None self.context = ctx self.context.title_callback = self.__on_change_title self._label = ClosableLabel(ctx.title) self._label.connect('context-menu', self.__on_popup) self.set_border_width(4) self.create_ui() # Now apply the bindings for this Session PMApp().main_window.apply_bindings(self, self.session_id)
class Session(gtk.VBox): session_id = 0 # Setted automatically session_name = "" # Shoud be setted session_menu = None # Set it if you want a menu item added in main window session_menu_object = None session_orientation = [gtk.ORIENTATION_VERTICAL] def __init__(self, ctx): super(Session, self).__init__(False, 2) if self.session_orientation == gtk.ORIENTATION_HORIZONTAL: self.paneds = [HMultiPaned()] else: self.paneds = [VMultiPaned()] self.paned_nb = gtk.Notebook() self.paned_nb.set_show_tabs(False) self.paned_nb.set_show_border(False) self.paned_nb.append_page(self.paneds[0], gtk.Label('Main')) self.pages = ['Main'] self.perspectives = [] self.container_cbs = [] self.editor_cbs = [] self.packet = None self.context = ctx self.context.title_callback = self.__on_change_title self._label = ClosableLabel(ctx.title) self._label.connect('context-menu', self.__on_popup) self.set_border_width(4) self.create_ui() # Now apply the bindings for this Session PMApp().main_window.apply_bindings(self, self.session_id) def create_ui(self): self.paned_nb.set_current_page(0) self.pack_start(self.paned_nb) self.show_all() def remove_perspective(self, klass): """ Remove the perspective from the current session @param klass the perspective klass to remove @return True if everything is ok """ for paned in self.paneds: for persp in self.perspectives: if isinstance(persp, klass): widget = persp while not isinstance(widget.get_parent(), gtk.Paned): widget = widget.get_parent() widget.hide() self.perspectives.remove(persp) paned.remove_child(widget) def add_perspective(self, klass, show_pers=True, resize=False, page=0): """ Add the perspective to the current session @param klass a Perspective base class of the perspective to add @param show_pers choose to show the perspective @param resize if True child should resize when the paned is resized @param page page index where the perspective will be inserted @return the perspective instance """ pers = klass(self) self.perspectives.append(pers) if Prefs()['gui.expander.standard'].value: widget = gtk.Expander(pers.title) widget.add(pers) widget.set_expanded(True) else: widget = AnimatedExpander(pers.title, pers.icon, self.session_orientation[page]) widget.add_widget(pers, show_pers) self.paneds[page].add_child(widget, resize) widget.show() return pers def append_page(self, page_name, orientation=gtk.ORIENTATION_VERTICAL): self.session_orientation.append(orientation) page_id = len(self.session_orientation) - 1 child = orientation is gtk.ORIENTATION_HORIZONTAL and \ HMultiPaned() or VMultiPaned() self.pages.append(page_name) self.paneds.append(child) child.show() self.paned_nb.append_page(child, gtk.Label(page_name)) self._label.set_menu_active(True) def get_current_page(self): return self.paned_nb.get_current_page() def get_current_page_name(self): return self.pages[self.paned_nb.get_current_page()].upper() def reload(self): self.reload_containers() self.reload_editors() def save(self): "@return True if the content is saved or False" return self._on_save(None) def save_as(self): return self._on_save_as(None) def save_session(self, fname, async=True): """ Override this method to do the real save phase @param fname the filename on witch save the context will be saved @param async specify if you want to have an async saving in a separate thread (new FileOperation) without freezing the gui. @return True if the content is saved or False (if async is False) """ if not self.context.file_types: log.debug("Saving is disabled (%s)" % self.context) return False self.context.cap_file = fname if not async: return self.context.save() else: tab = PMApp().main_window.get_tab("OperationsTab") tab.tree.append_operation(FileOperation(self, FileOperation.TYPE_SAVE))