From 6e811fdfda036626b74093949e4c4f96867fbeae Mon Sep 17 00:00:00 2001 From: Dominik Kutra Date: Thu, 22 Aug 2024 17:17:10 +0200 Subject: [PATCH] remove all things related to ipc (#2900) this was used in the past for interop with KNIME, but isn't used anymore. --- .../objectClassificationGui.py | 17 - .../applets/tracking/base/trackingBaseGui.py | 1 - .../conservation/conservationTrackingGui.py | 43 -- .../structured/structuredTrackingGui.py | 122 ---- ilastik/config.py | 25 - ilastik/ilastik_logging/logging_config.json | 1 - ilastik/shell/gui/ilastikShell.py | 49 -- ilastik/shell/gui/ipcManager.py | 680 ------------------ ilastik/utility/commandProcessor.py | 64 -- ilastik/utility/ipcProtocol.py | 100 --- ilastik/widgets/ipcserver/__init__.py | 0 .../widgets/ipcserver/ipcServerInfoWindow.py | 15 - .../widgets/ipcserver/ipcServerInfoWindow.ui | 95 --- .../widgets/ipcserver/tcpServerInfoWidget.py | 157 ---- .../widgets/ipcserver/tcpServerInfoWidget.ui | 144 ---- .../widgets/ipcserver/zmqPubSubInfoWidget.py | 95 --- .../widgets/ipcserver/zmqPubSubInfoWidget.ui | 202 ------ 17 files changed, 1810 deletions(-) delete mode 100644 ilastik/shell/gui/ipcManager.py delete mode 100644 ilastik/utility/commandProcessor.py delete mode 100644 ilastik/utility/ipcProtocol.py delete mode 100644 ilastik/widgets/ipcserver/__init__.py delete mode 100644 ilastik/widgets/ipcserver/ipcServerInfoWindow.py delete mode 100644 ilastik/widgets/ipcserver/ipcServerInfoWindow.ui delete mode 100644 ilastik/widgets/ipcserver/tcpServerInfoWidget.py delete mode 100644 ilastik/widgets/ipcserver/tcpServerInfoWidget.ui delete mode 100644 ilastik/widgets/ipcserver/zmqPubSubInfoWidget.py delete mode 100644 ilastik/widgets/ipcserver/zmqPubSubInfoWidget.ui diff --git a/ilastik/applets/objectClassification/objectClassificationGui.py b/ilastik/applets/objectClassification/objectClassificationGui.py index 55a105d22..cbbaa1ece 100644 --- a/ilastik/applets/objectClassification/objectClassificationGui.py +++ b/ilastik/applets/objectClassification/objectClassificationGui.py @@ -24,7 +24,6 @@ from PyQt5.QtCore import pyqtSlot, Qt from PyQt5.QtGui import QColor from PyQt5.QtWidgets import QFileDialog, QTableWidget, QTableWidgetItem, QGridLayout, QProgressBar -from ilastik.shell.gui.ipcManager import IPCFacade, Protocol from ilastik.applets.objectExtraction.opObjectExtraction import default_features_key @@ -759,22 +758,6 @@ def handleEditorRightClick(self, position5d, globalWindowCoordinate): text = "Print info for object {} in the terminal".format(obj) menu.addAction(text) - # IPC stuff - if ilastik_config.getboolean("ilastik", "debug"): - menu.addSeparator() - if any(IPCFacade().sending): - time = position5d[0] - - sub = menu.addMenu("Hilite Object") - for mode in Protocol.ValidHiliteModes[:-1]: - where = Protocol.simple("and", time=time, ilastik_id=obj) - cmd = Protocol.cmd(mode, where) - sub.addAction(mode.capitalize(), IPCFacade().broadcast(cmd)) - menu.addAction("Clear Hilite", IPCFacade().broadcast(Protocol.cmd("clear"))) - else: - menu.addAction("Open IPC Server Window", IPCFacade().show_info) - menu.addAction("Start All IPC Servers", IPCFacade().start) - menu.addSeparator() clearlabel = "Clear label for object {}".format(obj) menu.addAction(clearlabel) diff --git a/ilastik/applets/tracking/base/trackingBaseGui.py b/ilastik/applets/tracking/base/trackingBaseGui.py index a07fe7179..435f165b0 100644 --- a/ilastik/applets/tracking/base/trackingBaseGui.py +++ b/ilastik/applets/tracking/base/trackingBaseGui.py @@ -46,7 +46,6 @@ from ilastik.utility.gui.threadRouter import threadRouted from ilastik.utility.gui.titledMenu import TitledMenu from ilastik.utility import log_exception -from ilastik.shell.gui.ipcManager import IPCFacade, Protocol logger = logging.getLogger(__name__) diff --git a/ilastik/applets/tracking/conservation/conservationTrackingGui.py b/ilastik/applets/tracking/conservation/conservationTrackingGui.py index 872ee9681..821d77caf 100644 --- a/ilastik/applets/tracking/conservation/conservationTrackingGui.py +++ b/ilastik/applets/tracking/conservation/conservationTrackingGui.py @@ -15,8 +15,6 @@ from ilastik.utility.exportingOperator import ExportingGui from ilastik.utility.gui.threadRouter import threadRouted from ilastik.utility.gui.titledMenu import TitledMenu -from ilastik.utility.ipcProtocol import Protocol -from ilastik.shell.gui.ipcManager import IPCFacade from ilastik.config import cfg as ilastik_config from ilastik.plugins.manager import pluginManager @@ -405,13 +403,10 @@ def get_export_dialog_title(self): return "Export Tracking Information" def handleEditorRightClick(self, position5d, win_coord): - debug = ilastik_config.getboolean("ilastik", "debug") obj, time = self.get_object(position5d) if obj == 0: menu = TitledMenu(["Background"]) - if debug: - menu.addAction("Clear Hilite", IPCFacade().broadcast(Protocol.cmd("clear"))) menu.exec_(win_coord) return @@ -425,44 +420,6 @@ def handleEditorRightClick(self, position5d, win_coord): color = hypothesesGraph.getLineageId(time, obj) track = hypothesesGraph.getTrackId(time, obj) - tracks = None - children = None - parents = None - menu = TitledMenu(["Object {} of lineage id {}".format(obj, color), "Track id: " + (str(track) or "None")]) - if not debug: - menu.exec_(win_coord) - return - - if any(IPCFacade().sending): - - obj_sub_menu = menu.addMenu("Hilite Object") - for mode in Protocol.ValidHiliteModes: - where = Protocol.simple("and", ilastik_id=obj, time=time) - cmd = Protocol.cmd(mode, where) - obj_sub_menu.addAction(mode.capitalize(), IPCFacade().broadcast(cmd)) - - sub_menus = [ - ("Tracks", Protocol.simple_in, tracks), - ("Parents", Protocol.simple_in, parents), - ("Children", Protocol.simple_in, children), - ] - for name, protocol, args in sub_menus: - if args: - sub = menu.addMenu("Hilite {}".format(name)) - for mode in Protocol.ValidHiliteModes[:-1]: - mode = mode.capitalize() - where = protocol("track_id*", args) - cmd = Protocol.cmd(mode, where) - sub.addAction(mode, IPCFacade().broadcast(cmd)) - else: - sub = menu.addAction("Hilite {}".format(name)) - sub.setEnabled(False) - - menu.addAction("Clear Hilite", IPCFacade().broadcast(Protocol.cmd("clear"))) - else: - menu.addAction("Open IPC Server Window", IPCFacade().show_info) - menu.addAction("Start IPC Server", IPCFacade().start) - menu.exec_(win_coord) diff --git a/ilastik/applets/tracking/structured/structuredTrackingGui.py b/ilastik/applets/tracking/structured/structuredTrackingGui.py index d1ae730a8..c7675dee3 100644 --- a/ilastik/applets/tracking/structured/structuredTrackingGui.py +++ b/ilastik/applets/tracking/structured/structuredTrackingGui.py @@ -17,8 +17,6 @@ from ilastik.utility.exportingOperator import ExportingGui from ilastik.utility.gui.threadRouter import threadRouted from ilastik.utility.gui.titledMenu import TitledMenu -from ilastik.utility.ipcProtocol import Protocol -from ilastik.shell.gui.ipcManager import IPCFacade from ilastik.config import cfg as ilastik_config from ilastik.utility import bind @@ -654,92 +652,10 @@ def get_gui_applet(self): def get_export_dialog_title(self): return "Export Tracking Information" - # def handleEditorRightClick(self, position5d, win_coord): - # debug = ilastik_config.getboolean("ilastik", "debug") - # - # obj, time = self.get_object(position5d) - # if obj == 0: - # menu = TitledMenu(["Background"]) - # if debug: - # menu.addAction("Clear Hilite", IPCFacade().broadcast(Protocol.cmd("clear"))) - # menu.exec_(win_coord) - # return - # - # try: - # extra = self.mainOperator.extra_track_ids - # except (IndexError, KeyError): - # extra = {} - # - # # if this is a resolved merger, find which of the merged IDs we actually clicked on - # if time in extra and obj in extra[time]: - # colors = [self.mainOperator.label2color[time][t] for t in extra[time][obj]] - # tracks = [self.mainOperator.track_id[time][t] for t in extra[time][obj]] - # selected_track = self.get_color(position5d) - # idx = colors.index(selected_track) - # color = colors[idx] - # track = tracks[idx] - # else: - # try: - # color = self.mainOperator.label2color[time][obj] - # track = [self.mainOperator.track_id[time][obj]][0] - # except (IndexError, KeyError): - # color = None - # track = [] - # - # if track: - # children, parents = self.mainOperator.track_family(track) - # else: - # children, parents = None, None - # - # menu = TitledMenu([ - # "Object {} of lineage id {}".format(obj, color), - # "Track id: " + (str(track) or "None"), - # ]) - # - # if not debug: - # menu.exec_(win_coord) - # return - # - # if any(IPCFacade().sending): - # - # obj_sub_menu = menu.addMenu("Hilite Object") - # for mode in Protocol.ValidHiliteModes: - # where = Protocol.simple("and", ilastik_id=obj, time=time) - # cmd = Protocol.cmd(mode, where) - # obj_sub_menu.addAction(mode.capitalize(), IPCFacade().broadcast(cmd)) - # - # sub_menus = [ - # ("Tracks", Protocol.simple_in, tracks), - # ("Parents", Protocol.simple_in, parents), - # ("Children", Protocol.simple_in, children) - # ] - # for name, protocol, args in sub_menus: - # if args: - # sub = menu.addMenu("Hilite {}".format(name)) - # for mode in Protocol.ValidHiliteModes[:-1]: - # mode = mode.capitalize() - # where = protocol("track_id*", args) - # cmd = Protocol.cmd(mode, where) - # sub.addAction(mode, IPCFacade().broadcast(cmd)) - # else: - # sub = menu.addAction("Hilite {}".format(name)) - # sub.setEnabled(False) - # - # menu.addAction("Clear Hilite", IPCFacade().broadcast(Protocol.cmd("clear"))) - # else: - # menu.addAction("Open IPC Server Window", IPCFacade().show_info) - # menu.addAction("Start IPC Server", IPCFacade().start) - # - # menu.exec_(win_coord) - def handleEditorRightClick(self, position5d, win_coord): - debug = ilastik_config.getboolean("ilastik", "debug") - obj, time = self.get_object(position5d) if obj == 0: menu = TitledMenu(["Background"]) - if debug: - menu.addAction("Clear Hilite", IPCFacade().broadcast(Protocol.cmd("clear"))) menu.exec_(win_coord) return @@ -752,46 +668,8 @@ def handleEditorRightClick(self, position5d, win_coord): color = hypothesesGraph.getLineageId(time, obj) track = hypothesesGraph.getTrackId(time, obj) - tracks = None - children = None - parents = None - menu = TitledMenu(["Object {} of lineage id {}".format(obj, color), "Track id: " + (str(track) or "None")]) - if not debug: - menu.exec_(win_coord) - return - - if any(IPCFacade().sending): - - obj_sub_menu = menu.addMenu("Hilite Object") - for mode in Protocol.ValidHiliteModes: - where = Protocol.simple("and", ilastik_id=obj, time=time) - cmd = Protocol.cmd(mode, where) - obj_sub_menu.addAction(mode.capitalize(), IPCFacade().broadcast(cmd)) - - sub_menus = [ - ("Tracks", Protocol.simple_in, tracks), - ("Parents", Protocol.simple_in, parents), - ("Children", Protocol.simple_in, children), - ] - for name, protocol, args in sub_menus: - if args: - sub = menu.addMenu("Hilite {}".format(name)) - for mode in Protocol.ValidHiliteModes[:-1]: - mode = mode.capitalize() - where = protocol("track_id*", args) - cmd = Protocol.cmd(mode, where) - sub.addAction(mode, IPCFacade().broadcast(cmd)) - else: - sub = menu.addAction("Hilite {}".format(name)) - sub.setEnabled(False) - - menu.addAction("Clear Hilite", IPCFacade().broadcast(Protocol.cmd("clear"))) - else: - menu.addAction("Open IPC Server Window", IPCFacade().show_info) - menu.addAction("Start IPC Server", IPCFacade().start) - menu.exec_(win_coord) @threadRouted diff --git a/ilastik/config.py b/ilastik/config.py index d994e6845..f4bdcf358 100644 --- a/ilastik/config.py +++ b/ilastik/config.py @@ -59,31 +59,6 @@ token_url: https://web.ilastik.org/token/ upload_file_url: https://web.ilastik.org/v1/files/ create_project_url: https://web.ilastik.org/v1/batch/projects/ - -[ipc raw tcp] -autostart: false -autoaccept: true -port: 9999 -interface: localhost - -[ipc zmq tcp publisher] -autostart: false -address: 127.0.0.1:9998 - -[ipc zmq tcp subscriber] -autostart: false -address: localhost:9997 - -[ipc zmq ipc] -basedir: /tmp/ilastik - -[ipc zmq ipc publisher] -autostart: false -filename: out - -[ipc zmq ipc subscriber] -autostart: false -filename: in """ diff --git a/ilastik/ilastik_logging/logging_config.json b/ilastik/ilastik_logging/logging_config.json index cf34f654f..32b82a2da 100644 --- a/ilastik/ilastik_logging/logging_config.json +++ b/ilastik/ilastik_logging/logging_config.json @@ -23,7 +23,6 @@ "ilastik.applets.blockwiseObjectClassification": { "level":"INFO" }, "ilastik.shell": { "level":"INFO" }, "ilastik.shell.projectManager": { "level":"INFO" }, - "ilastik.shell.gui.ipcManager": { "level":"INFO" }, "ilastik.utility": { "level":"INFO" }, "ilastik.utility.exportingOperator": { "level":"INFO" }, "ilastik.utility.exportFile": { "level":"INFO" }, diff --git a/ilastik/shell/gui/ilastikShell.py b/ilastik/shell/gui/ilastikShell.py index eebdf5c23..0c224897c 100644 --- a/ilastik/shell/gui/ilastikShell.py +++ b/ilastik/shell/gui/ilastikShell.py @@ -60,8 +60,6 @@ ) # lazyflow -from ilastik.widgets.ipcserver.tcpServerInfoWidget import TCPServerInfoWidget -from ilastik.widgets.ipcserver.zmqPubSubInfoWidget import ZMQPublisherInfoWidget from ilastik.widgets.collapsibleWidget import CollapsibleWidget from lazyflow.roi import TinyVector from lazyflow.graph import Operator @@ -97,7 +95,6 @@ from ilastik.widgets.appletDrawerToolBox import AppletDrawerToolBox, AppletBarManager from ilastik.widgets.filePathButton import FilePathButton -from ilastik.shell.gui.ipcManager import IPCFacade, TCPServer, TCPClient, ZMQPublisher, ZMQSubscriber, ZMQBase # Import all known workflows now to make sure they are all registered with getWorkflowFromName() import ilastik.workflows @@ -327,50 +324,6 @@ def __init__(self, parent=None, workflow_cmdline_args=None, flags=Qt.WindowFlags self.thunkEventHandler = ThunkEventHandler(self) self.threadRouter = ThreadRouter(self) # Enable @threadRouted - # Server/client for inter process communication for receiving remote commands (e.g. from KNIME) - # For now, this is a developer-only feature, activated by a debug menu item. - if ilastik_config.getboolean("ilastik", "debug"): - facade = IPCFacade() - facade.register_shell(self) - facade.register_widget(TCPServerInfoWidget(), "TCP Connection", "raw tcp") - interface = ilastik_config.get("ipc raw tcp", "interface") - port = ilastik_config.getint("ipc raw tcp", "port") - start = ilastik_config.getboolean("ipc raw tcp", "autostart") - facade.register_module(TCPServer(interface, port), "receiver", "raw tcp server", "raw tcp", start=start) - facade.register_module(TCPClient(), "sender", "raw tcp client", "raw tcp", "tcp") - - if ZMQBase.available("tcp"): - facade.register_widget(ZMQPublisherInfoWidget(), "ZeroMQ Pub Sub TCP", "zmq tcp") - start = ilastik_config.getboolean("ipc zmq tcp publisher", "autostart") - address = ilastik_config.get("ipc zmq tcp publisher", "address") - facade.register_module(ZMQPublisher("tcp", address), "sender", "zmq tcp pub", "zmq tcp", start=start) - start = ilastik_config.getboolean("ipc zmq tcp subscriber", "autostart") - address = ilastik_config.get("ipc zmq tcp subscriber", "address") - facade.register_module(ZMQSubscriber("tcp", address), "receiver", "zmq tcp sub", "zmq tcp", start=start) - - if ZMQBase.available("ipc"): - base_dir = ilastik_config.get("ipc zmq ipc", "basedir") - can_start = True - try: - os.mkdir(base_dir) - except OSError as e: - if e.errno != 17: # exists - can_start = False - if can_start: - facade.register_widget(ZMQPublisherInfoWidget(), "ZeroMQ Pub Sub IPC", "zmq ipc") - start = ilastik_config.getboolean("ipc zmq ipc publisher", "autostart") - filename = ilastik_config.get("ipc zmq ipc publisher", "filename") - path = os.path.join(base_dir, filename) - facade.register_module( - ZMQPublisher("ipc", path), "sender", "zmq ipc pub", "zmq ipc", start=start - ) - start = ilastik_config.getboolean("ipc zmq ipc subscriber", "autostart") - filename = ilastik_config.get("ipc zmq ipc subscriber", "filename") - path = os.path.join(base_dir, filename) - facade.register_module( - ZMQSubscriber("ipc", path), "receiver", "zmq ipc sub", "zmq ipc", start=start - ) - self.openFileButtons = [] self.cleanupFunctions = [] @@ -789,8 +742,6 @@ def _createDebugMenu(self): menu.addMenu(self._createAllocationTrackingSubmenu()) - menu.addAction("Show IPC Server Info", IPCFacade().show_info) - def hideApplets(hideThem): self.mainSplitter.setVisible(not hideThem) diff --git a/ilastik/shell/gui/ipcManager.py b/ilastik/shell/gui/ipcManager.py deleted file mode 100644 index 74473f93a..000000000 --- a/ilastik/shell/gui/ipcManager.py +++ /dev/null @@ -1,680 +0,0 @@ -from future import standard_library - -standard_library.install_aliases() -from socketserver import BaseRequestHandler, TCPServer as BaseTCPServer -import logging -import threading -import atexit -import json -from itertools import chain -from collections import OrderedDict -from operator import itemgetter -from PyQt5.QtCore import QObject, pyqtSignal -from ilastik.utility.commandProcessor import CommandProcessor -from future.utils import with_metaclass - -try: - import zmq -except ImportError: - zmq = None -from sys import platform as platform_ -from PyQt5.QtWidgets import QInputDialog - -from ilastik.widgets.ipcserver.ipcServerInfoWindow import IPCServerInfoWindow -from ilastik.utility.decorators import lazy -from ilastik.utility.singleton import Singleton -from ilastik.utility.ipcProtocol import Protocol -from ilastik.utility.numpyJsonEncoder import NumpyJsonEncoder -from ilastik.utility.contextSocket import socket, socket_error -from ilastik.config import cfg as ilastik_config - -logger = logging.getLogger(__name__) - - -class IPCFacade(with_metaclass(Singleton, object)): - """ - The Singleton that encapsulates all IPC functionality - Use this to register new server modules or send broadcasts - """ - - def __init__(self): - self.info = IPCServerInfoWindow() - self.senders = {} - self.receivers = {} - self.widgets = {} - self.protocol_map = {} - self.processor = CommandProcessor() - - def register_shell(self, shell): - """ - This sets the shell. Must be called before incoming command can be executed - :param shell: the ilastik shell - """ - self.processor.set_shell(shell) - - def register_widget(self, widget, title, key): - """ - Add a new widget to the IPCServerWindow - :param widget: the widget to add - :param title: the title to appear in the tab bar - :param key: the key to identify and reference the widget - """ - if key in self.widgets: - raise RuntimeError("Widget {} already exists".format(key)) - self.widgets[key] = widget - self.info.add_widget(title, widget) - - def register_module(self, module, type_, key, widget_key=None, protocol=None, start=False): - """ - Adds a new module to the IPCServer - :param module: the module e.g. TCPServer, ZMQPublisher - :param type_: "sender" or "receiver" - :param key: the key to identify the module later - :param widget_key: a reference to the view widget. If not None the module will connect to it - :param protocol: set this to redirect handshake command with the matching protocol to this module - :param start: if set the module will start immediately - """ - if type_ == "receiver": - container = self.receivers - self.processor.connect_receiver(module) - elif type_ == "sender": - container = self.senders - else: - raise RuntimeError("Type {} is invalid".format(type_)) - - if key in container: - raise RuntimeError("{} {} already exists".format(type_, key)) - container[key] = module - if widget_key is not None: - module.connect_widget(self.widgets[widget_key]) - if protocol is not None: - self.protocol_map[protocol] = module - - if start: - module.start() - - def handshake(self, protocol, name, address): - """ - Redirects a handshake command to the registered module - Currently only TCPClient handles handshake commands from TCPServer - :param protocol: the protocol to identify the handler ( e.g. tcp ) - :param name: the name of the peer ( e.g. KNIME ) - :param address: the address of the peer. Depends on the protocol ( e.g. for tcp => (str: host, int: port) - """ - if protocol not in self.protocol_map: - raise RuntimeError("No such protocol {}".format(protocol)) - self.protocol_map[protocol].add_peer(name, address) - - @property - def sending(self): - """ - Check if the senders are running ( e.g. any(IPCFacade().running) or all(IPCFacade().running) - :return: a list containing True or False for each sender - """ - return (sender.running for sender in self.senders.values()) - - @property - def receiving(self): - """ - The same as IPCFacade.sending for the receivers - """ - return (rec.running for rec in self.receivers.values()) - - def start(self): - """ - Start all registered modules - """ - for module in self._all_modules(): - module.start() - - def stop(self): - """ - Stop all registered modules - """ - for module in self._all_modules(): - module.stop() - - def _all_modules(self): - return chain(iter(self.senders.values()), iter(self.receivers.values())) - - @lazy - def broadcast(self, command): - """ - Creates functions that can directly be passed to Qt's connect mechanism - e.g. - action = IPCFacade().broadcast( ... a command ... ) - qtSignal.connect(action) - :param command: the command ( dict ) - """ - # from pprint import PrettyPrinter - # PrettyPrinter(indent=4).pprint(command) - message = json.dumps(command, cls=NumpyJsonEncoder) - log = Protocol.verbose(command) - for server in self.senders.values(): - server.broadcast(message, log) - - def show_info(self): - """ - Displays the IPC Info Widget or moves the windows to the top - :return: - """ - self.info.show() - self.info.activateWindow() # bring to top - - -class InvalidAddress(Exception): - """ - raise this inside IPCModule._start to automaticely prompt for a new address - """ - - def __init__(self, what): - self._what = what - - @property - def what(self): - return self._what - - -class IPCModul(object): - """ - The base class for the IPC modules registered in the IPCFacade - """ - - def start(self): - pass - - @property - def running(self): - """ - Implement this to return if the module is currently running or not - """ - raise NotImplementedError - - @property - def widget(self): - """ - :return: the info widget of the IPC module - """ - raise NotImplementedError - - def connect_widget(self, widget): - """ - This will be called by the IPCFacade to connect the module to its widget - :param widget: the QtWidget - """ - raise NotImplementedError - - @staticmethod - def available(mode=None): - """ - Implement this to return if the module is available on the current platform - e.g. ZeroMQ's ipc protocol is only available on UNIX - :param mode: this can be used to distinguish different modes ( e.g. protocols ) - """ - raise NotImplementedError - - -class HasPeers(IPCModul): - """ - Interface for all modules that maintain a list of peers in any way - """ - - def add_peer(self, name, address): - """ - Call this to add a peer to the list - :param name: its name ( e.g. KNIME ) - :param address: its address ( depends on the protocol ) - """ - raise NotImplementedError - - def update_peer(self, key, **kvargs): - """ - Call this to change settings for a peer - :param key: the internal identifier for the peer ( e.g. the index to the peer list ) - :param kvargs: key-value pairs that should be changed - """ - raise NotImplementedError - - -class Sending(IPCModul): - """ - Interface for all modules that can broadcast messages - """ - - def broadcast(self, message, log): - """ - Wrapper to only broadcast if running and logging of the message - """ - if self.running: - self._broadcast(message) - self.widget.add_sent_command(log, 0) - - def _broadcast(self, message): - """ - Implement this to broadcast the message - :param message: the message to broadcast as a str - """ - raise NotImplementedError - - -class Receiving(IPCModul): - """ - Interface for all modules that can receive messages - """ - - @property - def signal(self): - """ - :return: the signal that will be emitted if a message was received - Signature: ( str: command_name, dict: command_data ) - """ - raise NotImplementedError - - -class Binding(IPCModul): - """ - Interface for all modules that must be started as they bind to an address ( that might not be available ) in any way - """ - - def start(self): - """ - Start the server if it is not running - This also automatically displays the address_prompt if problem occurred - """ - if not self.running: - while True: - try: - self._start() - except InvalidAddress as e: - new_address, ok = self.address_prompt(e.what) - if not ok: - return - self.change_address(new_address) - else: - return - - def stop(self, kill=True): - """ - Stop the server if it is running - """ - if self.running: - self._stop(kill) - - def toggle(self): - """ - Stop if running, start if not running - """ - if self.running: - self._stop() - else: - self.start() - - def change_address(self, address): - """ - Changes the address. This can only be done if the server is not running - :param address: the new address - :type address: depends on implementation ( see subclass ) - """ - if not self.running: - self._change_address(address) - - def _start(self): - """ - Implement this to start the module. - raise InvalidAddress if the module could not be started - """ - raise NotImplementedError - - def _stop(self, kill=False): - """ - Implement this to stop the module - the module should be able to restart after this - """ - raise NotImplementedError - - def _change_address(self, address): - """ - Implement this to change the address of the module - This will only be called if the module is not running - """ - raise NotImplementedError - - def address_prompt(self, message): - """ - Display a graphical window to ask the user for a different address. - This might happen if the previous address is invalid or simply if the user wanted to change the address - """ - raise NotImplementedError - - -class Handler(BaseRequestHandler): - """ - Basic Handler for the SocketServer - """ - - def handle(self): - """ - Receive one Message and emit the signal - """ - try: - data = self.request.recv(4096).strip() - host, port = self.request.getpeername() - if data == "": - return - command = json.loads(data) - except (socket_error, ValueError) as e: - logger.exception(e) - return - name = command.pop("command") - if name == "handshake": - command.update({"protocol": "tcp"}) - command.update({"host": host}) - - self.server.signal.emit(name, command) - - -class TCPServer(Binding, Receiving, QObject): - """ - raw tcp server. accepts handshakes which will be forwarded to the TCPClient - """ - - commandReceived = pyqtSignal(str, dict) - - def __init__(self, interface, port): - super(TCPServer, self).__init__() - self.port = port - self.interface = interface - self.thread = None - self.server = None - - self.info = None - - @property - def signal(self): - return self.commandReceived - - def connect_widget(self, widget): - self.info = widget - widget.statusToggled.connect(self.toggle) - widget.changePort.connect(self.on_address_change) - widget.notify_server_status_update("port", self.port) - - def on_address_change(self): - port, ok = self.address_prompt(level="Info") - if ok: - self.change_address(port) - - @staticmethod - def available(mode=None): - return True - - @property - def widget(self): - return self.info - - @property - def running(self): - return self.server is not None - - def _start(self): - try: - server = BaseTCPServer((self.interface, self.port), Handler) - except socket.error as e: - self.server = None - self.info.notify_server_status_update("running", False) - if e.errno in [13, 98]: # Permission denied or Address already in use - raise InvalidAddress(str(e)) - raise - self.server = server - server.signal = self.signal - - thread = threading.Thread(target=self.server.serve_forever, name="TCPServer Thread") - thread.daemon = True - thread.start() - logger.info("IPC Server started on port %d" % self.server.socket.getsockname()[1]) - self.info.notify_server_status_update("running", True) - - self.thread = thread - - def _stop(self, kill=False): - self.server.shutdown() - if kill: - return - self.info.notify_server_status_update("running", False) - logger.info("IPC Server stopped") - self.server = None - - def address_prompt(self, message="", level="Warning"): - message = "{}. Change port".format(message) - return QInputDialog.getInt(QInputDialog(), level, message, self.port, 1024, 65535) - - def _change_address(self, address): - self.port = address - - -class TCPClient(Sending, HasPeers): - """ - This module keeps a list of peers an connects to them if a message must be broadcast - The tcp connection will be closed right after the messages were sent - """ - - def __init__(self): - self.peers = OrderedDict() - - self.info = None - - def connect_widget(self, widget): - self.info = widget - widget.connectionChanged.connect(self.update_peer) - - def add_peer(self, name, address): - host, port = address - key = (host, name) - if key not in self.peers: - self.peers[key] = { - "enabled": ilastik_config.getboolean("ipc raw tcp", "autoaccept"), - "address": [host, port], - } - - elif self.peers[key]["address"][1] != port: - self.peers[key]["address"][1] = port - else: - return - self.info.update_connections(self.peers) - - def update_peer(self, key, **kvargs): - enabled = kvargs["enabled"] - list(self.peers.values())[key]["enabled"] = enabled - - def _broadcast(self, message): - count = 0 - for peer in filter(itemgetter("enabled"), iter(self.peers.values())): - try: - with socket() as s: - # noinspection PyTypeChecker - host, port = peer["address"] - s.connect((host, port)) - s.sendall(message) - except socket_error as e: - logger.exception(e) - else: - count += 1 - return count - - @property - def widget(self): - return self.info - - @property - def running(self): - return bool(self.peers) - - @staticmethod - def available(mode=None): - return True - - -class ZMQBase(Binding): - """ - Base class for the zmq modules - """ - - def __init__(self, protocol, address): - self.protocol = protocol - self.address = address - - def address_prompt(self, message="", level="Warning"): - message = "{}. Change address".format(message) - return QInputDialog.getText(QInputDialog(), level, message, 0, self.address) - - def on_address_change(self): - address, ok = self.address_prompt(level="Info") - if ok: - self.change_address(address) - - @staticmethod - def available(mode=None): - if zmq is None: - return False - if "tcp" in mode: - return True - elif "ipc" in mode: - return platform_ in ["linux", "linux2"] - else: - return False - - @property - def full_addr(self): - return "{}://{}".format(self.protocol, self.address) - - -class ZMQPublisher(ZMQBase, Sending): - """ - This module publishes the hilite commands - """ - - def __init__(self, protocol, address): - super(ZMQPublisher, self).__init__(protocol, address) - - self.context = zmq.Context() - self.socket = None - self.info = None - - # atexit.register(self.stop) - - def connect_widget(self, widget): - self.info = widget - widget.pubStatusToggled.connect(self.toggle) - widget.notify_server_status_update("pub", "address", self.full_addr) - widget.changePubAddress.connect(self.on_address_change) - - def _change_address(self, address): - self.address = address - self.info.notify_server_status_update("pub", "address", self.full_addr) - - def _broadcast(self, message): - self.socket.send_string(message, zmq.NOBLOCK) - - @property - def running(self): - return self.socket is not None - - @property - def widget(self): - return self.info - - def _start(self): - pub = self.context.socket(zmq.PUB) - try: - pub.bind(self.full_addr) - except zmq.ZMQError as e: - self.info.notify_server_status_update("pub", "running", False) - if e.errno in [98, 13]: # Address already in use - raise InvalidAddress(str(e)) - raise - self.socket = pub - logger.info("ZMQ Publisher started on {}".format(self.full_addr)) - self.info.notify_server_status_update("pub", "running", True) - - def _stop(self, kill=None): - self.socket.unbind(self.full_addr) - self.socket.close() - self.socket = None - if kill: - return - logger.info("ZMQ Publisher {} stopped".format(self.full_addr)) - self.info.notify_server_status_update("pub", "running", False) - - -class ZMQSubscriber(QObject, ZMQBase, Receiving): - """ - This module subscribes to all publishers on a given address - """ - - commandReceived = pyqtSignal(str, dict) - - def __init__(self, protocol, address): - super().__init__(protocol=protocol, address=address) - self.context = zmq.Context() - self.socket = None - self.thread = None - self.stop_event = threading.Event() - - self.info = None - - @property - def widget(self): - return self.info - - def connect_widget(self, widget): - self.info = widget - widget.subStatusToggled.connect(self.toggle) - widget.changeSubAddress.connect(self.on_address_change) - widget.notify_server_status_update("sub", "address", self.full_addr) - self.signal.connect(widget.add_recv_command) - - def _change_address(self, address): - self.address = address - self.info.notify_server_status_update("sub", "address", self.full_addr) - - @property - def running(self): - return self.socket is not None - - @property - def signal(self): - return self.commandReceived - - def _start(self): - # noinspection PyArgumentList - s = self.context.socket(zmq.SUB) - s.setsockopt(zmq.SUBSCRIBE, "") - s.connect(self.full_addr) - self.socket = s - - self.stop_event.clear() - thread = threading.Thread(target=self.serve, name="ZMQ Sub {} Thread".format(self.protocol)) - thread.daemon = True - thread.start() - self.thread = thread - logger.info("ZMQ Subscriber started on {}".format(self.full_addr)) - self.info.notify_server_status_update("sub", "running", True) - - def _stop(self, kill=False): - self.stop_event.set() - self.thread.join() - self.socket.disconnect(self.full_addr) - self.socket.close() - self.socket = None - logger.info("ZMQ Subscriber {} stopped".format(self.full_addr)) - self.info.notify_server_status_update("sub", "running", False) - - def serve(self): - poll = zmq.Poller() - poll.register(self.socket, zmq.POLLIN) - while not self.stop_event.is_set(): - s = dict(poll.poll(1000)) - if s.get(self.socket) == zmq.POLLIN: - command = self.socket.recv_json() - name = command.pop("command") - self.signal.emit(name, command) diff --git a/ilastik/utility/commandProcessor.py b/ilastik/utility/commandProcessor.py deleted file mode 100644 index c2e062655..000000000 --- a/ilastik/utility/commandProcessor.py +++ /dev/null @@ -1,64 +0,0 @@ -############################################################################### -# ilastik: interactive learning and segmentation toolkit -# -# Copyright (C) 2011-2014, the ilastik developers -# -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# In addition, as a special exception, the copyright holders of -# ilastik give you permission to combine ilastik with applets, -# workflows and plugins which are not covered under the GNU -# General Public License. -# -# See the LICENSE file for details. License information is also available -# on the ilastik web site at: -# http://ilastik.org/license.html -############################################################################### - - -from future import standard_library - -standard_library.install_aliases() - - -def handshake(_, protocol, name, **address): - from ilastik.shell.gui.ipcManager import IPCFacade - - if "host" in address and "port" in address: - address = (address["host"], address["port"]) - IPCFacade().handshake(protocol, name, address) - - -def set_position(shell, t=0, x=0, y=0, z=0, c=0, **_): - try: - shell.setAllViewersPosition([t, x, y, z, c]) - except IndexError: - pass # No project loaded - - -commands = {"handshake": handshake, "setviewerposition": set_position} - - -class CommandProcessor(object): - def __init__(self): - self.shell = None - - def set_shell(self, shell): - self.shell = shell - - def connect_receiver(self, receiver): - receiver.signal.connect(self.execute) - - def disconnect_receiver(self, receiver): - receiver.signal.disconnect(self.execute) - - def execute(self, command, data): - command = str(command) - handler = commands.get(command) - if not handler: - raise RuntimeError("Command '{}' is not available".format(command)) - handler(self.shell, **data) diff --git a/ilastik/utility/ipcProtocol.py b/ilastik/utility/ipcProtocol.py deleted file mode 100644 index 6080c4d9f..000000000 --- a/ilastik/utility/ipcProtocol.py +++ /dev/null @@ -1,100 +0,0 @@ -class Protocol(object): - ValidOps = ["and", "or"] - ValidHiliteModes = ["hilite", "unhilite", "toggle", "clear"] - - @staticmethod - def simple(operator, *wheres, **attributes): - """ - Builds a simple where clause for the hilite command - - :param wheres: a list of finished where sub clauses - :param attributes: the attributes and their values to be added - :returns: the where dict - - e.g. - simple("and", ilastik_id=42, time=1337) - => WHERE ( ilastik_id == 42 AND time == 1337 ) - """ - operands = list(wheres) - for name, value in attributes.items(): - operands.append({"operator": "==", "row": name, "value": value}) - - return {"operator": operator, "operands": operands} - - @staticmethod - def simple_in(row, possibilities): - """ - Builds a simple where clause ( using 'in' ) for the hilite command - - :param row: the row name that must be in possibilities - :param possibilities: the possible values row can have - :returns: the where dict - - e.g. - simple("track_id1", [42, 1337, 12345]) - => WHERE ( track_id1 == 42 OR track_id1 == 1337 OR track_id1 == 12345 ) - """ - operands = [] - for p in possibilities: - operands.append({"operator": "==", "row": row, "value": p}) - - return {"operator": "or", "operands": operands} - - @staticmethod - def clear(): - """ - Builds the clear hilite command to clear all hilites - :returns: the command dict - """ - return {"command": "hilite", "mode": "clear"} - - @staticmethod - def cmd(mode, where=None): - if mode.lower() not in Protocol.ValidHiliteModes: - raise ValueError("Mode '{}' not supported".format(mode)) - command = {"command": "hilite", "mode": mode} - if where is not None: - command["where"] = where - return command - - @staticmethod - def verbose(command): - """ - returns the command in an SQL like readable form - - :param command: the command to convert - :type command: dict - :returns: the command as str - """ - assert "command" in command, "Must be a command dict" - assert command["command"] == "hilite", "Only hilite commands supported" - - mode = command["mode"] - if mode == "clear": - return "CLEAR *" - where = [] - Protocol._parse(where, command["where"]) - - return "{} * WHERE {}".format(mode.upper(), " ".join(where)) - - @staticmethod - def _parse(where, sub): - if "operand" in sub: - where.append(sub["operator"].upper()) - where.append("(") - Protocol._parse(where, sub["operand"]) - where.append(")") - elif "operands" in sub: - if not sub["operands"]: - where.append("MISSING") - where.append(None) - for operand in sub["operands"]: - where.append("(") - Protocol._parse(where, operand) - where.append(")") - where.append(sub["operator"].upper()) - where.pop() - else: - where.append(sub["row"]) - where.append(sub["operator"].upper()) - where.append(str(sub["value"])) diff --git a/ilastik/widgets/ipcserver/__init__.py b/ilastik/widgets/ipcserver/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/ilastik/widgets/ipcserver/ipcServerInfoWindow.py b/ilastik/widgets/ipcserver/ipcServerInfoWindow.py deleted file mode 100644 index 5caec39ec..000000000 --- a/ilastik/widgets/ipcserver/ipcServerInfoWindow.py +++ /dev/null @@ -1,15 +0,0 @@ -from PyQt5.QtWidgets import QMainWindow -from PyQt5 import uic -import os - - -class IPCServerInfoWindow(QMainWindow): - def __init__(self, parent=None): - super(IPCServerInfoWindow, self).__init__(parent) - - ui_class, widget_class = uic.loadUiType(os.path.split(__file__)[0] + "/ipcServerInfoWindow.ui") - self.ui = ui_class() - self.ui.setupUi(self) - - def add_widget(self, name, widget): - self.ui.tabWidget.addTab(widget, name) diff --git a/ilastik/widgets/ipcserver/ipcServerInfoWindow.ui b/ilastik/widgets/ipcserver/ipcServerInfoWindow.ui deleted file mode 100644 index e2568f466..000000000 --- a/ilastik/widgets/ipcserver/ipcServerInfoWindow.ui +++ /dev/null @@ -1,95 +0,0 @@ - - - MainWindow - - - - 0 - 0 - 800 - 600 - - - - MainWindow - - - - - 0 - - - 0 - - - - - - - - QFrame::NoFrame - - - QFrame::Plain - - - 0 - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Close - - - - - - - - - - - - 0 - 0 - 800 - 25 - - - - - - - - - close_button - clicked() - MainWindow - close() - - - 747 - 554 - - - 399 - 299 - - - - - diff --git a/ilastik/widgets/ipcserver/tcpServerInfoWidget.py b/ilastik/widgets/ipcserver/tcpServerInfoWidget.py deleted file mode 100644 index d129b220d..000000000 --- a/ilastik/widgets/ipcserver/tcpServerInfoWidget.py +++ /dev/null @@ -1,157 +0,0 @@ -from __future__ import print_function -from PyQt5 import uic -from PyQt5.QtCore import pyqtSignal, Qt -from PyQt5.QtGui import QColor, QBrush -from PyQt5.QtWidgets import QWidget, QMenu, QListWidgetItem - -import logging -import os -from functools import partial - -logger = logging.getLogger(__name__) - - -def convert_to_type(string): - if string[0] == "'" and string[-1] == "'" or string[0] == '"' and string[-1] == '"': - return string[1:-1] - try: - return int(string) - except ValueError: - pass - try: - return float(string) - except ValueError: - pass - return string - - -class TCPServerInfoWidget(QWidget): - """ - Displays various information about the IPCServerManager - and allows manipulation of some of its properties - """ - - statusToggled = pyqtSignal() - connectionChanged = pyqtSignal(int, bool) - changePort = pyqtSignal() - - broadcast = pyqtSignal(dict) # debug - - connectionColors = [QColor("yellow"), QColor("lime")] - commandFailureColor = QColor(255, 150, 150) # bright red - - def __init__(self, parent=None): - super(TCPServerInfoWidget, self).__init__(parent) - - ui_class, widget_class = uic.loadUiType(os.path.split(__file__)[0] + "/tcpServerInfoWidget.ui") - self.ui = ui_class() - self.ui.setupUi(self) - - self.server_status = {"port": None, "running": False} - - self.ui.toggleStatus.clicked.connect(partial(self.ui.toggleStatus.setEnabled, False)) - self.ui.toggleStatus.clicked.connect(self.statusToggled.emit) - menu = QMenu("options") - self.change_port_action = menu.addAction("Change Port", self.changePort.emit) - self.ui.toggleStatus.setMenu(menu) - - self.status_style = "background-color: %s; border: 3px inset gray" - - def notify_server_status_update(self, attribute, value): - """ - Notifies to the GUI that the IPCServer's status has changed - :param attribute: the attribute that has changed ("port", "running") - :type attribute: str - :param value: the value that the attribute has changed to - :type value: any - """ - - if attribute == "port": - pass - elif attribute == "running": - if value: # server is running now - self.ui.serverStatus.setText("running: %s" % self.server_status["port"]) - self.ui.serverStatus.setStyleSheet(self.status_style % "lime") - self.ui.toggleStatus.setText("Stop Server") - else: - self.ui.serverStatus.setText("shutdown") - self.ui.serverStatus.setStyleSheet(self.status_style % "red") - self.ui.toggleStatus.setText("Start Server") - self.change_port_action.setEnabled(not value) - self.ui.toggleStatus.setEnabled(True) - - else: - logger.warning("'%s' is no valid server status attribute ") - return - self.server_status[attribute] = value - - def add_command(self, cmd, success): - """ - adds a new command to the list - :param cmd: the command including the arguments - :type cmd: dict - :param success: flag if the execution of the command was successful - :type success: bool - """ - text = "%s (" % cmd["command"] - for k, v in cmd.items(): - if k == "command": - continue - text += " %s:%s" % (k, v) - text += " )" - - item = QListWidgetItem("::RECV :: {}".format(text)) - if not success: - item.setBackground(QBrush(self.commandFailureColor, Qt.SolidPattern)) - self.ui.commandList.addItem(item) - self.ui.commandList.scrollToBottom() - - def add_sent_command(self, cmd, count): - """ - Adds the sent command to the history list - :param cmd: the command - :type cmd: str - :param count: the number of clients that received the message - :type count: int - """ - item = QListWidgetItem("::SENT({:^4}):: {}".format(count, cmd)) - self.ui.commandList.addItem(item) - self.ui.commandList.scrollToBottom() - - def update_connections(self, connections): - """ - Clears the connection list and adds an entry for each item in connetions - :param connections: the new connections - :type connections: dict - """ - self.ui.connectionList.clear() - for c in connections.keys(): - item = QListWidgetItem("%s (%s)" % (c[0], c[1])) - enabled = connections[c]["enabled"] - client = connections[c]["address"] - item.setCheckState(Qt.Checked if enabled else Qt.Unchecked) - color = self.connectionColors[0 if client is None else 1] - item.setBackground(QBrush(color, Qt.SolidPattern)) - self.ui.connectionList.addItem(item) - - # slot called from QListWidgetItem check - def list_widget_changed(self, item): - index = self.ui.connectionList.row(item) - self.connectionChanged.emit(index, True if item.checkState() == Qt.Checked else False) - - # slot called from QCheckBox toggle - def stay_on_top(self, state): - pass - - # debug - def broadcast_clicked(self): - command = convert_to_type(str(self.ui.debugCommandName.text())) - args = str(self.ui.debugCommandArgs.toPlainText()) - kvargs = {} - for arg in args.splitlines(): - key, value = arg.split(None, 1) - value = convert_to_type(value) - kvargs[key] = value - kvargs["command"] = command - print(kvargs) - self.broadcast.emit(kvargs) diff --git a/ilastik/widgets/ipcserver/tcpServerInfoWidget.ui b/ilastik/widgets/ipcserver/tcpServerInfoWidget.ui deleted file mode 100644 index a2e042031..000000000 --- a/ilastik/widgets/ipcserver/tcpServerInfoWidget.ui +++ /dev/null @@ -1,144 +0,0 @@ - - - Form - - - - 0 - 0 - 577 - 508 - - - - Form - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - Server status: - - - - - - - - 150 - 0 - - - - background-color: red; border: 3px inset gray - - - QFrame::NoFrame - - - QFrame::Plain - - - 0 - - - 0 - - - shutdown - - - Qt::AlignCenter - - - - - - - - 100 - 27 - - - - Qt::NoFocus - - - Start Server - - - QToolButton::MenuButtonPopup - - - false - - - Qt::NoArrow - - - - - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - Monospace - - - - QAbstractItemView::NoSelection - - - - - - - QAbstractItemView::NoSelection - - - - - - - Command History - - - - - - - Connections - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - - - - diff --git a/ilastik/widgets/ipcserver/zmqPubSubInfoWidget.py b/ilastik/widgets/ipcserver/zmqPubSubInfoWidget.py deleted file mode 100644 index 4ff863578..000000000 --- a/ilastik/widgets/ipcserver/zmqPubSubInfoWidget.py +++ /dev/null @@ -1,95 +0,0 @@ -from PyQt5 import uic -from PyQt5.QtCore import pyqtSignal -from PyQt5.QtWidgets import QWidget, QMenu, QListWidgetItem - -import logging -import os -from functools import partial -from ilastik.utility.ipcProtocol import Protocol - -logger = logging.getLogger(__name__) - - -class ZMQPublisherInfoWidget(QWidget): - """ - Displays various information about the ZMQPublisher - and allows manipulation of some of its properties - """ - - subStatusToggled = pyqtSignal() - pubStatusToggled = pyqtSignal() - changeSubAddress = pyqtSignal() - changePubAddress = pyqtSignal() - - def __init__(self, parent=None): - super(ZMQPublisherInfoWidget, self).__init__(parent) - - ui_class, widget_class = uic.loadUiType(os.path.split(__file__)[0] + "/zmqPubSubInfoWidget.ui") - self.ui = ui_class() - self.ui.setupUi(self) - - self.status = {"pub": {"address": None, "running": False}, "sub": {"address": None, "running": False}} - - self.ui.toggleSubStatus.clicked.connect(partial(self.ui.toggleSubStatus.setEnabled, False)) - self.ui.togglePubStatus.clicked.connect(partial(self.ui.togglePubStatus.setEnabled, False)) - self.ui.toggleSubStatus.clicked.connect(self.subStatusToggled.emit) - self.ui.togglePubStatus.clicked.connect(self.pubStatusToggled.emit) - - menu = QMenu("options") - self.change_pub_addr_action = menu.addAction("Change Address", self.changePubAddress.emit) - self.ui.togglePubStatus.setMenu(menu) - - menu = QMenu("options") - self.change_sub_addr_action = menu.addAction("Change Address", self.changeSubAddress.emit) - self.ui.toggleSubStatus.setMenu(menu) - - self.status_style = "background-color: %s; border: 3px inset gray; padding: 5px" - - def notify_server_status_update(self, mode, attribute, value): - if attribute == "address": - pass - elif attribute == "running": - if mode == "pub": - status_widget = self.ui.pubStatus - status = self.status["pub"] - toggle_widget = self.ui.togglePubStatus - action = self.change_pub_addr_action - msg = "publish" - elif mode == "sub": - status_widget = self.ui.subStatus - status = self.status["sub"] - toggle_widget = self.ui.toggleSubStatus - action = self.change_sub_addr_action - msg = "subscribe" - else: - logger.warning("'{}' is not a valid mode".format(mode)) - return - if value: - status_widget.setText("running: %s" % status["address"]) - status_widget.setStyleSheet(self.status_style % "lime") - toggle_widget.setText("Un{}".format(msg)) - else: - status_widget.setText("shutdown") - status_widget.setStyleSheet(self.status_style % "red") - toggle_widget.setText(msg.capitalize()) - toggle_widget.setEnabled(True) - action.setEnabled(not value) - else: - logger.warning("'%s' is no valid server status attribute ") - return - self.status[mode][attribute] = value - - def add_sent_command(self, cmd, _): - """ - Adds the sent command to the history list - :param cmd: the command - :type cmd: str - """ - item = QListWidgetItem("::SENT:: {}".format(cmd)) - self.ui.commandList.addItem(item) - self.ui.commandList.scrollToBottom() - - def add_recv_command(self, name, data): - item = QListWidgetItem("::RECV:: {} {}".format(name, data)) - self.ui.commandList.addItem(item) - self.ui.commandList.scrollToBottom() diff --git a/ilastik/widgets/ipcserver/zmqPubSubInfoWidget.ui b/ilastik/widgets/ipcserver/zmqPubSubInfoWidget.ui deleted file mode 100644 index 630d4d057..000000000 --- a/ilastik/widgets/ipcserver/zmqPubSubInfoWidget.ui +++ /dev/null @@ -1,202 +0,0 @@ - - - Form - - - - 0 - 0 - 577 - 508 - - - - Form - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - Publisher status: - - - - - - - - 150 - 0 - - - - background-color: red; border: 3px inset gray; padding: 5px - - - QFrame::NoFrame - - - QFrame::Plain - - - 0 - - - 0 - - - shutdown - - - Qt::AlignCenter - - - - - - - - 100 - 27 - - - - Qt::NoFocus - - - Publish - - - QToolButton::MenuButtonPopup - - - false - - - Qt::NoArrow - - - - - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - Subscriber status: - - - - - - - - 150 - 0 - - - - background-color: red; border: 3px inset gray; padding: 5px - - - QFrame::NoFrame - - - QFrame::Plain - - - 0 - - - 0 - - - shutdown - - - Qt::AlignCenter - - - - - - - - 100 - 27 - - - - Qt::NoFocus - - - Subscribe - - - QToolButton::MenuButtonPopup - - - false - - - Qt::NoArrow - - - - - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - Command History - - - - - - - - Monospace - - - - QAbstractItemView::NoSelection - - - - - - - - - - -