- Implemented line limit for text overlay

- Remove attachments when that are out of scope
This commit is contained in:
Trigg 2022-05-17 10:11:59 +00:00
parent 3a97c6dbed
commit 57b482ebf4
3 changed files with 48 additions and 3 deletions

View file

@ -91,8 +91,10 @@ class Discover:
if self.voice_overlay.needsredraw:
self.voice_overlay.redraw()
if self.text_overlay and self.text_overlay.needsredraw:
self.text_overlay.redraw()
if self.text_overlay:
self.text_overlay.tick()
if self.text_overlay.needsredraw:
self.text_overlay.redraw()
if self.notification_overlay and self.notification_overlay.enabled:
self.notification_overlay.tick()

View file

@ -38,6 +38,7 @@ class TextOverlayWindow(OverlayWindow):
self.text_time = None
self.show_attach = None
self.popup_style = None
self.line_limit = 100
# 0, 0, self.text_size, self.text_size)
self.pango_rect = Pango.Rectangle()
self.pango_rect.width = self.text_size * Pango.SCALE
@ -54,17 +55,30 @@ class TextOverlayWindow(OverlayWindow):
self.set_title("Discover Text")
self.redraw()
def tick(self):
if len(self.attachment) > self.line_limit:
# We've probably got old images!
oldlist = self.attachment
self.attachment = {}
log.info("Cleaning old images")
for message in self.content:
if 'attach' in message and message['attach']:
url = message['attach'][0]['url']
log.info("keeping %s", url)
self.attachment[url] = oldlist[url]
def set_text_time(self, timer):
"""
Set the duration that a message will be visible for.
"""
self.text_time = timer
self.needsredraw = True
def set_text_list(self, tlist, altered):
"""
Update the list of text messages to show
"""
self.content = tlist
self.content = tlist[-self.line_limit:]
if altered:
self.needsredraw = True
@ -107,6 +121,12 @@ class TextOverlayWindow(OverlayWindow):
self.pango_rect.height = font.get_size() * Pango.SCALE
self.needsredraw = True
def set_line_limit(self, limit):
"""
Change maximum number of lines in overlay
"""
self.line_limit = limit
def make_line(self, message):
"""
Decode a recursive JSON object into pango markup.

View file

@ -64,6 +64,7 @@ class TextSettingsWindow(SettingsWindow):
self.popup_style = None
self.text_time = None
self.show_attach = None
self.line_limit = None
self.enabled = None
self.set_size_request(400, 200)
@ -239,6 +240,7 @@ class TextSettingsWindow(SettingsWindow):
self.text_time = config.getint("text", "text_time", fallback=30)
self.show_attach = config.getboolean(
"text", "show_attach", fallback=True)
self.line_limit = config.getint("text", "line_limit", fallback=20)
self.autohide = config.getboolean("text", "autohide", fallback=False)
log.info(
@ -257,6 +259,7 @@ class TextSettingsWindow(SettingsWindow):
self.overlay.set_popup_style(self.popup_style)
self.overlay.set_text_time(self.text_time)
self.overlay.set_show_attach(self.show_attach)
self.overlay.set_line_limit(self.line_limit)
self.overlay.set_hide_on_mouseover(self.autohide)
if self.font:
@ -286,6 +289,7 @@ class TextSettingsWindow(SettingsWindow):
config.set("text", "fg_col", json.dumps(self.fg_col))
config.set("text", "popup_style", "%s" % (int(self.popup_style)))
config.set("text", "text_time", "%s" % (int(self.text_time)))
config.set("text", "line_limit", "%s" % (int(self.line_limit)))
config.set("text", "show_attach", "%s" % (int(self.show_attach)))
if self.font:
@ -426,6 +430,14 @@ class TextSettingsWindow(SettingsWindow):
show_attach.set_active(self.show_attach)
show_attach.connect("toggled", self.change_show_attach)
# Line Limit
line_limit_label = Gtk.Label.new(_("Line limit"))
line_limit_label.set_xalign(0)
line_limit_adjustment = Gtk.Adjustment.new(
self.line_limit, 10, 400, 1, 1, 8)
line_limit = Gtk.SpinButton.new(line_limit_adjustment, 0, 0)
line_limit.connect("value-changed", self.change_line_limit)
self.align_x_widget = align_x
self.align_y_widget = align_y
self.align_monitor_widget = monitor
@ -464,6 +476,8 @@ class TextSettingsWindow(SettingsWindow):
box.attach(align_placement_button, 1, 13, 1, 1)
box.attach(show_attach_label, 0, 14, 1, 1)
box.attach(show_attach, 1, 14, 1, 1)
box.attach(line_limit_label, 0, 15, 1, 1)
box.attach(line_limit, 1, 15, 1, 1)
self.add(box)
@ -585,3 +599,12 @@ class TextSettingsWindow(SettingsWindow):
self.show_attach = button.get_active()
self.save_config()
def change_line_limit(self, button):
"""
Line limit setting changed
"""
self.overlay.set_line_limit(button.get_value())
self.line_limit = button.get_value()
self.save_config()