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 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
def _color_set_cb(self, colorbutton): color_gdk = colorbutton.get_color() r, g, b = uicolor.from_gdk_color(color_gdk).get_rgb() a = float(colorbutton.get_alpha()) / 65535 self.app.preferences["frame.color_rgba"] = (r, g, b, a) self.app.doc.tdw.queue_draw()