Initial remake efforts, new menu structure, constants
Highway has changed fl0w. In a good way I presume but still: Legacy code has to be updated and made good. This entails a rework of the menu system which is now officially under way and utilises the new magic features of SublimeMenu. MORE_CONSTANTS = 1
This commit is contained in:
parent
80f984ab28
commit
003bf3aa84
1 changed files with 62 additions and 17 deletions
|
@ -17,8 +17,7 @@ from watchdog.events import FileSystemEventHandler
|
||||||
import sublime
|
import sublime
|
||||||
import sublime_plugin
|
import sublime_plugin
|
||||||
|
|
||||||
from Highway import Client
|
from Highway import Client, Route
|
||||||
import Routing
|
|
||||||
|
|
||||||
from SublimeMenu import *
|
from SublimeMenu import *
|
||||||
import Logging
|
import Logging
|
||||||
|
@ -26,6 +25,7 @@ import Logging
|
||||||
import webbrowser
|
import webbrowser
|
||||||
|
|
||||||
CHANNEL = 1
|
CHANNEL = 1
|
||||||
|
FL0W_STATUS = "fl0w"
|
||||||
|
|
||||||
def plugin_unloaded():
|
def plugin_unloaded():
|
||||||
for window in windows:
|
for window in windows:
|
||||||
|
@ -42,42 +42,88 @@ class Fl0wClient(Client):
|
||||||
|
|
||||||
def ready(self):
|
def ready(self):
|
||||||
self.fl0w.connected = True
|
self.fl0w.connected = True
|
||||||
Logging.info("Connection ready!")
|
if self.fl0w.debug:
|
||||||
|
Logging.info("Connection ready!")
|
||||||
|
|
||||||
|
|
||||||
def closed(self, code, reason):
|
def closed(self, code, reason):
|
||||||
self.fl0w.connected = False
|
self.fl0w.connected = False
|
||||||
Logging.info("Connection closed: %s (%s)" % (reason, code))
|
if self.fl0w.debug:
|
||||||
|
Logging.info("Connection closed: %s (%s)" % (reason, code))
|
||||||
|
|
||||||
|
|
||||||
class Info(Routing.Route):
|
class Info(Route):
|
||||||
def run(self, data, handler):
|
def run(self, data, handler):
|
||||||
info = ""
|
info = ""
|
||||||
for key in data:
|
for key in data:
|
||||||
info += "%s: %s\n" % (key.capitalize(), ", ".join(data[key]))
|
info += "%s: %s\n" % (key.capitalize(), ", ".join(data[key]))
|
||||||
sublime.message_dialog(info)
|
sublime.message_dialog(info)
|
||||||
handler.fl0w.invoke_main_menu()
|
handler.fl0w.meta.invoke(handler.fl0w.window, back=handler.fl0w.main_menu)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Fl0w:
|
class Fl0w:
|
||||||
def __init__(self, window):
|
def __init__(self, window, debug=False):
|
||||||
self.connected = False
|
self.connected = False
|
||||||
self.window = window
|
self.window = window
|
||||||
self.folder = window.folders()[0]
|
self.folder = window.folders()[0]
|
||||||
|
self._debug = debug
|
||||||
|
|
||||||
|
|
||||||
self.start_menu = Menu()
|
self.start_menu = Menu()
|
||||||
self.start_menu.add(Entry("Connect", "Connect to a fl0w server", action=self.invoke_connect))
|
self.start_menu += Entry("Connect", "Connect to a fl0w server",
|
||||||
self.start_menu.add(Entry("About", "Information about fl0w", action=self.invoke_about))
|
action=self.invoke_connect)
|
||||||
|
self.start_menu += Entry("About", "Information about fl0w",
|
||||||
|
action=self.invoke_about)
|
||||||
|
|
||||||
|
self.debug_menu = Menu(subtitles=False)
|
||||||
|
self.debug_menu += Entry("On",
|
||||||
|
action=lambda: self.set_debug(True))
|
||||||
|
self.debug_menu += Entry("Off",
|
||||||
|
action=lambda: self.set_debug(False))
|
||||||
|
|
||||||
|
self.settings = Menu()
|
||||||
|
self.settings += Entry("Debug", "Toggle debug mode",
|
||||||
|
sub_menu=self.debug_menu)
|
||||||
|
|
||||||
|
self.meta = Menu()
|
||||||
|
self.meta += Entry("Info", "Server info",
|
||||||
|
action=lambda: self.ws.send(None, "info"))
|
||||||
|
self.meta_entry = Entry("Meta", "Debug information about fl0w",
|
||||||
|
sub_menu=self.meta)
|
||||||
|
if self.debug:
|
||||||
|
self.main_menu += self.meta_entry
|
||||||
|
|
||||||
|
|
||||||
self.main_menu = Menu()
|
self.main_menu = Menu()
|
||||||
#self.main_menu.add(Entry("Wallaby Control", "Control a connected Wallaby", action=self.invoke_wallaby_control))
|
self.main_menu += Entry("Settings", "General purpose settings",
|
||||||
self.main_menu.add(Entry("Info", "Server info", action=lambda: self.ws.send(None, "info")))
|
sub_menu=self.settings)
|
||||||
#self.main_menu.add(Entry("Debug", "Debug options", action=self.invoke_debug_options))
|
self.main_menu += Entry("Disconnect", "Disconnect from server",
|
||||||
self.main_menu.add(Entry("Disconnect", "Disconnect from server", action=self.invoke_disconnect))
|
action=self.invoke_disconnect)
|
||||||
|
|
||||||
|
|
||||||
|
@property
|
||||||
|
def debug(self):
|
||||||
|
return self._debug
|
||||||
|
|
||||||
|
|
||||||
|
def set_debug(self, debug):
|
||||||
|
self.debug = debug
|
||||||
|
|
||||||
|
|
||||||
|
@debug.setter
|
||||||
|
def debug(self, debug):
|
||||||
|
if debug:
|
||||||
|
self._debug = True
|
||||||
|
if not self.meta_entry in self.main_menu.entries.values():
|
||||||
|
self.main_menu += self.meta_entry
|
||||||
|
else:
|
||||||
|
self._debug = False
|
||||||
|
self.main_menu -= self.meta_entry
|
||||||
|
self.window.active_view().set_status(FL0W_STATUS,
|
||||||
|
"Debug set to %s" % self._debug)
|
||||||
|
|
||||||
|
|
||||||
def invoke_start_menu(self):
|
def invoke_start_menu(self):
|
||||||
|
@ -95,7 +141,6 @@ class Fl0w:
|
||||||
|
|
||||||
|
|
||||||
def connect(self, connect_details):
|
def connect(self, connect_details):
|
||||||
compression_level = int(sublime.load_settings("fl0w.sublime-settings").get("compression_level"))
|
|
||||||
try:
|
try:
|
||||||
self.ws = Fl0wClient('ws://%s' % connect_details)
|
self.ws = Fl0wClient('ws://%s' % connect_details)
|
||||||
self.ws.setup({"info" : Fl0wClient.Info()}, self, debug=False)
|
self.ws.setup({"info" : Fl0wClient.Info()}, self, debug=False)
|
||||||
|
@ -114,7 +159,8 @@ class Fl0w:
|
||||||
def invoke_disconnect(self):
|
def invoke_disconnect(self):
|
||||||
if self.connected:
|
if self.connected:
|
||||||
self.ws.close()
|
self.ws.close()
|
||||||
sublime.message_dialog("Connection closed ('%s')" % self.folder)
|
self.window.active_view().set_status(FL0W_STATUS,
|
||||||
|
"Connection closed ('%s')" % self.folder)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -154,8 +200,7 @@ class Fl0wCommand(sublime_plugin.WindowCommand):
|
||||||
else:
|
else:
|
||||||
if hasattr(self.window, "fl0w"):
|
if hasattr(self.window, "fl0w"):
|
||||||
sublime.error_message("Window setup was invalidated (Don't close or open any additional folders in a fl0w window)")
|
sublime.error_message("Window setup was invalidated (Don't close or open any additional folders in a fl0w window)")
|
||||||
if self.window.fl0w.connected:
|
self.window.fl0w.invoke_disconnect()
|
||||||
self.window.fl0w.invoke_disconnect()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in a new issue