Skip to content

Commit

Permalink
feat(notifications): add clear close KlipperScreen#1178
Browse files Browse the repository at this point in the history
  • Loading branch information
alfrix committed Jul 6, 2024
1 parent 115dba8 commit fde41e8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
23 changes: 18 additions & 5 deletions panels/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,19 @@ def __init__(self, screen, title):

scroll = Gtk.ScrolledWindow(hexpand=True, vexpand=True)
scroll.add(tv)
self.content.add(scroll)

clear_button = self._gtk.Button("refresh", _('Clear') + " ", None, self.bts, Gtk.PositionType.RIGHT, 1)
clear_button.get_style_context().add_class("buttons_slim")
clear_button.set_vexpand(False)
clear_button.connect("clicked", self.clear)

content_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
content_box.add(clear_button)
content_box.add(scroll)
self.content.add(content_box)

def activate(self):
self.clear()
for log in self._screen.notification_log:
self.add_notification(log)
self.refresh()

def add_notification(self, log):
if log["level"] == 0:
Expand All @@ -55,8 +62,14 @@ def add_notification(self, log):
-1
)

def clear(self):
def clear(self, widget):
self.tb.set_text("")
self._screen.notification_log_clear()

def refresh(self):
self.tb.set_text("")
for log in self._screen.notification_log:
self.add_notification(log)

def process_update(self, action, data):
if action != "notify_log":
Expand Down
3 changes: 3 additions & 0 deletions screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ def log_notification(self, message, level=0):
self.notification_log.append(log_entry)
self.process_update("notify_log", log_entry)

def notification_log_clear(self):
self.notification_log.clear()

def show_popup_message(self, message, level=3, from_ws=False):
if from_ws:
if (datetime.now() - self.last_popup_time).seconds < 1:
Expand Down

0 comments on commit fde41e8

Please sign in to comment.