def run(self, procedure, args, data): run_mode = args.index(0) palette = args.index(1) selection = args.index(2) slice_expr = args.index(3) channel1 = args.index(4) ascending1 = args.index(5) channel2 = args.index(6) ascending2 = args.index(7) quantize = args.index(8) pchannel = args.index(9) pquantize = args.index(10) if palette == '' or palette is None: palette = Gimp.context_get_palette() (exists, num_colors) = Gimp.palette_get_info(palette) if not exists: error = 'Unknown palette: {}'.format(palette) return procedure.new_return_values( Gimp.PDBStatusType.CALLING_ERROR, GLib.Error(error)) # TODO: Add UI try: new_palette = palette_sort(palette, selection, slice_expr, channel1, ascending1, channel2, ascending2, quantize, pchannel, pquantize) except ValueError as err: return procedure.new_return_values( Gimp.PDBStatusType.EXECUTION_ERROR, GLib.Error(str(err))) return_val = procedure.new_return_values(Gimp.PDBStatusType.SUCCESS, GLib.Error()) value = GObject.Value(GObject.TYPE_STRING, new_palette) return_val.remove(1) return_val.insert(1, value) return return_val
def run(procedure, args, data): # Get the parameters palette = None if args.length() > 1: palette = args.index(1) if palette == '' or palette is None: palette = Gimp.context_get_palette() (exists, num_colors) = Gimp.palette_get_info(palette) if not exists: error = 'Unknown palette: {}'.format(palette) return procedure.new_return_values(Gimp.PDBStatusType.CALLING_ERROR, GLib.Error(error)) if procedure.get_name() == 'python-fu-palette-to-gradient': num_segments = num_colors - 1 else: # 'python-fu-palette-to-gradient-repeating' num_segments = num_colors gradient = make_gradient(palette, num_segments, num_colors) # XXX: for the error parameter, we want to return None. # Unfortunately even though the argument is (nullable), pygobject # looks like it may have a bug. So workaround is to just set a # generic GLib.Error() since anyway the error won't be process with # GIMP_PDB_SUCCESS status. # See pygobject#351 retval = procedure.new_return_values(Gimp.PDBStatusType.SUCCESS, GLib.Error()) # XXX: I don't try to get the GValue with retval.index(1) because it # actually return a string (cf. pygobject#353). Just create a new # GValue and replace the default one with this one. value = GObject.Value(GObject.TYPE_STRING, gradient) retval.remove(1) retval.insert(1, value) return retval
def run(self, procedure, args, data): palette = None amount = 1 # Get the parameters if args.length() < 1: error = 'No parameters given' return procedure.new_return_values( Gimp.PDBStatusType.CALLING_ERROR, GLib.Error(error)) runmode = args.index(0) if args.length() > 1: palette = args.index(1) if palette == '' or palette is None: palette = Gimp.context_get_palette() (exists, num_colors) = Gimp.palette_get_info(palette) if not exists: error = 'Unknown palette: {}'.format(palette) return procedure.new_return_values( Gimp.PDBStatusType.CALLING_ERROR, GLib.Error(error)) if args.length() > 2: amount = args.index(2) if runmode == Gimp.RunMode.INTERACTIVE: gi.require_version('Gtk', '3.0') from gi.repository import Gtk Gimp.ui_init("palette-offset.py") use_header_bar = Gtk.Settings.get_default().get_property( "gtk-dialogs-use-header") dialog = Gimp.Dialog(use_header_bar=use_header_bar, title=_("Offset Palette...")) dialog.add_button("_Cancel", Gtk.ResponseType.CANCEL) dialog.add_button("_OK", Gtk.ResponseType.OK) box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, homogeneous=False, spacing=12) dialog.get_content_area().add(box) box.show() label = Gtk.Label.new_with_mnemonic("Off_set") box.pack_start(label, False, False, 1) label.show() amount = self.set_property("amount", amount) spin = Gimp.prop_spin_button_new(self, "amount", 1.0, 5.0, 0) spin.set_activates_default(True) box.pack_end(spin, False, False, 1) spin.show() dialog.show() if dialog.run() != Gtk.ResponseType.OK: return procedure.new_return_values(Gimp.PDBStatusType.CANCEL, GLib.Error()) amount = self.get_property("amount") #If palette is read only, work on a copy: editable = Gimp.palette_is_editable(palette) if not editable: palette = Gimp.palette_duplicate(palette) tmp_entry_array = [] for i in range(num_colors): tmp_entry_array.append((Gimp.palette_entry_get_name(palette, i)[1], Gimp.palette_entry_get_color(palette, i)[1])) for i in range(num_colors): target_index = i + amount if target_index >= num_colors: target_index -= num_colors elif target_index < 0: target_index += num_colors Gimp.palette_entry_set_name(palette, target_index, tmp_entry_array[i][0]) Gimp.palette_entry_set_color(palette, target_index, tmp_entry_array[i][1]) retval = procedure.new_return_values(Gimp.PDBStatusType.SUCCESS, GLib.Error()) value = GObject.Value(GObject.TYPE_STRING, palette) retval.remove(1) retval.insert(1, value) return retval
def run(name, n_params, params): # run_mode = params[0].get_int32() if name == 'python-fu-palette-to-gradient-repeating': return palette_to_gradient_repeating(Gimp.context_get_palette()) else: return palette_to_gradient(Gimp.context_get_palette())