def __init__(self, monitor=None): """Initialize :param Monitor monitor: monitor instance (for testing) By default, the central app's `device_monitor` is used to permit parameterless construction. """ super(SettingsEditor, self).__init__() if monitor is None: app = gui.application.get_app() monitor = app.device_monitor self._monitor = monitor self._devices_store = Gtk.ListStore(object) self._devices_view = Gtk.TreeView(model=self._devices_store) col = Gtk.TreeViewColumn( C_( "prefs: devices table: column header", # TRANSLATORS: Column's data is the device's name "Device", )) col.set_min_width(200) col.set_expand(True) col.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE) self._devices_view.append_column(col) cell = Gtk.CellRendererText() cell.set_property("ellipsize", Pango.EllipsizeMode.MIDDLE) col.pack_start(cell, True) col.set_cell_data_func(cell, self._device_name_datafunc) col = Gtk.TreeViewColumn( C_( "prefs: devices table: column header", # TRANSLATORS: Column's data is the number of axes (an integer) "Axes", )) col.set_min_width(30) col.set_resizable(True) col.set_expand(False) col.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE) self._devices_view.append_column(col) cell = Gtk.CellRendererText() col.pack_start(cell, True) col.set_cell_data_func(cell, self._device_axes_datafunc) col = Gtk.TreeViewColumn( C_( "prefs: devices table: column header", # TRANSLATORS: Column shows type labels ("Touchscreen", "Pen" etc.) "Type", )) col.set_min_width(120) col.set_resizable(True) col.set_expand(False) col.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE) self._devices_view.append_column(col) cell = Gtk.CellRendererText() cell.set_property("ellipsize", Pango.EllipsizeMode.END) col.pack_start(cell, True) col.set_cell_data_func(cell, self._device_type_datafunc) # Usage config value => string store (dropdowns) store = Gtk.ListStore(str, str) for conf_val in AllowedUsage.VALUES: string = AllowedUsage.DISPLAY_STRING[conf_val] store.append([conf_val, string]) self._usage_store = store col = Gtk.TreeViewColumn( C_( "prefs: devices table: column header", # TRANSLATORS: Column's data is a dropdown allowing the allowed # TRANSLATORS: tasks for the row's device to be configured. u"Use for…", )) col.set_min_width(100) col.set_resizable(True) col.set_expand(False) self._devices_view.append_column(col) cell = Gtk.CellRendererCombo() cell.set_property("model", self._usage_store) cell.set_property("text-column", self._USAGE_STRING_COL) cell.set_property("mode", Gtk.CellRendererMode.EDITABLE) cell.set_property("editable", True) cell.set_property("has-entry", False) cell.set_property("ellipsize", Pango.EllipsizeMode.END) cell.connect("changed", self._usage_cell_changed_cb) col.pack_start(cell, True) col.set_cell_data_func(cell, self._device_usage_datafunc) # Scroll action config value => string store (dropdowns) store = Gtk.ListStore(str, str) for conf_val in ScrollAction.VALUES: string = ScrollAction.DISPLAY_STRING[conf_val] store.append([conf_val, string]) self._scroll_store = store col = Gtk.TreeViewColumn( C_( "prefs: devices table: column header", # TRANSLATORS: Column's data is a dropdown for how the device's # TRANSLATORS: scroll wheel or scroll-gesture events are to be # TRANSLATORS: interpreted normally. u"Scroll…", )) col.set_min_width(100) col.set_resizable(True) col.set_expand(False) self._devices_view.append_column(col) cell = Gtk.CellRendererCombo() cell.set_property("model", self._scroll_store) cell.set_property("text-column", self._USAGE_STRING_COL) cell.set_property("mode", Gtk.CellRendererMode.EDITABLE) cell.set_property("editable", True) cell.set_property("has-entry", False) cell.set_property("ellipsize", Pango.EllipsizeMode.END) cell.connect("changed", self._scroll_cell_changed_cb) col.pack_start(cell, True) col.set_cell_data_func(cell, self._device_scroll_datafunc) # Pretty borders view_scroll = Gtk.ScrolledWindow() view_scroll.set_shadow_type(Gtk.ShadowType.ETCHED_IN) pol = Gtk.PolicyType.AUTOMATIC view_scroll.set_policy(pol, pol) view_scroll.add(self._devices_view) view_scroll.set_hexpand(True) view_scroll.set_vexpand(True) self.attach(view_scroll, 0, 0, 1, 1) self._update_devices_store() self._monitor.devices_updated += self._update_devices_store
def __init__(self): """Initialise. """ super(ButtonMappingEditor, self).__init__() import gui.application self.app = gui.application.get_app() self.actions = set() self.default_action = None self.bindings = None #: dict of bindings being edited self.vbox = Gtk.VBox() self.add(self.vbox) # Display strings for action names self.action_labels = dict() # Model: combo cellrenderer's liststore ls = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING) self.action_liststore = ls self.action_liststore_value_column = 0 self.action_liststore_display_column = 1 # Model: main list's liststore # This is reflected into self.bindings when it changes column_types = [GObject.TYPE_STRING] * 3 ls = Gtk.ListStore(*column_types) self.action_column = 0 self.bp_column = 1 self.bpd_column = 2 for sig in ("row-changed", "row-deleted", "row_inserted"): ls.connect(sig, self._liststore_updated_cb) self.liststore = ls # Bindings hash observers, external interface self.bindings_observers = [] #: List of cb(editor) callbacks # View: treeview scrolledwin = Gtk.ScrolledWindow() scrolledwin.set_shadow_type(Gtk.ShadowType.IN) tv = Gtk.TreeView() tv.set_model(ls) scrolledwin.add(tv) self.vbox.pack_start(scrolledwin, True, True, 0) tv.set_size_request(480, 320) tv.set_headers_clickable(True) self.treeview = tv self.selection = tv.get_selection() self.selection.connect("changed", self._selection_changed_cb) # Column 0: action name cell = Gtk.CellRendererCombo() cell.set_property("model", self.action_liststore) cell.set_property("text-column", self.action_liststore_display_column) cell.set_property("mode", Gtk.CellRendererMode.EDITABLE) cell.set_property("editable", True) cell.set_property("has-entry", False) cell.connect("changed", self._action_cell_changed_cb) # TRANSLATORS: Name of first column in the button map preferences. # TRANSLATORS: Refers to an action bound to a mod+button combination. col = Gtk.TreeViewColumn(_("Action"), cell) col.set_cell_data_func(cell, self._liststore_action_datafunc) col.set_min_width(150) col.set_resizable(False) col.set_expand(False) col.set_sort_column_id(self.action_column) tv.append_column(col) # Column 1: button press cell = Gtk.CellRendererText() cell.set_property("ellipsize", Pango.EllipsizeMode.END) cell.set_property("mode", Gtk.CellRendererMode.EDITABLE) cell.set_property("editable", True) cell.connect("edited", self._bp_cell_edited_cb) cell.connect("editing-started", self._bp_cell_editing_started_cb) # TRANSLATORS: Name of second column in the button map preferences. # TRANSLATORS: Column lists mod+button combinations (bound to actions) # TRANSLATORS: E.g. Button1 or Ctrl+Button2 or Alt+Button3 col = Gtk.TreeViewColumn(_("Button press"), cell) col.add_attribute(cell, "text", self.bpd_column) col.set_expand(True) col.set_resizable(True) col.set_min_width(200) col.set_sort_column_id(self.bpd_column) tv.append_column(col) # List editor toolbar list_tools = Gtk.Toolbar() list_tools.set_style(Gtk.ToolbarStyle.ICONS) list_tools.set_icon_size(widgets.ICON_SIZE_LARGE) context = list_tools.get_style_context() context.add_class("inline-toolbar") self.vbox.pack_start(list_tools, False, False, 0) # Add binding btn = Gtk.ToolButton() btn.set_tooltip_text(_("Add a new binding")) btn.set_icon_name("mypaint-add-symbolic") btn.connect("clicked", self._add_button_clicked_cb) list_tools.add(btn) # Remove (inactive if list is empty) btn = Gtk.ToolButton() btn.set_icon_name("mypaint-remove-symbolic") btn.set_tooltip_text(_("Remove the current binding")) btn.connect("clicked", self._remove_button_clicked_cb) list_tools.add(btn) self.remove_button = btn self._updating_model = False