From 179cceed57fa6bbc5d13b386cb5af53c5cc5103d Mon Sep 17 00:00:00 2001 From: Isaiah Odhner Date: Wed, 6 Sep 2023 13:57:12 -0400 Subject: [PATCH] Avoid global statement for ID counter --- src/textual_paint/windows.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/textual_paint/windows.py b/src/textual_paint/windows.py index a4e7914..667536a 100644 --- a/src/textual_paint/windows.py +++ b/src/textual_paint/windows.py @@ -51,7 +51,6 @@ class WindowTitleBar(Container): yield restore_button yield Button(self.CLOSE_ICON, classes="window_close") -id_counter = 0 class Window(Container): """A draggable window widget.""" @@ -77,6 +76,8 @@ class Window(Container): ("left,up", "focus_previous_button", "Focus Previous Button"), ] + id_counter: ClassVar[int] = 0 + def __init__( self, *children: Widget, @@ -98,9 +99,8 @@ class Window(Container): self.last_focused_descendant: Widget | None = None if not self.id: # ID is needed for focus cycling - global id_counter - self.id = f"window_auto_id_{id_counter}" - id_counter += 1 + self.id = f"window_auto_id_{Window.id_counter}" + Window.id_counter += 1 def action_focus_next(self) -> None: """Override action to focus the next widget only within the window."""