Remove superfluous whitespaces at the end of lines

This commit is contained in:
Christoph Heiss 2017-03-22 19:38:49 +01:00
parent 526695e209
commit e3f6d56d02
3 changed files with 76 additions and 77 deletions

View file

@ -51,7 +51,7 @@ views = []
sensor_phantoms = []
def set_status(status, window):
window.active_view().set_status(FL0W_STATUS,
window.active_view().set_status(FL0W_STATUS,
"fl0w: %s" % status)
class Target:
@ -120,38 +120,38 @@ class Fl0wClient(Client):
utilities_menu = Menu()
action_menu.id_ = id_
action_menu.name = data[id_]["name"]
action_menu += Entry("Set Target",
"Set controller as target for program execution and sensor readouts",
action=partial(self.set_target,
handler, id_, data[id_]["name"]))
action_menu += Entry("Run program",
"Run a botball program on the controller",
action_menu += Entry("Set Target",
"Set controller as target for program execution and sensor readouts",
action=partial(self.set_target,
handler, id_, data[id_]["name"]))
action_menu += Entry("Run program",
"Run a botball program on the controller",
action=partial(handler.pipe, None, "list_programs", id_))
action_menu += Entry("Stop programs",
"Stop all currently running botball programs",
action=partial(handler.pipe, None, "stop_programs", id_))
utilities_menu += Entry("Set Name",
action_menu += Entry("Stop programs",
"Stop all currently running botball programs",
action=partial(handler.pipe, None, "stop_programs", id_))
utilities_menu += Entry("Set Name",
"Sets the hostname of the selected controller",
action=partial(lambda handler, id_: Input("New Hostname:",
initial_text=data[id_]["name"],
action=partial(lambda handler, id_: Input("New Hostname:",
initial_text=data[id_]["name"],
on_done=lambda hostname: handler.pipe(
{"set" : hostname},
{"set" : hostname},
"hostname", id_)).invoke(handler.fl0w.window), handler, id_))
utilities_menu += Entry("Processes",
"Lists processes currently running on controller",
utilities_menu += Entry("Processes",
"Lists processes currently running on controller",
action=partial(handler.pipe, None, "processes", id_))
utilities_menu += Entry("Identify",
"Plays an identification sound on the controller.",
utilities_menu += Entry("Identify",
"Plays an identification sound on the controller.",
action=partial(handler.pipe, None, "identify", id_))
action_menu += Entry("Utilities", "Stuff you might need but probably won't",
action_menu += Entry("Utilities", "Stuff you might need but probably won't",
sub_menu=utilities_menu)
power_menu += Entry("Shutdown",
"Shutdown the controller",
power_menu += Entry("Shutdown",
"Shutdown the controller",
action=partial(handler.pipe, None, "shutdown", id_))
power_menu += Entry("Reboot",
"Reboot the controller",
power_menu += Entry("Reboot",
"Reboot the controller",
action=partial(handler.pipe, None, "reboot", id_))
action_menu += Entry("Power", "Power related actions", sub_menu=power_menu)
action_menu += Entry("Power", "Power related actions", sub_menu=power_menu)
action_menu.back = handler.fl0w.controller_menu
handler.fl0w.controller_menu += Entry(data[id_]["name"], id_, sub_menu=action_menu,
action=self.set_selected_action_menu,
@ -182,11 +182,11 @@ class Fl0wClient(Client):
def run(self, data, peer, handler):
program_menu = Menu(subtitles=False)
for program in data:
program_menu += Entry(program,
program_menu += Entry(program,
action=partial(self.run_program,
handler, handler.routes["peers"].selected_action_menu.id_,
program))
program_menu.invoke(handler.fl0w.window,
program_menu.invoke(handler.fl0w.window,
back=handler.routes["peers"].selected_action_menu)
def run_program(self, handler, id_, program):
@ -206,7 +206,7 @@ class Fl0wClient(Client):
def run(self, data, peer, handler):
if data == self.__class__.NO_PROGRAMS_RUNNING:
sublime.error_message("No programs running.")
sublime.error_message("No programs running.")
class StdStream(Pipe):
@ -218,7 +218,7 @@ class Fl0wClient(Client):
self.handler = None
self.fetcher = self.Fetcher(self.buffer, self.write_to_panel,
self.fetcher = self.Fetcher(self.buffer, self.write_to_panel,
self.lock)
self.fetcher.start()
@ -237,7 +237,7 @@ class Fl0wClient(Client):
self.handler = handler
if type(data) is str:
self.lock.acquire()
# try/except is faster than an explicit if as long as the
# try/except is faster than an explicit if as long as the
# condition is not met
try:
self.buffer[peer].append(data)
@ -252,9 +252,9 @@ class Fl0wClient(Client):
elif type(data) is dict:
meta_text = ""
if "exit_code" in data:
meta_text += "Program finished with exit code: %d\n" % data["exit_code"]
meta_text += "Program finished with exit code: %d\n" % data["exit_code"]
self.lock.acquire()
# try/except is faster than an explicit if as long as the
# try/except is faster than an explicit if as long as the
# condition is not met
# function call is also slower
try:
@ -264,7 +264,7 @@ class Fl0wClient(Client):
self.create_output_panel(handler.fl0w.window, peer)
self.output_panels[peer] = self.create_output_panel(handler.fl0w.window, peer)
self.buffer[peer].append(meta_text)
self.lock.release()
self.lock.release()
@ -275,8 +275,8 @@ class Fl0wClient(Client):
self.handler.fl0w.window.run_command("show_panel", {"panel": "output.%s" % peer})
# Sublime gets quite overwhelmed when faced with typical
# "while (1) { printf(...)}" output.
# Sublime gets quite overwhelmed when faced with typical
# "while (1) { printf(...)}" output.
# That's why instead of directly writing to the view all received text
# is bundled together after a fixed period of time.
class Fetcher(threading.Thread):
@ -294,7 +294,7 @@ class Fl0wClient(Client):
for peer in self.buffer:
if len(self.buffer[peer]) > 0:
self.write_to_panel(
"".join(self.buffer[peer]),
"".join(self.buffer[peer]),
peer)
self.buffer[peer] = []
self.lock.release()
@ -310,51 +310,51 @@ class Fl0w:
self.folder = self.folder + "/"
self.connected = False
self.subscriptions = {}
self.subscriptions_lock = threading.Lock()
self._combined_subscriptions = {"analog" : [], "digital" : []}
self._target = None
self._debug = debug
self.start_menu = Menu()
self.start_menu += Entry("Connect", "Connect to a fl0w server",
action=partial(Input("Address:Port (auto-connect nyi)",
initial_text=self.settings.get("address", "127.0.0.1:3077"),
self.start_menu += Entry("Connect", "Connect to a fl0w server",
action=partial(Input("Address:Port (auto-connect nyi)",
initial_text=self.settings.get("address", "127.0.0.1:3077"),
on_done=self.invoke_connect).invoke, self.window))
self.start_menu += Entry("About", "Information about fl0w",
self.start_menu += Entry("About", "Information about fl0w",
action=self.invoke_about)
self.debug_menu = Menu(subtitles=False)
self.debug_menu += Entry("On",
self.debug_menu += Entry("On",
action=lambda: self.set_debug(True))
self.debug_menu += Entry("Off",
self.debug_menu += Entry("Off",
action=lambda: self.set_debug(False))
self.settings_menu = Menu()
self.settings_menu += Entry("Debug", "Toggle debug mode",
self.settings_menu += Entry("Debug", "Toggle debug mode",
sub_menu=self.debug_menu)
self.meta = Menu()
self.meta += Entry("Info", "Server info",
self.meta += Entry("Info", "Server info",
action=lambda: self.ws.send(None, "info"))
self.meta_entry = Entry("Meta", "Debug information about fl0w",
self.meta_entry = Entry("Meta", "Debug information about fl0w",
sub_menu=self.meta)
if self.debug:
if self.debug:
self.main_menu += self.meta_entry
self.main_menu = Menu()
self.controller_menu = Menu()
self.main_menu += Entry("Controllers", "All connected controllers",
self.main_menu += Entry("Controllers", "All connected controllers",
sub_menu=self.controller_menu)
self.main_menu += Entry("Settings", "General purpose settings",
self.main_menu += Entry("Settings", "General purpose settings",
sub_menu=self.settings_menu)
self.main_menu += Entry("Disconnect", "Disconnect from server",
self.main_menu += Entry("Disconnect", "Disconnect from server",
action=self.invoke_disconnect)
self.sync_client = behem0th.Client(path=self.folder, verbose_log=True)
@ -410,7 +410,7 @@ class Fl0w:
# Could be simplified because only one view can be active at any time.
# This would definetly lead to some major performace improvements on
# view switching and less unnecessary unsubscribes.
# On the other hand it might be a good idea to leave it in and provide
# an option to disable aggressive unsubscribes
@property
@ -442,7 +442,7 @@ class Fl0w:
"""
print("Lock will be aquired.")
self.subscriptions_lock.acquire()
print("Lock was aquired.")
print("Lock was aquired.")
del self.subscriptions[sensor_phantom]
print("Lock will be released.")
self.subscriptions_lock.release()
@ -459,7 +459,7 @@ class Fl0w:
for sensor_phantom in self.subscriptions:
for sensor_type in ("analog", "digital"):
combined_subscriptions[sensor_type] = list(
set(combined_subscriptions[sensor_type]) |
set(combined_subscriptions[sensor_type]) |
set(self.subscriptions[sensor_phantom][sensor_type])
)
self.combined_subscriptions = combined_subscriptions
@ -492,15 +492,14 @@ class Fl0w:
webbrowser.open("http://robot0nfire.com")
def connect(self, address):
try:
self.ws = Fl0wClient(address)
self.ws.setup({"info" : Fl0wClient.Info(), "peers" : Fl0wClient.Peers(),
"processes" : Fl0wClient.Processes(),
"processes" : Fl0wClient.Processes(),
"list_programs" : Fl0wClient.ListPrograms(), "sensor" : Fl0wClient.Sensor(),
"std_stream" : Fl0wClient.StdStream(), "run_program" : Fl0wClient.RunProgram(),
"stop_programs" : Fl0wClient.StopPrograms()},
"stop_programs" : Fl0wClient.StopPrograms()},
self, debug=True)
self.ws.connect()
sublime.set_timeout_async(self.ws.run_forever, 0)
@ -614,10 +613,10 @@ class SensorCommand(sublime_plugin.WindowCommand):
view.sensor_phantom.enabled = not view.sensor_phantom.enabled
view_file_name = view.file_name()
if view_file_name == None:
view_file_name = "untitled"
view_file_name = "untitled"
set_status("%s sensor phantoms for '%s'." % (
"Enabled" if view.sensor_phantom.enabled else "Disabled",
view_file_name),
"Enabled" if view.sensor_phantom.enabled else "Disabled",
view_file_name),
self.window)
else:
sublime.error_message("fl0w is not connected.")
@ -633,7 +632,7 @@ class SensorPhantom(sublime_plugin.ViewEventListener):
if not view in views:
views.append(view)
self.window = view.window()
# Is patched by the fl0w instance that is in control of the same window
self.fl0w = None
self._enabled = False
@ -656,7 +655,7 @@ class SensorPhantom(sublime_plugin.ViewEventListener):
def enabled(self):
return self._enabled
@enabled.setter
def enabled(self, enabled_):
if enabled_:
@ -704,7 +703,7 @@ class SensorPhantom(sublime_plugin.ViewEventListener):
if port_candidates[0].isnumeric():
matches[method_name].append(
(
int(port_candidates[0]),
int(port_candidates[0]),
sublime.Region(self.view.line(candidate.a).b)
))
self.matches = matches
@ -715,12 +714,12 @@ class SensorPhantom(sublime_plugin.ViewEventListener):
self.view.erase_phantoms(sensor_type)
for match in self.matches[sensor_type]:
try:
self.view.add_phantom(sensor_type, match[1],
STYLE_OPEN + str(readouts[sensor_type][str(match[0])]) + STYLE_CLOSE,
self.view.add_phantom(sensor_type, match[1],
STYLE_OPEN + str(readouts[sensor_type][str(match[0])]) + STYLE_CLOSE,
sublime.LAYOUT_INLINE)
except KeyError:
self.view.add_phantom(sensor_type, match[1],
ERROR_OPEN + "!" + ERROR_CLOSE,
self.view.add_phantom(sensor_type, match[1],
ERROR_OPEN + "!" + ERROR_CLOSE,
sublime.LAYOUT_INLINE)
@ -751,7 +750,7 @@ class SensorPhantom(sublime_plugin.ViewEventListener):
self.enabled = True
def __del__(self):
def __del__(self):
self.enabled = False
if self in sensor_phantoms:
del sensor_phantoms[sensor_phantoms.index(self)]