Skip to content

Commit b4845a8

Browse files
authored
Merge pull request #600 from davidhozic/develop
Fixed toast message exception
2 parents 80ec882 + 33618f8 commit b4845a8

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

docs/source/changelog.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ v4.1.0
5050
information.
5151
- Fixed SQL log removal through the GUI.
5252
- Fixed CSV and JSON reading through remote.
53-
- Disabled the :ref:`Automatic guild discovery and join` features due to the search provider shutting down its
53+
- Fixed exception when GUI tried to print a message.
54+
- |BREAK_CH| Disabled the :ref:`Automatic guild discovery and join` features due to the search provider shutting down its
5455
services. It will be reenabled in a future version.
5556

5657

src/daf/message/messageperiod.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ class NamedDayOfYearPeriod(EveryXPeriod):
300300
----------
301301
.. code-block:: python
302302
303-
# Every second monday of December at 12:00.
303+
# Every second Monday of December at 12:00.
304304
NamedDayOfYearPeriod(
305305
time=time(hour=12), # Time
306306
day="Mon", # Day (Monday)
@@ -377,8 +377,6 @@ class NamedDayOfMonthPeriod(EveryXPeriod):
377377
The day of week when to send.
378378
week: int
379379
The week number of which to send. E.g., 1 for 1st week, 2 for second week.
380-
month: 1 - 12
381-
The month in which to send.
382380
next_send_time: datetime | timedelta
383381
Represents the time at which the message should first be sent.
384382
Use ``datetime`` to specify the exact date and time at which the message should start being sent.
@@ -389,12 +387,11 @@ class NamedDayOfMonthPeriod(EveryXPeriod):
389387
----------
390388
.. code-block:: python
391389
392-
# Every second monday of December at 12:00.
393-
NamedDayOfYearPeriod(
390+
# Second Monday of every month at 12:00.
391+
NamedDayOfMonthPeriod(
394392
time=time(hour=12), # Time
395393
day="Mon", # Day (Monday)
396394
week=2, # Which week (second monday)
397-
month=12 # Month (December)
398395
)
399396
"""
400397
DAYS = Literal["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]

src/daf_gui/main.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,17 @@ def init_event_listeners(self):
149149
}
150150
dpi_78, dpi_600 = dpi_scaled(78), dpi_scaled(600)
151151

152+
last_toast: ToastNotification = None
152153
def trace_listener(level: daf.TraceLEVELS, message: str):
153-
last_toast: ToastNotification = ToastNotification.last_toast
154-
if last_toast is not None and last_toast.toplevel.winfo_exists():
154+
nonlocal last_toast
155+
156+
if last_toast is None:
157+
next_position = dpi_78
158+
elif last_toast.toplevel is None or last_toast.toplevel.winfo_exists():
159+
# If toplevel is None, that means that tkinter re-entered the its event loop in the
160+
# toast.show_toast() call before that same function was able to set the toplevel attribute.
161+
# This happens due to ttkbootstrap library providing the 'alpha' parameter to Tkinter's TopLevel class,
162+
# which causes Tkinter to re-enter its event loop and process another after_idle(trace_listener, ...) command.
155163
next_position = max((last_toast.position[1] + dpi_78) % dpi_600, dpi_78)
156164
else:
157165
next_position = dpi_78
@@ -165,10 +173,9 @@ def trace_listener(level: daf.TraceLEVELS, message: str):
165173
position=(10, next_position, "se"),
166174
topmost=True
167175
)
168-
ToastNotification.last_toast = toast
176+
last_toast = toast
169177
toast.show_toast()
170178

171-
ToastNotification.last_toast = None
172179
evt = daf.get_global_event_ctrl()
173180
evt.add_listener(
174181
daf.EventID.g_trace, lambda level, message: self.win_main.after_idle(trace_listener, level, message)

0 commit comments

Comments
 (0)