diff --git a/bin/linspector b/bin/linspector index 8d5eb61..3ac1d42 100755 --- a/bin/linspector +++ b/bin/linspector @@ -34,6 +34,7 @@ from linspector.config.parser import FullConfigParser from linspector.core.interface import LinspectorInterface from linspector.core.job import Job from linspector.core.scheduler import Scheduler +from linspector.frontends.lish import LishFrontend from linspector.tasks.task import TaskExecutor logger = logging.getLogger(__name__) @@ -167,16 +168,7 @@ def main(): jsonrpc.daemon = True jsonrpc.start() - frontend = None - if "frontend" in core and core["frontend"]: - frontend = core["frontend"] - - if frontend == "urlish": - from linspector.frontends.urlish import UrlishFrontend - UrlishFrontend(interface) - else: - from linspector.frontends.lish import LishFrontend - LishFrontend(interface) + LishFrontend(interface) print("Shutting down... please wait!") diff --git a/linspector/frontends/lish.py b/linspector/frontends/lish.py index 325dc05..5ea74c3 100644 --- a/linspector/frontends/lish.py +++ b/linspector/frontends/lish.py @@ -31,7 +31,7 @@ from shlex import split as shsplit from linspector.frontends.frontend import Frontend -__version__ = "0.2.3-alpha" +__version__ = "0.3" PURPLE = "\033[95m" BLUE = "\033[94m" @@ -174,7 +174,6 @@ class Command(Cmd, object): if len(line) > 0 and line[0] in [child.alias for child in self.get_children()]: pass - def completenames(self, text, *ignored): ret = super(Command, self).completenames(text, *ignored) if len(self.get_children()) > 0: @@ -200,11 +199,11 @@ class CommandTree(object): class LishCommander(Exit): - def __init__(self, linspectorInterface): + def __init__(self, linspector_interface): super(LishCommander, self).__init__() self.prompt = BLUE + ": " + END - self.interface = linspectorInterface + self.interface = linspector_interface def do_python(self, text): exec text @@ -289,6 +288,20 @@ Usage: list Lists all jobs ''') + def do_gui(self, text): + try: + from linspector.frontends.lishgui import LishGui + gui = LishGui(self.interface) + gui.run() + except Exception, err: + self.print_color(RED, "Error: " + str(err) + ", no GUI support!") + + def help_gui(self): + print(''' +Usage: + gui start the graphical user interface +''') + def do_host(self, text): pass diff --git a/linspector/frontends/urlish.py b/linspector/frontends/lishgui.py similarity index 97% rename from linspector/frontends/urlish.py rename to linspector/frontends/lishgui.py index ec20f56..3fd0f4d 100644 --- a/linspector/frontends/urlish.py +++ b/linspector/frontends/lishgui.py @@ -49,10 +49,6 @@ import urwid from logging import getLogger -from linspector.frontends.frontend import Frontend - -__version__ = "0.1.2" - logger = getLogger(__name__) @@ -101,7 +97,7 @@ class CommandPrompt(urwid.Edit): elif command[0] in ('version', 'v'): self.clear() - status_bar.set_text(" Linspector " + str(interface.get_version()) + ", urlish " + __version__) + status_bar.set_text(" Linspector " + str(interface.get_version())) main_frame.set_focus('body') else: @@ -233,59 +229,9 @@ class RootParentNode(urwid.ParentNode): return childclass(childdata, parent=self, key=key, depth=childdepth) -class UrlishFrontend(Frontend): +class LishGui(): def __init__(self, linspector_interface): - super(UrlishFrontend, self) - - global job_list_box - global command_prompt - global header_bar - global status_bar - global main_frame - global loop - global interface - - palette = [('body', 'white', 'black'), - ('foot_bar', 'white', 'black'), - ('top', 'white', 'dark red'), - ('status', 'white', 'dark blue'), - ('prompt', 'white', 'black')] - - foot_text = [('title', "Navigation:"), " ", - ('key', "UP"), ",", ('key', "DOWN"), ",", - ('key', "PAGE UP"), ",", ('key', "PAGE DOWN"), - " ", - ('key', "+"), ",", - ('key', "-"), " ", - ('key', "LEFT"), " ", - ('key', "HOME"), " ", - ('key', "END")] - - interface = linspector_interface - - top_node = RootParentNode(get_example_tree()) - job_list_box = urwid.TreeListBox(urwid.TreeWalker(top_node)) - job_list_box.offset_rows = 1 - - header_message = ' Linspector (' + str(linspector_interface.get_version()) + ')' - header_bar = urwid.Text(header_message, align='left') - header = urwid.Pile([urwid.AttrMap(header_bar, 'top')]) - - command_prompt = CommandPrompt() - - foot_bar = urwid.Text(foot_text, align='left') - - welcome_message = ' Type ":h " for help, ":q " to quit' - status_bar = urwid.Text(welcome_message, align='left') - footer = urwid.Pile([urwid.AttrMap(foot_bar, 'foot_bar'), - urwid.AttrMap(status_bar, 'status'), - urwid.AttrMap(command_prompt, 'prompt')]) - - main_frame = urwid.Frame(body=job_list_box, header=header, footer=footer) - - loop = urwid.MainLoop(main_frame, palette, unhandled_input=self.unhandled_input, handle_mouse=False) - loop.set_alarm_in(0, update) - loop.run() + self.interface = linspector_interface @staticmethod def unhandled_input(key): @@ -317,6 +263,57 @@ class UrlishFrontend(Frontend): #expand all nodes pass + def run(self): + global job_list_box + global command_prompt + global header_bar + global status_bar + global main_frame + global loop + global interface + + palette = [('body', 'white', 'black'), + ('foot_bar', 'white', 'black'), + ('top', 'white', 'dark red'), + ('status', 'white', 'dark blue'), + ('prompt', 'white', 'black')] + + foot_text = [('title', "Navigation:"), " ", + ('key', "UP"), ",", ('key', "DOWN"), ",", + ('key', "PAGE UP"), ",", ('key', "PAGE DOWN"), + " ", + ('key', "+"), ",", + ('key', "-"), " ", + ('key', "LEFT"), " ", + ('key', "HOME"), " ", + ('key', "END")] + + interface = self.interface + + top_node = RootParentNode(get_example_tree()) + job_list_box = urwid.TreeListBox(urwid.TreeWalker(top_node)) + job_list_box.offset_rows = 1 + + header_message = ' Linspector (' + str(self.interface.get_version()) + ')' + header_bar = urwid.Text(header_message, align='left') + header = urwid.Pile([urwid.AttrMap(header_bar, 'top')]) + + command_prompt = CommandPrompt() + + foot_bar = urwid.Text(foot_text, align='left') + + welcome_message = ' Type ":h " for help, ":q " to quit' + status_bar = urwid.Text(welcome_message, align='left') + footer = urwid.Pile([urwid.AttrMap(foot_bar, 'foot_bar'), + urwid.AttrMap(status_bar, 'status'), + urwid.AttrMap(command_prompt, 'prompt')]) + + main_frame = urwid.Frame(body=job_list_box, header=header, footer=footer) + + loop = urwid.MainLoop(main_frame, palette, unhandled_input=self.unhandled_input, handle_mouse=False) + loop.set_alarm_in(0, update) + loop.run() + def update(main_loop, user_data): thread_count = interface.get_thread_count()