From c7c1743dd077cabe053da6418b317fdf7b67ebb1 Mon Sep 17 00:00:00 2001 From: Kamil Burda <123164-kamilburda@users.noreply.gitlab.gnome.org> Date: Mon, 12 Feb 2024 19:55:07 +0100 Subject: [PATCH] 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. --- plug-ins/python/python-console/python-console.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/plug-ins/python/python-console/python-console.py b/plug-ins/python/python-console/python-console.py index 9f88c08e31..542f0fb217 100755 --- a/plug-ins/python/python-console/python-console.py +++ b/plug-ins/python/python-console/python-console.py @@ -28,6 +28,7 @@ from gi.repository import Gio from gi.repository import GLib import sys +import warnings import pyconsole #import gimpshelf, gimpui, pyconsole @@ -265,15 +266,18 @@ def run(procedure, config, data): def save_dialog(self): 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_transient_for(dlg, self) Gtk.Dialog.add_button(dlg, _("_Cancel"), Gtk.ResponseType.CANCEL) Gtk.Dialog.add_button(dlg, _("_Save"), Gtk.ResponseType.OK) Gtk.Dialog.set_default_response(self, Gtk.ResponseType.OK) - GimpUi.Dialog.set_alternative_button_order_from_array(dlg, - [ Gtk.ResponseType.OK, - Gtk.ResponseType.CANCEL ]) + + with warnings.catch_warnings(): + warnings.filterwarnings('ignore') + Gtk.FileChooserDialog.set_alternative_button_order_from_array(dlg, + [ Gtk.ResponseType.OK, + Gtk.ResponseType.CANCEL ]) dlg.connect('response', self.save_response)