示例#1
0
    def _on_action_activate(self, action, value):
        """Apply a format set from a Gtk.Action type of action."""
        style = getattr(StyledTextTagType, action.get_name())
        current_value = self.textbuffer.get_style_at_cursor(style)

        if style == StyledTextTagType.FONTCOLOR:
            color_dialog = Gtk.ColorChooserDialog(
                title=_("Select font color"),
                transient_for=self.transient_parent)
        elif style == StyledTextTagType.HIGHLIGHT:
            color_dialog = Gtk.ColorChooserDialog(
                title=_("Select background color"),
                transient_for=self.transient_parent)
        else:
            _LOG.debug("unknown style: '%d'" % style)
            return

        if current_value:
            rgba = Gdk.RGBA()
            rgba.parse(current_value)
            color_dialog.set_rgba(rgba)

        response = color_dialog.run()
        rgba = color_dialog.get_rgba()
        value = '#%02x%02x%02x' % (int(rgba.red * 255),
                                   int(rgba.green * 255),
                                   int(rgba.blue * 255))
        color_dialog.destroy()

        if response == Gtk.ResponseType.OK:
            _LOG.debug("applying style '%d' with value '%s'" %
                       (style, str(value)))
            self.textbuffer.apply_style(style, value)
    def color_button_clicked(self, color_button, prop_name):
        if not self.prop_object: return
        color_type = color_button.get_color_type()
        if color_type == "None":
            color_button.set_color(None)
        elif color_type == "Flat":
            value = self.prop_object.get_prop_value(prop_name)
            if not value:
                value = Color(0,0,0,1)
            dialog = Gtk.ColorChooserDialog()
            rgba = Gdk.RGBA(*value.get_array())
            dialog.set_rgba(rgba)
            if dialog.run() == Gtk.ResponseType.OK:
                rgba = dialog.get_rgba()
                color = Color(rgba.red, rgba.green, rgba.blue, rgba.alpha)
                dialog.destroy()
                color_button.set_color(color)
            else:
                dialog.destroy()
        elif color_type == "Image":
            color = self.prop_object.get_prop_value(prop_name)
            dialog = ImageColorDialog(self.parent_window, color, color_button)
            if dialog.run() == Gtk.ResponseType.OK:
                color = dialog.get_image_color()
                dialog.destroy()
            else:
                dialog.destroy()
            color_button.set_color(color)

        else:
            shape_manager = self.parent_window.get_shape_manager()
            shape_manager.toggle_color_editor(prop_name, color_type)
            self.parent_window.redraw()
示例#3
0
    def _on_color_activated(self, tree, path, column):
        """GUI handler"""
        treeiter = self.color_store.get_iter(path)

        color_dialog = Gtk.ColorChooserDialog("Choose Color",
                                              self._app.mainwin.gui["window"],
                                              use_alpha=False)
        color_dialog.set_rgba(
            rgba_from_hex(
                self.color_store[treeiter][self.color_view_data.index.HEX]))
        response = color_dialog.run()

        if response == Gtk.ResponseType.OK:
            color_index = self.color_store[treeiter][
                self.color_view_data.index.INDEX]
            hex_color = hex_from_rgba(color_dialog.get_rgba())
            logger.debug("New color %s in line %s", hex_color, color_index)

            self.color_store[treeiter][
                self.color_view_data.index.HEX] = hex_color
            self.color_store[treeiter][
                self.color_view_data.index.COLOR] = pixbuf_from_hex(
                    hex_color, width=self.PIXBUF_PATTERN_WIDTH)
            self._parser.current.change_color(hex_color, color_index)
            self._color_changes_apply()

        color_dialog.destroy()
 def on_foreground_menuitem_activated(self, menuitem):
     colorchooserdialog = Gtk.ColorChooserDialog(parent=self)
     if colorchooserdialog.run() == Gtk.ResponseType.OK:
         color = colorchooserdialog.get_rgba()
         self.terminal.set_color_foreground(color)
         self.foreground = color
     colorchooserdialog.destroy()
 def on_btnColor_clicked(self, widget):
     dialog = Gtk.ColorChooserDialog("Please choose a color")
     dialog.set_rgba(self.color)
     response = dialog.run()
     if response == Gtk.ResponseType.OK:
         dialog.get_rgba(self.color)
     dialog.destroy()
示例#6
0
    def toggle_color(self, button, name, textview):
        text_buffer = textview.get_buffer()
        insert = text_buffer.get_insert()
        try:
            start, end = text_buffer.get_selection_bounds()
        except ValueError:
            start = end = None
        else:
            # Use offset position to preserve across buffer modification
            start = start.get_offset()
            end = end.get_offset()

        dialog = Gtk.ColorChooserDialog(title=_('Select a color'),
                                        transient_for=get_toplevel_window(),
                                        use_alpha=False)
        color = Gdk.RGBA()
        if name in self.colors:
            color.parse(self.colors[name])
            dialog.set_rgba(color)
        if dialog.run() == Gtk.ResponseType.OK:
            color = dialog.get_rgba()
            if start is not None and end is not None:
                start = text_buffer.get_iter_at_offset(start)
                end = text_buffer.get_iter_at_offset(end)
                tag = register_foreground(text_buffer, color)
                remove_tags(text_buffer, start, end, name)
                text_buffer.apply_tag(tag, start, end)
        dialog.destroy()
        text_buffer.place_cursor(text_buffer.get_iter_at_mark(insert))
示例#7
0
 def on_choose_color_button_clicked(self, widget):
     if self.activeCurve != None:
         colorChooserDialog = Gtk.ColorChooserDialog()
         stat = colorChooserDialog.run()
         if stat > -6:
             col = colorChooserDialog.get_rgba()
             self.activeCurve.change_line_color(col.red, col.green,
                                                col.blue)
         colorChooserDialog.destroy()
示例#8
0
 def background_color_callback(self, *whatever):
     dialog = Gtk.ColorChooserDialog(_("Background Color"), self)
     color = self.buffer.get_background_color()
     rgba = Gdk.RGBA(color[0], color[1], color[2])
     dialog.set_rgba(rgba)
     if dialog.run() == Gtk.ResponseType.OK:
         rgba = dialog.get_rgba()
         self.buffer.set_background_color((rgba.red, rgba.green, rgba.blue))
         self.paintview.queue_draw()
     dialog.destroy()
示例#9
0
 def on_select_color(self, action):
     dialog = Gtk.ColorChooserDialog("Select Color")
     if dialog.run() == Gtk.ResponseType.OK:
         (r, g, b, a) = dialog.get_rgba()
         color = "#%0.2x%0.2x%0.2x%0.2x" % (
             int(r * 255),
             int(g * 255),
             int(b * 255),
             int(a * 255))
         self.editor.run_javascript("document.execCommand('forecolor', null, '%s');" % color)
     dialog.destroy()
示例#10
0
def color_dialog(parent, title=None, color=None):
    ret_color = None
    colordialog = Gtk.ColorChooserDialog(title or 'Select color', parent)
    colordialog.set_use_alpha(False)
    if color:
        colordialog.set_rgba(Gdk.RGBA(*color))

    if colordialog.run() == Gtk.ResponseType.OK:
        ret_color = list(colordialog.get_rgba())[:3]

    colordialog.destroy()
    return ret_color
示例#11
0
    def on_mnuColore_activate(self, menuItem):
        def color_activated(dialog):
            color = dialog.get_rgba()
            # deprecated
            self.txtTotaleParziale.override_color(Gtk.StateFlags.NORMAL,
                                                  Gdk.RGBA(*color))

        dialog = Gtk.ColorChooserDialog(title="Scegli un colore",
                                        parent=self.window)
        if dialog.run() == Gtk.ResponseType.OK:
            color_activated(dialog)
        dialog.destroy()
示例#12
0
def edit_task_color(task):
    """Create Dialog to edit task color"""

    dialog = Gtk.ColorChooserDialog()
    color = Gdk.RGBA()
    color.parse(task.color)
    dialog.set_rgba(color)
    result = dialog.run()
    if result == -5:  # OK
        color = dialog.get_rgba()
        task.set_color(strFromColor(color))
    dialog.destroy()
    def select_fore_color(self):
        dlg = Gtk.ColorChooserDialog(_("a title"), self.OptionsWindow)
        response = dlg.run()
        #print(response,Gtk.ResponseType.OK, response == Gtk.ResponseType.OK)
        #print(dlg.get_rgba().to_string())
        if response == Gtk.ResponseType.OK:
            #thetuple = tuple(int(x) for x in dlg.get_rgba().to_string().split("(")[1].split(")")[0].split(","))
            dlgrgba = dlg.get_rgba()
            thetuple = (dlgrgba.red,dlgrgba.green,dlgrgba.blue)
            self.color = thetuple
            self.drawingareaExample.queue_draw()

        dlg.destroy()
 def choose_color(self):
     if not self.selected_edit_box:
         return
     color = self.selected_edit_box.fill_color
     dialog = Gtk.ColorChooserDialog()
     rgba = Gdk.RGBA(*color.get_array())
     dialog.set_rgba(rgba)
     res = True
     if dialog.run() == Gtk.ResponseType.OK:
         rgba = dialog.get_rgba()
         new_color = Color(rgba.red, rgba.green, rgba.blue, rgba.alpha)
         color.copy_from(new_color)
         res = True
         self.update_color()
     dialog.destroy()
     return res
示例#15
0
    def show_file_chooser(self, widget):

        colorchooserdialog = Gtk.ColorChooserDialog()

        response = colorchooserdialog.run()

        if response == -5:
            # colorsel  = colorchooserdialog.colorsel
            # color = colorsel.get_current_color()
            color = colorchooserdialog.get_rgba()
            self.window.modify_bg(Gtk.StateType.NORMAL, color)
        else:
            pass

        logger.debug(response)
        colorchooserdialog.destroy()
示例#16
0
    def on_color_picker_activate(self):
        if not self._dialog:
            self._dialog = Gtk.ColorChooserDialog(_('Pick Color'), self.window)

            self._dialog.connect_after('response', self.on_dialog_response)

        rgba_str = self._color_helper.get_current_color(
            self.window.get_active_document(), False)

        if rgba_str:
            rgba = Gdk.RGBA()
            parsed = rgba.parse(rgba_str)

            if parsed:
                self._dialog.set_rgba(rgba)

        self._dialog.present()
示例#17
0
    def on_row_activated(self, widget, row, col):
        """
        Método que modifica o cor seleccionado polo usuario na base de datos

        :param widget:
        :param row:
        :param col:
        :return:
        """
        model = widget.get_model()

        self.colorchooserdialog = Gtk.ColorChooserDialog(parent=self)

        if self.colorchooserdialog.run() == Gtk.ResponseType.OK:
            model[row][4] = str(self.color_activated())
            self.datos1[4] = [model[row][4], model[row][0]]
        self.colorchooserdialog.destroy()
    def choose_separator_color(self, rgb=[127, 127, 127]):
        colorchooser = Gtk.ColorChooserDialog(title=APP_NAME,
                                              rgba=Gdk.RGBA(
                                                  rgb[0] / 255, rgb[1] / 255,
                                                  rgb[2] / 255))
        colorchooser.set_use_alpha(False)
        colorchooser.set_position(Gtk.WindowPosition.MOUSE)

        response = colorchooser.run()
        if response == Gtk.ResponseType.OK:
            color = colorchooser.get_rgba()
            rgb = [
                math.floor(color.red * 255),
                math.floor(color.green * 255),
                math.floor(color.blue * 255)
            ]
            colorchooser.destroy()
            return rgb

        colorchooser.destroy()
        return None
示例#19
0
    def custom_color_dialog(self):
        """Pick color dialog"""
        dialog = Gtk.ColorChooserDialog()
        dialog.set_use_alpha(False)
        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            # Color
            color = dialog.get_rgba()
            dialog.destroy()
            red = (color.red * 255)
            green = (color.green * 255)
            blue = (color.blue * 255)
            # Light
            hex_light = "%02x%02x%02x" % (red, green, blue)
            # Middle
            red = red - self.foldercolor.GRADIENT_RANGE
            if red < 0:
                red = 0
            green = green - self.foldercolor.GRADIENT_RANGE
            if green < 0:
                green = 0
            blue = blue - self.foldercolor.GRADIENT_RANGE
            if blue < 0:
                blue = 0
            hex_middle = "%02x%02x%02x" % (red, green, blue)
            # Dark
            red = red - self.foldercolor.GRADIENT_RANGE
            if red < 0:
                red = 0
            green = green - self.foldercolor.GRADIENT_RANGE
            if green < 0:
                green = 0
            blue = blue - self.foldercolor.GRADIENT_RANGE
            if blue < 0:
                blue = 0
            hex_dark = "%02x%02x%02x" % (red, green, blue)
            return {'light': hex_light, 'middle': hex_middle, 'dark': hex_dark}

        dialog.destroy()
        return None
示例#20
0
    def on_suitcolour_clicked(self, suit):
        # Get symbol in Suit corresponding to button clicked.

        title = _("Select colour for %s symbol" % SUIT_NAMES[suit])
        dialog = Gtk.ColorChooserDialog(title)
        dialog.set_use_alpha(False)
        dialog.set_rgba(self.suit_colours[suit])

        def dialog_response_cb(dialog, response_id):
            if response_id == Gtk.ResponseType.OK:
                rgba = dialog.get_rgba()
                self.suit_colours[suit] = rgba
                # Set button label to colour selected by user.
                hexrep = rgba_hexrep(rgba)
                label = getattr(self, 'label_%scolour' % suit.name.lower())
                label.set_markup(SUIT_LABEL_TEMPLATE %
                                 (hexrep, SUIT_SYMBOLS[suit]))

            dialog.destroy()

        dialog.connect('response', dialog_response_cb)
        dialog.run()  # show()
示例#21
0
#!/usr/bin/env python3

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk


def color_activated():
    color = colorchooserdialog.get_rgba()

    red = (color.red * 255)
    green = (color.green * 255)
    blue = (color.blue * 255)

    print('Hex: #%02x%02x%02x' % (red, green, blue))


colorchooserdialog = Gtk.ColorChooserDialog()

if colorchooserdialog.run() == Gtk.ResponseType.OK:
    color_activated()

colorchooserdialog.destroy()