def close_server(self): """ Closes the server for which the service is running """ pid = os.getpid() operating_system = get_os() if operating_system == 'Windows': handle = ctypes.windll.kernel32.OpenProcess(1, False, pid) ctypes.windll.kernel32.TerminateProcess(handle, -1) ctypes.windll.kernel32.CloseHandle(handle) elif operating_system == 'Linux': os.kill(pid, signal.SIGTERM)
def __init__(self, host, port, key='pylabnet.pem'): """ Connects to server :param host: (str) hostname :param port: (int) port number :param key: (str) name of keyfile """ # Internal vars to store server info self.operating_system = get_os() self._host = '' self._port = 0 # Internal vars to store refs to server self._connection = None self._service = None # Connect to server self.connect(host=host, port=port, key=key)
def warning_popup(message): """ Creates a warning popup without a base GUI :param message: (str) message to display """ app = QtWidgets.QApplication(sys.argv) app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5()) operating_system = get_os() app.setWindowIcon( QtGui.QIcon( os.path.join(os.path.dirname(os.path.realpath(__file__)), 'devices.ico'))) if operating_system == 'Windows': ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID( 'pylabnet') QtWidgets.QMessageBox.critical(None, "Error", message, QtWidgets.QMessageBox.Ok, QtWidgets.QMessageBox.NoButton)
def fresh_popup(**params): """ Creates a fresh ParameterPopup without a base GUI :param params: kwargs of parameters as keywords and data types as values :return: ParameterPopup """ app = QtWidgets.QApplication(sys.argv) app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5()) operating_system = get_os() app.setWindowIcon( QtGui.QIcon( os.path.join(os.path.dirname(os.path.realpath(__file__)), 'devices.ico'))) if operating_system == 'Windows': ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID( 'pylabnet') return app, ParameterPopup(**params)
def run(self): """Starts up the staticline GUI and initializes the buttons. """ # Starts up an application for the window if get_os() == 'Windows': ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('pylabnet') self.app = QtWidgets.QApplication(sys.argv) self.app.setWindowIcon( QtGui.QIcon(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'devices.ico')) ) # Create a GUI window with layout determined by the config file self.gui = GUIWindowFromConfig(config=self.config, host=self.host, port=self.port, staticlines=self.staticlines) self.gui.show() self.widgets = self.gui.widgets # Binds the function of the buttons to the staticline Driver functions self.initialize_buttons() self.app.exec_()
def __init__(self, host, port, key='pylabnet.pem', module_tag='', server_port=None, ui=None): # Declare all internal vars self._host = '' self._port = 0 self._connection = None self._service = None self._level_str = '' self._level = 0 self._module_tag = '' self._server_port = server_port # Identifies a server running in client's thread self._ui = ui # Identifies a relevant .ui file for the client self.operating_system = get_os() #self.lab_name = None # try: # lab_name_dict = load_config("lab_name") # self.lab_name = lab_name_dict['lab_name'] # except: # print('found no lab_name config file, assigning to NO LAB') # self.lab_name = None # Set module alias to display with log messages self._module_tag = module_tag # Connect to log server self.connect(host=host, port=port, key=key) # Set module alias to display with log messages self._module_tag = module_tag # Log test message self.info('Started logging')
def __init__(self, app=None, gui_template=None, run=True, host=None, port=None, auto_close=True, max=False): """ Instantiates main window object. :param app: instance of QApplication class - MUST be instantiated prior to Window :param gui_template: (str, optional) name of gui template to use. By default uses self._default_template. Only the filename is required (no filepath or extension) :param run: (bool, optional) whether or not to run (display) the GUI upon instantiation. Can set to false in order to debug and access Window methods directly in an interactive session :param max: (bool, optional) whether or not to show GUI maximized """ self.app = app # Application instance onto which to load the GUI. if self.app is None: if get_os() == 'Windows': ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID( 'pylabnet') self.app = QtWidgets.QApplication(sys.argv) self.app.setWindowIcon( QtGui.QIcon( os.path.join(os.path.dirname(os.path.realpath(__file__)), 'devices.ico'))) # Initialize parent class QWidgets.QMainWindow super(Window, self).__init__() self._ui = None # .ui file to use as a template # Holds all widgets assigned to the GUI from an external script # Reference is by keyword (widget_label), and the keyword can be used to access the widget once assigned self.plots = {} self.scalars = {} self.labels = {} self.event_buttons = {} self.containers = {} self.windows = {} self.auto_close = auto_close # Configuration queue lists # When a script requests to configure a widget (e.g. add or remove a plot, curve, scalar, or label), the request # is added to this list and can be implemented by the GUI when it is ready. This prevents overloading the # client-server interface self._plots_to_assign = [] self._plots_to_remove = [] self._curves_to_assign = [] self._scalars_to_assign = [] self._labels_to_assign = [] self._buttons_to_assign = [] self._containers_to_assign = [] self._curves_to_remove = [] # List of Numerical widgets for future use in dynamical step size updating self.num_widgets = None # Load and run the GUI self._load_gui(gui_template=gui_template, run=run) if max: self.showMaximized() else: self.showNormal() self.host = None self.port = None # Confgiure stop button, host and port try: self.stop_button.clicked.connect(self.close) if host is not None: self.ip_label.setText(f'IP Address: {host}') self.host = host if port is not None: self.port_label.setText(f'Port: {port}') self.port = port except: pass self.apply_stylesheet()
def __init__(self, proxy=False, master=False, staticproxy=False): """ Initializes launch control GUI """ self.operating_system = get_os() self.app = QtWidgets.QApplication(sys.argv) self.app.setWindowIcon( QtGui.QIcon( os.path.join(os.path.dirname(os.path.realpath(__file__)), 'devices.ico'))) # Instantiate GUI application if self.operating_system == 'Windows': ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID( 'pylabnet') self.main_window = LaunchWindow(self.app, self, gui_template=self.LOGGER_UI) self.main_window.stop_button.clicked.connect(self._kill) if self.operating_system not in ['Linux', 'Windows']: raise UnsupportedOSException try: if sys.argv[1] == '-m' or master: self.master = True else: self.master = False except IndexError: if master: self.master = True else: self.master = False try: if sys.argv[1] == '-p' or proxy: self.proxy = True else: self.proxy = False except IndexError: if proxy: self.proxy = True else: self.proxy = False try: if sys.argv[1] == '-sp' or staticproxy: self.staticproxy = True else: self.staticproxy = False except IndexError: if staticproxy: self.staticproxy = True else: self.staticproxy = False self.host = get_ip() self.update_index = 0 # Retrieve static port info. if self.master: try: static_proxy_dict = load_config('static_proxy') except: print('No config found named static_proxy.json') time.sleep(10) raise self.log_port = static_proxy_dict['master_log_port'] self.gui_port = static_proxy_dict['master_gui_port'] hide_console() elif self.proxy: popup = ParameterPopup(host=str, log_port=str, gui_port=str) self.waiting_flag = True popup.parameters.connect(self.fill_parameters) while self.waiting_flag: self.app.processEvents() elif self.staticproxy: try: static_proxy_dict = load_config('static_proxy') except: print('No config found named static_proxy.json') time.sleep(10) raise self.host = static_proxy_dict['master_ip'] self.log_port = static_proxy_dict['master_log_port'] self.gui_port = static_proxy_dict['master_gui_port'] self.proxy = True hide_console() else: self.log_port = self.LOG_PORT self.gui_port = self.GUI_PORT self.log_service = None self.log_server = None self.gui_client = None self.gui_logger = None self.gui_service = None self.gui_server = None self.client_list = {} self.port_list = {} self.script_list = {} self.client_data = {} self.disconnection = False self.debug = False self.debug_level = None self.autoscroll_off = False # date string is None if not logging to file, and gives today's date if logging to file. # For day-chopping purposes self.logfile_date_str = None self.filenamepath = None self.MAX_LOG_FILE_SIZE = 5000000 # 5MB self.last_seen_buffer = "" # setting selection mode for server list to multi-select self.main_window.client_list.setSelectionMode( QtWidgets.QAbstractItemView.ExtendedSelection)