def _on_action_activate(self, action): """Apply a format set from a Gtk.Action type of action.""" style = int(action.get_name()) current_value = self.textbuffer.get_style_at_cursor(style) if style == StyledTextTagType.FONTCOLOR: color_dialog = Gtk.ColorSelectionDialog(_("Select font color")) elif style == StyledTextTagType.HIGHLIGHT: color_dialog = Gtk.ColorSelectionDialog( _("Select " "background color")) else: _LOG.debug("unknown style: '%d'" % style) return color_selection = color_dialog.get_color_selection() if current_value: color_selection.set_current_color(hex_to_color(current_value)) response = color_dialog.run() color = color_selection.get_current_color() value = color_to_hex(color) 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 __init__(self, start_color, window_parent=None, position=0): super().__init__() self.set_position(position) self.__picked = False self._rectangle_width = 50 self._rectangle_height = 50 self.__menu = Gtk.Menu() gtk_image = Gtk.Image() gtk_image.set_from_stock(Gtk.STOCK_DELETE, 1) self.__delete_menuitem = Gtk.ImageMenuItem('Delete') self.__delete_menuitem.set_image(gtk_image) self.__delete_menuitem.connect('activate', self.__on_delete_menuitem_clicked) self.__menu.append(self.__delete_menuitem) self.__menu.show_all() self.__color_selector = Gtk.ColorSelectionDialog( "Select a color", window_parent) self.set_color(start_color) self.__drawing_area = Gtk.DrawingArea() self.__drawing_area.set_size_request(self._rectangle_width, self._rectangle_height) self.__drawing_area.connect('draw', self.__on_draw) self.__drawing_area.add_events(Gdk.EventMask.BUTTON_PRESS_MASK) self.__drawing_area.connect('button-press-event', self.__on_clicked) self.add(self.__drawing_area)
def __init__(self, show_palette, opacity_control, *args, **kwargs): super(ZColorSelection, self).__init__(*args, **kwargs) self.dialog = Gtk.ColorSelectionDialog() self.dialog.get_color_selection().set_has_palette(show_palette) self.opacity_control = opacity_control self.dialog.get_color_selection().set_has_opacity_control(opacity_control) self.init_dialog()
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
def RunColorSelection(self, *args): """ This function creates a window for Color selection. This function is used to change the block back color and the border color. """ if self.m_oColorSelectionDlg == None: self.m_oColorSelectionDlg = Gtk.ColorSelectionDialog( _("Color selection")) t_oColorSelection = self.m_oColorSelectionDlg.colorsel t_oResponse = self.m_oColorSelectionDlg.run() if t_oResponse == Gtk.ResponseType.OK: t_oColor = t_oColorSelection.get_current_color() self.m_oColorSelectionDlg.hide() return t_oColor else: self.m_oColorSelectionDlg.hide() return None
def set_static_colour(self, widget, colour_index): """ Sets the colour for effects. :param widget: MenuItem object :type widget: Gtk.MenuItem :param colour_index: index of colour :type colour_index: int """ print("[Change Colour] Current: {0}".format( AppIndicator.colour_to_hex(self.colour))) # Create a colour selection dialog #colorsel = gtk.ColorSelection() color_selection_dlg = Gtk.ColorSelectionDialog('Change Static Colour') color_selection_result = color_selection_dlg.run() # If new colour is chosen. if color_selection_result == Gtk.ResponseType.OK: color_rgb = color_selection_dlg.get_color_selection( ).get_current_color() # Returns value between 0.0 - 1.0 * 255 = 8-bit RGB Value if colour_index == 1: self.colour = razer.keyboard.KeyboardColour.gdk_colour_to_rgb( color_rgb) self.primary_colour_button.set_label( "Change Primary Colour... ({0})".format( AppIndicator.colour_to_hex(self.colour))) print("[Change Primary Colour] New: {0}".format( AppIndicator.colour_to_hex(self.colour))) else: self.secondary_colour = razer.keyboard.KeyboardColour.gdk_colour_to_rgb( color_rgb) self.secondary_colour_button.set_label( "Change Primary Colour... ({0})".format( AppIndicator.colour_to_hex(self.secondary_colour))) print("[Change Secondary Colour] New: {0}".format( AppIndicator.colour_to_hex(self.secondary_colour))) # If 'static', 'reactive' or 'breath' mode is set, refresh the effect. if self.active_effect == 'static': print("[Change Colour] Refreshing Static Mode") self.menuitem_keyboard_effect_response( self.effect_menu_items["static"], 'static') elif self.active_effect == 'reactive': print("[Change Colour] Refreshing Reactive Mode") self.menuitem_keyboard_effect_response( self.effect_menu_items["reactive"], 'reactive') elif self.active_effect == 'breath': print("[Change Colour] Refreshing Breath Mode") self.menuitem_keyboard_effect_response( self.effect_menu_items["breath"], 'breath') color_selection_dlg.destroy()
def on_select_color(self, action): dialog = Gtk.ColorSelectionDialog("Select Color") if dialog.run() == Gtk.ResponseType.OK: color = dialog.get_color_selection().get_current_color() rgba = dialog.get_color_selection().get_current_rgba() color = '#%02x%02x%02x' % (rgba.red * 256, rgba.green * 256, rgba.blue * 256) self.editor.execute_script( "document.execCommand('forecolor', null, '%s');" % color) dialog.destroy()
def _fetch_color(self): color_selector = Gtk.ColorSelectionDialog("Select Color") color_selector.get_color_selection().set_has_palette(True) random_color = self._random_color() color_selector.get_color_selection().set_current_color(random_color) response = color_selector.run() color = None if response == Gtk.ResponseType.OK: color = color_selector.get_color_selection().get_current_rgba() color_selector.destroy() return color
def on_select_color(self, *a): dialog = Gtk.ColorSelectionDialog("اختر لونا") colorsel = dialog.get_color_selection() response = dialog.run() if response == Gtk.ResponseType.OK: color = colorsel.get_current_color().to_string() color = "#" + "".join([color[1:3], color[5:7], color[9:11]]) self.editor.execute_script( "document.execCommand('forecolor', null, '{}');".format( color, )) dialog.destroy()
def canv_colsel(oldcol, title): csd = Gtk.ColorSelectionDialog(title) col = csd.get_color_selection() #col.set_current_color(float2col(oldcol)) response = csd.run() color = 0 if response == Gtk.ResponseType.OK: color = col.get_current_color() #print ("color", color) csd.destroy() return col2float(color)
def on_select_color_clicked(self, button: Gtk.Button) -> None: color_dialog = Gtk.ColorSelectionDialog() color_dialog.props.cancel_button.hide() color_selection = color_dialog.get_color_selection() rgba_color = _led_color_to_rgba( config.get_from_index('back', 'led_colors', self.fan_index, 9)) color_selection.set_current_rgba(rgba_color) color_selection.connect('color_changed', self.on_led_color_changed) color_dialog.connect("response", self.on_select_color_response) color_dialog.run()
def on_run_color_selection_dialog(self, button, window, domodal): if domodal: title = ("Choose Color -- Modal") else: title = ("Choose Color -- Non-Modal") dialog = Gtk.ColorSelectionDialog(title=title, parent=window, modal=domodal) colorsel = dialog.get_color_selection() colorsel.set_has_opacity_control(True) colorsel.set_current_color(global_color) dialog.connect("response", self.on_dialog_response) dialog.show_all()
def onclick(self, widget, event): tp, tc, x, y = self.treeview.get_path_at_pos(event.x, event.y) if tc == self.column2: colordialog = Gtk.ColorSelectionDialog( _('Select background color')) colordialog.get_color_selection().set_current_color( Gdk.color_parse(self.store[tp][1])) if colordialog.run() == Gtk.ResponseType.OK: color = colordialog.get_color_selection().get_current_color( ).to_string() self.store[tp][1] = color colordialog.destroy() elif tc == self.column3: colordialog = Gtk.ColorSelectionDialog( _('Select foreground color')) colordialog.get_color_selection().set_current_color( Gdk.color_parse(self.store[tp][2])) if colordialog.run() == Gtk.ResponseType.OK: color = colordialog.get_color_selection().get_current_color( ).to_string() self.store[tp][2] = color colordialog.destroy()
def callback(widget): dialog = Gtk.ColorSelectionDialog(title=title) dialog.set_transient_for(self) selection = dialog.get_color_selection() rgba = Gdk.RGBA() if rgba.parse(combobox.get_active_text()): selection.set_current_rgba(rgba) if dialog.run(): rgba = selection.get_current_rgba() fmt = "#{:02x}{:02x}{:02x}".format( int(rgba.red * 255), int(rgba.green * 255), int(rgba.blue * 255)) combobox.get_child().set_text(fmt) dialog.destroy()
def colsel(ev, title): csd = Gtk.ColorSelectionDialog(title) col = csd.get_color_selection() col.set_current_color(float2col(ev.color)) response = csd.run() if response == Gtk.ResponseType.OK: #print "col", col.get_current_color() ev.color = col2float(col.get_current_color()) #print "ev.color", ev.color ev.modify_bg(Gtk.StateFlags.NORMAL, col.get_current_color()) csd.destroy() return ev.color
def buttonTrackPropertiesClicked(self, *args): model, _iter = self.tv.get_selection().get_selected() if _iter: trace, OsmGpsMapTracks = self.trackManager.getTraceFromModel(_iter) colorseldlg = Gtk.ColorSelectionDialog("Select track color") colorseldlg.get_color_selection().set_current_color(OsmGpsMapTracks[0].props.color) result = colorseldlg.run() if result == Gtk.ResponseType.OK: color = colorseldlg.get_color_selection().get_current_rgba() print color for OsmGpsMapTrack in OsmGpsMapTracks: OsmGpsMapTrack.set_color(color) self.map.map_redraw() colorseldlg.destroy()
def on_clickedTextColorTitle(self, widget): cdia = Gtk.ColorSelectionDialog("Select color") response = cdia.run() if response == Gtk.ResponseType.OK: colorsel = cdia.get_color_selection() rgb = colorsel.get_current_rgba().to_string() rgb = rgb.replace("rgb", "").replace("(", "").replace(")", "").split(',') setF3(self.rgb_to_hex((int(rgb[0]), int(rgb[1]), int(rgb[2])))) self.noteTextTitle.override_color(Gtk.StateFlags.NORMAL, colorsel.get_current_rgba()) cdia.destroy()
def on_choose_color(self, widget): color_selection_dialog = Gtk.ColorSelectionDialog("Select color") color_selection_dialog.set_transient_for(self.parent_window) if self.event is not None: color_selection_dialog.connect("destroy", self.event) color_selection = color_selection_dialog.get_color_selection() if self.color is not None: color_selection.set_current_color(self.color) response = color_selection_dialog.run() if response == Gtk.ResponseType.OK: self.color = color_selection.get_current_color() self.color_block.modify_bg(Gtk.StateType.NORMAL, self.color) color_selection_dialog.destroy()
def on_clicked(self, widget, data): cdia = Gtk.ColorSelectionDialog(_('Select color')) colorsel = cdia.get_color_selection() colorsel.set_current_color( Gdk.Color(self.color.r * 65535.0, self.color.g * 65535.0, self.color.b * 65535.0)) colorsel.set_current_alpha(self.color.a * 65535.0) colorsel.set_has_opacity_control(True) colorsel.set_has_palette(True) if cdia.run() == Gtk.ResponseType.OK: colorsel = cdia.get_color_selection() color = colorsel.get_current_color() alpha = colorsel.get_current_alpha() self.color = drawing.fromGdk2Color(color, alpha) cdia.destroy() self.queue_draw()
def change_color_cb(self, button): dialog = Gtk.ColorSelectionDialog(title='Changing color') dialog.set_transient_for(self.window) colorsel = dialog.get_color_selection() colorsel.set_previous_rgba(self.color) colorsel.set_current_rgba(self.color) colorsel.set_has_palette(True) response = dialog.run() if response == Gtk.ResponseType.OK: self.color = colorsel.get_current_rgba() self.da.override_background_color(0, self.color) dialog.destroy()
def __init__(self, window_parent): super().__init__() GObject.signal_new('colorlist-changed', self, GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, ()) self.__window_parent = window_parent self.__color_selector = Gtk.ColorSelectionDialog( "Select a color", window_parent) self.__current_colortoolitem = None add_button = Gtk.ToolButton.new_from_stock(Gtk.STOCK_ADD) add_button.connect("clicked", self.__on_add_button_clicked) add_button.set_label(None) self.insert(add_button, 0) self.reset_colors()
def set_color(widget, tag): d = Gtk.ColorSelectionDialog( _("Choose the color for tag %s") % tag) try: color = self.get_element_color(tag) if color: d.get_color_selection().set_current_color(color) except: pass res = d.run() if res == Gtk.ResponseType.OK: col = d.get_color_selection().get_current_color() self.controller.package._tag_colors[tag] = "#%04x%04x%04x" % ( col.red, col.green, col.blue) self.controller.notify('TagUpdate', tag=tag) # The color setting of the widget is done in the callback for TagUpdate d.destroy() return True
def change_color(self, _widget, terminal): """ Handle menu item callback by saving text to a file""" color_dialog = Gtk.ColorSelectionDialog( "Pick new terminal's titlebar color") color_sel = color_dialog.get_color_selection() # set previous colors previous_color = Gdk.color_parse( terminal.config['title_transmit_bg_color']) color_sel.set_previous_color(previous_color) color_sel.set_current_color(previous_color) color_sel.set_has_palette(True) response = color_dialog.run() if response == Gtk.ResponseType.OK: self.set_titlebar_color(terminal, color_sel.get_current_color()) color_dialog.destroy()
def __on_choose_color(self, widget): self.dialog = Gtk.ColorSelectionDialog() self.dialog.set_title("Select color") self.dialog.set_modal(True) self.dialog.set_transient_for(self.parent_window) if self.event is not None: self.dialog.connect("destroy", self.event) color_selection = self.dialog.get_color_selection() if self.color is not None: try: color_selection.set_current_rgba(self.color) except: pass response = self.dialog.run() if response == Gtk.ResponseType.OK: color_selection = self.dialog.get_color_selection() self.color = color_selection.get_current_rgba() self.__change_bg_color() self.dialog.destroy()
def on_editcolor_clicked(self, widget): selected, iter = self.sportTreeView.get_selection().get_selected() if iter: sport_desc = selected.get_value(iter, 0) sport = self._sport_service.get_sport_by_name(sport_desc) colorseldlg = Gtk.ColorSelectionDialog("test") colorseldlg.get_color_selection().set_has_palette(True) colorseldlg.get_color_selection().set_current_color( ColorConverter().convert_to_gdk_color(sport.color)) colorseldlg.run() gdk_color = colorseldlg.get_color_selection().get_current_color() self.stored_color = ColorConverter().convert_to_color(gdk_color) colorPixBuf = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, False, 8, 250, 20) colorPixBuf.fill(self.stored_color.rgba_val) self.newcolor.set_from_pixbuf(colorPixBuf) self.editcolor.set_from_pixbuf(colorPixBuf) colorseldlg.hide()
def __on_choose_color(self, widget): self.dialog = Gtk.ColorSelectionDialog() self.dialog.set_title("Select color") self.dialog.set_modal(True) self.dialog.set_transient_for(self.parent_window) if self.event is not None: self.dialog.connect("destroy", self.event) color_selection = self.dialog.get_color_selection() if self.color is not None: try: color_selection.set_current_rgba(self.color) except: pass response = self.dialog.show() if response == Gtk.ResponseType.OK: color_selection = self.dialog.get_color_selection() self.color = color_selection.get_current_rgba() self.color_block.get_style_context().add_class( "frame {background-color: " + self.color.to_string() + ";}") self.dialog.destroy()
def gestion_color(self, a, b): """TODO: Docstring for gestion_color. :returns: TODO """ colorseldlg = Gtk.ColorSelectionDialog("Selección de color") response = colorseldlg.run() if response - -Gtk.ResponseType.OK: color = colorseldlg.get_color_selection() color = color.get_current_color() # color devuelve un Gtk.gdk.color # pero el RGB es un integer de 65535 valores # con una regla de tres simple lo adapto a los # 255 valores que soporta pygame self.fondo.FONDO = ((color.red * 255) / 65535, (color.green * 255) / 65535, (color.blue * 255) / 65535) else: colorseldlg.hide() colorseldlg.hide()
def colorbox(title="Changing color", previous_color='', current_color=''): ''' ''' dialog = Gtk.ColorSelectionDialog("Changing color") colorsel = dialog.get_color_selection() if current_color: colorsel.set_previous_color(previous_color) if current_color: colorsel.set_current_color(current_color) colorsel.set_has_palette(True) response = dialog.run() htmlcolor = '' if response == Gtk.ResponseType.OK: color = colorsel.get_current_color() rgb = (color.red, color.green, color.blue) htmlcolor = '#' + ''.join( (str(hex(i / 257))[2:].rjust(2, '0') for i in rgb)) dialog.destroy() return htmlcolor
def on_button_color_activated(self, widget): dialog = Gtk.ColorSelectionDialog( title=_('Select color'), flags=Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT) dialog.get_color_selection().set_current_color( Gdk.Color(self.viewport2.color[0]*65535, self.viewport2.color[1]*65535, self.viewport2.color[2]*65535)) dialog.get_color_selection().set_current_alpha( self.viewport2.color[3]*65535) response = dialog.run() print(response) if response == -5: color1 = dialog.get_color_selection().get_current_color() color2 = dialog.get_color_selection().get_current_alpha() self.viewport2.color = [color1.red/65535.0, color1.green/65535.0, color1.blue/65535.0, color2/65535.0] print(self.viewport2.color) self.update_preview() dialog.destroy()
def open_color_picker_via_gtk(): color_sel = Gtk.ColorSelectionDialog("Sublime Color Picker") if len(sys.argv) > 1: current_color = Gdk.color_parse(sys.argv[1]) if current_color: try: color_sel.colorsel.set_current_color(current_color) except AttributeError: # newer version of GTK color_sel.get_color_selection().set_current_color( current_color) if color_sel.run() == getattr(Gtk, 'RESPONSE_OK', Gtk.ResponseType.OK): color = color_sel.get_color_selection().get_current_color() #Convert to 8bit channels red = int(color.red / 256) green = int(color.green / 256) blue = int(color.blue / 256) #Format finalcolor = "%02x%02x%02x" % (red, green, blue) print(finalcolor.upper()) color_sel.destroy()