From 9693e3e8144963827209b2c17961292ceea1f22e Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Tue, 4 May 2021 11:08:16 +0200 Subject: [PATCH] Text UI general structure --- nomadnet/ui/textui/Conversations.py | 21 ++++++++ nomadnet/ui/textui/Directory.py | 21 ++++++++ nomadnet/ui/textui/Extras.py | 63 ++++++++++++++++++++++++ nomadnet/ui/textui/Main.py | 75 +++++++++++++++++++++++++++++ nomadnet/ui/textui/Map.py | 21 ++++++++ nomadnet/ui/textui/Network.py | 21 ++++++++ nomadnet/ui/textui/__init__.py | 5 ++ 7 files changed, 227 insertions(+) create mode 100644 nomadnet/ui/textui/Conversations.py create mode 100644 nomadnet/ui/textui/Directory.py create mode 100644 nomadnet/ui/textui/Extras.py create mode 100644 nomadnet/ui/textui/Main.py create mode 100644 nomadnet/ui/textui/Map.py create mode 100644 nomadnet/ui/textui/Network.py create mode 100644 nomadnet/ui/textui/__init__.py diff --git a/nomadnet/ui/textui/Conversations.py b/nomadnet/ui/textui/Conversations.py new file mode 100644 index 0000000..9f96bd1 --- /dev/null +++ b/nomadnet/ui/textui/Conversations.py @@ -0,0 +1,21 @@ +class ConversationsDisplayShortcuts(): + def __init__(self, app): + import urwid + self.app = app + + self.widget = urwid.AttrMap(urwid.Text("Conversations Display Shortcuts"), "shortcutbar") + +class ConversationsDisplay(): + def __init__(self, app): + import urwid + self.app = app + + pile = urwid.Pile([ + urwid.Text(("body_text", "Conversations Display \U0001F332")), + ]) + + self.shortcuts_display = ConversationsDisplayShortcuts(self.app) + self.widget = urwid.Filler(pile, 'top') + + def shortcuts(self): + return self.shortcuts_display \ No newline at end of file diff --git a/nomadnet/ui/textui/Directory.py b/nomadnet/ui/textui/Directory.py new file mode 100644 index 0000000..aeec463 --- /dev/null +++ b/nomadnet/ui/textui/Directory.py @@ -0,0 +1,21 @@ +class DirectoryDisplayShortcuts(): + def __init__(self, app): + import urwid + self.app = app + + self.widget = urwid.AttrMap(urwid.Text("Directory Display Shortcuts"), "shortcutbar") + +class DirectoryDisplay(): + def __init__(self, app): + import urwid + self.app = app + + pile = urwid.Pile([ + urwid.Text(("body_text", "Directory Display \U0001F332")), + ]) + + self.shortcuts_display = DirectoryDisplayShortcuts(self.app) + self.widget = urwid.Filler(pile, 'top') + + def shortcuts(self): + return self.shortcuts_display \ No newline at end of file diff --git a/nomadnet/ui/textui/Extras.py b/nomadnet/ui/textui/Extras.py new file mode 100644 index 0000000..d07e6b3 --- /dev/null +++ b/nomadnet/ui/textui/Extras.py @@ -0,0 +1,63 @@ +from nomadnet.ui import * + +class IntroDisplay(): + def __init__(self, app): + import urwid + self.app = app + + font = urwid.font.HalfBlock5x4Font() + + big_text = urwid.BigText(("intro_title", "Nomad Network"), font) + big_text = urwid.Padding(big_text, align="center", width="clip") + + intro = urwid.Pile([ + big_text, + urwid.Text(("Version %s" % (str(self.app.version))), align="center"), + urwid.Divider(), + urwid.Text(("-= Starting =- "), align="center"), + ]) + + self.widget = urwid.Filler(intro) + + +class DemoDisplay(): + def __init__(self, ui, app): + import urwid + + def color_mono(btn): + ui.set_colormode(nomadnet.ui.COLORMODE_MONO) + + def color_16(btn): + ui.set_colormode(nomadnet.ui.COLORMODE_16) + + def color_88(btn): + ui.set_colormode(nomadnet.ui.COLORMODE_88) + + def color_8bit(btn): + ui.set_colormode(nomadnet.ui.COLORMODE_256) + + def color_true(btn): + ui.set_colormode(nomadnet.ui.COLORMODE_TRUE) + + # pile = urwid.Pile([ + # urwid.Text(("heading", "This is a heading")), + # urwid.Text(("body_text", "Hello World \U0001F332")), + # urwid.Button(("buttons", "Monochrome"), color_mono), + # urwid.Button(("buttons", "16 color"), color_16), + # urwid.Button(("buttons", "88 color"), color_88), + # urwid.Button(("buttons", "256 color"), color_8bit), + # urwid.Button(("buttons", "True color"), color_true), + # ]) + + gf = urwid.GridFlow([ + urwid.Text(("heading", "This is a heading")), + urwid.Text(("body_text", "Hello World \U0001F332")), + urwid.Button(("buttons", "Monochrome"), color_mono), + urwid.Button(("buttons", "16 color"), color_16), + urwid.Button(("buttons", "88 color"), color_88), + urwid.Button(("buttons", "256 color"), color_8bit), + urwid.Button(("buttons", "True color"), color_true), + ], cell_width=20, h_sep=0, v_sep=0, align="left") + + self.widget = urwid.Filler(urwid.Padding((urwid.Text("Test"),urwid.Text("Test 2"))), 'top') + #self.widget = urwid.Filler(pile, 'top') \ No newline at end of file diff --git a/nomadnet/ui/textui/Main.py b/nomadnet/ui/textui/Main.py new file mode 100644 index 0000000..34d99ae --- /dev/null +++ b/nomadnet/ui/textui/Main.py @@ -0,0 +1,75 @@ +import RNS + +from .Network import * +from .Conversations import * +from .Directory import * +from .Map import * + +class SubDisplays(): + def __init__(self, app): + import urwid + self.app = app + self.network_display = NetworkDisplay(self.app) + self.conversations_display = ConversationsDisplay(self.app) + self.directory_display = DirectoryDisplay(self.app) + self.map_display = MapDisplay(self.app) + + self.active_display = self.network_display + + def active(self): + return self.active_display + + +class MainDisplay(): + def __init__(self, ui, app): + import urwid + self.ui = ui + self.app = app + + self.menu_display = MenuDisplay(self.app, self) + self.sub_displays = SubDisplays(self.app) + + self.frame = urwid.Frame(self.sub_displays.active().widget, header=self.menu_display.widget, footer=self.sub_displays.active().shortcuts().widget) + self.widget = self.frame + + def show_network(self, user_data): + self.sub_displays.active_display = self.sub_displays.network_display + self.update_active_sub_display() + + def show_conversations(self, user_data): + self.sub_displays.active_display = self.sub_displays.conversations_display + self.update_active_sub_display() + + def show_directory(self, user_data): + self.sub_displays.active_display = self.sub_displays.directory_display + self.update_active_sub_display() + + def show_map(self, user_data): + self.sub_displays.active_display = self.sub_displays.map_display + self.update_active_sub_display() + + def update_active_sub_display(self): + self.frame.contents["body"] = (self.sub_displays.active().widget, None) + self.frame.contents["footer"] = (self.sub_displays.active().shortcuts().widget, None) + + +class MenuDisplay(): + def __init__(self, app, handler): + import urwid + + class MenuButton(urwid.Button): + button_left = urwid.Text('[') + button_right = urwid.Text(']') + + self.app = app + + menu_text = ("pack", urwid.Text(" \U00002638")) + 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)) + button_map = (7, MenuButton("Map", on_press=handler.show_map)) + + buttons = [menu_text, button_network, button_conversations, button_directory, button_map] + columns = urwid.Columns(buttons, dividechars=1) + + self.widget = urwid.AttrMap(columns, "menubar") diff --git a/nomadnet/ui/textui/Map.py b/nomadnet/ui/textui/Map.py new file mode 100644 index 0000000..3d4a03d --- /dev/null +++ b/nomadnet/ui/textui/Map.py @@ -0,0 +1,21 @@ +class MapDisplayShortcuts(): + def __init__(self, app): + import urwid + self.app = app + + self.widget = urwid.AttrMap(urwid.Text("Map Display Shortcuts"), "shortcutbar") + +class MapDisplay(): + def __init__(self, app): + import urwid + self.app = app + + pile = urwid.Pile([ + urwid.Text(("body_text", "Map Display \U0001F332")), + ]) + + self.shortcuts_display = MapDisplayShortcuts(self.app) + self.widget = urwid.Filler(pile, 'top') + + def shortcuts(self): + return self.shortcuts_display \ No newline at end of file diff --git a/nomadnet/ui/textui/Network.py b/nomadnet/ui/textui/Network.py new file mode 100644 index 0000000..3d4e66d --- /dev/null +++ b/nomadnet/ui/textui/Network.py @@ -0,0 +1,21 @@ +class NetworkDisplayShortcuts(): + def __init__(self, app): + import urwid + self.app = app + + self.widget = urwid.AttrMap(urwid.Text("Network Display Shortcuts"), "shortcutbar") + +class NetworkDisplay(): + def __init__(self, app): + import urwid + self.app = app + + pile = urwid.Pile([ + urwid.Text(("body_text", "Network Display \U0001F332")), + ]) + + self.shortcuts_display = NetworkDisplayShortcuts(self.app) + self.widget = urwid.Filler(pile, 'top') + + def shortcuts(self): + return self.shortcuts_display diff --git a/nomadnet/ui/textui/__init__.py b/nomadnet/ui/textui/__init__.py new file mode 100644 index 0000000..e3164b0 --- /dev/null +++ b/nomadnet/ui/textui/__init__.py @@ -0,0 +1,5 @@ +import os +import glob + +modules = glob.glob(os.path.dirname(__file__)+"/*.py") +__all__ = [ os.path.basename(f)[:-3] for f in modules if not f.endswith('__init__.py')]