예제 #1
0
    def _get_gui_item(self):
        def _value_changed_cb(combo):
            self._set_value(combo.get_active_text())

        box = Gtk.ComboBoxText()
        items = self._items
        box.connect("changed", _value_changed_cb)
        if isinstance(self._items, dict):
            items = list(self._items.keys())
        for i in items:
            box.append_text(i)

        try:
            box.set_active(items.index(self._get_preference_value()))
        except ValueError:
            box.set_active(items.index(self._dfl_val))

        return box
    def _get_gui_item(self):

        grid = Gtk.Grid()

        self.xref = Gtk.ComboBoxText()
        self.yref = Gtk.Label()

        def _setup_slider(slider,
                          settype: SliderColorAdjuster,
                          reset_color=None):
            pos = slider.get_bar_amount_for_color(slider.managed_color)

            def forced_get_background_validity(slider):
                if slider.color_manager.force_redraw:
                    col = slider.get_managed_color()
                    if col.r > 0:
                        col = RGBColor(0, col.g, col.b)
                    else:
                        col = RGBColor(255, col.g, col.b)
                    slider.color_manager.force_redraw = False
                    return repr(col)
                return SliderColorAdjuster.get_background_validity(slider)

            setattr(
                slider,
                "get_background_validity",
                partial(forced_get_background_validity, slider),
            )
            setattr(
                slider,
                "get_color_for_bar_amount",
                partial(settype.get_color_for_bar_amount, slider),
            )
            setattr(
                slider,
                "get_bar_amount_for_color",
                partial(settype.get_bar_amount_for_color, slider),
            )
            setattr(slider, "samples", settype.samples)
            slider.color_manager.force_redraw = True

            if reset_color is not None:
                slider.color_manager.set_color(reset_color)
            newcol = slider.get_color_for_bar_amount(pos)
            slider.color_manager.set_color(newcol)

        def _update_xref(combo):
            xref = combo.get_active_text()
            v = self.get_value()
            if xref in v.references:
                v.xref = xref
                self._set_value(v)
                v = self.get_value()

                for r in v.references.keys():
                    if r == v.yref:
                        self.yref.set_text(r)

            _setup_slider(
                self._color_sliders["xmin"],
                v.references[v.xref][1],
                self._color_sliders["target"].managed_color,
            )
            _setup_slider(
                self._color_sliders["xmax"],
                v.references[v.xref][1],
                self._color_sliders["target"].managed_color,
            )
            _setup_slider(
                self._color_sliders["ymin"],
                v.references[v.yref][1],
                self._color_sliders["target"].managed_color,
            )
            _setup_slider(
                self._color_sliders["ymax"],
                v.references[v.yref][1],
                self._color_sliders["target"].managed_color,
            )

        def _update_refval(combo):
            ref = combo.get_active_text()
            if ref in self.__refs:
                oldv = self.get_value()
                newv = oldv
                if ref not in oldv.references:
                    for xr in self.__refs[ref].references.keys():
                        if xr != ref:
                            newv = self.__refs[ref](
                                ref,
                                oldv.target,
                                xr,
                                oldv.xrange,
                                oldv.yrange,
                                oldv.targetdelta,
                            )
                            break
                else:
                    newv.refval = ref
                    for xr in newv.references.keys():
                        if xr != ref:
                            newv.xref = xr
                            break
                self._set_value(newv)
                v = self.get_value()

                activeid = 0
                refs = list(v.references.keys())
                self.xref.remove_all()
                for r in range(len(refs)):
                    if refs[r] != v.refval:
                        self.xref.append_text(refs[r])
                        if refs[r] == v.xref:
                            activeid = r
                self.xref.set_active(activeid)

                _setup_slider(
                    self._color_sliders["target"],
                    v.references[v.refval][1],
                    v.base_color,
                )

            _update_xref(self.xref)

        rvbox = Gtk.ComboBoxText()
        rvbox.connect("changed", _update_refval)
        activeid = 0
        refs = list(self.__refs.keys())
        for r in range(len(refs)):
            rvbox.append_text(refs[r])
            if refs[r] == self.get_value().refval:
                activeid = r
        rvbox.set_active(activeid)

        grid.attach(rvbox, 0, 0, 1, 1)

        grid.attach(self._color_sliders["target"], 1, 0, 2, 1)

        self.xref.connect("changed", _update_xref)
        _update_refval(rvbox)

        grid.attach(self.xref, 0, 1, 1, 1)

        grid.attach(self._color_sliders["xmin"], 1, 1, 1, 1)
        grid.attach(self._color_sliders["xmax"], 2, 1, 1, 1)

        grid.attach(self.yref, 0, 2, 1, 1)

        grid.attach(self._color_sliders["ymin"], 1, 2, 1, 1)
        grid.attach(self._color_sliders["ymax"], 2, 2, 1, 1)

        grid.attach(self._cube, 1, 3, 2, 3)

        return grid
예제 #3
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)
예제 #4
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)