def construct_preview(self, filename): if filename is None: return gtk.Label() view = gtk.TextView() buffer = view.get_buffer() view.set_editable(False) view.show() tag_main = buffer.create_tag(family="Courier") tag_linenr = buffer.create_tag(family="Courier", weight=pango.WEIGHT_HEAVY) # fill preview buffer with at most 100 lines try: fd = open(filename, 'r') except IOError: raise RuntimeError("Could not open file %s for preview!" % filename) iter = buffer.get_start_iter() try: for j in range(1,100): line = fd.readline() if len(line) == 0: break buffer.insert_with_tags(iter, u"%3d\t" % j, tag_linenr) try: buffer.insert_with_tags(iter, unicode(line), tag_main) except UnicodeDecodeError: buffer.insert_with_tags(iter, u"<unreadable line>\n", tag_main) finally: fd.close() return uihelper.new_section("Preview", uihelper.add_scrollbars(view))
def __init__(self, owner, title="Edit Options", parent=None): """ owner: instance of HasProps that owns the properties parent: parent window @note: 'parent' is currently ignored, since it produces a silly window placement! """ gtk.Dialog.__init__(self, title, None, gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)) self.owner = owner try: keys = owner.public_props except AttributeError: keys = owner._checks.keys() if len(keys) == 0: raise NoOptionsError self.factory = checkwidgets.DisplayFactory(owner) self.factory.add_keys(keys) table = self.factory.create_table() frame = uihelper.new_section(title, table) self.vbox.pack_start(frame, False, True) self.show_all()
def __init__(self, template_key, previewfile=None, gladefile=None): gtk.Dialog.__init__(self, "Importing %s" % template_key, None, gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)) self.set_size_request(520,480) # create a new importer based on the template self.template = globals.import_templates[template_key] self.importer = self.template.new_instance() # # set up widget factory # self.factory = widget_factory.CWidgetFactory(self.importer) self.factory.add_keys(self.importer.public_props) table_options = self.factory.create_table() widget = uihelper.new_section("Import Options", table_options) self.vbox.pack_start(widget,False,True) self.factory.check_in() # # add preview widget # preview = self.construct_preview(previewfile) self.vbox.pack_start(preview,True,True) hint = gtk.Label() hint.set_markup("<i>Hint: These importer settings can later on be retrieved\nas 'recently used' template in the Edit|Preferences dialog.</i>") hint.set_use_markup(True) self.vbox.pack_start(hint,False,True) self.vbox.show_all()
def __init__(self, legend): AbstractTab.__init__(self) keys = ['label', 'position', 'visible', 'border', 'x', 'y'] self.factory = widget_factory.CWidgetFactory(legend) self.factory.add_keys(keys) table = self.factory.create_table() frame = uihelper.new_section("Legend", table) self.add(frame) self.show_all()
def __init__(self, layer): AbstractTab.__init__(self) keys = ['title', 'visible', 'grid'] self.factory = widget_factory.CWidgetFactory(layer) self.factory.add_keys(keys) table = self.factory.create_table() frame = uihelper.new_section("Layer", table) self.add(frame) self.layer = layer self.show_all()
def __init__(self): gtk.VBox.__init__(self) vbox = gtk.VBox() vbox.set_spacing(uihelper.SECTION_SPACING) vbox.set_border_width(uihelper.SECTION_SPACING) # # Create informational label # note = "Custom plugins are not yet supported. " label = gtk.Label(note) # # Create TreeView with the Plugin Information # # model: plugin object model = gtk.ListStore(object) for plugin in globals.app.plugins.itervalues(): model.append( (plugin,) ) treeview = gtk.TreeView(model) treeview.set_headers_visible(False) cell = gtk.CellRendererText() column = gtk.TreeViewColumn() column.pack_start(cell) def render(column, cell, model, iter): object = model.get_value(iter, 0) name = "<big><b>%s</b></big>" % object.name if object.blurb is not None: blurb = "<i>%s</i>" % object.blurb else: blurb = "<i>no description</i>" text = "%s\n%s" % (name, blurb) cell.set_property('markup', text) column.set_cell_data_func(cell, render) treeview.append_column(column) vbox.pack_start(label, False, True) vbox.pack_start(treeview, True, True) frame = uihelper.new_section("Available Plugins", vbox) self.add(frame)
def create_sections(self, *layout): if not isinstance(layout, (list,tuple)): raise RuntimeError("Must be a list or tuple.") vbox = gtk.VBox() for section in layout: name, keys = section[0], section[1:] self._create_displays(keys) w = uihelper.new_section(name, self._create_table_from_keys(keys)) vbox.pack_start(w, False, True) return vbox
def __init__(self, axesdict): AbstractTab.__init__(self) keys = ['label', 'start', 'end', 'scale', 'format'] self.factorylist = [] for key, axis in axesdict.iteritems(): factory = widget_factory.CWidgetFactory(axis) factory.add_keys(keys) table = factory.create_table() frame = uihelper.new_section(key, table) self.pack_start(frame, False, True) self.factorylist.append(factory) self.show_all()
def __init__(self, col_info, col_name, used_names): gtk.Dialog.__init__(self, "Edit Column",None, gtk.DIALOG_MODAL, (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)) # TODO: It would be nicer to have all entries arranged in # TODO: one table. A nice implementation would be similar # TODO: to the one in CRendererFactory, defining dummy # TODO: pseudo keys in the factory and then filling this # TODO: entry on our own. self.col_info = col_info self.col_name = col_name self.used_names = used_names self.new_name = None # result name_label = gtk.Label("Name:") name_entry = gtk.Entry() name_entry.set_text(unicode(col_name)) name_entry.set_activates_default(True) name_box = gtk.HBox() name_box.pack_start(name_label,False,True) name_box.pack_start(name_entry,True,True) hint = gtk.Label() factory = widget_factory.CWidgetFactory(col_info) factory.add_keys('label', 'designation') table = factory.create_table() factory.check_in() vbox = gtk.VBox() vbox.pack_start(name_box, True, True) vbox.pack_start(hint, False, True) # self.vbox.pack_start(gtk.HSeparator(), False, True) vbox.pack_start(table, True, True) frame = uihelper.new_section('Edit Column Information', vbox) self.vbox.add(frame) self.vbox.show_all() self.name_entry = name_entry self.factory = factory self.hint = hint
def __init__(self): gtk.VBox.__init__(self) vbox = gtk.VBox() vbox.set_spacing(uihelper.SECTION_SPACING) vbox.set_border_width(uihelper.SECTION_SPACING) label = gtk.Label("SloppyPlot - %s" % version.DESCRIPTION ) label.set_alignment(0.0,0.0) vbox.pack_start(label,False,True) label = gtk.Label("Version: %s" % version.VERSION ) label.set_alignment(0.0,0.0) vbox.pack_start(label,False,True) description = gtk.TextView() description.set_property('editable', False) description.set_property('cursor-visible', False) description.get_buffer().set_text(version.LONG_DESCRIPTION) vbox.pack_start(description,False,True) frame = uihelper.new_section("About SloppyPlot", vbox) self.add(frame)
def __init__(self, layer): AbstractTab.__init__(self) self.layer = layer # # Construct TreeView and ButtonBox # keys = ['visible', 'label', 'style', 'width', 'color', 'marker', 'marker_color', 'marker_size', 'source', 'cx', 'cy', 'row_first', 'row_last'] self.factory = widget_factory.CTreeViewFactory(layer, 'lines') self.factory.add_columns(keys, source=self.create_source_column) self.treeview = self.factory.create_treeview() sw = uihelper.add_scrollbars(self.treeview) # # keybox = label + key_combo # model = gtk.ListStore(str, object) key_combo = gtk.ComboBox(model) cell = gtk.CellRendererText() key_combo.pack_start(cell, True) key_combo.add_attribute(cell, 'text', 0) key_combo.connect('changed', lambda cb: self.limit_columns()) self.key_combo = key_combo # for use in limit_columns() viewdict = {'all' : ['_all'], 'style' : ['visible', 'label', 'style', 'width', 'color', 'marker', 'marker_color', 'marker_size'], 'data' : ['visible', 'label', 'source', 'cx', 'cy', 'row_first', 'row_last']} for key, alist in viewdict.iteritems(): model.append((key, alist)) keybox = gtk.HBox(False, 5) keybox.pack_start(gtk.Label("Display:"), False, False) keybox.pack_start(key_combo, False, False) keybox.pack_start(gtk.Label(), True, True) self.key_combo.set_active(0) self.limit_columns() buttons = [(gtk.STOCK_ADD, self.on_insert_new), (gtk.STOCK_REMOVE, self.on_remove_selection), (gtk.STOCK_GO_UP, self.on_move_selection, -1), (gtk.STOCK_GO_DOWN, self.on_move_selection, +1)] buttonbox = uihelper.construct_vbuttonbox(buttons, labels=False) hbox = gtk.HBox(False, 5) hbox.pack_start(sw, True, True) hbox.pack_start(buttonbox, False, True) vbox = gtk.VBox(False, 5) vbox.pack_start(keybox, False, False) vbox.pack_start(hbox) frame1 = uihelper.new_section('Lines', vbox) # # Construct Group Boxes # #self.gblist = [GroupBox(self.layer, 'group_linestyle'), # GroupBox(self.layer, 'group_linemarker'), # GroupBox(self.layer, 'group_linewidth'), # GroupBox(self.layer, 'group_linecolor')] self.gblist = [] # DISABLE GROUP BOXES RIGHT NOW! self.gblist = [] # # Wrap group boxes into a table # table = gtk.Table(rows=len(self.gblist), columns=3) # n = 0 # for widget in self.gblist: # # label (put into an event box to display the tooltip) # label = gtk.Label(widget.prop.blurb or widget.propname) # ebox = gtk.EventBox() # ebox.add(label) # if widget.prop.doc is not None: # tooltips.set_tip(ebox, widget.prop.doc) # table.attach(ebox, 0, 1, n, n+1, # xoptions=gtk.FILL, yoptions=0, # xpadding=5, ypadding=1) # table.attach(widget, 1, 2, n, n+1, # xoptions=gtk.EXPAND|gtk.FILL, yoptions=0, # xpadding=5, ypadding=1) # n += 1 # frame2 = uihelper.new_section('Group Properties', table) # # Put everything together! # self.pack_start(frame1,True,True) # DISABLE GROUP BOXES RIGHT NOW #self.pack_start(frame2,False,True) self.show_all()
def __init__(self): gtk.VBox.__init__(self) # We create copies of all templates and put these into the # treeview. This allows the user to reject the modifications # (RESPONSE_REJECT). If however he wishes to use the # modifications (RESPONSE_ACCEPT), then we simply need to # replace the current templates with these temporary ones. # check in self.model = gtk.ListStore(str, object) # key, object model = self.model # TBR # # create gui # # columns should be created in the order given by COLUMN_xxx # definitions above. tv = gtk.TreeView(model) tv.set_headers_visible(False) cell = gtk.CellRendererText() column = gtk.TreeViewColumn() column.pack_start(cell) def render(column, cell, model, iter): object = model.get_value(iter, self.MODEL_OBJECT) key = model.get_value(iter, self.MODEL_KEY) key = "<big><b>%s</b></big>" % key if object.blurb is not None: blurb = "<i>%s</i>" % object.blurb else: blurb = "<i>no description</i>" if object.immutable is True: blurb += " <i>(immutable)</i>" text = "%s\n%s" % (key, blurb) cell.set_property('markup', text) column.set_cell_data_func(cell, render) tv.append_column(column) self.treeview = tv sw = uihelper.add_scrollbars(tv) tv.connect("row-activated", (lambda a,b,c: self.on_edit_item(a,c))) buttons=[(gtk.STOCK_EDIT, self.on_edit_item), (gtk.STOCK_ADD, self.on_add_item), (gtk.STOCK_COPY, self.on_copy_item), (gtk.STOCK_DELETE, self.on_delete_item)] btnbox = uihelper.construct_vbuttonbox(buttons) btnbox.set_spacing(uihelper.SECTION_SPACING) btnbox.set_border_width(uihelper.SECTION_SPACING) sw.set_border_width(uihelper.SECTION_SPACING) hbox = gtk.HBox() hbox.pack_start(sw,True,True) hbox.pack_start(btnbox,False,True) frame = uihelper.new_section("Import Templates", hbox) self.add(frame) self.show_all()
def __init__(self): toolbox.Tool.__init__(self) self.settings = settings = Settings() self.depends_on(globals.app, 'active_backend') # # find button # self.btn_find = btn_find = gtk.Button('Find') btn_find.connect('clicked', self.on_btn_find_clicked) # # Settings # df = checkwidgets.DisplayFactory(Settings) ##self.display_line = DisplayLine() ##df.add_keys(self.settings._checks.keys(), line=self.display_line) df.add_keys(self.settings._checks.keys()) self.table = table = df.create_sections(['Settings', 'line','threshold','accuracy']) df.connect(self.settings) # # Treeview (displaying the found peaks) # # model: (float, float, str) = (x,y, symobl) model = gtk.ListStore(float, float, str) self.treeview = treeview = gtk.TreeView(model) treeview.set_headers_visible(False) cell = gtk.CellRendererText() column = gtk.TreeViewColumn('X', cell) column.set_attributes(cell, text=0) cell = gtk.CellRendererText() treeview.append_column(column) cell = gtk.CellRendererText() column = gtk.TreeViewColumn('Y', cell) column.set_attributes(cell, text=1) cell = gtk.CellRendererText() treeview.append_column(column) cell = gtk.CellRendererText() column = gtk.TreeViewColumn('Symbol', cell) column.set_attributes(cell, text=2) cell = gtk.CellRendererText() treeview.append_column(column) #treeview.connect("row-activated", self.on_row_activated) #treeview.connect("cursor-changed", self.on_cursor_changed) # results is the section containing the treeview results = uihelper.new_section('Results:', uihelper.add_scrollbars(treeview)) # # pack everything in a vbox # vbox = gtk.VBox() vbox.pack_start(results, True, True) vbox.pack_start(table, False, False) vbox.pack_start(btn_find, False, True) vbox.show_all() self.add(vbox)