Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed toast message exception #600

Merged
merged 3 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ v4.1.0
information.
- Fixed SQL log removal through the GUI.
- Fixed CSV and JSON reading through remote.
- Disabled the :ref:`Automatic guild discovery and join` features due to the search provider shutting down its
- Fixed exception when GUI tried to print a message.
- |BREAK_CH| Disabled the :ref:`Automatic guild discovery and join` features due to the search provider shutting down its
services. It will be reenabled in a future version.


Expand Down
9 changes: 3 additions & 6 deletions src/daf/message/messageperiod.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ class NamedDayOfYearPeriod(EveryXPeriod):
----------
.. code-block:: python

# Every second monday of December at 12:00.
# Every second Monday of December at 12:00.
NamedDayOfYearPeriod(
time=time(hour=12), # Time
day="Mon", # Day (Monday)
Expand Down Expand Up @@ -377,8 +377,6 @@ class NamedDayOfMonthPeriod(EveryXPeriod):
The day of week when to send.
week: int
The week number of which to send. E.g., 1 for 1st week, 2 for second week.
month: 1 - 12
The month in which to send.
next_send_time: datetime | timedelta
Represents the time at which the message should first be sent.
Use ``datetime`` to specify the exact date and time at which the message should start being sent.
Expand All @@ -389,12 +387,11 @@ class NamedDayOfMonthPeriod(EveryXPeriod):
----------
.. code-block:: python

# Every second monday of December at 12:00.
NamedDayOfYearPeriod(
# Second Monday of every month at 12:00.
NamedDayOfMonthPeriod(
time=time(hour=12), # Time
day="Mon", # Day (Monday)
week=2, # Which week (second monday)
month=12 # Month (December)
)
"""
DAYS = Literal["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
Expand Down
15 changes: 11 additions & 4 deletions src/daf_gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,17 @@ def init_event_listeners(self):
}
dpi_78, dpi_600 = dpi_scaled(78), dpi_scaled(600)

last_toast: ToastNotification = None
def trace_listener(level: daf.TraceLEVELS, message: str):
last_toast: ToastNotification = ToastNotification.last_toast
if last_toast is not None and last_toast.toplevel.winfo_exists():
nonlocal last_toast

if last_toast is None:
next_position = dpi_78
elif last_toast.toplevel is None or last_toast.toplevel.winfo_exists():
# If toplevel is None, that means that tkinter re-entered the its event loop in the
# toast.show_toast() call before that same function was able to set the toplevel attribute.
# This happens due to ttkbootstrap library providing the 'alpha' parameter to Tkinter's TopLevel class,
# which causes Tkinter to re-enter its event loop and process another after_idle(trace_listener, ...) command.
next_position = max((last_toast.position[1] + dpi_78) % dpi_600, dpi_78)
else:
next_position = dpi_78
Expand All @@ -165,10 +173,9 @@ def trace_listener(level: daf.TraceLEVELS, message: str):
position=(10, next_position, "se"),
topmost=True
)
ToastNotification.last_toast = toast
last_toast = toast
toast.show_toast()

ToastNotification.last_toast = None
evt = daf.get_global_event_ctrl()
evt.add_listener(
daf.EventID.g_trace, lambda level, message: self.win_main.after_idle(trace_listener, level, message)
Expand Down