From f8f0b0618ccd68d7a34ff750216f4977d8a12bab Mon Sep 17 00:00:00 2001 From: Romain Failliot Date: Sat, 8 Apr 2023 15:00:46 -0400 Subject: [PATCH] refactor: remove thin layer for Gtk.AboutDialog --- src/diffuse/constants.py | 1 + src/diffuse/dialogs.py | 34 ---------------------------------- src/diffuse/main.py | 2 +- src/diffuse/window.py | 40 ++++++++++++++++++++++++++++++++++++---- 4 files changed, 38 insertions(+), 39 deletions(-) diff --git a/src/diffuse/constants.py b/src/diffuse/constants.py index 642d8d6..91041ac 100644 --- a/src/diffuse/constants.py +++ b/src/diffuse/constants.py @@ -21,6 +21,7 @@ from gettext import gettext as _ from typing import Final APP_NAME: Final[str] = 'Diffuse' +APP_ID: Final[str] = 'io.github.mightycreak.Diffuse' COPYRIGHT: Final[str] = '''{copyright} © 2006-2019 Derrick Moser {copyright} © 2015-2023 Romain Failliot'''.format(copyright=_("Copyright")) WEBSITE: Final[str] = 'https://mightycreak.github.io/diffuse/' diff --git a/src/diffuse/dialogs.py b/src/diffuse/dialogs.py index ef74e81..ea9b88c 100644 --- a/src/diffuse/dialogs.py +++ b/src/diffuse/dialogs.py @@ -22,7 +22,6 @@ import os from gettext import gettext as _ from typing import Optional -from diffuse import constants from diffuse import utils import gi # type: ignore @@ -31,39 +30,6 @@ gi.require_version('Gtk', '3.0') from gi.repository import GObject, Gtk # type: ignore # noqa: E402 -# the about dialog -class AboutDialog(Gtk.AboutDialog): - def __init__(self, parent: Gtk.Widget) -> None: - Gtk.AboutDialog.__init__(self) - self.set_transient_for(parent) - self.set_logo_icon_name('io.github.mightycreak.Diffuse') - self.set_program_name(constants.APP_NAME) - self.set_version(constants.VERSION) - self.set_comments(_('Diffuse is a graphical tool for merging and comparing text files.')) - self.set_copyright(constants.COPYRIGHT) - self.set_website(constants.WEBSITE) - self.set_authors(['Derrick Moser ', - 'Romain Failliot ']) - self.set_translator_credits(_('translator-credits')) - license_text = [ - constants.APP_NAME + ' ' + constants.VERSION + '\n\n', - constants.COPYRIGHT + '\n\n', - '''This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.'''] - self.set_license(''.join(license_text)) - - # custom dialogue for picking files with widgets for specifying the encoding # and revision class FileChooserDialog(Gtk.FileChooserDialog): diff --git a/src/diffuse/main.py b/src/diffuse/main.py index 589703e..befa6b4 100644 --- a/src/diffuse/main.py +++ b/src/diffuse/main.py @@ -37,7 +37,7 @@ class DiffuseApplication(Gtk.Application): def __init__(self, sysconfigdir): super().__init__( - application_id='io.github.mightycreak.Diffuse', + application_id=constants.APP_ID, flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE | Gio.ApplicationFlags.NON_UNIQUE) self.window = None diff --git a/src/diffuse/window.py b/src/diffuse/window.py index 805658d..7f6e53a 100644 --- a/src/diffuse/window.py +++ b/src/diffuse/window.py @@ -28,7 +28,7 @@ from typing import List, Optional from urllib.parse import urlparse from diffuse import constants, utils -from diffuse.dialogs import AboutDialog, FileChooserDialog, NumericDialog, SearchDialog +from diffuse.dialogs import FileChooserDialog, NumericDialog, SearchDialog from diffuse.preferences import Preferences from diffuse.resources import theResources from diffuse.utils import LineEnding @@ -1733,9 +1733,41 @@ class DiffuseWindow(Gtk.ApplicationWindow): # callback for the about menu item def about_cb(self, widget, data): - dialog = AboutDialog(self.get_toplevel()) - dialog.run() - dialog.destroy() + authors = [ + 'Derrick Moser ', + 'Romain Failliot ' + ] + license = f'''{constants.APP_NAME} {constants.VERSION} + +{constants.COPYRIGHT} + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.''' + + dialog = Gtk.AboutDialog( + transient_for=self.get_toplevel(), + modal=True, + program_name=constants.APP_NAME, + logo_icon_name=constants.APP_ID, + version=constants.VERSION, + comments=_('Diffuse is a graphical tool for merging and comparing text files.'), + copyright=constants.COPYRIGHT, + website=constants.WEBSITE, + authors=authors, + translator_credits=_('translator-credits'), + license=license) + dialog.present() def _append_buttons(box, size, specs):