def __init__(self): super(SizedVBoxToolWidget, self).__init__() from gui.application import get_app app = get_app() self.app = app toolbar = inline_toolbar(app, [ ("ScratchNew", "mypaint-add-symbolic"), ("ScratchLoad", None), ("ScratchSaveAs", "mypaint-document-save-symbolic"), ("ScratchRevert", "mypaint-document-revert-symbolic"), ]) scratchpad_view = app.scratchpad_doc.tdw scratchpad_view.set_size_request(64, 64) self.connect("destroy-event", self._save_cb) self.connect("delete-event", self._save_cb) scratchpad_box = Gtk.EventBox() scratchpad_box.add(scratchpad_view) self.pack_start(scratchpad_box, True, True, 0) self.pack_start(toolbar, False, True, 0)
def __init__(self, markup, menu): """Initialize :param markup: Markup to display in the button. :param menu: The menu to present when clicked. """ Gtk.EventBox.__init__(self) self.menu = menu self.label = Gtk.Label() self.label.set_markup(markup) self.label.set_padding(8, 0) # Intercept mouse clicks and use them for activating the togglebutton # even if they're in its border, or (0, 0). Fitts would approve. invis = Gtk.EventBox() invis.set_visible_window(False) invis.set_above_child(True) invis.connect("button-press-event", self._button_press_cb) invis.connect("enter-notify-event", self._enter_cb) invis.connect("leave-notify-event", self._leave_cb) self.invis_window = invis # Toggle button, for the look of the thing only self.togglebutton = Gtk.ToggleButton() self.togglebutton.add(self.label) self.togglebutton.set_relief(Gtk.ReliefStyle.NONE) self.togglebutton.connect("toggled", self._togglebutton_toggled_cb) # The underlying togglebutton can default and focus. Might as well make # the Return key do something useful rather than invoking the 1st # toolbar item. self.togglebutton.set_can_default(True) self.togglebutton.set_can_focus(True) # Packing invis.add(self.togglebutton) self.add(invis) # Menu signals for sig in "selection-done", "deactivate", "cancel": menu.connect(sig, self._menu_dismiss_cb)
def _accel_editing_started_cb(self, cell, editable, treepath): """Begin editing by showing a key capture dialog""" it = self._filter.get_iter(treepath) accel_path = self._filter.get_value(it, self._PATH_COLUMN) accel_label = self._accel_labels[accel_path] action_label = self._action_labels[accel_path] editable.set_sensitive(False) dialog = Gtk.Dialog() dialog.set_modal(True) # TRANSLATORS: Window title for the keybinding dialog. The %s is # TRANSLATORS: replaced with the name of the action that the key # TRANSLATORS: combination is being bound to, e.g. "Fit to View". dialog.set_title(_("Edit Key for '%s'") % action_label) dialog.set_transient_for(self.get_toplevel()) dialog.set_position(Gtk.WindowPosition.CENTER_ON_PARENT) dialog.add_buttons( Gtk.STOCK_DELETE, Gtk.ResponseType.REJECT, Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.OK, ) dialog.set_default_response(Gtk.ResponseType.OK) dialog.connect("response", self._edit_dialog_response_cb, editable, accel_path) evbox = Gtk.EventBox() evbox.set_border_width(12) dialog.connect("key-press-event", self._edit_dialog_key_press_cb, editable) grid = Gtk.Grid() grid.set_row_spacing(12) grid.set_column_spacing(12) row = 0 label = Gtk.Label() label.set_alignment(0, 0.5) label.set_text(_("Action:")) grid.attach(label, 0, row, 1, 1) label = Gtk.Label() label.set_alignment(0, 0.5) label.set_text(str(action_label)) label.set_tooltip_text(str(accel_path)) label.set_hexpand(True) grid.attach(label, 1, row, 1, 1) if self._SHOW_ACCEL_PATH: row += 1 label = Gtk.Label() label.set_alignment(0, 0.5) # TRANSLATORS: Path refers to an "action path" that is part of an # TRANSLATORS: accelerator (keybinding). Found in the dialog for # TRANSLATORS: adding new keybindings. This is a technical field # TRANSLATORS: that probably shouldn't even be part of the gui, # TRANSLATORS: so don't worry too much about the translation. label.set_text(_("Path:")) grid.attach(label, 0, row, 1, 1) label = Gtk.Label() label.set_alignment(0, 0.5) label.set_text(str(accel_path)) label.set_hexpand(True) grid.attach(label, 1, row, 1, 1) row += 1 label = Gtk.Label() label.set_alignment(0, 0.5) # TRANSLATORS: Key refers to a key on the keyboard, this is a label # TRANSLATORS: in the dialog for adding new keyboard bindings. label.set_text(_("Key:")) grid.attach(label, 0, row, 1, 1) label = Gtk.Label() label.set_alignment(0, 0.5) label.set_text(str(accel_label)) dialog.accel_label_widget = label label.set_hexpand(True) grid.attach(label, 1, row, 1, 1) row += 1 label = Gtk.Label() label.set_hexpand(True) label.set_vexpand(True) label.set_margin_top(12) label.set_margin_bottom(12) label.set_alignment(0, 0) label.set_line_wrap(True) label.set_size_request(200, 75) dialog.hint_widget = label self._edit_dialog_set_standard_hint(dialog) grid.attach(label, 0, row, 2, 1) evbox.add(grid) dialog.get_content_area().pack_start(evbox, True, True, 0) evbox.show_all() dialog.initial_accel_label = accel_label dialog.accel_path = accel_path dialog.result_keyval = None dialog.result_mods = None dialog.show()
def _bp_cell_editing_started_cb(self, cell, editable, path): iter = self.liststore.get_iter(path) action_name = self.liststore.get_value(iter, self.action_column) bp_name = self.liststore.get_value(iter, self.bp_column) bp_displayname = button_press_displayname(*button_press_parse(bp_name)) editable.set_sensitive(False) dialog = Gtk.Dialog() dialog.set_modal(True) dialog.set_title(_("Edit binding for '%s'") % action_name) dialog.set_transient_for(self.get_toplevel()) dialog.set_position(Gtk.WindowPosition.CENTER_ON_PARENT) dialog.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.OK) dialog.set_default_response(Gtk.ResponseType.OK) dialog.connect("response", self._bp_edit_dialog_response_cb, editable) dialog.ok_btn = dialog.get_widget_for_response(Gtk.ResponseType.OK) dialog.ok_btn.set_sensitive(bp_name is not None) evbox = Gtk.EventBox() evbox.set_border_width(12) evbox.connect("button-press-event", self._bp_edit_box_button_press_cb, dialog, editable) evbox.connect("enter-notify-event", self._bp_edit_box_enter_cb) table = Gtk.Table(3, 2) table.set_row_spacings(12) table.set_col_spacings(12) row = 0 label = Gtk.Label() label.set_alignment(0, 0.5) # TRANSLATORS: Part of interface when adding a new button map binding. # TRANSLATORS: It's a label for the action part of the combination. # TRANSLATORS: Probably always the same as the column name # TRANSLATORS: "Action" with a trailing ":" or lang-specific symbol label.set_text(_("Action:")) table.attach(label, 0, 1, row, row + 1, Gtk.AttachOptions.FILL) label = Gtk.Label() label.set_alignment(0, 0.5) label.set_text(str(action_name)) table.attach(label, 1, 2, row, row + 1, Gtk.AttachOptions.FILL | Gtk.AttachOptions.EXPAND) row += 1 label = Gtk.Label() label.set_alignment(0, 0.5) # TRANSLATORS: Part of interface when adding a new button map binding. # TRANSLATORS: It's a label for the mod+button part of the combination. # TRANSLATORS: Probably always the same as "Button press" (column name) # TRANSLATORS: but with a trailing ":" or other lang-specific symbol. label.set_text(_("Button press:")) table.attach(label, 0, 1, row, row + 1, Gtk.AttachOptions.FILL) label = Gtk.Label() label.set_alignment(0, 0.5) label.set_text(str(bp_displayname)) dialog.bp_name = bp_name dialog.bp_name_orig = bp_name dialog.bp_label = label table.attach(label, 1, 2, row, row + 1, Gtk.AttachOptions.FILL | Gtk.AttachOptions.EXPAND) row += 1 label = Gtk.Label() label.set_size_request(300, 75) label.set_alignment(0, 0) label.set_line_wrap(True) dialog.hint_label = label self._bp_edit_dialog_set_standard_hint(dialog) table.attach(label, 0, 2, row, row + 1, Gtk.AttachOptions.FILL | Gtk.AttachOptions.EXPAND, Gtk.AttachOptions.FILL | Gtk.AttachOptions.EXPAND, 0, 12) evbox.add(table) dialog.get_content_area().pack_start(evbox, True, True, 0) evbox.show_all() dialog.show()