def __init__(self, editor, graph, selection, cursor): gtk.VBox.__init__(self) self.ctrl = editor # Close button image = gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU) button = gtk.Button() button.set_relief(gtk.RELIEF_NONE) button.set_focus_on_click(False) button.set_image(image) style = gtk.RcStyle() style.xthickness = 0 style.ythickness = 0 button.modify_style(style) button.connect("clicked", self.must_close) # Tab title self.title = gtk.Label() self.tab = gtk.HBox() self.tab.modify_style(style) self.tab.pack_start(self.title, True, True) self.tab.pack_end(button, False, False) self.tab.show_all() # Popup menu page title self.menu_title = gtk.Label() self.waveform = GraphView(graph, selection, cursor) self.scrollbar = GraphScrollbar(graph) self.statusbar = gtk.Statusbar() self.pack_start(self.waveform, expand=True, fill=True) self.pack_start(self.scrollbar, expand=False, fill=False) self.pack_end(self.statusbar, expand=False, fill=False) self.waveform.connect("selection-changed", self.on_selection_changed) self.ctrl.filename_changed.connect(self._update_filename) self.ctrl.error.connect(self.emit_error) self.connect("destroy", self.on_destroy) self._update_filename()
class EditorPage(gtk.VBox): __gsignals__ = {'filename-changed': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,)), 'must-close': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), 'error': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,gobject.TYPE_PYOBJECT))} def __init__(self, editor, graph, selection, cursor): gtk.VBox.__init__(self) self.ctrl = editor # Close button image = gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU) button = gtk.Button() button.set_relief(gtk.RELIEF_NONE) button.set_focus_on_click(False) button.set_image(image) style = gtk.RcStyle() style.xthickness = 0 style.ythickness = 0 button.modify_style(style) button.connect("clicked", self.must_close) # Tab title self.title = gtk.Label() self.tab = gtk.HBox() self.tab.modify_style(style) self.tab.pack_start(self.title, True, True) self.tab.pack_end(button, False, False) self.tab.show_all() # Popup menu page title self.menu_title = gtk.Label() self.waveform = GraphView(graph, selection, cursor) self.scrollbar = GraphScrollbar(graph) self.statusbar = gtk.Statusbar() self.pack_start(self.waveform, expand=True, fill=True) self.pack_start(self.scrollbar, expand=False, fill=False) self.pack_end(self.statusbar, expand=False, fill=False) self.waveform.connect("selection-changed", self.on_selection_changed) self.ctrl.filename_changed.connect(self._update_filename) self.ctrl.error.connect(self.emit_error) self.connect("destroy", self.on_destroy) self._update_filename() def must_close(self, *args): self.emit('must-close') def close(self, force=False): self.ctrl.close(force) def on_destroy(self, widget): # For some reason, the "tab" widget has to be destroyed # explicitely. Otherwise, it does not get garbage-collected. self.tab.destroy() def emit_error(self, title, text): self.emit('error', title, text) def _update_filename(self): filename = self.ctrl.filename() or None if filename: name = os.path.basename(filename) else: name = "Unsaved" self.title.set_text(name) self.menu_title.set_text(name) self.emit('filename-changed', filename) def __getattr__(self, name): if name in ["new", "save", "play", "toggle_play", "stop", "goto_start", "goto_end", "select_all", "cut", "copy", "paste", "mix", "undo", "redo", "zoom_in", "zoom_out", "zoom_fit", "select_till_start", "select_till_end", "effect", "open", "save_as", "save_selection_as", "filename", "on_selection_changed"]: method = getattr(self.ctrl, name) def forward(*args): return method(*args) return forward else: raise AttributeError(name)