made urlish the gui command in lish

This commit is contained in:
Johannes Findeisen 2013-12-05 03:59:22 +01:00
commit b869053aec
3 changed files with 55 additions and 53 deletions

View file

@ -34,6 +34,7 @@ from linspector.config.parser import FullConfigParser
from linspector.core.interface import LinspectorInterface from linspector.core.interface import LinspectorInterface
from linspector.core.job import Job from linspector.core.job import Job
from linspector.core.scheduler import Scheduler from linspector.core.scheduler import Scheduler
from linspector.frontends.lish import LishFrontend
from linspector.tasks.task import TaskExecutor from linspector.tasks.task import TaskExecutor
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -167,16 +168,7 @@ def main():
jsonrpc.daemon = True jsonrpc.daemon = True
jsonrpc.start() jsonrpc.start()
frontend = None LishFrontend(interface)
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)
print("Shutting down... please wait!") print("Shutting down... please wait!")

View file

@ -31,7 +31,7 @@ from shlex import split as shsplit
from linspector.frontends.frontend import Frontend from linspector.frontends.frontend import Frontend
__version__ = "0.2.3-alpha" __version__ = "0.3"
PURPLE = "\033[95m" PURPLE = "\033[95m"
BLUE = "\033[94m" 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()]: if len(line) > 0 and line[0] in [child.alias for child in self.get_children()]:
pass pass
def completenames(self, text, *ignored): def completenames(self, text, *ignored):
ret = super(Command, self).completenames(text, *ignored) ret = super(Command, self).completenames(text, *ignored)
if len(self.get_children()) > 0: if len(self.get_children()) > 0:
@ -200,11 +199,11 @@ class CommandTree(object):
class LishCommander(Exit): class LishCommander(Exit):
def __init__(self, linspectorInterface): def __init__(self, linspector_interface):
super(LishCommander, self).__init__() super(LishCommander, self).__init__()
self.prompt = BLUE + "<Lish@" + socket.gethostname() + ">: " + END self.prompt = BLUE + "<Lish@" + socket.gethostname() + ">: " + END
self.interface = linspectorInterface self.interface = linspector_interface
def do_python(self, text): def do_python(self, text):
exec text exec text
@ -289,6 +288,20 @@ Usage:
list Lists all jobs 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): def do_host(self, text):
pass pass

View file

@ -49,10 +49,6 @@ import urwid
from logging import getLogger from logging import getLogger
from linspector.frontends.frontend import Frontend
__version__ = "0.1.2"
logger = getLogger(__name__) logger = getLogger(__name__)
@ -101,7 +97,7 @@ class CommandPrompt(urwid.Edit):
elif command[0] in ('version', 'v'): elif command[0] in ('version', 'v'):
self.clear() 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') main_frame.set_focus('body')
else: else:
@ -233,59 +229,9 @@ class RootParentNode(urwid.ParentNode):
return childclass(childdata, parent=self, key=key, depth=childdepth) return childclass(childdata, parent=self, key=key, depth=childdepth)
class UrlishFrontend(Frontend): class LishGui():
def __init__(self, linspector_interface): def __init__(self, linspector_interface):
super(UrlishFrontend, self) self.interface = linspector_interface
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 <Enter>" for help, ":q <Enter>" 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()
@staticmethod @staticmethod
def unhandled_input(key): def unhandled_input(key):
@ -317,6 +263,57 @@ class UrlishFrontend(Frontend):
#expand all nodes #expand all nodes
pass 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 <Enter>" for help, ":q <Enter>" 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): def update(main_loop, user_data):
thread_count = interface.get_thread_count() thread_count = interface.get_thread_count()