Avoid global statement for ID counter

This commit is contained in:
Isaiah Odhner 2023-09-06 13:57:12 -04:00
parent ea0d90952a
commit 179cceed57

View File

@ -51,7 +51,6 @@ class WindowTitleBar(Container):
yield restore_button yield restore_button
yield Button(self.CLOSE_ICON, classes="window_close") yield Button(self.CLOSE_ICON, classes="window_close")
id_counter = 0
class Window(Container): class Window(Container):
"""A draggable window widget.""" """A draggable window widget."""
@ -77,6 +76,8 @@ class Window(Container):
("left,up", "focus_previous_button", "Focus Previous Button"), ("left,up", "focus_previous_button", "Focus Previous Button"),
] ]
id_counter: ClassVar[int] = 0
def __init__( def __init__(
self, self,
*children: Widget, *children: Widget,
@ -98,9 +99,8 @@ class Window(Container):
self.last_focused_descendant: Widget | None = None self.last_focused_descendant: Widget | None = None
if not self.id: if not self.id:
# ID is needed for focus cycling # ID is needed for focus cycling
global id_counter self.id = f"window_auto_id_{Window.id_counter}"
self.id = f"window_auto_id_{id_counter}" Window.id_counter += 1
id_counter += 1
def action_focus_next(self) -> None: def action_focus_next(self) -> None:
"""Override action to focus the next widget only within the window.""" """Override action to focus the next widget only within the window."""