def __init__(self): Tool.__init__(self, "Labels", gtk.STOCK_EDIT) self.set_size_request(-1, 200) # # treeview # model = gtk.ListStore(object) treeview = gtk.TreeView(model) treeview.set_headers_visible(False) cell = gtk.CellRendererText() column = gtk.TreeViewColumn("label", cell) def render_label(column, cell, model, iter): label = model.get_value(iter, 0) text = "'%s': (%s,%s) %s" % (label.text, label.x, label.y, label.halign) cell.set_property("text", text) column.set_cell_data_func(cell, render_label) treeview.append_column(column) treeview.connect("row-activated", (lambda a, b, c: self.on_edit(a))) treeview.show() # # buttons # buttons = [ (None, gtk.STOCK_EDIT, self.on_edit), (None, gtk.STOCK_REMOVE, self.on_remove), (None, gtk.STOCK_NEW, self.on_new), ] btnbox = uihelper.construct_buttonbox(buttons, show_stock_labels=False) btnbox.show() # put everything together self.pack_start(treeview, True, True) self.pack_end(btnbox, False, True) # save variables for reference and update view self.treeview = treeview
def __init__(self, table, parent=None): self.table = table gtk.Dialog.__init__(self, "Modify Table", parent, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)) self.set_size_request(480,300) # # button box # buttons = [(gtk.STOCK_EDIT, self.on_row_activated), (gtk.STOCK_NEW, self.on_btn_add_clicked), (gtk.STOCK_REMOVE, self.on_btn_remove_clicked), (gtk.STOCK_GO_UP, self.on_btn_move_clicked, -1), (gtk.STOCK_GO_DOWN, self.on_btn_move_clicked, +1) ] btnbox = uihelper.construct_buttonbox( buttons, horizontal=False, layout=gtk.BUTTONBOX_START) btnbox.set_spacing(uihelper.SECTION_SPACING) btnbox.set_border_width(uihelper.SECTION_SPACING) # cview = column view cview = TableColumnView(table) cview.connect( "row-activated", self.on_row_activated ) self.cview = cview # put cview and btnbox next to each other into a hbox hbox = gtk.HBox() hbox.set_spacing(5) hbox.pack_start(cview, True, True) hbox.pack_start(btnbox, False, True) self.vbox.add(hbox) self.show_all()
def __init__(self): ConfigurationPage.__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(True) cell = gtk.CellRendererText() column = gtk.TreeViewColumn("Key", cell) column.set_attributes(cell, text=self.MODEL_KEY) column.set_resizable(True) tv.append_column(column) def render_blurb(column, cell, model, iter): object = model.get_value(iter, self.MODEL_OBJECT) blurb = object.blurb or "" if object.is_internal: blurb += " (immutable)" cell.set_property('text', blurb) cell = gtk.CellRendererText() column = gtk.TreeViewColumn("Description", cell) column.set_cell_data_func(cell, render_blurb) column.set_resizable(True) 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), ('sloppy-rename', self.on_rename_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_buttonbox(buttons, horizontal=False, layout=gtk.BUTTONBOX_START) 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) self.pack_start(hbox,True,True) self.show_all()