Added unread indicator to menu bar.

This commit is contained in:
Mark Qvist 2021-09-23 17:20:13 +02:00
parent 953c8c94c7
commit f86cdb4c5e
4 changed files with 50 additions and 12 deletions

View File

@ -223,6 +223,12 @@ class NomadNetworkApp:
def conversations(self):
return nomadnet.Conversation.conversation_list(self)
def has_unread_conversations(self):
if len(nomadnet.Conversation.unread_conversations) > 0:
return True
else:
return False
def conversation_is_unread(self, source_hash):
if bytes.fromhex(source_hash) in nomadnet.Conversation.unread_conversations:
return True

View File

@ -103,13 +103,14 @@ GLYPHS = {
("arrow_d", "\\/", "\u2193", "\u2193"),
("warning", "!", "\u26a0", "\uf12a"),
("info", "i", "\u2139", "\ufb4d"),
("unread", "[U]", "\u2709", "\uf003 "),
("unread", "[!]", "\u2709", "\uf003 "),
("divider1", "-", "\u2504", "\u2504"),
("peer", "[P]", "\u24c5 ", "\uf415"),
("node", "[N]", "\u24c3 ", "\uf502"),
("page", "", "\u25a4", "\uf719 "),
("speed", "", "\u25F7", "\uf9c4"),
("decoration_menu", "", "", " \uf93a"),
("decoration_menu", " +", " +", " \uf93a"),
("unread_menu", " !", " \u2709", " \uf003 "),
("globe", "", "", "\uf484"),
}
@ -183,6 +184,7 @@ class TextUI:
self.set_colormode(colormode)
self.main_display.start()
self.loop.run()
def set_colormode(self, colormode):

View File

@ -316,14 +316,15 @@ class ConversationsDisplay():
self.ilb.select_item(ilb_position)
nomadnet.NomadNetworkApp.get_shared_instance().ui.loop.draw_screen()
if self.currently_displayed_conversation != None:
if self.app.conversation_is_unread(self.currently_displayed_conversation):
self.app.mark_conversation_read(self.currently_displayed_conversation)
try:
if os.path.isfile(self.app.conversationpath + "/" + self.currently_displayed_conversation + "/unread"):
os.unlink(self.app.conversationpath + "/" + self.currently_displayed_conversation + "/unread")
except Exception as e:
raise e
if self.app.ui.main_display.sub_displays.active_display == self.app.ui.main_display.sub_displays.conversations_display:
if self.currently_displayed_conversation != None:
if self.app.conversation_is_unread(self.currently_displayed_conversation):
self.app.mark_conversation_read(self.currently_displayed_conversation)
try:
if os.path.isfile(self.app.conversationpath + "/" + self.currently_displayed_conversation + "/unread"):
os.unlink(self.app.conversationpath + "/" + self.currently_displayed_conversation + "/unread")
except Exception as e:
raise e

View File

@ -135,6 +135,9 @@ class MainDisplay():
def redraw_now(self, sender=None, data=None):
self.app.ui.loop.draw_screen()
def start(self):
self.menu_display.start()
def quit(self, sender=None):
raise urwid.ExitMainLoop
@ -147,11 +150,16 @@ class MenuColumns(urwid.Columns):
return super(MenuColumns, self).keypress(size, key)
class MenuDisplay():
UPDATE_INTERVAL = 2
def __init__(self, app, handler):
self.app = app
g = self.app.ui.glyphs
self.update_interval = MenuDisplay.UPDATE_INTERVAL
self.g = self.app.ui.glyphs
menu_text = ("pack", urwid.Text(g["decoration_menu"]))
self.menu_indicator = urwid.Text("")
menu_text = ("pack", self.menu_indicator)
button_network = (11, MenuButton("Network", on_press=handler.show_network))
button_conversations = (17, MenuButton("Conversations", on_press=handler.show_conversations))
button_directory = (13, MenuButton("Directory", on_press=handler.show_directory))
@ -170,4 +178,25 @@ class MenuDisplay():
columns = MenuColumns(buttons, dividechars=1)
columns.handler = handler
self.update_display()
self.widget = urwid.AttrMap(columns, "menubar")
def start(self):
self.update_display_job()
def update_display_job(self, event = None, sender = None):
self.update_display()
self.app.ui.loop.set_alarm_in(self.update_interval, self.update_display_job)
def update_display(self):
if self.app.has_unread_conversations():
self.indicate_unread()
else:
self.indicate_normal()
def indicate_normal(self):
self.menu_indicator.set_text(self.g["decoration_menu"])
def indicate_unread(self):
self.menu_indicator.set_text(self.g["unread_menu"])