mirror of
https://github.com/markqvist/NomadNet.git
synced 2025-05-04 07:05:17 -04:00
Added configuration editor
This commit is contained in:
parent
8aec40fba2
commit
0783b21272
4 changed files with 76 additions and 6 deletions
|
@ -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
|
||||
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)
|
Loading…
Add table
Add a link
Reference in a new issue