From a93368d3e9e85ee29a830e7edaffb8c70e7ebc6b Mon Sep 17 00:00:00 2001 From: David Hozic Date: Fri, 22 Dec 2023 23:29:54 +0100 Subject: [PATCH] Fixed bug --- docs/source/changelog.rst | 7 +++++++ tkclasswiz/__init__.py | 2 +- tkclasswiz/object_frame/window.py | 30 +++++++++++++++++++++--------- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index c7d125d..8a8c1b6 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -24,6 +24,13 @@ Glossary Releases --------------------- +v1.0.1 +================= +- Fixed a bug where the window didn't close and couldn't be closed + if an exception was raised when trying to define a class without annotations, and there + were no previously opened frames. + + v1.0.0 ================= - Initial release diff --git a/tkclasswiz/__init__.py b/tkclasswiz/__init__.py index 27a468a..24e2f60 100644 --- a/tkclasswiz/__init__.py +++ b/tkclasswiz/__init__.py @@ -3,7 +3,7 @@ Works with Tkinter / TTKBootstrap. """ -__version__ = "1.0.0" +__version__ = "1.0.1" from .object_frame import * from .annotations import * diff --git a/tkclasswiz/object_frame/window.py b/tkclasswiz/object_frame/window.py index 4cd49d7..39a7ecf 100644 --- a/tkclasswiz/object_frame/window.py +++ b/tkclasswiz/object_frame/window.py @@ -76,7 +76,6 @@ def __init__(self, *args, **kwargs): def closed(self) -> bool: return self._closed - @gui_except() def open_object_edit_frame( self, class_, @@ -104,16 +103,26 @@ def open_object_edit_frame( allow_save: bool If False, will open in read-only mode. """ - if len(self.opened_frames): - prev_frame = self.opened_frames[-1] - else: - prev_frame = None + frame = self._create_and_add_frame(class_, return_widget, old_data, check_parameters, allow_save, kwargs) + if frame is None and not self.opened_frames: + self.destroy() + self._closed = True + @gui_except() + def _create_and_add_frame( + self, + class_: type, + return_widget, + old_data, + check_parameters: bool, + allow_save: bool, + kwargs + ): + frame: NewObjectFrameBase class_origin = get_origin(class_) if class_origin is None: class_origin = class_ - frame: NewObjectFrameBase frame_class = self.TYPE_INIT_MAP.get(class_origin, NewObjectFrameStruct) self.opened_frames.append( frame := frame_class( @@ -126,13 +135,16 @@ def open_object_edit_frame( **kwargs ) ) + + if len(self.opened_frames) > 1: + self.opened_frames[-2].pack_forget() + frame.pack(fill=tk.BOTH, expand=True) frame.update_window_title() - if prev_frame is not None: - prev_frame.pack_forget() - self.set_default_size_y() + return frame + def close_object_edit_frame(self): self.opened_frames[-1].close_frame()