Exemple #1
0
    def add_to_grid(self, grid, row):
        for c in self._confmap.values():
            c.setup_preference(self.get_prefpath())

        outgrid = grid
        outrow = row
        if self.label is not None:
            self._expander = Gtk.Expander(label=self.label)
            self._expander.set_expanded(self.expanded)
            outgrid = Gtk.Grid()
            self._expander.add(outgrid)
            grid.attach(self._expander, 1, row, 1, 1)
            outrow = 0
            row += 1

        if self.removable:
            self._remove_btn = Gtk.Button(label="Remove")
            self._remove_btn.connect("clicked", self.remove)
            outgrid.attach(self._remove_btn, 0, outrow, 2, 1)
            outrow += 1

        for c in self._confmap.values():
            outrow = c.add_to_grid(outgrid, outrow)

        for sc in self._subconfigs:
            outrow = sc.add_to_grid(outgrid, outrow)

        if self.label is not None:
            return row
        return outrow
Exemple #2
0
 def _make_image_button(text, icon_name, cb):
     b = Gtk.Button(label=text)
     i = Gtk.Image()
     i.set_from_icon_name(icon_name, Gtk.IconSize.BUTTON)
     b.set_image(i)
     b.set_image_position(Gtk.PositionType.TOP)
     b.connect("clicked", cb)
     b.set_can_focus(False)
     b.set_can_default(False)
     return b
Exemple #3
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 #5
0
 def __init__(self, parent, target):
     super(HCYMaskTemplateDialog, self).__init__(
         title=C_(
             u"HCY Gamut Mask new-from-template dialog: window title",
             "New Gamut Mask from Template",
         ),
         transient_for=parent,
         modal=True,
         destroy_with_parent=True,
         window_position=Gtk.WindowPosition.MOUSE,
     )
     self.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT)
     target_mgr = target.get_color_manager()
     prefs_ro = deepcopy(target_mgr.get_prefs())
     datapath = target_mgr.get_data_path()
     mgr = ColorManager(prefs=prefs_ro, datapath=datapath)
     mgr.set_wheel_type(target_mgr.get_wheel_type())
     self.target = target
     for name, desc, mask_shapes_float in self.__templates:
         mask = []
         for mask_shape_float in mask_shapes_float:
             shape = []
             for h, c, y in mask_shape_float:
                 h = mgr.undistort_hue(h)
                 shape.append(HCYColor(h, c, y))
             mask.append(shape)
         label = Gtk.Label()
         label.set_markup("<b>%s</b>\n\n%s" % (name, desc))
         label.set_size_request(375, -1)
         label.set_line_wrap(True)
         label.set_alignment(0, 0.5)
         preview = HCYMaskPreview()
         preview.set_color_manager(mgr)
         preview.set_mask(mask)
         preview_frame = Gtk.AspectFrame(obey_child=True)
         preview_frame.add(preview)
         preview_frame.set_shadow_type(Gtk.ShadowType.NONE)
         hbox = Gtk.HBox()
         hbox.set_spacing(6)
         hbox.pack_start(preview_frame, False, False, 0)
         hbox.pack_start(label, True, True, 0)
         button = Gtk.Button()
         button.add(hbox)
         button.set_relief(Gtk.ReliefStyle.NONE)
         button.connect("clicked", self.__button_clicked_cb, mask)
         self.vbox.pack_start(button, True, True, 0)
     self.connect("response", self.__response_cb)
     self.connect("show", self.__show_cb)
     for w in self.vbox:
         w.show_all()
     ref_color = target.get_managed_color()
     mgr.set_color(ref_color)
Exemple #6
0
    def __init__(self):
        from gui import application
        app = application.get_app()
        assert app is not None

        windowing.Dialog.__init__(self,
                                  app=app,
                                  title=_('Background'),
                                  modal=True)
        self.add_button(_('Save as Default'), RESPONSE_SAVE_AS_DEFAULT)
        self.add_button(Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT)

        self._current_background_pixbuf = None  # set when changed

        # Set up window.
        self.connect('response', self._response_cb)

        notebook = self.nb = Gtk.Notebook()
        self.vbox.pack_start(notebook, True, True, 0)

        # Set up patterns tab.
        patterns_scroll = Gtk.ScrolledWindow()
        patterns_scroll.set_policy(
            Gtk.PolicyType.NEVER,
            Gtk.PolicyType.AUTOMATIC,
        )
        notebook.append_page(patterns_scroll, Gtk.Label(label=_('Pattern')))

        self.bgl = BackgroundList(self)
        patterns_scroll.add(self.bgl)

        self.connect("realize", self._realize_cb)
        self.connect("show", self._show_cb)
        self.connect("hide", self._hide_cb)

        # Set up colors tab.
        color_vbox = Gtk.VBox()
        notebook.append_page(color_vbox, Gtk.Label(label=_('Color')))

        self.cs = Gtk.ColorSelection()
        self.cs.connect('color-changed', self._color_changed_cb)
        color_vbox.pack_start(self.cs, True, True, 0)

        b = Gtk.Button(label=_('Add color to Patterns'))
        b.connect('clicked', self._add_color_to_patterns_cb)
        color_vbox.pack_start(b, False, True, 0)
Exemple #7
0
def borderless_button(stock_id=None,
                      icon_name=None,
                      size=ICON_SIZE_SMALL,
                      tooltip=None,
                      action=None):
    """Create a button styled to be borderless.

    >>> borderless_button(icon_name="mypaint")  # doctest: +ELLIPSIS
    <Gtk.Button...>

    """
    button = Gtk.Button()
    if stock_id is not None:
        image = Gtk.Image()
        image.set_from_stock(stock_id, size)
        set_margins(image, 0)
        button.add(image)
    elif icon_name is not None:
        image = Gtk.Image()
        image.set_from_icon_name(icon_name, size)
        set_margins(image, 0)
        button.add(image)
    elif action is not None:
        button.set_related_action(action)
        if button.get_child() is not None:
            button.remove(button.get_child())
        img = action.create_icon(size)
        img.set_padding(4, 4)
        set_margins(img, 0)
        button.add(img)
    button.set_relief(Gtk.ReliefStyle.NONE)
    button.set_can_default(False)
    button.set_can_focus(False)
    set_margins(button, 0)
    if tooltip is not None:
        button.set_tooltip_text(tooltip)
    elif action is not None:
        button.set_tooltip_text(action.get_tooltip())
    cssprov = Gtk.CssProvider()
    cssprov.load_from_data(b"GtkButton { padding: 0px; margin: 0px; }")
    style = button.get_style_context()
    style.add_provider(cssprov, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
    button.set_has_tooltip(tooltip is not None)
    return button
Exemple #8
0
def borderless_button(stock_id=None,
                      icon_name=None,
                      size=Gtk.IconSize.SMALL_TOOLBAR,
                      tooltip=None):
    button = Gtk.Button()
    if stock_id is not None:
        image = Gtk.Image()
        image.set_from_stock(stock_id, size)
        button.add(image)
    elif icon_name is not None:
        image = Gtk.Image()
        image.set_from_icon_name(icon_name, size)
        button.add(image)
    button.set_name("borderless-button")
    button.set_relief(Gtk.ReliefStyle.NONE)
    button.set_can_default(False)
    button.set_can_focus(False)
    has_tooltip = tooltip is not None
    if has_tooltip:
        button.set_tooltip_text(tooltip)
    button.set_has_tooltip(has_tooltip)
    return button
Exemple #9
0
    def _init_ui(self):
        # Dialog for editing dimensions (width, height, DPI)
        app = self.app
        buttons = (Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT)
        self._size_dialog = windowing.Dialog(
            app, _("Frame Size"), app.drawWindow,
            buttons=buttons
        )
        unit = _('px')

        height_label = self._new_key_label(_('Height:'))
        width_label = self._new_key_label(_('Width:'))
        dpi_label1 = self._new_key_label(_('Resolution:'))

        dpi_label2 = Gtk.Label(label=_('DPI'))
        dpi_label2.set_alignment(0.0, 0.5)
        dpi_label2.set_hexpand(False)
        dpi_label2.set_vexpand(False)
        dpi_label2.set_tooltip_text(
            _("Dots Per Inch (really Pixels Per Inch)")
        )

        color_label = Gtk.Label(label=_('Color:'))
        color_label.set_alignment(0.0, 0.5)

        height_entry = Gtk.SpinButton(
            adjustment=self.height_adj,
            climb_rate=0.25,
            digits=0
        )
        height_entry.set_vexpand(False)
        height_entry.set_hexpand(True)
        self.height_adj.set_spin_button(height_entry)

        width_entry = Gtk.SpinButton(
            adjustment=self.width_adj,
            climb_rate=0.25,
            digits=0
        )
        width_entry.set_vexpand(False)
        width_entry.set_hexpand(True)
        self.width_adj.set_spin_button(width_entry)

        dpi_entry = Gtk.SpinButton(
            adjustment=self.dpi_adj,
            climb_rate=0.0,
            digits=0
        )
        dpi_entry.set_vexpand(False)
        dpi_entry.set_hexpand(True)

        color_button = Gtk.ColorButton()
        color_rgba = self.app.preferences.get("frame.color_rgba")
        color_rgba = [min(max(c, 0), 1) for c in color_rgba]
        color_gdk = uicolor.to_gdk_color(RGBColor(*color_rgba[0:3]))
        color_alpha = int(65535 * color_rgba[3])
        color_button.set_color(color_gdk)
        color_button.set_use_alpha(True)
        color_button.set_alpha(color_alpha)
        color_button.set_title(_("Frame Color"))
        color_button.connect("color-set", self._color_set_cb)
        color_align = Gtk.Alignment.new(0, 0.5, 0, 0)
        color_align.add(color_button)

        size_grid = Gtk.Grid()
        size_grid.set_border_width(12)

        size_grid.set_row_spacing(6)
        size_grid.set_column_spacing(6)

        unit_combobox = Gtk.ComboBoxText()
        for unit in UnitAdjustment.CONVERT_UNITS.keys():
            unit_combobox.append_text(unit)
        for i, key in enumerate(UnitAdjustment.CONVERT_UNITS):
            if key == _('px'):
                unit_combobox.set_active(i)
        unit_combobox.connect('changed', self.on_unit_changed)
        unit_combobox.set_hexpand(False)
        unit_combobox.set_vexpand(False)
        self._unit_combobox = unit_combobox

        row = 0
        label = self._new_header_label(_("<b>Frame dimensions</b>"))
        label.set_margin_top(0)
        size_grid.attach(label, 0, row, 3, 1)

        row += 1
        size_grid.attach(width_label, 0, row, 1, 1)
        size_grid.attach(width_entry, 1, row, 1, 1)
        size_grid.attach(unit_combobox, 2, row, 1, 1)

        row += 1
        size_grid.attach(height_label, 0, row, 1, 1)
        size_grid.attach(height_entry, 1, row, 1, 1)

        row += 1
        label = self._new_header_label(_("<b>Pixel density</b>"))
        size_grid.attach(label, 0, row, 3, 1)

        row += 1
        size_grid.attach(dpi_label1, 0, row, 1, 1)
        size_grid.attach(dpi_entry, 1, row, 1, 1)
        size_grid.attach(dpi_label2, 2, row, 1, 1)

        # Options panel UI
        opts_table = Gtk.Table(3, 3)
        opts_table.set_border_width(3)
        xopts = Gtk.AttachOptions.FILL | Gtk.AttachOptions.EXPAND
        yopts = Gtk.AttachOptions.FILL
        xpad = ypad = 3

        row = 0
        size_button = Gtk.Button(label="<size-summary>")
        self._size_button = size_button
        size_button.connect("clicked", self._size_button_clicked_cb)
        opts_table.attach(size_button, 0, 2, row, row+1,
                          xopts, yopts, xpad, ypad)

        row += 1
        opts_table.attach(color_label, 0, 1, row, row+1,
                          xopts, yopts, xpad, ypad)
        opts_table.attach(color_align, 1, 2, row, row+1,
                          xopts, yopts, xpad, ypad)

        crop_layer_button = Gtk.Button(label=_('Set Frame to Layer'))
        crop_layer_button.set_tooltip_text(_("Set frame to the extents of "
                                             "the current layer"))
        crop_document_button = Gtk.Button(label=_('Set Frame to Document'))
        crop_document_button.set_tooltip_text(_("Set frame to the combination "
                                                "of all layers"))
        crop_layer_button.connect('clicked', self.crop_frame_cb,
                                  'CropFrameToLayer')
        crop_document_button.connect('clicked', self.crop_frame_cb,
                                     'CropFrameToDocument')

        trim_button = Gtk.Button()
        trim_action = self.app.find_action("TrimLayer")
        trim_button.set_related_action(trim_action)
        trim_button.set_label(_('Trim Layer to Frame'))
        trim_button.set_tooltip_text(_("Trim parts of the current layer "
                                       "which lie outside the frame"))

        self.enable_button = Gtk.CheckButton()
        frame_toggle_action = self.app.find_action("FrameToggle")
        self.enable_button.set_related_action(frame_toggle_action)
        self.enable_button.set_label(_('Enabled'))

        row += 1
        opts_table.attach(self.enable_button, 1, 2, row, row+1,
                          xopts, yopts, xpad, ypad)

        row += 1
        opts_table.attach(crop_layer_button, 0, 2, row, row+1,
                          xopts, yopts, xpad, ypad)

        row += 1
        opts_table.attach(crop_document_button, 0, 2, row, row+1,
                          xopts, yopts, xpad, ypad)

        row += 1
        opts_table.attach(trim_button, 0, 2, row, row+1,
                          xopts, yopts, xpad, ypad)

        content_area = self._size_dialog.get_content_area()
        content_area.pack_start(size_grid, True, True, 0)

        self._size_dialog.connect('response', self._size_dialog_response_cb)

        self.add(opts_table)
Exemple #10
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
Exemple #11
0
        )
        Gtk.show_uri(None, report_url, Gdk.CURRENT_TIME)
    else:
        dialog.destroy()
        exception_dialog_active = False


original_excepthook = sys.excepthook
sys.excepthook = _info
exception_dialog_active = False


if __name__ == '__main__':
    import sys
    import os

    def _test_button_clicked_cb(*a):
        class _TestException (Exception):
            pass
        raise _TestException("That was supposed to happen.")

    win = Gtk.Window()
    win.set_size_request(200, 150)
    win.set_title(os.path.basename(sys.argv[0]))
    btn = Gtk.Button(label="Break it")
    btn.connect("clicked", _test_button_clicked_cb)
    win.add(btn)
    win.connect("destroy", lambda *a: Gtk.main_quit())
    win.show_all()
    Gtk.main()
Exemple #12
0
    def __init__(self):
        Gtk.Grid.__init__(self)

        self.set_row_spacing(6)
        self.set_column_spacing(6)
        from gui.application import get_app
        self.app = get_app()
        prefs = self.app.preferences

        row = 0
        label = Gtk.Label()
        label.set_markup(
            C_(
                "fill options: numeric value that determines whether tested pixels"
                " will be included in the fill, based on color difference",
                u"Tolerance:"))
        label.set_tooltip_text(
            C_(
                "fill options: Tolerance (tooltip) "
                "Note: 'the start' refers to the color of "
                "the starting point (pixel) of the fill",
                u"How much pixel colors are allowed to vary from the start\n"
                u"before Flood Fill will refuse to fill them"))
        label.set_alignment(1.0, 0.5)
        label.set_hexpand(False)
        self.attach(label, 0, row, 1, 1)
        value = prefs.get(self.TOLERANCE_PREF, self.DEFAULT_TOLERANCE)
        value = float(value)
        adj = Gtk.Adjustment(value=value,
                             lower=0.0,
                             upper=1.0,
                             step_increment=0.05,
                             page_increment=0.05,
                             page_size=0)
        adj.connect("value-changed", self._tolerance_changed_cb)
        self._tolerance_adj = adj
        scale = Gtk.Scale()
        scale.set_hexpand(True)
        scale.set_adjustment(adj)
        scale.set_draw_value(False)
        self.attach(scale, 1, row, 1, 1)

        row += 1
        label = Gtk.Label()
        label.set_markup(
            C_(
                "fill options: option category (label) "
                "Options under this category relate to what the fill is"
                "based on, not where the actual fill ends up.", u"Source:"))
        label.set_tooltip_text(
            C_("fill options: 'Source:' category (tooltip)",
               u"The input that the fill will be based on"))
        label.set_alignment(1.0, 0.5)
        label.set_hexpand(False)
        self.attach(label, 0, row, 1, 1)

        # Selection independent fill-basis

        root = self.app.doc.model.layer_stack
        src_list = FlatLayerList(root)
        self.src_list = src_list
        combo = Gtk.ComboBox.new_with_model(src_list)
        cell = Gtk.CellRendererText()
        cell.set_property("ellipsize", Pango.EllipsizeMode.END)
        combo.pack_start(cell, True)

        def layer_name_render(_, name_cell, model, it):
            """
            Display layer groups in italics and child layers
            indented with two spaces per level
            """
            name, path, layer = model[it][:3]
            if name is None:
                name = "Layer"
            if layer is None:
                name_cell.set_property("markup",
                                       "( <i>{text}</i> )".format(text=name))
                return
            indented = "  " * (len(path) - 1) + name
            if isinstance(layer, lib.layer.LayerStack):
                name_cell.set_property("markup",
                                       "<i>{text}</i>".format(text=indented))
            else:
                name_cell.set_property("text", indented)

        def sep_func(model, it):
            return model[it][0] is None

        combo.set_row_separator_func(sep_func)
        combo.set_cell_data_func(cell, layer_name_render)
        combo.set_tooltip_text(
            C_("fill options: 'Source' category: Layer dropdown (tooltip)",
               u"Select a specific layer you want the fill to be based on"))
        combo.set_active(0)
        self._prev_src_layer = None
        root.layer_inserted += self._layer_inserted_cb
        self._src_combo_cb_id = combo.connect("changed",
                                              self._src_combo_changed_cb)
        self._src_combo = combo
        self.attach(combo, 1, row, 2, 1)

        row += 1

        text = C_(
            "fill options: 'Source:' category: toggle (label)\n"
            "When this option is enabled, the fill is based\n"
            "on the combination of all visible layers", u"Sample Merged")
        checkbut = Gtk.CheckButton.new_with_label(text)
        checkbut.set_tooltip_text(
            C_(
                "fill options: Sample Merged (tooltip)",
                u"When considering which area to fill, use a\n"
                u"temporary merge of all the visible layers\n"
                u"underneath the current layer"))
        self.attach(checkbut, 1, row, 1, 1)
        active = bool(
            prefs.get(self.SAMPLE_MERGED_PREF, self.DEFAULT_SAMPLE_MERGED))
        checkbut.set_active(active)
        checkbut.connect("toggled", self._sample_merged_toggled_cb)
        self._sample_merged_toggle = checkbut
        self._src_combo.set_sensitive(not active)

        row += 1

        text = C_(
            "fill options: toggle whether the fill will be limited "
            "by the viewport", u"Limit to View")
        checkbut = Gtk.CheckButton.new_with_label(text)
        checkbut.set_tooltip_text(
            C_(
                "fill options: Limit to View (tooltip)\n"
                "Note: 'that can fit the view' is equivalent to: "
                "'in which the entire visible part of the canvas can fit",
                u"Limit the area that can be filled, based on the viewport.\n"
                u"If the view is rotated, the fill will be limited to the\n"
                u"smallest canvas-aligned rectangle that can fit the view."))
        self.attach(checkbut, 1, row, 1, 1)
        active = bool(
            prefs.get(self.LIM_TO_VIEW_PREF, self.DEFAULT_LIM_TO_VIEW))
        checkbut.set_active(active)
        checkbut.connect("toggled", self._limit_to_view_toggled_cb)
        self._limit_to_view_toggle = checkbut

        row += 1
        label = Gtk.Label()
        label.set_markup(
            C_(
                "fill options: option category (label)\n"
                "Options under this category relate to where the fill "
                "will end up (default: the active layer) and how it "
                "will be combined with that layer.", u"Target:"))
        label.set_tooltip_text(
            C_("fill options: 'Target:' category (tooltip)",
               u"Where the output should go"))
        label.set_alignment(1.0, 0.5)
        label.set_hexpand(False)
        self.attach(label, 0, row, 1, 1)

        text = C_(
            "fill options: Target | toggle (label)\n"
            "When this option is enabled, the fill will be placed on a new\n"
            "layer above the active layer. Option resets after each fill.",
            u"New Layer (once)")
        checkbut = Gtk.CheckButton.new_with_label(text)
        checkbut.set_tooltip_text(
            C_(
                "fill options: Target | New Layer (tooltip)",
                u"Create a new layer with the results of the fill.\n"
                u"This is turned off automatically after use."))
        self.attach(checkbut, 1, row, 1, 1)
        active = self.DEFAULT_MAKE_NEW_LAYER
        checkbut.set_active(active)
        self._make_new_layer_toggle = checkbut

        row += 1
        label = Gtk.Label()
        label.set_markup(u"<b>\u26a0</b>")  # unicode warning sign
        label.set_tooltip_text(
            C_("fill options: Target | Blend Mode dropdown - warning text",
               u"This mode does nothing when alpha locking is enabled!"))
        label.set_alignment(1.0, 0.5)
        label.set_hexpand(False)
        self._warning_shown = False
        # Not attached here, warning label is only shown for no-op combinations
        self._bm_warning_label = (label, 0, row, 1, 1)

        modes = list(lib.modes.STANDARD_MODES)
        modes.remove(lib.mypaintlib.CombineSpectralWGM)
        modes.insert(0, lib.mypaintlib.CombineSpectralWGM)
        combo = gui.layers.new_blend_mode_combo(modes, lib.modes.MODE_STRINGS)
        combo.set_tooltip_text(
            C_("fill options: Target | Blend Mode dropdown (tooltip)",
               u"Blend mode used when filling"))
        # Reinstate the last _mode id_ independent of mode-list order
        mode_type = prefs.get(self.BLEND_MODE_PREF, self.DEFAULT_BLEND_MODE)
        mode_dict = {mode: index for index, mode, in enumerate(modes)}
        # Fallback is only necessary for compat. if a mode is ever removed
        active = mode_dict.get(int(mode_type), self.DEFAULT_BLEND_MODE)
        combo.set_active(active)
        combo.connect("changed", self._bm_combo_changed_cb)
        self._blend_mode_combo = combo
        self.attach(combo, 1, row, 2, 1)

        row += 1
        label = Gtk.Label()
        label.set_markup(_(u"Opacity:"))
        label.set_tooltip_text(
            C_("fill options: Opacity slider (tooltip)",
               u"Opacity of the fill"))
        label.set_alignment(1.0, 0.5)
        label.set_hexpand(False)
        self.attach(label, 0, row, 1, 1)
        value = prefs.get(self.OPACITY_PREF, self.DEFAULT_OPACITY)
        adj = Gtk.Adjustment(value=value,
                             lower=0.0,
                             upper=1.0,
                             step_increment=0.05,
                             page_increment=0.05,
                             page_size=0)
        adj.connect("value-changed", self._opacity_changed_cb)
        self._opacity_adj = adj
        scale = Gtk.Scale()
        scale.set_hexpand(True)
        scale.set_adjustment(adj)
        scale.set_draw_value(False)
        self.attach(scale, 1, row, 1, 1)

        row += 1
        self.attach(Gtk.Separator(), 0, row, 2, 1)

        row += 1
        label = Gtk.Label()
        label.set_markup(
            C_("fill options: numeric option - grow/shrink fill (label)",
               u"Offset:"))
        label.set_alignment(1.0, 0.5)
        label.set_hexpand(False)
        self.attach(label, 0, row, 1, 1)

        TILE_SIZE = lib.floodfill.TILE_SIZE
        value = prefs.get(self.OFFSET_PREF, self.DEFAULT_OFFSET)
        adj = Gtk.Adjustment(value=value,
                             lower=-TILE_SIZE,
                             upper=TILE_SIZE,
                             step_increment=1,
                             page_increment=4)
        adj.connect("value-changed", self._offset_changed_cb)
        self._offset_adj = adj
        spinbut = Gtk.SpinButton()
        spinbut.set_tooltip_text(
            C_("fill options: Offset (tooltip)",
               u"The distance in pixels to grow or shrink the fill"))
        spinbut.set_hexpand(True)
        spinbut.set_adjustment(adj)
        spinbut.set_numeric(True)
        self.attach(spinbut, 1, row, 1, 1)

        row += 1
        label = Gtk.Label()
        label.set_markup(
            C_("fill options: numeric option for blurring fill (label)",
               u"Feather:"))
        label.set_alignment(1.0, 0.5)
        label.set_hexpand(False)
        self.attach(label, 0, row, 1, 1)

        value = prefs.get(self.FEATHER_PREF, self.DEFAULT_FEATHER)
        adj = Gtk.Adjustment(value=value,
                             lower=0,
                             upper=TILE_SIZE,
                             step_increment=1,
                             page_increment=4)
        adj.connect("value-changed", self._feather_changed_cb)
        self._feather_adj = adj
        spinbut = Gtk.SpinButton()
        spinbut.set_tooltip_text(
            C_("fill options: Feather (tooltip)",
               u"The amount of blur to apply to the fill"))
        spinbut.set_hexpand(True)
        spinbut.set_adjustment(adj)
        spinbut.set_numeric(True)
        self.attach(spinbut, 1, row, 1, 1)

        row += 1
        self.attach(Gtk.Separator(), 0, row, 2, 1)

        row += 1
        gap_closing_params = Gtk.Grid()
        self._gap_closing_grid = gap_closing_params

        text = C_("fill options: gap detection toggle (label)",
                  u'Use Gap Detection')
        checkbut = Gtk.CheckButton.new_with_label(text)
        checkbut.set_tooltip_text(
            C_(
                "fill options: Use Gap Detection (tooltip)",
                u"Try to detect gaps and not fill past them.\n"
                u"Note: This can be a lot slower than the regular fill, "
                u"only enable when you need it."))
        self._gap_closing_toggle = checkbut
        checkbut.connect("toggled", self._gap_closing_toggled_cb)
        active = prefs.get(self.GAP_CLOSING_PREF, self.DEFAULT_GAP_CLOSING)
        checkbut.set_active(active)
        gap_closing_params.set_sensitive(active)
        self.attach(checkbut, 0, row, 2, 1)

        row += 1
        self.attach(gap_closing_params, 0, row, 2, 1)

        gcp_row = 0
        label = Gtk.Label()
        label.set_markup(
            C_(
                "fill options: gap-detection sub-option, numeric setting (label)",
                u"Max Gap Size:"))
        label.set_alignment(1.0, 0.5)
        label.set_hexpand(False)
        gap_closing_params.attach(label, 0, gcp_row, 1, 1)

        value = prefs.get(self.GAP_SIZE_PREF, self.DEFAULT_GAP_SIZE)
        adj = Gtk.Adjustment(value=value,
                             lower=1,
                             upper=int(TILE_SIZE / 2),
                             step_increment=1,
                             page_increment=4)
        adj.connect("value-changed", self._max_gap_size_changed_cb)
        self._max_gap_adj = adj
        spinbut = Gtk.SpinButton()
        spinbut.set_tooltip_text(
            C_(
                "fill options: Max Gap Size (tooltip)",
                u"The size of the largest gaps that can be detected.\n"
                u"Using large values can make the fill run a lot slower."))
        spinbut.set_hexpand(True)
        spinbut.set_adjustment(adj)
        spinbut.set_numeric(True)
        gap_closing_params.attach(spinbut, 1, gcp_row, 1, 1)

        gcp_row += 1
        text = C_(
            "fill options: on/off sub-option, numeric (label)\n"
            "When enabled, if the fill stops after going past a detected gap, "
            "it 'pulls' the fill back out of the gap to the other side of it.",
            u"Prevent seeping")
        checkbut = Gtk.CheckButton.new_with_label(text)
        active = prefs.get(self.RETRACT_SEEPS_PREF, self.DEFAULT_RETRACT_SEEPS)
        checkbut.set_active(active)
        checkbut.set_tooltip_text(
            C_(
                "fill options: Prevent seeping (tooltip)",
                u"Try to prevent the fill from seeping into the gaps.\n"
                u"If a fill starts in a detected gap, this option will do nothing."
            ))
        checkbut.connect("toggled", self._retract_seeps_toggled_cb)
        self._retract_seeps_toggle = checkbut
        gap_closing_params.attach(checkbut, 1, gcp_row, 1, 1)

        row += 1
        align = Gtk.Alignment.new(0.5, 1.0, 1.0, 0.0)
        align.set_vexpand(True)
        button = Gtk.Button(label=_("Reset"))
        button.connect("clicked", self._reset_clicked_cb)
        button.set_tooltip_text(
            C_("fill options: Reset button (tooltip)",
               "Reset options to their defaults"))
        align.add(button)
        self.attach(align, 0, row, 2, 1)

        # Set up blend modifier callbacks
        self.bm = self.get_blend_modes()
        self.bm.mode_changed += self.update_blend_mode
Exemple #13
0
    def _init_ui(self):
        app = self.app

        # Dialog for showing and editing the axis value directly
        buttons = (Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT)
        dialog = gui.windowing.Dialog(
            app, C_(
                "symmetry axis options panel: "
                "axis position dialog: window title",
                u"X axis Position",
            ),
            app.drawWindow,
            buttons=buttons,
        )
        dialog.connect('response', self._axis_pos_dialog_response_cb)
        grid = Gtk.Grid()
        grid.set_border_width(gui.widgets.SPACING_LOOSE)
        grid.set_column_spacing(gui.widgets.SPACING)
        grid.set_row_spacing(gui.widgets.SPACING)
        label = Gtk.Label(label=self._POSITION_LABEL_X_TEXT)
        label.set_hexpand(False)
        label.set_vexpand(False)
        grid.attach(label, 0, 0, 1, 1)
        entry = Gtk.SpinButton(
            adjustment=self._axis_pos_adj_x,
            climb_rate=0.25,
            digits=0
        )
        entry.set_hexpand(True)
        entry.set_vexpand(False)
        grid.attach(entry, 1, 0, 1, 1)
        dialog_content_box = dialog.get_content_area()
        dialog_content_box.pack_start(grid, True, True, 0)
        self._axis_pos_x_dialog = dialog

        # Dialog for showing and editing the axis value directly
        buttons = (Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT)
        dialog = gui.windowing.Dialog(
            app, C_(
                "symmetry axis options panel: "
                "axis position dialog: window title",
                u"Y axis Position",
            ),
            app.drawWindow,
            buttons=buttons,
        )
        dialog.connect('response', self._axis_pos_dialog_response_cb)
        grid = Gtk.Grid()
        grid.set_border_width(gui.widgets.SPACING_LOOSE)
        grid.set_column_spacing(gui.widgets.SPACING)
        grid.set_row_spacing(gui.widgets.SPACING)
        label = Gtk.Label(label=self._POSITION_LABEL_Y_TEXT)
        label.set_hexpand(False)
        label.set_vexpand(False)
        grid.attach(label, 0, 0, 1, 1)
        entry = Gtk.SpinButton(
            adjustment=self._axis_pos_adj_y,
            climb_rate=0.25,
            digits=0
        )
        entry.set_hexpand(True)
        entry.set_vexpand(False)
        grid.attach(entry, 1, 0, 1, 1)
        dialog_content_box = dialog.get_content_area()
        dialog_content_box.pack_start(grid, True, True, 0)
        self._axis_pos_y_dialog = dialog

        # Layout grid
        row = 0
        grid = Gtk.Grid()
        grid.set_border_width(gui.widgets.SPACING_CRAMPED)
        grid.set_row_spacing(gui.widgets.SPACING_CRAMPED)
        grid.set_column_spacing(gui.widgets.SPACING_CRAMPED)
        self.add(grid)

        row += 1
        label = Gtk.Label(label=self._ALPHA_LABEL_TEXT)
        label.set_hexpand(False)
        label.set_halign(Gtk.Align.START)
        grid.attach(label, 0, row, 1, 1)
        scale = Gtk.Scale.new_with_range(
            orientation = Gtk.Orientation.HORIZONTAL,
            min = 0,
            max = 1,
            step = 0.1,
        )
        scale.set_draw_value(False)
        line_alpha = self.app.preferences.get(_ALPHA_PREFS_KEY, _DEFAULT_ALPHA)
        scale.set_value(line_alpha)
        scale.set_hexpand(True)
        scale.set_vexpand(False)
        scale.connect("value-changed", self._scale_value_changed_cb)
        grid.attach(scale, 1, row, 1, 1)

        row += 1
        store = Gtk.ListStore(int, str)
        sym_types = lib.tiledsurface.SYMMETRY_TYPES
        active_idx = 0
        rootstack = self.app.doc.model.layer_stack
        starts_with_rotate = (
            rootstack.symmetry_type in
            {
                lib.mypaintlib.SymmetryRotational,
                lib.mypaintlib.SymmetrySnowflake,
            }
        )
        for i, sym_type in enumerate(sym_types):
            label = lib.tiledsurface.SYMMETRY_STRINGS.get(sym_type)
            store.append([sym_type, label])
            if sym_type == rootstack.symmetry_type:
                active_idx = i
        self._symmetry_type_combo = Gtk.ComboBox()
        self._symmetry_type_combo.set_model(store)
        self._symmetry_type_combo.set_active(active_idx)
        self._symmetry_type_combo.set_hexpand(True)
        cell = Gtk.CellRendererText()
        self._symmetry_type_combo.pack_start(cell, True)
        self._symmetry_type_combo.add_attribute(cell, "text", 1)
        self._symmetry_type_combo.connect(
            'changed',
            self._symmetry_type_combo_changed_cb
        )
        label = Gtk.Label(label=self._SYMMETRY_TYPE_TEXT)
        label.set_hexpand(False)
        label.set_halign(Gtk.Align.START)
        grid.attach(label, 0, row, 1, 1)
        grid.attach(self._symmetry_type_combo, 1, row, 1, 1)

        row += 1
        label = Gtk.Label(label=self._SYMMETRY_ROT_LINES_TEXT)
        label.set_hexpand(False)
        label.set_halign(Gtk.Align.START)
        self._axis_rot_sym_lines_entry = Gtk.SpinButton(
            adjustment=self._axis_rot_symmetry_lines,
            climb_rate=0.25
        )
        grid.attach(label, 0, row, 1, 1)
        grid.attach(self._axis_rot_sym_lines_entry, 1, row, 1, 1)

        row += 1
        label = Gtk.Label(label=self._POSITION_LABEL_X_TEXT)
        label.set_hexpand(False)
        label.set_halign(Gtk.Align.START)
        button = Gtk.Button(label=self._POSITION_BUTTON_TEXT_INACTIVE)
        button.set_vexpand(False)
        button.connect("clicked", self._axis_pos_x_button_clicked_cb)
        button.set_hexpand(True)
        button.set_vexpand(False)
        grid.attach(label, 0, row, 1, 1)
        grid.attach(button, 1, row, 1, 1)
        self._axis_pos_x_button = button

        row += 1
        label = Gtk.Label(label=self._POSITION_LABEL_Y_TEXT)
        label.set_hexpand(False)
        label.set_halign(Gtk.Align.START)
        button = Gtk.Button(label=self._POSITION_BUTTON_TEXT_INACTIVE)
        button.set_vexpand(False)
        button.connect("clicked", self._axis_pos_y_button_clicked_cb)
        button.set_hexpand(True)
        button.set_vexpand(False)
        grid.attach(label, 0, row, 1, 1)
        grid.attach(button, 1, row, 1, 1)
        self._axis_pos_y_button = button

        row += 1
        button = Gtk.CheckButton()
        toggle_action = self.app.find_action("SymmetryActive")
        button.set_related_action(toggle_action)
        button.set_label(C_(
            "symmetry axis options panel: axis active checkbox",
            u'Enabled',
        ))
        button.set_hexpand(True)
        button.set_vexpand(False)
        grid.attach(button, 1, row, 2, 1)
        self._axis_active_button = button
Exemple #14
0
    def __init__(self, parent, target):
        super(HCYMaskPropertiesDialog, self).__init__(
            title=C_(
                "HCY Gamut Mask Editor dialog: window title",
                u"Gamut Mask Editor",
            ),
            transient_for=parent,
            modal=True,
            destroy_with_parent=True,
            window_position=Gtk.WindowPosition.CENTER_ON_PARENT,
            buttons=(
                Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT,
                Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT,
            ),
        )
        self.target = target
        ed = HCYMaskEditorWheel()
        target_mgr = target.get_color_manager()
        prefs_ro = deepcopy(target_mgr.get_prefs())
        datapath = target_mgr.get_data_path()
        ed_mgr = ColorManager(prefs=prefs_ro, datapath=datapath)
        ed.set_color_manager(ed_mgr)
        self.editor = ed
        ed.set_size_request(300, 300)
        ed.mask_toggle.set_active(True)
        self.mask_toggle_ctrl = Gtk.CheckButton(
            C_(
                "HCY Gamut Mask Editor dialog: mask-is-active checkbox",
                u"Active",
            ),
            use_underline=False,
        )
        self.mask_toggle_ctrl.set_tooltip_text(ed.mask_toggle.get_tooltip())
        ed.mask_observers.append(self.__mask_changed_cb)

        hbox = Gtk.HBox()
        hbox.set_spacing(3)

        # Sidebar buttonbox
        # On the right and packed to the top. This places its secondary
        # control, a mask toggle button, next to the "OK" button so it's less
        # likely to be missed.
        bbox = Gtk.VButtonBox()
        new_btn = self.__new_button = Gtk.Button(stock=Gtk.STOCK_NEW)
        load_btn = self.__load_button = Gtk.Button(stock=Gtk.STOCK_OPEN)
        save_btn = self.__save_button = Gtk.Button(stock=Gtk.STOCK_SAVE)
        clear_btn = self.__clear_button = Gtk.Button(stock=Gtk.STOCK_CLEAR)

        help_btn = self.__help_button = Gtk.LinkButton.new_with_label(
            uri = MASK_EDITOR_HELP_URI,
            label = C_(
                "HCY Mask Editor: action button labels",
                u"Help…",
            ),
        )

        new_btn.set_tooltip_text(C_(
            "HCY Mask Editor: action button tooltips",
            u"Create mask from template."),
        )
        load_btn.set_tooltip_text(C_(
            "HCY Mask Editor: action button tooltips",
            u"Load mask from a GIMP palette file."),
        )
        save_btn.set_tooltip_text(C_(
            "HCY Mask Editor: action button tooltips",
            u"Save mask to a GIMP palette file."),
        )
        clear_btn.set_tooltip_text(C_(
            "HCY Mask Editor: action button tooltips",
            u"Erase the mask."),
        )
        help_btn.set_tooltip_text(C_(
            "HCY Mask Editor: action button tooltips",
            u"Open the online help for this dialog in a web browser."),
        )

        new_btn.connect("clicked", self.__new_clicked)
        save_btn.connect("clicked", self.__save_clicked)
        load_btn.connect("clicked", self.__load_clicked)
        clear_btn.connect("clicked", self.__clear_clicked)

        bbox.pack_start(new_btn, True, True, 0)
        bbox.pack_start(load_btn, True, True, 0)
        bbox.pack_start(save_btn, True, True, 0)
        bbox.pack_start(clear_btn, True, True, 0)

        action_area = self.get_action_area()
        if isinstance(action_area, Gtk.ButtonBox):
            action_area.pack_start(help_btn, True, True, 0)
            action_area.set_child_secondary(help_btn, True)
            action_area.set_child_non_homogeneous(help_btn, True)
            bbox.pack_start(self.mask_toggle_ctrl, True, True, 0)
            bbox.set_child_secondary(self.mask_toggle_ctrl, True)
        else:
            bbox.pack_start(self.mask_toggle_ctrl, True, True, 0)
            bbox.pack_start(help_btn, True, True, 0)
            bbox.set_child_secondary(help_btn, True)

        bbox.set_layout(Gtk.ButtonBoxStyle.START)

        hbox.pack_start(ed, True, True, 0)
        hbox.pack_start(bbox, False, False, 0)
        hbox.set_border_width(9)

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

        self.connect("response", self.__response_cb)
        self.connect("show", self.__show_cb)
        for w in self.vbox:
            w.show_all()
Exemple #15
0
def _test():
    logging.basicConfig(level=logging.DEBUG)
    import os
    import sys

    class _TestLabel(Gtk.Label):
        __gtype_name__ = 'TestLabel'
        tool_widget_icon_name = 'gtk-ok'
        tool_widget_description = "Just a test widget"

        def __init__(self, text):
            Gtk.Label.__init__(self, text)
            self.set_size_request(200, 150)

    class _TestSpinner(Gtk.Spinner):
        __gtype_name__ = "TestSpinner"
        tool_widget_icon_name = 'gtk-cancel'
        tool_widget_description = "Spinner test"

        def __init__(self):
            Gtk.Spinner.__init__(self)
            self.set_size_request(150, 150)
            self.set_property("active", True)

    def _tool_shown_cb(*a):
        logger.debug("TOOL-SHOWN %r", a)

    def _tool_hidden_cb(*a):
        logger.debug("TOOL-HIDDEN %r", a)

    def _floating_window_created(*a):
        logger.debug("FLOATING-WINDOW-CREATED %r", a)

    workspace = Workspace()
    workspace.floating_window_title_suffix = u" - Test"
    button = Gtk.Button(label="Click to close this demo")
    frame = Gtk.Frame()
    frame.add(button)
    frame.set_shadow_type(Gtk.ShadowType.IN)
    workspace.set_canvas(frame)
    window = Gtk.Window()
    window.add(workspace)
    window.set_title(os.path.basename(sys.argv[0]))
    workspace.set_size_request(600, 400)
    workspace.tool_widget_added += _tool_shown_cb
    workspace.tool_widget_removed += _tool_hidden_cb
    workspace.floating_window_created += _floating_window_created
    workspace.build_from_layout({
        'position': {
            'x': 100,
            'y': 75,
            'h': -100,
            'w': -100
        },
        'floating': [{
            'position': {
                'y': -100,
                'h': 189,
                'w': 152,
                'x': -200
            },
            'contents': {
                'groups': [{
                    'tools': [('TestLabel', "1"), ('TestLabel', "2")],
                }],
            }
        }],
        'right_sidebar': {
            'w': 400,
            'groups': [{
                'tools': [('TestSpinner', ), ("TestLabel", "3")],
            }],
        },
        'left_sidebar': {
            'w': 250,
            'groups': [{
                'tools': [('TestLabel', "4"), ('TestLabel', "5")],
            }],
        },
        'maximized':
        False,
        'fullscreen':
        True,
    })
    window.show_all()

    def _quit_cb(*a):
        logger.info("Demo quit, workspace dump follows")
        print(workspace.get_layout())
        Gtk.main_quit()

    window.connect("destroy", _quit_cb)
    button.connect("clicked", _quit_cb)
    Gtk.main()
Exemple #16
0
    def _init_ui(self):

        height_label = self._new_key_label(_('Height:'))
        width_label = self._new_key_label(_('Width:'))
        dpi_label1 = self._new_key_label(_('Resolution:'))

        dpi_label2 = self._new_key_label(_('DPI'))
        dpi_label2.set_tooltip_text(
            _("Dots Per Inch (really Pixels Per Inch)"))

        color_label = self._new_key_label(_('Color:'))

        height_entry = Gtk.SpinButton(adjustment=self.height_adj,
                                      climb_rate=0.25,
                                      digits=0)
        height_entry.set_vexpand(False)
        height_entry.set_hexpand(True)
        self.height_adj.set_spin_button(height_entry)

        width_entry = Gtk.SpinButton(adjustment=self.width_adj,
                                     climb_rate=0.25,
                                     digits=0)
        width_entry.set_vexpand(False)
        width_entry.set_hexpand(True)
        self.width_adj.set_spin_button(width_entry)

        dpi_entry = Gtk.SpinButton(adjustment=self.dpi_adj,
                                   climb_rate=0.0,
                                   digits=0)
        dpi_entry.set_vexpand(False)
        dpi_entry.set_hexpand(True)

        color_button = Gtk.ColorButton()
        color_rgba = self.app.preferences.get("frame.color_rgba")
        color_rgba = [min(max(c, 0), 1) for c in color_rgba]
        color_gdk = uicolor.to_gdk_color(RGBColor(*color_rgba[0:3]))
        color_alpha = int(65535 * color_rgba[3])
        color_button.set_color(color_gdk)
        color_button.set_use_alpha(True)
        color_button.set_alpha(color_alpha)
        color_button.set_title(_("Frame Color"))
        color_button.connect("color-set", self._color_set_cb)

        unit_combobox = Gtk.ComboBoxText()
        for unit in sorted(UnitAdjustment.CONVERT_UNITS.keys()):
            unit_combobox.append_text(_Unit.STRINGS[unit])
        unit_combobox.set_active(_Unit.PX)
        unit_combobox.connect('changed', self.on_unit_changed)
        unit_combobox.set_hexpand(False)
        unit_combobox.set_vexpand(False)
        self._unit_combobox = unit_combobox

        # Options panel UI
        self.set_border_width(3)
        self.set_row_spacing(6)
        self.set_column_spacing(6)

        row = 0

        self.enable_button = Gtk.CheckButton()
        frame_toggle_action = self.app.find_action("FrameToggle")
        self.enable_button.set_related_action(frame_toggle_action)
        self.enable_button.set_label(_('Enabled'))
        self.attach(self.enable_button, 0, row, 3, 1)

        row += 1
        label = self._new_header_label(_("<b>Frame dimensions</b>"))
        self.attach(label, 0, row, 3, 1)

        row += 1
        self.attach(width_entry, 1, row, 1, 1)
        self.attach(unit_combobox, 2, row, 1, 1)
        self.attach(width_label, 0, row, 1, 1)

        row += 1
        self.attach(height_label, 0, row, 1, 1)
        self.attach(height_entry, 1, row, 1, 1)

        row += 1
        self.attach(dpi_label1, 0, row, 1, 1)
        self.attach(dpi_entry, 1, row, 1, 1)
        self.attach(dpi_label2, 2, row, 1, 1)

        row += 1
        self.attach(color_label, 0, row, 1, 1)
        self.attach(color_button, 1, row, 3, 1)

        crop_layer_button = Gtk.Button(label=_('Set Frame to Layer'))
        crop_layer_button.set_tooltip_text(
            _("Set frame to the extents of "
              "the current layer"))
        crop_document_button = Gtk.Button(label=_('Set Frame to Document'))
        crop_document_button.set_tooltip_text(
            _("Set frame to the combination "
              "of all layers"))
        crop_layer_button.connect('clicked', self.crop_frame_cb,
                                  'CropFrameToLayer')
        crop_document_button.connect('clicked', self.crop_frame_cb,
                                     'CropFrameToDocument')

        trim_button = Gtk.Button()
        trim_action = self.app.find_action("TrimLayer")
        trim_button.set_related_action(trim_action)
        trim_button.set_label(_('Trim Layer to Frame'))
        trim_button.set_tooltip_text(
            _("Trim parts of the current layer "
              "which lie outside the frame"))

        row += 1
        self.attach(crop_layer_button, 0, row, 3, 1)

        row += 1
        self.attach(crop_document_button, 0, row, 3, 1)

        row += 1
        self.attach(trim_button, 0, row, 3, 1)