diff --git a/nomadnet/NomadNetworkApp.py b/nomadnet/NomadNetworkApp.py index 81c220a..1a86ec5 100644 --- a/nomadnet/NomadNetworkApp.py +++ b/nomadnet/NomadNetworkApp.py @@ -244,6 +244,11 @@ class NomadNetworkApp: if not "editor" in self.config["textui"]: self.config["textui"]["editor"] = "editor" + if not "mouse_enabled" in self.config["textui"]: + self.config["textui"]["mouse_enabled"] = True + else: + self.config["textui"]["animation_interval"] = self.config["textui"].as_bool("mouse_enabled") + if not "animation_interval" in self.config["textui"]: self.config["textui"]["animation_interval"] = 1 else: @@ -345,6 +350,11 @@ colormode = 16 # colormode = 256 # colormode = 24bit +# You can specify whether mouse events +# should be considered as input to the +# application. On by default. +mouse_enabled = True + # What editor to use for editing text. By # default the operating systems "editor" # alias will be used. diff --git a/nomadnet/ui/TextUI.py b/nomadnet/ui/TextUI.py index 4adf738..5db21b4 100644 --- a/nomadnet/ui/TextUI.py +++ b/nomadnet/ui/TextUI.py @@ -61,6 +61,7 @@ class TextUI: intro_timeout = self.app.config["textui"]["intro_time"] colormode = self.app.config["textui"]["colormode"] theme = self.app.config["textui"]["theme"] + mouse_enabled = self.app.config["textui"]["mouse_enabled"] palette = THEMES[theme] @@ -75,7 +76,7 @@ class TextUI: else: initial_widget = self.main_display.widget - self.loop = urwid.MainLoop(initial_widget, screen=self.screen) + self.loop = urwid.MainLoop(initial_widget, screen=self.screen, handle_mouse=mouse_enabled) if intro_timeout > 0: self.loop.set_alarm_in(intro_timeout, self.display_main) diff --git a/nomadnet/ui/textui/Config.py b/nomadnet/ui/textui/Config.py index 9bdab42..582f1d9 100644 --- a/nomadnet/ui/textui/Config.py +++ b/nomadnet/ui/textui/Config.py @@ -1,3 +1,6 @@ +import nomadnet +import urwid + class ConfigDisplayShortcuts(): def __init__(self, app): import urwid @@ -5,17 +8,67 @@ class ConfigDisplayShortcuts(): self.widget = urwid.AttrMap(urwid.Text("Config Display Shortcuts"), "shortcutbar") +class ConfigFiller(urwid.WidgetWrap): + def __init__(self, widget, app): + self.app = app + self.filler = urwid.Filler(widget, "top") + urwid.WidgetWrap.__init__(self, self.filler) + + + def keypress(self, size, key): + if key == "up": + self.app.ui.main_display.frame.set_focus("header") + + return super(ConfigFiller, self).keypress(size, key) + class ConfigDisplay(): def __init__(self, app): import urwid self.app = app + def open_editor(sender): + self.editor_term = EditorTerminal(self.app, self) + self.widget = urwid.LineBox(self.editor_term) + self.app.ui.main_display.update_active_sub_display() + self.app.ui.main_display.frame.set_focus("body") + self.editor_term.term.change_focus(True) + pile = urwid.Pile([ - urwid.Text(("body_text", "Config Display \U0001F332")), + urwid.Text(("body_text", "\nTo change the configuration, edit the config file located at:\n\n"+self.app.configpath+"\n\nRestart Nomad Network for chanes to take effect\n"), align="center"), + urwid.Padding(urwid.Button("Open Editor", on_press=open_editor), width=15, align="center"), ]) + self.config_explainer = ConfigFiller(pile, self.app) self.shortcuts_display = ConfigDisplayShortcuts(self.app) - self.widget = urwid.Filler(pile, 'top') + self.widget = self.config_explainer def shortcuts(self): - return self.shortcuts_display \ No newline at end of file + return self.shortcuts_display + +class EditorTerminal(urwid.WidgetWrap): + def __init__(self, app, parent): + self.app = app + self.parent = parent + editor_cmd = self.app.config["textui"]["editor"] + self.term = urwid.Terminal( + (editor_cmd, self.app.configpath), + encoding='utf-8', + main_loop=self.app.ui.loop, + ) + + def quit_term(*args, **kwargs): + self.parent.widget = self.parent.config_explainer + self.app.ui.main_display.update_active_sub_display() + self.app.ui.main_display.show_config(None) + self.app.ui.main_display.request_redraw() + + urwid.connect_signal(self.term, 'closed', quit_term) + + urwid.WidgetWrap.__init__(self, self.term) + + + def keypress(self, size, key): + # TODO: Decide whether there should be a way to get out while editing + #if key == "up": + # nomadnet.NomadNetworkApp.get_shared_instance().ui.main_display.frame.set_focus("header") + return super(EditorTerminal, self).keypress(size, key) \ No newline at end of file diff --git a/nomadnet/ui/textui/Main.py b/nomadnet/ui/textui/Main.py index 73a52da..a95fa0d 100644 --- a/nomadnet/ui/textui/Main.py +++ b/nomadnet/ui/textui/Main.py @@ -72,8 +72,8 @@ class MainFrame(urwid.Frame): def keypress(self, size, key): self.keypress_focus_check() - if key == "ctrl q": - raise urwid.ExitMainLoop + #if key == "ctrl q": + # raise urwid.ExitMainLoop return super(MainFrame, self).keypress(size, key) @@ -120,6 +120,12 @@ class MainDisplay(): def update_active_shortcuts(self): self.frame.contents["footer"] = (self.sub_displays.active().shortcuts().widget, None) + def request_redraw(self): + self.app.ui.loop.set_alarm_in(0.25, self.redraw_now) + + def redraw_now(self, sender=None, data=None): + self.app.ui.loop.draw_screen() + def quit(self, sender=None): raise urwid.ExitMainLoop