Exemple #1
0
def confirm_rewrite_group(window, groupname, deleted_groupname):
    flags = Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT
    dialog = Gtk.Dialog(_("Overwrite brush group?"), window, flags)

    cancel = Gtk.Button(stock=Gtk.STOCK_CANCEL)
    cancel.show_all()
    img_yes = Gtk.Image()
    img_yes.set_from_stock(Gtk.STOCK_YES, Gtk.IconSize.BUTTON)
    img_no = Gtk.Image()
    img_no.set_from_stock(Gtk.STOCK_NO, Gtk.IconSize.BUTTON)
    overwrite_this = Gtk.Button(label=_("Replace"))
    overwrite_this.set_image(img_yes)
    overwrite_this.show_all()
    skip_this = Gtk.Button(label=_("Rename"))
    skip_this.set_image(img_no)
    skip_this.show_all()

    buttons = [
        (cancel, CANCEL),
        (skip_this, DONT_OVERWRITE_THIS),
        (overwrite_this, OVERWRITE_THIS),
    ]
    for button, code in buttons:
        dialog.add_action_widget(button, code)

    question = Gtk.Label(label=_(
        u"<b>A group named “{groupname}” already exists.</b>\n"
        u"Do you want to replace it, or should the new group be renamed?\n"
        u"If you replace it, the brushes may be moved to a group called"
        u" “{deleted_groupname}”.").format(
            groupname=groupname,
            deleted_groupname=deleted_groupname,
        ))
    question.set_use_markup(True)

    dialog.vbox.pack_start(question, True, True, 0)
    dialog.vbox.show_all()

    answer = dialog.run()
    dialog.destroy()
    return answer
 def tool_widget_properties(self):
     """Run the properties dialog"""
     if not self._dialog:
         title = C_(
             "brush group properties dialog: title",
             # TRANSLATORS: properties dialog for the current brush group
             u"Group \u201C{group_name}\u201D",
         ).format(
             group_name = self._group,
         )
         dia = Gtk.Dialog(
             title=title,
             modal=True,
             destroy_with_parent=True,
             window_position=Gtk.WindowPosition.MOUSE,
         )
         dia.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT)
         btn = Gtk.Button(label=C_(
             "brush group properties dialog: action buttons",
             "Rename Group",
         ))
         btn.connect("clicked", self._rename_cb)
         dia.vbox.pack_start(btn, False, False, 0)
         btn = Gtk.Button(label=C_(
             "brush group properties dialog: action buttons",
             "Export as Zipped Brushset",
         ))
         btn.connect("clicked", self._export_cb)
         dia.vbox.pack_start(btn, False, False, 0)
         btn = Gtk.Button(label=C_(
             "brush group properties dialog: action buttons",
             "Delete Group",
         ))
         btn.connect("clicked", self._delete_cb)
         dia.vbox.pack_start(btn, False, False, 0)
         dia.vbox.show_all()
         self._dialog = dia
     self._dialog.set_transient_for(self.get_toplevel())
     self._dialog.run()
     self._dialog.hide()
Exemple #3
0
def ask_for_name(widget, title, default):
    window = widget.get_toplevel()
    d = Gtk.Dialog(title, window, Gtk.DialogFlags.MODAL,
                   (Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT, Gtk.STOCK_OK,
                    Gtk.ResponseType.ACCEPT))
    d.set_position(Gtk.WindowPosition.CENTER_ON_PARENT)

    hbox = Gtk.HBox()
    hbox.set_property("spacing", widgets.SPACING)
    hbox.set_border_width(widgets.SPACING)

    d.vbox.pack_start(hbox, True, True, 0)
    hbox.pack_start(Gtk.Label(label=_('Name')), False, False, 0)

    if default is None:
        default = ""

    d.e = e = Gtk.Entry()
    e.set_size_request(250, -1)
    e.set_text(default)
    e.select_region(0, len(default))
    e.set_input_hints(Gtk.InputHints.UPPERCASE_WORDS)
    e.set_input_purpose(Gtk.InputPurpose.FREE_FORM)

    e.connect("activate", _entry_activate_dialog_response_cb, d)

    hbox.pack_start(e, True, True, 0)
    d.vbox.show_all()
    if d.run() == Gtk.ResponseType.ACCEPT:
        result = d.e.get_text()
        if isinstance(result, bytes):
            result = result.decode('utf-8')
    else:
        result = None
    d.destroy()
    return result
Exemple #4
0
def confirm_brushpack_import(packname, window=None, readme=None):

    dialog = Gtk.Dialog(
        _("Import brush package?"), window,
        Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
        (Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT, Gtk.STOCK_OK,
         Gtk.ResponseType.ACCEPT))

    dialog.vbox.set_spacing(12)

    if readme:
        tv = Gtk.TextView()
        tv.set_wrap_mode(Gtk.WrapMode.WORD_CHAR)
        tv.get_buffer().set_text(readme)
        tv.set_editable(False)
        tv.set_left_margin(12)
        tv.set_right_margin(12)
        try:  # methods introduced in GTK 3.18
            tv.set_top_margin(6)
            tv.set_bottom_margin(6)
        except AttributeError:
            pass
        scrolls = Gtk.ScrolledWindow()
        scrolls.set_size_request(640, 480)
        scrolls.add(tv)
        dialog.vbox.pack_start(scrolls, True, True, 0)

    question = Gtk.Label(label=_(
        "<b>Do you really want to import package “{brushpack_name}”?</b>").
                         format(brushpack_name=packname, ))
    question.set_use_markup(True)
    dialog.vbox.pack_start(question, True, True, 0)
    dialog.vbox.show_all()
    answer = dialog.run()
    dialog.destroy()
    return answer
Exemple #5
0
def confirm_rewrite_brush(window, brushname, existing_preview_pixbuf,
                          imported_preview_data):
    flags = Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT
    dialog = Gtk.Dialog(_("Overwrite brush?"), window, flags)

    cancel = Gtk.Button(stock=Gtk.STOCK_CANCEL)
    cancel.show_all()
    img_yes = Gtk.Image()
    img_yes.set_from_stock(Gtk.STOCK_YES, Gtk.IconSize.BUTTON)
    img_no = Gtk.Image()
    img_no.set_from_stock(Gtk.STOCK_NO, Gtk.IconSize.BUTTON)
    overwrite_this = Gtk.Button(label=_("Replace"))
    overwrite_this.set_image(img_yes)
    overwrite_this.show_all()
    skip_this = Gtk.Button(label=_("Rename"))
    skip_this.set_image(img_no)
    skip_this.show_all()
    overwrite_all = Gtk.Button(label=_("Replace all"))
    overwrite_all.show_all()
    skip_all = Gtk.Button(label=_("Rename all"))
    skip_all.show_all()

    buttons = [
        (cancel, CANCEL),
        (skip_all, DONT_OVERWRITE_ANYTHING),
        (overwrite_all, OVERWRITE_ALL),
        (skip_this, DONT_OVERWRITE_THIS),
        (overwrite_this, OVERWRITE_THIS),
    ]
    for button, code in buttons:
        dialog.add_action_widget(button, code)

    hbox = Gtk.HBox()
    vbox_l = Gtk.VBox()
    vbox_r = Gtk.VBox()
    try:
        preview_r = Gtk.image_new_from_pixbuf(existing_preview_pixbuf)
    except AttributeError:
        preview_r = Gtk.Image.new_from_pixbuf(existing_preview_pixbuf)
    label_l = Gtk.Label(label=_("Imported brush"))
    label_r = Gtk.Label(label=_("Existing brush"))

    question = Gtk.Label(label=_(
        u"<b>A brush named “{brush_name}” already exists.</b>\n"
        u"Do you want to replace it, "
        u"or should the new brush be renamed?").format(brush_name=brushname, ))
    question.set_use_markup(True)

    preview_l = image_new_from_png_data(imported_preview_data)

    vbox_l.pack_start(preview_l, True, True, 0)
    vbox_l.pack_start(label_l, False, True, 0)

    vbox_r.pack_start(preview_r, True, True, 0)
    vbox_r.pack_start(label_r, False, True, 0)

    hbox.pack_start(vbox_l, False, True, 0)
    hbox.pack_start(question, True, True, 0)
    hbox.pack_start(vbox_r, False, True, 0)
    hbox.show_all()

    dialog.vbox.pack_start(hbox, True, True, 0)

    answer = dialog.run()
    dialog.destroy()
    return answer
    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()
Exemple #7
0
    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()