def __init__(self): toolbox.Tool.__init__(self) # create gui (a treeview in a scrolled window with a # buttonbox underneath) treeview = ProjectTreeView() scrollwindow = uihelper.add_scrollbars(treeview) buttons = [(gtk.STOCK_ADD, lambda sender: None), (gtk.STOCK_REMOVE, lambda sender: None)] buttonbox = uihelper.construct_hbuttonbox(buttons, labels=False) self.pack_start(scrollwindow, True, True) #self.pack_start(buttonbox, False, True) self.show_all() self.buttonbox = buttonbox self.treeview = treeview self.scrollwindow = scrollwindow # connect to callbacks treeview.connect( "row-activated", self.on_row_activated ) treeview.connect( "button-press-event", self.on_button_press_event ) treeview.connect( "popup-menu", self.on_popup_menu, 3, 0 ) # create actions for ui manager uimanager = globals.app.window.uimanager uihelper.add_actions(uimanager, "ProjectView", self.actions, self) uimanager.add_ui_from_string(globals.app.get_uistring('project_explorer'))
def __init__(self): toolbox.Tool.__init__(self) self.depends_on(globals.app, 'active_backend') self.popup_info = None # # Treeview # # model (object) model = gtk.TreeStore(object, str) self.treeview = treeview = gtk.TreeView(model) treeview.set_headers_visible(False) treeview.get_selection().set_mode(gtk.SELECTION_MULTIPLE) column = gtk.TreeViewColumn('label') cell = gtk.CellRendererPixbuf() column.pack_start(cell,expand=False) def render_icon(column, cell, model, iter): obj = model.get_value(iter, 0) key = model.get_value(iter, 1) if key is not None: stock_id = 'sloppy-%s'%key.lower() else: stock_id = 'sloppy-%s'%obj.__class__.__name__.lower() cell.set_property('stock_id', stock_id) column.set_cell_data_func(cell, render_icon) treeview.append_column(column) cell = gtk.CellRendererText() column.pack_start(cell) def render_label(column, cell, model, iter): obj = model.get_value(iter, 0) key = model.get_value(iter, 1) if key is None: for attr in ['label', 'title', 'key']: if hasattr(obj, attr): key = getattr(obj, attr) label = key cell.set_property('text', label) label = None if key is not None: label = key else: try: label = obj.get_description() except: for attr in ['label', 'title', 'key']: if hasattr(obj, attr): label = getattr(obj, attr) break else: label = "<%s>" % obj.__class__.__name__ cell.set_property('text', label) column.set_cell_data_func(cell, render_label) treeview.append_column(column) treeview.connect("button-press-event", self.on_button_press_event) treeview.connect("cursor-changed", self.on_cursor_changed) treeview.connect("popup-menu", self.on_popup_menu, 3, 0) treeview.show() # The edit_cache is a dict where the keys are the classes # of the objects that can be edited and the values are # tuples (widget, factory), which are the edit widget for this # class and the corresponding DisplayFactory object to make # the connection to actual objects. The factory may be None. self.edit_cache = {} # The currently edited object. Use edit_cache[self.obj.__class__] # to get the currently active widget and its factory self.obj = None # # Both the treeview and the table are stuffed into # a vbox; but there is no no table to begin with. # It is created in the on_cursor_changed event. # self.paned = gtk.VPaned() self.paned.pack1(uihelper.add_scrollbars(treeview),True,True) self.add(self.paned) #self.vbox = vbox = gtk.VBox() #vbox.add(uihelper.add_scrollbars(treeview)) #self.add(vbox) # Connect to Backend. self.backend = -1 #self.dock.connect('backend', ...) sender = globals.app sender.sig_connect('update::active_backend', self.on_update_backend) self.on_update_backend(sender, 'backend', sender.active_backend) # ui manager uimanager = globals.app.window.uimanager uihelper.add_actions(uimanager, "PropertyEditor", self.actions, self) uimanager.add_ui_from_string(globals.app.get_uistring('property_editor'))
def _construct_uimanager(self): uim = gtk.UIManager() uihelper.add_actions(uim, "Application", self.actions_application, globals.app) uihelper.add_actions(uim, "AppWin", self.actions_appwin, self) uihelper.add_actions(uim, "Matplotlib", self.actions_matplotlib, globals.app) uihelper.add_actions(uim, "Gnuplot", self.actions_gnuplot, globals.app) uihelper.add_actions(uim, "Debug", self.actions_debug, globals.app) uihelper.add_actions(uim, "UndoRedo", self.actions_undoredo, globals.app) uihelper.add_actions(uim, "RecentFiles", self.actions_recentfiles, globals.app) return uim
def _construct_uimanager(self): uimanager = gtk.UIManager() uihelper.add_actions(uimanager, 'root', self.actions, map=self) uimanager.add_ui_from_string(self.ui) self.add_accel_group(uimanager.get_accel_group()) return uimanager
def __init__(self): HasSignals.__init__(self) gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL) self.set_icon(self.render_icon('sloppy-Plot', gtk.ICON_SIZE_BUTTON)) self.connect("delete-event", (lambda sender, event: globals.app.quit())) self.is_fullscreen = False self._windows = list() # keeps track of all subwindows self._windowlist_merge_id = None self._recentfiles_merge_id = None # # Create GUI # # The action for the uimanager are created first. However, # since some actions are not yet defined (e.g. those defined # by 'set_up_visibility_toggle', this will be done after the # rest of the GUI initialization. # -- UIManager -- self.uimanager = uim = gtk.UIManager() uihelper.add_actions(uim, "Application", self.actions_application, globals.app) uihelper.add_actions(uim, "AppWin", self.actions_appwin, self) uihelper.add_actions(uim, "Matplotlib", self.actions_matplotlib, globals.app) uihelper.add_actions(uim, "Gnuplot", self.actions_gnuplot, globals.app) uihelper.add_actions(uim, "Debug", self.actions_debug, globals.app) uihelper.add_actions(uim, "UndoRedo", self.actions_undoredo, globals.app) uihelper.add_actions(uim, "RecentFiles", self.actions_recentfiles, globals.app) # -- Sidepane -- self.sidepane = toolbox.ToolBox('Sidepane') self.set_up_visibility_toggle(self.sidepane, 'ToggleSidepane', 'Show Sidepane', 'F9') self.sidepane.show() # -- Logwindow -- # logwindow is hidden by default. See _construct_uimanager if # you want to change this default self.logwindow = logwindow = logwin.LogWindow() logwindow.set_transient_for(self) logwindow.set_destroy_with_parent(True) self.set_up_visibility_toggle(self.logwindow, 'ToggleLogwindow', 'Show Logwindow') logwindow.hide() # create ui and accelerators # TODO: set_up_visibility_toggle should maybe also add the ui string # This way, all actions are already defined and we can put this # add_ui_from string above. self.uimanager.add_ui_from_string(globals.app.get_uistring('appwindow')) self.add_accel_group(self.uimanager.get_accel_group()) # -- Menubar -- self.menubar = menubar = self.uimanager.get_widget('/MainMenu') menubar.show() # -- Toolbar -- self.toolbar = toolbar = self.uimanager.get_widget('/MainToolbar') toolbar.set_style(gtk.TOOLBAR_ICONS) toolbar.show() self.init_user_actions() # -- Statusbar and Progressbar -- self.statusbar = statusbar = gtk.Statusbar() statusbar.set_has_resize_grip(True) statusbar.show() self.progressbar = progressbar = gtk.ProgressBar() progressbar.hide() # -- Notification Area -- notification_area = gtk.HBox() notification_area.pack_start(self.btn_cancel,False,True) notification_area.pack_start(self.statusbar,True,True) notification_area.pack_start(self.progressbar,False,True) notification_area.show() # -- Plotbook -- self.plotbook = gtk.Notebook() self.plotbook.show() def callback(notebook, page, page_num): # Activate the current page either if it is the first page # or if it is a newly selected one. The old page gets # of course deactivated. print "SWITCH" current_page = notebook.get_nth_page(notebook.get_current_page()) new_page = notebook.get_nth_page(page_num) if notebook.get_n_pages() == 1 or current_page is not new_page: print "A CHANGE" current_page.deactivate() new_page.activate() notebook.set_tab_label_text(new_page, new_page.get_title()) if isinstance(new_page, mpl.MatplotlibWidget): print "NEW BACKEND IS ", new_page.backend globals.app.project.active_backend = new_page.backend self.plotbook.connect('switch-page', callback) plot_area = gtk.VBox() plot_area.pack_start(self.plotbook, True, True) ##plot_area.pack_start(self.progressbar, False, False) ##plot_area.pack_end(self.statusbar,False, True) plot_area.show() self.hpaned = hpaned = gtk.HPaned() hpaned.pack1(plot_area, True, True) hpaned.pack2(self.sidepane, False, True) hpaned.show() vbox = gtk.VBox() vbox.pack_start(self.menubar, expand=False) vbox.pack_start(self.toolbar, expand=False) vbox.pack_start(hpaned, True, True) vbox.pack_start(notification_area, False, False) ##vbox.pack_end(self.statusbar, False, True) vbox.show() self.add(vbox) #--- globals.app.sig_connect("update-recent-files", lambda sender: self._refresh_recentfiles()) # # Restore window size and position. The size is taken # either from config file or set to default. # self.set_gravity(gtk.gdk.GRAVITY_NORTH_WEST) self.move(0,0) eWindow = globals.app.eConfig.find('AppWindow') if eWindow is not None: width = int(eWindow.attrib.get('width', 480)) height = int(eWindow.attrib.get('height',320)) position = eWindow.attrib.get('sidepane', width-120) self.hpaned.set_position(int(position)) else: width, height = 640,480 self.set_size_request(480,320) self.resize(width, height) # register for config file globals.app.sig_connect("write-config", self.write_config) self.show()