mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-07-04 09:53:25 +00:00
libgimp, plug-ins: create automatically a GimpFileChooser for GimpParamSpecFile arguments.
This new widget is much nicer, with proper label to document the GUI and also with support to save files or create folders. It also has mnemonic support and the label is put into the same size group as other so that it's nicely aligned. As a consequence, I remove bad support of object arguments with a GFile value. People should just create proper GimpParamSpecFile arguments (also GimpProcedure API now has a function only for such type of file argument). I also remove gimp_procedure_dialog_get_file_chooser() which was only useful when we didn't know what action a file argument was for. Now it's part of the param spec definition. libscriptfu was updated too because SF-DIRNAME arguments don't need special casing anymore. Finally I change gradients-save-as-css to just make use of the new automatic widget creation (more than 60 lines of plug-in code replaced by… 0 lines because it's automatic!). This whole commit is mostly a lot of code removal now that we have proper automatization for file arguments! \o/
This commit is contained in:
parent
db2d3cffa2
commit
10808f2830
5 changed files with 14 additions and 187 deletions
|
@ -64,75 +64,13 @@ def gradient_css_save(procedure, config, data):
|
|||
if runmode == Gimp.RunMode.INTERACTIVE:
|
||||
GimpUi.init('python-fu-gradient-save-as-css')
|
||||
dialog = GimpUi.ProcedureDialog(procedure=procedure, config=config)
|
||||
file = None
|
||||
|
||||
# Add gradient button
|
||||
dialog.fill (["gradient"])
|
||||
|
||||
# UI for the file parameter
|
||||
# from histogram-export.py
|
||||
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL,
|
||||
homogeneous=False, spacing=10)
|
||||
dialog.get_content_area().add(vbox)
|
||||
vbox.show()
|
||||
|
||||
grid = Gtk.Grid()
|
||||
grid.set_column_homogeneous(False)
|
||||
grid.set_border_width(10)
|
||||
grid.set_column_spacing(10)
|
||||
grid.set_row_spacing(10)
|
||||
vbox.add(grid)
|
||||
grid.show()
|
||||
|
||||
def choose_file(widget):
|
||||
if file_chooser_dialog.run() == Gtk.ResponseType.OK:
|
||||
if file_chooser_dialog.get_file() is not None:
|
||||
config.set_property("file", file_chooser_dialog.get_file())
|
||||
file_entry.set_text(file_chooser_dialog.get_file().get_path())
|
||||
file_chooser_dialog.hide()
|
||||
|
||||
file_chooser_button = Gtk.Button.new_with_mnemonic(label=_("_File..."))
|
||||
grid.attach(file_chooser_button, 0, 0, 1, 1)
|
||||
file_chooser_button.show()
|
||||
file_chooser_button.connect("clicked", choose_file)
|
||||
|
||||
file_entry = Gtk.Entry.new()
|
||||
grid.attach(file_entry, 1, 0, 1, 1)
|
||||
file_entry.set_width_chars(40)
|
||||
file_entry.set_placeholder_text(_("Choose CSS file..."))
|
||||
if config.get_property ("file") != None:
|
||||
file = config.get_property("file")
|
||||
if file is not None:
|
||||
file_entry.set_text(file.get_path())
|
||||
file_entry.show()
|
||||
|
||||
use_header_bar = Gtk.Settings.get_default().get_property("gtk-dialogs-use-header")
|
||||
file_chooser_dialog = Gtk.FileChooserDialog(use_header_bar=use_header_bar,
|
||||
title=_("Save as CSS file..."),
|
||||
action=Gtk.FileChooserAction.SAVE)
|
||||
file_chooser_dialog.add_button(_("_Cancel"), Gtk.ResponseType.CANCEL)
|
||||
file_chooser_dialog.add_button(_("_OK"), Gtk.ResponseType.OK)
|
||||
|
||||
#Connect config so reset works on custom widget
|
||||
def gradient_reset (*args):
|
||||
if len(args) >= 2:
|
||||
if config.get_property("file") is not None and config.get_property("file").get_path() != file_entry.get_text():
|
||||
file_entry.set_text(config.get_property("file").get_path())
|
||||
else:
|
||||
file_entry.set_text("")
|
||||
|
||||
config.connect("notify::gradient", gradient_reset)
|
||||
config.connect("notify::file", gradient_reset)
|
||||
# Fill the dialog.
|
||||
dialog.fill (["gradient", "file"])
|
||||
|
||||
if not dialog.run():
|
||||
dialog.destroy()
|
||||
return procedure.new_return_values(Gimp.PDBStatusType.CANCEL, GLib.Error())
|
||||
else:
|
||||
file = Gio.file_new_for_path(file_entry.get_text())
|
||||
#Save configs for non-connected UI element
|
||||
config.set_property ("file", file)
|
||||
|
||||
dialog.destroy()
|
||||
|
||||
gradient = config.get_property("gradient")
|
||||
file = config.get_property("file")
|
||||
|
@ -206,8 +144,8 @@ class GradientsSaveAsCSS (Gimp.PlugIn):
|
|||
"", True,
|
||||
None, True, # Default to context.
|
||||
GObject.ParamFlags.READWRITE)
|
||||
procedure.add_file_argument ("file", _("_File"),
|
||||
"", Gimp.FileChooserAction.SAVE,
|
||||
procedure.add_file_argument ("file", _("_File"), "",
|
||||
Gimp.FileChooserAction.SAVE,
|
||||
False, None, GObject.ParamFlags.READWRITE)
|
||||
return procedure
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue