mirror of https://github.com/GNOME/gimp.git
python: Minor enhancements to python plug-ins
* colorxhtml.py was converted to use GimpProcedureDialog. A new aux argument was added so that a widget could be created in the GUI. The text field and the file widgets were made to be sensitive to the source-file bool to better indicate to the user which one will be used. * palette-sort.py now uses babl instead of colormath libraries to get CIE LAB and CIE LCH(ab) values. This means all users will be able to sort by those options even if the colormath library isn't installed. * histogram-export.py's out-format widget was converted to a radio frame as it is in 2.10.
This commit is contained in:
parent
2a8e75de6a
commit
f5b7f734e2
|
@ -63,11 +63,6 @@ preamble = """<!DOCTYPE html>
|
|||
postamble = """\n</pre>\n</body>\n</html>\n"""
|
||||
|
||||
def export_colorxhtml(procedure, run_mode, image, file, metadata, config, data):
|
||||
source_file = config.get_property("source-file")
|
||||
characters = config.get_property("characters")
|
||||
size = config.get_property("font-size");
|
||||
separate = config.get_property("separate")
|
||||
|
||||
if file is None:
|
||||
error = 'No file given'
|
||||
return procedure.new_return_values(Gimp.PDBStatusType.CALLING_ERROR,
|
||||
|
@ -80,94 +75,27 @@ def export_colorxhtml(procedure, run_mode, image, file, metadata, config, data):
|
|||
|
||||
GimpUi.init ("file-colorxhtml-export")
|
||||
|
||||
use_header_bar = Gtk.Settings.get_default().get_property("gtk-dialogs-use-header")
|
||||
dialog = Gtk.Dialog(use_header_bar=use_header_bar,
|
||||
title=_("Save as colored HTML text..."))
|
||||
dialog.add_button(_("_Cancel"), Gtk.ResponseType.CANCEL)
|
||||
dialog.add_button(_("_OK"), Gtk.ResponseType.OK)
|
||||
dialog = GimpUi.ProcedureDialog.new(procedure, config, _("Save as colored HTML text..."))
|
||||
|
||||
choose_file_dialog = Gtk.FileChooserDialog(use_header_bar=use_header_bar,
|
||||
title=_("Read characters from file..."),
|
||||
action=Gtk.FileChooserAction.OPEN)
|
||||
choose_file_dialog.add_button(_("_Cancel"), Gtk.ResponseType.CANCEL)
|
||||
choose_file_dialog.add_button(_("_OK"), Gtk.ResponseType.OK)
|
||||
dialog.fill_frame("file-frame", "source-file", False, "aux-file")
|
||||
# Set the characters text field as not enabled when the user chooses a file
|
||||
dialog.set_sensitive("characters", True, config, "source-file", True)
|
||||
|
||||
def choose_file(button, user_data=None):
|
||||
choose_file_dialog.show()
|
||||
if choose_file_dialog.run() == Gtk.ResponseType.OK:
|
||||
characters_entry.set_text(choose_file_dialog.get_filename())
|
||||
dialog.fill(["characters", "file-frame", "font-size", "separate"])
|
||||
|
||||
choose_file_dialog.hide()
|
||||
|
||||
grid = Gtk.Grid()
|
||||
grid.set_column_homogeneous(False)
|
||||
grid.set_border_width(10)
|
||||
grid.set_column_spacing(10)
|
||||
grid.set_row_spacing(10)
|
||||
|
||||
row = 0
|
||||
label = Gtk.Label(label=_("Characters"))
|
||||
label.set_tooltip_text(_("Characters that will be used as colored pixels. "))
|
||||
|
||||
grid.attach(label, 0, row, 1 , 1)
|
||||
label.show()
|
||||
|
||||
characters_entry = Gtk.Entry()
|
||||
characters_entry.set_width_chars(20)
|
||||
characters_entry.set_max_width_chars(80)
|
||||
characters_entry.set_text(characters)
|
||||
characters_entry.set_placeholder_text(_("Characters or file location"))
|
||||
grid.attach(characters_entry, 1, row, 1, 1)
|
||||
characters_entry.show()
|
||||
|
||||
row += 1
|
||||
|
||||
characters_checkbox = Gtk.CheckButton(label=_("Read characters from file"))
|
||||
characters_checkbox.set_active(source_file)
|
||||
characters_checkbox.set_tooltip_text(
|
||||
_("If set, the Characters text entry will be used as a file name, "
|
||||
"from which the characters will be read. Otherwise, the characters "
|
||||
"in the text entry will be used to render the image."))
|
||||
grid.attach(characters_checkbox, 0, row, 1, 1)
|
||||
characters_checkbox.show()
|
||||
|
||||
choose_file_button = Gtk.Button(label=_("Choose file"))
|
||||
grid.attach(choose_file_button, 1, row, 1, 1)
|
||||
choose_file_button.connect("clicked", choose_file)
|
||||
choose_file_button.show()
|
||||
|
||||
row += 1
|
||||
|
||||
label = Gtk.Label(label=_("Font Size(px)"))
|
||||
grid.attach(label, 0, row, 1 , 1)
|
||||
label.show()
|
||||
|
||||
font_size_adj = Gtk.Adjustment.new(size, 0.0, 100.0, 1.0, 0.0, 0.0)
|
||||
font_size_spin = Gtk.SpinButton.new(font_size_adj, climb_rate=1.0, digits=0)
|
||||
font_size_spin.set_numeric(True)
|
||||
grid.attach(font_size_spin, 1, row, 1 , 1)
|
||||
font_size_spin.show()
|
||||
|
||||
row += 1
|
||||
|
||||
separate_checkbox = Gtk.CheckButton(label=_("Write separate CSS file"))
|
||||
separate_checkbox.set_active(separate)
|
||||
grid.attach(separate_checkbox, 0, row, 2, 1)
|
||||
separate_checkbox.show()
|
||||
|
||||
dialog.get_content_area().add(grid)
|
||||
grid.show()
|
||||
|
||||
dialog.show()
|
||||
if dialog.run() == Gtk.ResponseType.OK:
|
||||
separate = separate_checkbox.get_active()
|
||||
size = font_size_spin.get_value_as_int()
|
||||
source_file = characters_checkbox.get_active()
|
||||
characters = characters_entry.get_text()
|
||||
else:
|
||||
if not dialog.run():
|
||||
return procedure.new_return_values(Gimp.PDBStatusType.CANCEL,
|
||||
GLib.Error())
|
||||
|
||||
source_file = config.get_property("source-file")
|
||||
characters = config.get_property("characters")
|
||||
size = config.get_property("font-size");
|
||||
separate = config.get_property("separate")
|
||||
aux_file = config.get_property("aux-file")
|
||||
|
||||
if source_file and aux_file:
|
||||
characters = aux_file.get_path()
|
||||
|
||||
#For now, work with a single layer
|
||||
layer = image.list_layers()[0]
|
||||
|
||||
|
@ -291,11 +219,11 @@ class ColorXhtml(Gimp.PlugIn):
|
|||
procedure.set_extensions ("html,xhtml");
|
||||
|
||||
procedure.add_boolean_argument ("source-file",
|
||||
_("_Read characters from file, if true, or use text entry"),
|
||||
_("Rea_d characters from file"),
|
||||
_("Read characters from file, if true, or use text entry"),
|
||||
False, GObject.ParamFlags.READWRITE)
|
||||
procedure.add_string_argument ("characters", _("_File to read or characters to use"),
|
||||
_("File to read or characters to use"),
|
||||
procedure.add_string_argument ("characters", _("Charac_ters"),
|
||||
_("Characters that will be used as colored pixels."),
|
||||
"foo", GObject.ParamFlags.READWRITE)
|
||||
procedure.add_int_argument ("font-size", _("Fo_nt size in pixels"),
|
||||
_("Font size in pixels"), 5, 100, 10,
|
||||
|
@ -303,6 +231,9 @@ class ColorXhtml(Gimp.PlugIn):
|
|||
procedure.add_boolean_argument ("separate", _("_Write a separate CSS file"),
|
||||
_("Write a separate CSS file"),
|
||||
False, GObject.ParamFlags.READWRITE)
|
||||
#GUI only, used to create a widget to open a file if source-file is enabled
|
||||
procedure.add_file_aux_argument ("aux-file", _("Choose _File"),
|
||||
"", GObject.ParamFlags.READWRITE)
|
||||
|
||||
return procedure
|
||||
|
||||
|
|
|
@ -169,7 +169,11 @@ def run(procedure, run_mode, image, n_layers, layers, config, data):
|
|||
GimpUi.init("histogram-export.py")
|
||||
|
||||
dialog = GimpUi.ProcedureDialog.new(procedure, config, _("Histogram Export..."))
|
||||
dialog.fill()
|
||||
|
||||
dialog.get_file_chooser ("file", Gtk.FileChooserAction.SAVE)
|
||||
radio_frame = dialog.get_widget ("output-format", GimpUi.IntRadioFrame)
|
||||
|
||||
dialog.fill(None)
|
||||
|
||||
if not dialog.run():
|
||||
return procedure.new_return_values(Gimp.PDBStatusType.CANCEL,
|
||||
|
|
|
@ -65,7 +65,14 @@ channel_getters = [
|
|||
(lambda v, i: gegl_color_bytes_convert (v, "HSL float", 'fff', 2)),
|
||||
|
||||
(lambda v, i: i),
|
||||
(lambda v, i: randint(0, 0x7fffffff))
|
||||
(lambda v, i: randint(0, 0x7fffffff)),
|
||||
|
||||
(lambda v, i: gegl_color_bytes_convert (v, "CIE Lab float", 'fff', 0)),
|
||||
(lambda v, i: gegl_color_bytes_convert (v, "CIE Lab float", 'fff', 1)),
|
||||
(lambda v, i: gegl_color_bytes_convert (v, "CIE Lab float", 'fff', 2)),
|
||||
|
||||
(lambda v, i: gegl_color_bytes_convert (v, "CIE LCH(ab) float", 'fff', 1)),
|
||||
(lambda v, i: gegl_color_bytes_convert (v, "CIE LCH(ab) float", 'fff', 2))
|
||||
]
|
||||
|
||||
GRAIN_SCALE = (1.0, 1.0 , 1.0,
|
||||
|
@ -77,30 +84,6 @@ GRAIN_SCALE = (1.0, 1.0 , 1.0,
|
|||
100., 256., 256.,
|
||||
256., 360.,)
|
||||
|
||||
try:
|
||||
from colormath.color_objects import RGBColor, LabColor, LCHabColor
|
||||
|
||||
def to_lab(v):
|
||||
return RGBColor(v.get_rgba()[0], v.get_rgba()[1], v.get_rgba()[2]).convert_to('LAB').get_value_tuple()
|
||||
|
||||
def to_lchab(v):
|
||||
return RGBColor(v.get_rgba()[0], v.get_rgba()[1], v.get_rgba()[2]).convert_to('LCHab').get_value_tuple()
|
||||
|
||||
AVAILABLE_CHANNELS = AVAILABLE_CHANNELS + (_("Lightness (LAB)"),
|
||||
_("A-color"), _("B-color"),
|
||||
_("Chroma (LCHab)"),
|
||||
_("Hue (LCHab)"))
|
||||
channel_getters.extend([
|
||||
(lambda v, i: to_lab(v)[0]),
|
||||
(lambda v, i: to_lab(v)[1]),
|
||||
(lambda v, i: to_lab(v)[2]),
|
||||
|
||||
(lambda v, i: to_lchab(v)[1]),
|
||||
(lambda v, i: to_lchab(v)[2])
|
||||
])
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
def gegl_color_bytes_convert (color, format, precision, index):
|
||||
color_bytes = color.get_bytes(Babl.format(format))
|
||||
data = color_bytes.get_data()
|
||||
|
@ -488,5 +471,10 @@ class PaletteSort (Gimp.PlugIn):
|
|||
choice.add("lightness-hsl", 8, _("Lightness (HSL)"), "")
|
||||
choice.add("index", 9, _("Index"), "")
|
||||
choice.add("random", 10, _("Random"), "")
|
||||
choice.add("lightness-lab", 11, _("Lightness (LAB)"), "")
|
||||
choice.add("a-color", 12, _("A-color"), "")
|
||||
choice.add("b-color", 13, _("B-color"), "")
|
||||
choice.add("chroma-lchab", 14, _("Chroma (LCHab)"), "")
|
||||
choice.add("hue-lchab", 15, _("Hue (LCHab)"), "")
|
||||
|
||||
Gimp.main(PaletteSort.__gtype__, sys.argv)
|
||||
|
|
Loading…
Reference in New Issue