plug-ins: Fix Save button in Python Console

Clicking on the Save button threw an exception as the wrong class was
used to invoke the `set_alternative_button_order_from_array()` method.

Since `Gtk.Dialog.set_alternative_button_order_from_array()` is
deprecated and the GIMP functions with the same name suppress
deprecation warnings in the C code, we suppress the warning here as
well. The `warnings.catch_warnings()` function is not thread-safe
according to the Python documentation, which should not pose a problem
here.

Also, the file chooser dialog now allows specifying a new file instead
of overwriting an existing file.
This commit is contained in:
Kamil Burda 2024-02-12 19:55:07 +01:00 committed by Alx Sa
parent 57113323e2
commit c7c1743dd0
1 changed files with 8 additions and 4 deletions

View File

@ -28,6 +28,7 @@ from gi.repository import Gio
from gi.repository import GLib from gi.repository import GLib
import sys import sys
import warnings
import pyconsole import pyconsole
#import gimpshelf, gimpui, pyconsole #import gimpshelf, gimpui, pyconsole
@ -265,15 +266,18 @@ def run(procedure, config, data):
def save_dialog(self): def save_dialog(self):
if not self.save_dlg: if not self.save_dlg:
dlg = Gtk.FileChooserDialog() dlg = Gtk.FileChooserDialog(action=Gtk.FileChooserAction.SAVE)
Gtk.Window.set_title(dlg, _("Save Python-Fu Console Output")) Gtk.Window.set_title(dlg, _("Save Python-Fu Console Output"))
Gtk.Window.set_transient_for(dlg, self) Gtk.Window.set_transient_for(dlg, self)
Gtk.Dialog.add_button(dlg, _("_Cancel"), Gtk.ResponseType.CANCEL) Gtk.Dialog.add_button(dlg, _("_Cancel"), Gtk.ResponseType.CANCEL)
Gtk.Dialog.add_button(dlg, _("_Save"), Gtk.ResponseType.OK) Gtk.Dialog.add_button(dlg, _("_Save"), Gtk.ResponseType.OK)
Gtk.Dialog.set_default_response(self, Gtk.ResponseType.OK) Gtk.Dialog.set_default_response(self, Gtk.ResponseType.OK)
GimpUi.Dialog.set_alternative_button_order_from_array(dlg,
[ Gtk.ResponseType.OK, with warnings.catch_warnings():
Gtk.ResponseType.CANCEL ]) warnings.filterwarnings('ignore')
Gtk.FileChooserDialog.set_alternative_button_order_from_array(dlg,
[ Gtk.ResponseType.OK,
Gtk.ResponseType.CANCEL ])
dlg.connect('response', self.save_response) dlg.connect('response', self.save_response)