class PropertiesAdminGtkNode(BaseAdminGtkNode): gladeFile = os.path.join('flumotion', 'component', 'base', 'properties.glade') def __init__(self, state, admin): BaseAdminGtkNode.__init__(self, state, admin, title=_("Properties")) def haveWidgetTree(self): self.widget = gtk.VBox() self.widget.set_border_width(6) self.properties = ObjectList( [Column('name'), Column('value')]) self.properties.set_size_request(-1, 200) self.widget.pack_start(self.properties, False, False) self.properties.show() properties = self.state.get('config')['properties'] propertyNames = properties.keys()[:] propertyNames.sort() for name in propertyNames: self.properties.append( Settable(name=name, value=properties[name])) return self.widget
def _create_field_list(self): items = ObjectList([Column('description', width=200), Column('len', data_type=int, editable=True)]) items.enable_dnd() items.set_size_request(200, -1) descriptions = {} invoice_fields = get_invoice_fields() for invoice_field in sorted(invoice_fields, key=operator.attrgetter('name')): items.append( Settable(description=invoice_field.get_description(), name=invoice_field.name, len=invoice_field.length)) descriptions[invoice_field.name] = invoice_field.description self._field_descriptions = descriptions self.left_vbox.pack_end(items, True, True) items.show()
class DeviceConstantsDialog(BasicDialog): size = (500, 300) def __init__(self, store, printer): self._constant_slave = None self.store = store self.printer = printer BasicDialog.__init__(self, hide_footer=False, title='edit', size=self.size) self.main.set_border_width(6) self._create_ui() def _create_ui(self): hbox = Gtk.HBox() self.klist = ObjectList([Column('name')]) self.klist.set_size_request(150, -1) self.klist.get_treeview().set_headers_visible(False) self.klist.connect('selection-changed', self._on_klist__selection_changed) hbox.pack_start(self.klist, True, True, 0) hbox.show() for name, ctype in [(_(u'Units'), DeviceConstant.TYPE_UNIT), (_(u'Tax'), DeviceConstant.TYPE_TAX), (_(u'Payments'), DeviceConstant.TYPE_PAYMENT)]: self.klist.append(Settable(name=name, type=ctype)) self.klist.show() self._constant_slave = _DeviceConstantsList(self.store, self.printer) self._constant_slave.switch(DeviceConstant.TYPE_UNIT) hbox.pack_start(self._constant_slave.get_toplevel(), True, True, 0) # FIXME: redesign BasicDialog self.main.remove(self.main_label) self.main.add(hbox) hbox.show_all() def _on_klist__selection_changed(self, klist, selected): self._constant_slave.switch(selected.type)
class DeviceConstantsDialog(BasicDialog): size = (500, 300) def __init__(self, store, printer): self._constant_slave = None self.store = store self.printer = printer BasicDialog.__init__(self, hide_footer=False, title='edit', size=self.size) self.main.set_border_width(6) self._create_ui() def _create_ui(self): hbox = gtk.HBox() self.klist = ObjectList([Column('name')]) self.klist.set_size_request(150, -1) self.klist.get_treeview().set_headers_visible(False) self.klist.connect('selection-changed', self._on_klist__selection_changed) hbox.pack_start(self.klist) hbox.show() for name, ctype in [(_(u'Units'), DeviceConstant.TYPE_UNIT), (_(u'Tax'), DeviceConstant.TYPE_TAX), (_(u'Payments'), DeviceConstant.TYPE_PAYMENT)]: self.klist.append(Settable(name=name, type=ctype)) self.klist.show() self._constant_slave = _DeviceConstantsList(self.store, self.printer) self._constant_slave.switch(DeviceConstant.TYPE_UNIT) hbox.pack_start(self._constant_slave.get_toplevel()) # FIXME: redesign BasicDialog self.main.remove(self.main_label) self.main.add(hbox) hbox.show_all() def _on_klist__selection_changed(self, klist, selected): self._constant_slave.switch(selected.type)
def _create_field_list(self): items = ObjectList([ Column('description', width=200), Column('len', data_type=int, editable=True) ]) items.enable_dnd() items.set_size_request(200, -1) descriptions = {} invoice_fields = get_invoice_fields() for invoice_field in sorted(invoice_fields, key=operator.attrgetter('name')): items.append( Settable(description=invoice_field.get_description(), name=invoice_field.name, len=invoice_field.length)) descriptions[invoice_field.name] = invoice_field.description self._field_descriptions = descriptions self.left_vbox.pack_end(items, True, True) items.show()
class PropertiesAdminGtkNode(BaseAdminGtkNode): gladeFile = os.path.join('flumotion', 'component', 'base', 'properties.glade') uiStateHandlers = None _properties = {} def __init__(self, state, admin): BaseAdminGtkNode.__init__(self, state, admin, title=_("Properties")) def haveWidgetTree(self): self.widget = gtk.VBox() self.widget.set_border_width(6) self.properties = ObjectList( [Column('name'), Column('value')]) self.properties.set_size_request(-1, 200) self.widget.pack_start(self.properties, False, False) self.properties.show() self._reloadProperties(self.state.get('config')['properties']) return self.widget # IStateListener Interface def stateSet(self, object, key, value): if key == 'properties': self._reloadProperties(value) ### Private methods def _reloadProperties(self, properties): if properties is None: return self.properties.clear() propertyNames = properties.keys()[:] propertyNames.sort() for name in propertyNames: self.properties.append( Settable(name=name, value=properties[name]))
class FormFieldEditor(BasicDialog): size = (700, 400) title = _("Form fields") def __init__(self, store): self.store = store BasicDialog.__init__(self, size=FormFieldEditor.size, title=FormFieldEditor.title) self._create_ui() def _create_ui(self): hbox = gtk.HBox() self.main.remove(self.main.get_child()) self.main.add(hbox) hbox.show() self.forms = ObjectList( [Column('description', title=_('Description'), sorted=True, expand=True, format_func=stoqlib_gettext)], self.store.find(UIForm), gtk.SELECTION_BROWSE) self.forms.connect('selection-changed', self._on_forms__selection_changed) self.forms.set_headers_visible(False) self.forms.set_size_request(200, -1) hbox.pack_start(self.forms, False, False) self.forms.show() box = gtk.VBox() hbox.pack_start(box) box.show() self.fields = ObjectList(self._get_columns(), [], gtk.SELECTION_BROWSE) box.pack_start(self.fields) self.fields.show() box.show() def _on_forms__selection_changed(self, forms, form): if not form: return self.fields.add_list(self.store.find(UIField, ui_form=form), clear=True) def _get_columns(self): return [Column('description', title=_('Description'), data_type=str, expand=True, sorted=True, format_func=stoqlib_gettext), Column('visible', title=_('Visible'), data_type=bool, width=120, editable=True), Column('mandatory', title=_('Mandatory'), data_type=bool, width=120, editable=True)] def confirm(self, *args): self.store.confirm(True) BasicDialog.confirm(self, *args) info(_("Changes will be applied after all instances of Stoq are restarted.")) def cancel(self, *args): self.store.rollback(close=False) BasicDialog.confirm(self, *args)
class ShortcutsEditor(BasicDialog): size = (700, 400) title = _("Keyboard shortcuts") def __init__(self): BasicDialog.__init__(self, size=ShortcutsEditor.size, title=ShortcutsEditor.title) self._create_ui() def _create_ui(self): self.cancel_button.hide() hbox = gtk.HBox(spacing=6) self.main.remove(self.main.get_child()) self.main.add(hbox) hbox.show() self.categories = ObjectList( [Column('label', sorted=True, expand=True)], get_binding_categories(), gtk.SELECTION_BROWSE) self.categories.connect('selection-changed', self._on_categories__selection_changed) self.categories.set_headers_visible(False) self.categories.set_size_request(200, -1) hbox.pack_start(self.categories, False, False) self.categories.show() box = gtk.VBox(spacing=6) hbox.pack_start(box) box.show() self.shortcuts = ObjectList(self._get_columns(), [], gtk.SELECTION_BROWSE) box.pack_start(self.shortcuts) self.shortcuts.show() self._label = gtk.Label( _("You need to restart Stoq for the changes to take effect")) box.pack_start(self._label, False, False, 6) box.show() defaults_button = gtk.Button(_("Reset defaults")) defaults_button.connect('clicked', self._on_defaults_button__clicked) self.action_area.pack_start(defaults_button, False, False, 6) self.action_area.reorder_child(defaults_button, 0) defaults_button.show() def _on_categories__selection_changed(self, categories, category): if not category: return self.shortcuts.add_list(get_bindings(category.name), clear=True) def _on_defaults_button__clicked(self, button): old = self.categories.get_selected() api.user_settings.remove('shortcuts') remove_user_bindings() self._label.show() self.categories.refresh() self.categories.select(old) def _get_columns(self): return [Column('description', _("Description"), data_type=str, expand=True, sorted=True), ShortcutColumn('shortcut', _("Shortcut"), self)] def set_binding(self, binding): set_user_binding(binding.name, binding.shortcut) d = api.user_settings.get('shortcuts', {}) d[binding.name] = binding.shortcut self._label.show() def remove_binding(self, binding): remove_user_binding(binding.name) d = api.user_settings.get('shortcuts', {}) try: del d[binding.name] except KeyError: pass self._label.show()
class FormFieldEditor(BasicDialog): size = (700, 400) title = _("Form fields") def __init__(self, store): self.store = store BasicDialog.__init__(self, size=FormFieldEditor.size, title=FormFieldEditor.title) self._create_ui() def _create_ui(self): hbox = Gtk.HBox() self.main.remove(self.main.get_child()) self.main.add(hbox) hbox.show() self.forms = ObjectList( [Column('description', title=_('Description'), sorted=True, expand=True, format_func=stoqlib_gettext)], self.store.find(UIForm), Gtk.SelectionMode.BROWSE) self.forms.connect('selection-changed', self._on_forms__selection_changed) self.forms.set_headers_visible(False) self.forms.set_size_request(200, -1) hbox.pack_start(self.forms, False, False, 0) self.forms.show() box = Gtk.VBox() hbox.pack_start(box, True, True, 0) box.show() self.fields = ObjectList(self._get_columns(), [], Gtk.SelectionMode.BROWSE) box.pack_start(self.fields, True, True, 0) self.fields.show() box.show() def _on_forms__selection_changed(self, forms, form): if not form: return self.fields.add_list(self.store.find(UIField, ui_form=form), clear=True) self.fields.set_cell_data_func(self._uifield__cell_data_func) def _uifield__cell_data_func(self, column, renderer, obj, text): if isinstance(renderer, Gtk.CellRendererText): return text manager = get_plugin_manager() if manager.is_any_active(['nfe', 'nfce']): is_editable = obj.field_name not in [u'street', u'district', u'city', u'state', u'country', u'street_number'] renderer.set_property('sensitive', is_editable) renderer.set_property('activatable', is_editable) return text def _get_columns(self): return [Column('description', title=_('Description'), data_type=str, expand=True, sorted=True, format_func=stoqlib_gettext), Column('visible', title=_('Visible'), data_type=bool, width=120, editable=True), Column('mandatory', title=_('Mandatory'), data_type=bool, width=120, editable=True)] def confirm(self, *args): self.store.confirm(True) BasicDialog.confirm(self, *args) info(_("Changes will be applied after all instances of Stoq are restarted.")) def cancel(self, *args): self.store.rollback(close=False) BasicDialog.confirm(self, *args)
class VirtLabView(BaseView): ''' MVC View ''' def __init__(self, model): self.__model = model #self.__model.set_view(self) BaseView.__init__(self, gladefile="virtlab", delete_handler=self.quit_if_last) # self.__col_pixbuf = gtk.TreeViewColumn("Image") # cellrenderer_pixbuf = gtk.CellRendererPixbuf() # cellrenderer_pixbuf.set_properties("pixbuf", ) # self.__col_pixbuf.pack_start(cellrenderer_pixbuf, False) # self.__col_pixbuf.add_attribute(cellrenderer_pixbuf, "pixbuf", 1) tableColumns = [ Column("image", title=" ", width=30, data_type=gtk.gdk.Pixbuf, sorted=False), Column("name", title='VM Name', width=130, sorted=True), Column("state", title='State', width=70), Column("order", title='Order (Delay/min)', width=145), Column("ordinal", visible=False), Column("delay", visible=False), Column("desc", title='Description', width=200) ] self.vmlist_widget = ObjectList(tableColumns) self.vmlist_widget.set_size_request(300, 400) self.vmlist_widget.set_selection_mode(gtk.SELECTION_SINGLE) self.hbox4.pack_start(self.vmlist_widget) store = gtk.ListStore(gobject.TYPE_STRING) self.vmlist_widget.show() self.__dialog = None self.__status_text = gtk.TextBuffer() try: self.populate_vmlist() self.populate_order_dropdown(store, len(self.__model.get_vms())) except VMLabException as exception: if exception.vme_id is c.EXCEPTION_LIBVIRT_001: error("Initialization error", "No connection to Libvirtd.\n Exiting.") exit(1) self.ordercombo.set_model(store) cell = gtk.CellRendererText() self.ordercombo.pack_start(cell, True) self.ordercombo.add_attribute(cell, 'text', 0) self.virtlab.set_size_request(800, 460) self.change_title("") self.__statusbar_ctx = self.statusbar.get_context_id("virtlab") self.virtlab.set_icon(gtk.gdk.pixbuf_new_from_file("pixmaps/about-logo.png")) def __delaystring(self, delay): if delay > 0: return " (" + str(delay) + ")" else: return "" def change_title(self, value): if value == "" or None: self.virtlab.set_title(c.WINDOW_TITLE) else: self.virtlab.set_title(c.WINDOW_TITLE + "(" + value + ")") def dialog_filechooser_open(self): chooser = gtk.FileChooserDialog(title="Open VMLab Project", action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)) chooser.set_default_response(gtk.RESPONSE_OK) filter = gtk.FileFilter() filter.add_pattern("*"+c.SAVE_FILE_SUFFIX) chooser.set_filter(filter) file_name = "" response = chooser.run() if response == gtk.RESPONSE_OK: file_name = chooser.get_filename() chooser.destroy() return file_name elif response == gtk.RESPONSE_CANCEL: chooser.destroy() return def dialog_filechooser_save(self): chooser = gtk.FileChooserDialog(title="Save VMLab Project", action=gtk.FILE_CHOOSER_ACTION_SAVE, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK)) chooser.set_default_response(gtk.RESPONSE_CANCEL) filter = gtk.FileFilter() filter.add_pattern("*"+c.SAVE_FILE_SUFFIX) file_name = "" response = chooser.run() if response == gtk.RESPONSE_OK: file_name = chooser.get_filename() chooser.destroy() return file_name elif response == gtk.RESPONSE_CANCEL: chooser.destroy() return elif response == gtk.RESPONSE_CLOSE: chooser.destroy() return def populate_vmlist(self): ''' Populates view with current status ''' self.vmlist_widget.clear() for vm_instance in self.__model.get_vms(): self.vmlist_widget.append(Settable(image=populate_image(vm_instance.get_state()), name=vm_instance.get_name(), state=vm_instance.get_state().get_state_str(), order=self.get_display_order(vm_instance.get_order()) + self.__delaystring(vm_instance.get_delay()), ordinal=vm_instance.get_order(), delay=vm_instance.get_delay(), desc=vm_instance.get_desc())) def populate_order_dropdown(self, list_store, vm_count): list_store.clear() list_store.append([""]) if vm_count > 0: for num in range(1, vm_count + 1): list_store.append([self.get_display_order(num)]) def add_status_dialogbox(self, text): field_content = self.__status_text.get_text(self.__status_text.get_start_iter(), self.__status_text.get_end_iter(), False) field_content += strftime("%d %b %Y %H:%M:%S", localtime()) + " " + text + "\n" self.__status_text.set_text(field_content) def clear_dialog_log(self): self.__status_text.set_text("") def show_dialog(self): self.__dialog = gtk.Dialog(title="Launch status", parent=self.virtlab, flags=gtk.DIALOG_MODAL, buttons=None) self.__dialog.set_position(gtk.WIN_POS_CENTER_ON_PARENT) self.__dialog.set_transient_for(self.virtlab) close_button = gtk.Button("Close window") terminate_button = gtk.Button("Terminate") clear_button = gtk.Button("Clear log") start_button = gtk.Button("Launch scheduled") start_once_button = gtk.Button("Launch all once") close_button.connect("clicked", lambda d, r: r.destroy(), self.__dialog) clear_button.connect("clicked", lambda d, r: r.clear_dialog_log(), self) terminate_button.connect("clicked", self.controller.hook_dialog_terminate_clicked, None) start_button.connect("clicked", self.controller.hook_dialog_start_clicked, None) start_once_button.connect("clicked", self.controller.hook_dialog_all_start_clicked, None) scrolled_window = gtk.ScrolledWindow(hadjustment=None, vadjustment=None) scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS) text_view = gtk.TextView() scrolled_window.add_with_viewport(text_view) scrolled_window.show() text_view.set_buffer(self.__status_text) # pylint: disable=E1101 self.__dialog.action_area.pack_start(start_button, True, True, 0) self.__dialog.action_area.pack_start(start_once_button, True, True, 0) self.__dialog.action_area.pack_start(clear_button, True, True, 0) self.__dialog.action_area.pack_start(terminate_button, True, True, 0) self.__dialog.action_area.pack_start(close_button, True, True, 0) self.__dialog.vbox.pack_start(scrolled_window, True, True, 0) scrolled_window.set_size_request(500, 200) start_button.show() start_once_button.show() terminate_button.show() close_button.show() clear_button.show() text_view.show() self.__dialog.show() text_view.set_editable(False) text_view.set_cursor_visible(False) def show_about(self): about = gtk.AboutDialog() about.set_program_name("Virtual Lab Manager") about.set_version("1.0 RC") import os path = os.path.dirname(virtlab.__file__) f = open(path + '/LICENCE', 'r') about.set_license(f.read()) about.set_copyright("GPLv3, (c) Authors") about.set_logo(gtk.gdk.pixbuf_new_from_file("pixmaps/about-logo.png")) about.set_authors(["Harri Savolainen", "Esa Elo"]) about.set_comments("Virtual Machine lab tool") about.set_website("https://github.com/hsavolai/vmlab") about.run() about.hide() def dialog_overwrite(self): response = messagedialog(gtk.MESSAGE_QUESTION, "File exists, overwrite?", None, self.toplevel, gtk.BUTTONS_OK_CANCEL ) if response == gtk.RESPONSE_OK: return True return False def dialog_file_error(self, error_msg): messagedialog(gtk.MESSAGE_ERROR, "File operation failed!", error_msg, self.toplevel, gtk.BUTTONS_OK ) def set_statusbar(self, value): #self.statusbar.remove_all(self.__statusbar_ctx) self.statusbar.pop(self.__statusbar_ctx) self.statusbar.push(self.__statusbar_ctx, value) @staticmethod def get_display_order(number): if number is 0: return "" upper_suffixes = { "11": "th", "12": "th", "13": "th" } lower_suffixes = { "1": "st", "2": "nd", "3": "rd", } digits = str(number) if digits[-2:] in upper_suffixes: return digits + upper_suffixes[digits[-2:]] if digits[-1:] in lower_suffixes: return digits + lower_suffixes[digits[-1:]] else: return digits + "th"
class Connections(GladeWidget): gladeFile = "connections.glade" gsignal("have-connection", bool) gsignal("connection-activated", object) gsignal("connections-cleared") def __init__(self): GladeWidget.__init__(self) columns = [ Column("host", title=_("Hostname"), searchable=True), Column( "timestamp", title=_("Last used"), sorted=True, order=gtk.SORT_DESCENDING, format_func=format_timestamp ), ] self._connections = ObjectList(columns, objects=getRecentConnections(), mode=gtk.SELECTION_SINGLE) self._connections.connect("row-activated", self._on_objectlist_row_activated) self._connections.connect("selection-changed", self._on_objectlist_selection_changed) self._connections.set_size_request(-1, 160) self.page.pack_start(self._connections) self.page.reorder_child(self._connections, 0) self._connections.get_treeview().set_search_equal_func(self._searchEqual) self._connections.show() self._updateButtons() def _updateButtons(self): canClear = hasRecentConnections() self.button_clear.set_sensitive(canClear) self.button_clear_all.set_sensitive(canClear) if not canClear: self.emit("connections-cleared") def _searchEqual(self, model, column, key, iter): connection = model.get(iter, column)[0] if key in connection.name: return False # True means doesn't match return True def _clear_all(self): for conn in self._connections: os.unlink(conn.filename) self._connections.clear() def _clear(self, conn): self._connections.remove(conn) os.unlink(conn.filename) # Public API def grab_focus(self): if len(self._connections): self._connections.select(self._connections[0]) self._connections.grab_focus() def get_selected(self): return self._connections.get_selected() def update(self, connection): os.utime(connection.filename, None) # Callbacks def on_button_clear_clicked(self, button): conn = self._connections.get_selected() if conn: self._clear(conn) self._updateButtons() def on_button_clear_all_clicked(self, button): self._clear_all() self._updateButtons() def _on_objectlist_row_activated(self, connections, connection): self.emit("connection-activated", connection) def _on_objectlist_selection_changed(self, connections, connection): self.emit("have-connection", bool(connection))
class search_results_window: """A results window for a searching for a recipe""" def __init__ (self, searchline="", mode=gtk.SELECTION_SINGLE): """Search for the name like searchstring""" self.window=gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.connect("destroy", self.exit) self.window.set_size_request(600, 250) self.vbox=gtk.VBox(homogeneous=False,spacing=0) self.window.add(self.vbox) self.cur=con.cursor() if searchline.count(':') !=0: search_options=dict(self.parse_search_string(searchline)) print search_options results=[[5, 'Foo2', 'yummy food'], [6, 'Foobar', 'best foobar evar!']] else: searchline="%" + searchline + "%" self.cur.execute("""SELECT recipe_id,name,description FROM recipes WHERE name LIKE %s""", (searchline,)) results=self.cur.fetchall() my_columns = [ Column("name", title="Name", sorted=True), Column("desc", title="Description") ] self.objectlist = ObjectList(my_columns, mode=mode) self.objectlist.set_size_request(600,225) recipes=[RecipeInfo(x) for x in results] self.objectlist.add_list(recipes) self.b=gtk.Button("Show Selected") self.b.connect("clicked", self.show_recipe2) self.vbox.add(self.objectlist) self.vbox.add(self.b) self.window.show_all() def parse_search_string(self,s): foo,indexes=findall(':',s) p=0 l=[] s_len=len(s) for i in indexes: for j in range(i+1,s_len+1): #print (j,s_len) if j >= s_len: l.append(s[p:j].strip()) break else: if s[j] == " ": t=j if s[j] == ':': l.append(s[p:t].strip()) p=t break return [[y.lower() for y in x.split(':')] for x in l] def show_recipe2(self,widget,*data): recipe=self.objectlist.get_selected() self.window.hide() current_recipe(recipe_id=recipe.r_id) def show_recipe(self,widget,data): self.window.hide() recipe=current_recipe(recipe_id=data) def exit(self, widget): main_window.window.show()
class ShortcutsEditor(BasicDialog): size = (700, 400) title = _("Keyboard shortcuts") def __init__(self): BasicDialog.__init__(self, size=ShortcutsEditor.size, title=ShortcutsEditor.title) self._create_ui() def _create_ui(self): self.cancel_button.hide() hbox = gtk.HBox(spacing=6) self.main.remove(self.main.get_child()) self.main.add(hbox) hbox.show() self.categories = ObjectList( [Column('label', sorted=True, expand=True)], get_binding_categories(), gtk.SELECTION_BROWSE) self.categories.connect('selection-changed', self._on_categories__selection_changed) self.categories.set_headers_visible(False) self.categories.set_size_request(200, -1) hbox.pack_start(self.categories, False, False) self.categories.show() box = gtk.VBox(spacing=6) hbox.pack_start(box) box.show() self.shortcuts = ObjectList(self._get_columns(), [], gtk.SELECTION_BROWSE) box.pack_start(self.shortcuts) self.shortcuts.show() self._label = gtk.Label( _("You need to restart Stoq for the changes to take effect")) box.pack_start(self._label, False, False, 6) box.show() defaults_button = gtk.Button(_("Reset defaults")) defaults_button.connect('clicked', self._on_defaults_button__clicked) self.action_area.pack_start(defaults_button, False, False, 6) self.action_area.reorder_child(defaults_button, 0) defaults_button.show() def _on_categories__selection_changed(self, categories, category): if not category: return self.shortcuts.add_list(get_bindings(category.name), clear=True) def _on_defaults_button__clicked(self, button): old = self.categories.get_selected() api.user_settings.remove('shortcuts') remove_user_bindings() self._label.show() self.categories.refresh() self.categories.select(old) def _get_columns(self): return [ Column('description', _("Description"), data_type=str, expand=True, sorted=True), ShortcutColumn('shortcut', _("Shortcut"), self) ] def set_binding(self, binding): set_user_binding(binding.name, binding.shortcut) d = api.user_settings.get('shortcuts', {}) d[binding.name] = binding.shortcut self._label.show() def remove_binding(self, binding): remove_user_binding(binding.name) d = api.user_settings.get('shortcuts', {}) try: del d[binding.name] except KeyError: pass self._label.show()
class FormFieldEditor(BasicDialog): size = (700, 400) title = _("Form fields") def __init__(self, store): self.store = store BasicDialog.__init__(self, size=FormFieldEditor.size, title=FormFieldEditor.title) self._create_ui() def _create_ui(self): hbox = gtk.HBox() self.main.remove(self.main.get_child()) self.main.add(hbox) hbox.show() self.forms = ObjectList( [Column('description', title=_('Description'), sorted=True, expand=True, format_func=stoqlib_gettext)], self.store.find(UIForm), gtk.SELECTION_BROWSE) self.forms.connect('selection-changed', self._on_forms__selection_changed) self.forms.set_headers_visible(False) self.forms.set_size_request(200, -1) hbox.pack_start(self.forms, False, False) self.forms.show() box = gtk.VBox() hbox.pack_start(box) box.show() self.fields = ObjectList(self._get_columns(), [], gtk.SELECTION_BROWSE) box.pack_start(self.fields) self.fields.show() box.show() def _on_forms__selection_changed(self, forms, form): if not form: return self.fields.add_list(self.store.find(UIField, ui_form=form), clear=True) def _get_columns(self): return [Column('description', title=_('Description'), data_type=str, expand=True, sorted=True, format_func=stoqlib_gettext), Column('visible', title=_('Visible'), data_type=bool, width=120, editable=True), Column('mandatory', title=_('Mandatory'), data_type=bool, width=120, editable=True)] def confirm(self, *args): self.store.confirm(True) BasicDialog.confirm(self, *args) def cancel(self, *args): self.store.rollback(close=False) BasicDialog.confirm(self, *args)