Exemple #1
0
def ask_for_color(title, color=None, previous_color=None, parent=None):
    """Returns a color chosen by the user via a modal dialog.

    The dialog is a standard `Gtk.ColorSelectionDialog`.
    The returned value may be `None`,
    which means that the user pressed Cancel in the dialog.

    """
    if color is None:
        color = RGBColor(0.5, 0.5, 0.5)
    if previous_color is None:
        previous_color = RGBColor(0.5, 0.5, 0.5)
    dialog = Gtk.ColorSelectionDialog(title)
    sel = dialog.get_color_selection()
    sel.set_current_color(uicolor.to_gdk_color(color))
    sel.set_previous_color(uicolor.to_gdk_color(previous_color))
    dialog.set_position(Gtk.WindowPosition.MOUSE)
    dialog.set_modal(True)
    dialog.set_resizable(False)
    if parent is not None:
        dialog.set_transient_for(parent)
    dialog.set_default_response(Gtk.ResponseType.OK)
    response_id = dialog.run()
    result = None
    if response_id == Gtk.ResponseType.OK:
        col_gdk = sel.get_current_color()
        result = uicolor.from_gdk_color(col_gdk)
    dialog.destroy()
    return result
Exemple #2
0
def ask_for_color(title, color=None, previous_color=None, parent=None):
    """Returns a color chosen by the user via a modal dialog.

    The dialog is a standard `Gtk.ColorSelectionDialog`.
    The returned value may be `None`,
    which means that the user pressed Cancel in the dialog.

    """
    if color is None:
        color = RGBColor(0.5, 0.5, 0.5)
    if previous_color is None:
        previous_color = RGBColor(0.5, 0.5, 0.5)
    dialog = Gtk.ColorSelectionDialog(title)
    sel = dialog.get_color_selection()
    sel.set_current_color(uicolor.to_gdk_color(color))
    sel.set_previous_color(uicolor.to_gdk_color(previous_color))
    dialog.set_position(Gtk.WindowPosition.MOUSE)
    dialog.set_modal(True)
    dialog.set_resizable(False)
    if parent is not None:
        dialog.set_transient_for(parent)
    dialog.set_default_response(Gtk.ResponseType.OK)
    response_id = dialog.run()
    result = None
    if response_id == Gtk.ResponseType.OK:
        col_gdk = sel.get_current_color()
        result = uicolor.from_gdk_color(col_gdk)
    dialog.destroy()
    return result
Exemple #3
0
def ask_for_color(title, color=None, previous_color=None, parent=None):
    """Returns a color chosen by the user via a modal dialog.

    The dialog is a standard `Gtk.ColorSelectionDialog`.
    The returned value may be `None`,
    which means that the user pressed Cancel in the dialog.

    """
    if color is None:
        color = RGBColor(0.5, 0.5, 0.5)
    if previous_color is None:
        previous_color = RGBColor(0.5, 0.5, 0.5)
    dialog = Gtk.ColorSelectionDialog(title)
    sel = dialog.get_color_selection()
    sel.set_current_color(uicolor.to_gdk_color(color))
    sel.set_previous_color(uicolor.to_gdk_color(previous_color))
    dialog.set_position(Gtk.WindowPosition.MOUSE)
    dialog.set_modal(True)
    dialog.set_resizable(False)
    if parent is not None:
        dialog.set_transient_for(parent)
    # GNOME likes to darken the main window
    # when it is set as the transient-for parent window.
    # The setting is "Attached Modal Dialogs", which defaultss to ON.
    # See https://github.com/mypaint/mypaint/issues/325 .
    # This is unhelpful for art programs,
    # but advertising the dialog
    # as a utility window restores sensible behaviour.
    dialog.set_type_hint(Gdk.WindowTypeHint.UTILITY)
    dialog.set_default_response(Gtk.ResponseType.OK)
    response_id = dialog.run()
    result = None
    if response_id == Gtk.ResponseType.OK:
        col_gdk = sel.get_current_color()
        result = uicolor.from_gdk_color(col_gdk)
    dialog.destroy()
    return result
Exemple #4
0
def ask_for_color(title, color=None, previous_color=None, parent=None):
    """Returns a color chosen by the user via a modal dialog.

    The dialog is a standard `Gtk.ColorSelectionDialog`.
    The returned value may be `None`,
    which means that the user pressed Cancel in the dialog.

    """
    if color is None:
        color = RGBColor(0.5, 0.5, 0.5)
    if previous_color is None:
        previous_color = RGBColor(0.5, 0.5, 0.5)
    dialog = Gtk.ColorSelectionDialog(title)
    sel = dialog.get_color_selection()
    sel.set_current_color(uicolor.to_gdk_color(color))
    sel.set_previous_color(uicolor.to_gdk_color(previous_color))
    dialog.set_position(Gtk.WindowPosition.MOUSE)
    dialog.set_modal(True)
    dialog.set_resizable(False)
    if parent is not None:
        dialog.set_transient_for(parent)
    # GNOME likes to darken the main window
    # when it is set as the transient-for parent window.
    # The setting is "Attached Modal Dialogs", which defaultss to ON.
    # See https://github.com/mypaint/mypaint/issues/325 .
    # This is unhelpful for art programs,
    # but advertising the dialog
    # as a utility window restores sensible behaviour.
    dialog.set_type_hint(Gdk.WindowTypeHint.UTILITY)
    dialog.set_default_response(Gtk.ResponseType.OK)
    response_id = dialog.run()
    result = None
    if response_id == Gtk.ResponseType.OK:
        col_gdk = sel.get_current_color()
        result = uicolor.from_gdk_color(col_gdk)
    dialog.destroy()
    return result
Exemple #5
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("<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(_('Set Frame to Layer'))
        crop_layer_button.set_tooltip_text(
            _("Set frame to the extents of "
              "the current layer"))
        crop_document_button = Gtk.Button(_('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 #6
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("<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(_('Set Frame to Layer'))
        crop_layer_button.set_tooltip_text(_("Set frame to the extents of "
                                             "the current layer"))
        crop_document_button = Gtk.Button(_('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)

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

        self.add(opts_table)