diff --git a/lib/solaar/ui/about.py b/lib/solaar/ui/about.py deleted file mode 100644 index 6303d27b8d..0000000000 --- a/lib/solaar/ui/about.py +++ /dev/null @@ -1,105 +0,0 @@ -## Copyright (C) 2012-2013 Daniel Pavel -## Revisions Copyright (C) Contributors to the Solaar project. -## -## 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. - -import logging - -from gi.repository import Gtk - -from solaar import NAME -from solaar import __version__ -from solaar.i18n import _ - -# -# -# - -_dialog = None - - -def _create(): - about = Gtk.AboutDialog() - - about.set_program_name(NAME) - about.set_version(__version__) - about.set_comments(_("Manages Logitech receivers,\nkeyboards, mice, and tablets.")) - about.set_icon_name(NAME.lower()) - - about.set_copyright("© 2012-2023 Daniel Pavel and contributors to the Solaar project") - about.set_license_type(Gtk.License.GPL_2_0) - - about.set_authors(("Daniel Pavel http://github.com/pwr",)) - try: - about.add_credit_section(_("Additional Programming"), ("Filipe Laíns", "Peter F. Patel-Schneider")) - about.add_credit_section(_("GUI design"), ("Julien Gascard", "Daniel Pavel")) - about.add_credit_section( - _("Testing"), - ( - "Douglas Wagner", - "Julien Gascard", - "Peter Wu http://www.lekensteyn.nl/logitech-unifying.html", - ), - ) - about.add_credit_section( - _("Logitech documentation"), - ( - "Julien Danjou http://julien.danjou.info/blog/2012/logitech-unifying-upower", - "Nestor Lopez Casado http://drive.google.com/folderview?id=0BxbRzx7vEV7eWmgwazJ3NUFfQ28", - ), - ) - except TypeError: - # gtk3 < ~3.6.4 has incorrect gi bindings - logging.exception("failed to fully create the about dialog") - except Exception: - # the Gtk3 version may be too old, and the function does not exist - logging.exception("failed to fully create the about dialog") - - about.set_translator_credits( - "\n".join( - ( - "gogo (croatian)", - "Papoteur, David Geiger, Damien Lallement (français)", - "Michele Olivo (italiano)", - "Adrian Piotrowicz (polski)", - "Drovetto, JrBenito (Portuguese-BR)", - "Daniel Pavel (română)", - "Daniel Zippert, Emelie Snecker (svensk)", - "Dimitriy Ryazantcev (Russian)", - "El Jinete Sin Cabeza (Español)", - "Ferdina Kusumah (Indonesia)", - ) - ) - ) - - about.set_website("https://pwr-solaar.github.io/Solaar") - about.set_website_label(NAME) - - about.connect("response", lambda x, y: x.hide()) - - def _hide(dialog, event): - dialog.hide() - return True - - about.connect("delete-event", _hide) - - return about - - -def show_window(trigger=None): - global _dialog - if _dialog is None: - _dialog = _create() - _dialog.present() diff --git a/lib/solaar/ui/about/__init__.py b/lib/solaar/ui/about/__init__.py new file mode 100644 index 0000000000..97cbd89505 --- /dev/null +++ b/lib/solaar/ui/about/__init__.py @@ -0,0 +1 @@ +from .about import show_window # noqa: F401 diff --git a/lib/solaar/ui/about/about.py b/lib/solaar/ui/about/about.py new file mode 100644 index 0000000000..b3fc23d3b8 --- /dev/null +++ b/lib/solaar/ui/about/about.py @@ -0,0 +1,26 @@ +## Copyright (C) Solaar Contributors +## +## 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. + +from solaar.ui.about.model import AboutModel +from solaar.ui.about.presenter import Presenter +from solaar.ui.about.view import AboutView + + +def show_window(_args): + model = AboutModel() + view = AboutView() + presenter = Presenter(model, view) + presenter.run() diff --git a/lib/solaar/ui/about/model.py b/lib/solaar/ui/about/model.py new file mode 100644 index 0000000000..90f0972b5b --- /dev/null +++ b/lib/solaar/ui/about/model.py @@ -0,0 +1,68 @@ +## Copyright (C) Solaar Contributors +## +## 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. + +from solaar.i18n import _ + + +class AboutModel: + def get_authors(self) -> list[str]: + return [ + "Daniel Pavel http://github.com/pwr", + ] + + def get_comments(self) -> str: + return _("Manages Logitech receivers,\nkeyboards, mice, and tablets.") + + def get_copyright(self) -> str: + return "© 2012-2023 Daniel Pavel and contributors to the Solaar project" + + def get_translators(self) -> list[str]: + return [ + "gogo (croatian)", + "Papoteur, David Geiger, Damien Lallement (français)", + "Michele Olivo (italiano)", + "Adrian Piotrowicz (polski)", + "Drovetto, JrBenito (Portuguese-BR)", + "Daniel Pavel (română)", + "Daniel Zippert, Emelie Snecker (svensk)", + "Dimitriy Ryazantcev (Russian)", + "El Jinete Sin Cabeza (Español)", + "Ferdina Kusumah (Indonesia)", + ] + + def get_credit_sections(self) -> list[tuple[str, list[str]]]: + return [ + (_("Additional Programming"), ["Filipe Laíns", "Peter F. Patel-Schneider"]), + (_("GUI design"), ["Julien Gascard", "Daniel Pavel"]), + ( + _("Testing"), + [ + "Douglas Wagner", + "Julien Gascard", + "Peter Wu http://www.lekensteyn.nl/logitech-unifying.html", + ], + ), + ( + _("Logitech documentation"), + [ + "Julien Danjou http://julien.danjou.info/blog/2012/logitech-unifying-upower", + "Nestor Lopez Casado http://drive.google.com/folderview?id=0BxbRzx7vEV7eWmgwazJ3NUFfQ28", + ], + ), + ] + + def get_website(self): + return "https://pwr-solaar.github.io/Solaar" diff --git a/lib/solaar/ui/about/presenter.py b/lib/solaar/ui/about/presenter.py new file mode 100644 index 0000000000..187cdc2ddd --- /dev/null +++ b/lib/solaar/ui/about/presenter.py @@ -0,0 +1,89 @@ +## Copyright (C) Solaar Contributors +## +## 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. + +from __future__ import annotations + +import logging + +from typing import Protocol + +from solaar.ui.about.model import AboutModel + + +class AboutViewProtocol(Protocol): + def init_ui(self, presenter: Presenter) -> None: + ... + + def update_credit_sections(self, section_name: str, people: list[str]) -> None: + ... + + def update_comments(self, comments: str) -> None: + ... + + def update_authors(self, authors: list[str]) -> None: + ... + + def update_translator_credits(self, translators: list[str]) -> None: + ... + + def update_website(self, website): + ... + + def mainloop(self) -> None: + ... + + +class Presenter: + def __init__(self, model: AboutModel, view: AboutViewProtocol) -> None: + self.model = model + self.view = view + + def update_credit_sections(self) -> None: + credits_section = self.model.get_credit_sections() + for section_name, people in credits_section: + try: + self.view.update_credit_sections(section_name, people) + except TypeError: + # gtk3 < ~3.6.4 has incorrect gi bindings + logging.exception("failed to fully create the about dialog") + except Exception: + # the Gtk3 version may be too old, and the function does not exist + logging.exception("failed to fully create the about dialog") + + def update_comments(self) -> None: + comments = self.model.get_comments() + self.view.update_comments(comments) + + def update_authors(self) -> None: + authors = self.model.get_authors() + self.view.update_authors(authors) + + def update_translators(self) -> None: + translators = self.model.get_translators() + self.view.update_translator_credits(translators) + + def update_website(self) -> None: + website = self.model.get_website() + self.view.update_website(website) + + def run(self) -> None: + self.view.init_ui(self) + self.update_credit_sections() + self.update_comments() + self.update_authors() + self.update_translators() + self.update_website() + self.view.mainloop() diff --git a/lib/solaar/ui/about/view.py b/lib/solaar/ui/about/view.py new file mode 100644 index 0000000000..ea7b42c519 --- /dev/null +++ b/lib/solaar/ui/about/view.py @@ -0,0 +1,56 @@ +## Copyright (C) Solaar Contributors +## +## 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. + +from typing import Union + +from gi.repository import Gtk + +from solaar import NAME +from solaar import __version__ + + +class AboutView: + def __init__(self) -> None: + self.about: Union[Gtk.AboutDialog, None] = None + + def init_ui(self) -> None: + self.about = Gtk.AboutDialog() + self.about.set_program_name(NAME) + self.about.set_version(__version__) + self.about.set_icon_name(NAME.lower()) + self.about.set_license_type(Gtk.License.GPL_2_0) + self.about.set_website_label(NAME) + + self.about.connect("response", lambda x, y: self.handle_close(x)) + + def update_comments(self, comments: str) -> None: + self.about.set_comments(comments) + + def update_authors(self, authors: list[str]) -> None: + self.about.set_authors(authors) + + def update_translator_credits(self, translators: list[str]) -> None: + translator_credits = "\n".join(translators) + self.about.set_translator_credits(translator_credits) + + def update_website(self, website): + self.about.set_website(website) + + def mainloop(self) -> None: + self.about.present() + + def handle_close(self, event) -> None: + event.hide() diff --git a/lib/solaar/ui/window.py b/lib/solaar/ui/window.py index 8311246c6d..e74832604d 100644 --- a/lib/solaar/ui/window.py +++ b/lib/solaar/ui/window.py @@ -28,10 +28,10 @@ from solaar.i18n import _ from solaar.i18n import ngettext +from . import about from . import action as _action from . import config_panel as _config_panel from . import icons as _icons -from .about import show_window as _show_about_window from .common import ui_async as _ui_async from .diversion_rules import show_window as _show_diversion_window @@ -307,7 +307,7 @@ def _create_window_layout(): bottom_buttons_box.set_spacing(20) quit_button = _new_button(_("Quit %s") % NAME, "application-exit", _SMALL_BUTTON_ICON_SIZE, clicked=destroy) bottom_buttons_box.add(quit_button) - about_button = _new_button(_("About %s") % NAME, "help-about", _SMALL_BUTTON_ICON_SIZE, clicked=_show_about_window) + about_button = _new_button(_("About %s") % NAME, "help-about", _SMALL_BUTTON_ICON_SIZE, clicked=about.show_window) bottom_buttons_box.add(about_button) diversion_button = _new_button( _("Rule Editor"), "", _SMALL_BUTTON_ICON_SIZE, clicked=lambda *_trigger: _show_diversion_window(_model)