From d5e55f8aad718dbac60244781f17118356909d92 Mon Sep 17 00:00:00 2001 From: alfrix Date: Mon, 21 Aug 2023 15:55:29 -0300 Subject: [PATCH] PEP E721 --- ks_includes/KlippyGtk.py | 21 +++++++++------------ screen.py | 4 ++-- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/ks_includes/KlippyGtk.py b/ks_includes/KlippyGtk.py index a017e3e3..65602e28 100644 --- a/ks_includes/KlippyGtk.py +++ b/ks_includes/KlippyGtk.py @@ -9,17 +9,14 @@ from gi.repository import Gdk, GdkPixbuf, Gio, Gtk, Pango def format_label(widget, lines=2): - if type(widget) == Gtk.Label: - return widget - if type(widget) in (Gtk.Container, Gtk.Bin, Gtk.Button, Gtk.Alignment, Gtk.Box): + if isinstance(widget, Gtk.Label): + widget.set_line_wrap_mode(Pango.WrapMode.WORD_CHAR) + widget.set_line_wrap(True) + widget.set_ellipsize(Pango.EllipsizeMode.END) + widget.set_lines(lines) + elif isinstance(widget, (Gtk.Container, Gtk.Bin, Gtk.Button, Gtk.Alignment, Gtk.Box)): for _ in widget.get_children(): - lbl = format_label(_) - if lbl is not None: - lbl.set_line_wrap_mode(Pango.WrapMode.WORD_CHAR) - lbl.set_line_wrap(True) - lbl.set_ellipsize(True) - lbl.set_ellipsize(Pango.EllipsizeMode.END) - lbl.set_lines(lines) + format_label(_, lines) class KlippyGtk: @@ -187,12 +184,12 @@ class KlippyGtk: widget.set_sensitive(False) widget.set_always_show_image(False) box.get_children()[0].hide() - if type(box.get_children()[1]) == Gtk.Spinner: + if isinstance(box.get_children()[1], Gtk.Spinner): box.get_children()[1].start() box.get_children()[1].show() else: box.get_children()[0].show() - if type(box.get_children()[1]) == Gtk.Spinner: + if isinstance(box.get_children()[1], Gtk.Spinner): box.get_children()[1].stop() box.get_children()[1].hide() widget.set_always_show_image(True) diff --git a/screen.py b/screen.py index cbec0e6f..4859b5d7 100755 --- a/screen.py +++ b/screen.py @@ -788,7 +788,7 @@ class KlipperScreen(Gtk.Window): def _send_action(self, widget, method, params): logging.info(f"{method}: {params}") - if type(widget) == Gtk.Button: + if isinstance(widget, Gtk.Button): self.gtk.Button_busy(widget, True) self._ws.send_method(method, params, self.enable_widget, widget) else: @@ -796,7 +796,7 @@ class KlipperScreen(Gtk.Window): def enable_widget(self, *args): for x in args: - if type(x) == Gtk.Button: + if isinstance(x, Gtk.Button): GLib.timeout_add(150, self.gtk.Button_busy, x, False) def printer_initializing(self, msg, remove=False):