def send_access_state(self, read_access, write_access, *args, **kws): if is_pydm_app() and self.app.is_read_only(): self.write_access_signal.emit(False) return if write_access is not None: self.write_access_signal.emit(write_access)
def open_template_file(self, variables=None): """ Opens the widget specified in the templateFilename property. Parameters ---------- variables : dict A dictionary of macro variables to apply when loading, in addition to all the macros specified on the template repeater widget. Returns ------- display : QWidget """ if not variables: variables = {} # Expand user (~ or ~user) and environment variables. fname = os.path.expanduser(os.path.expandvars(self.templateFilename)) if is_pydm_app(): if not self._cached_template: self._cached_template = self.app.open_template(fname) return self.app.widget_from_template(self._cached_template, variables) else: try: f = macro.substitute_in_file(fname, variables) return uic.loadUi(f) except Exception as e: logger.exception("Exception while opening template file.") return None
def ensure_server_is_available(cls): """ Check if the class-wide EDM server is running. If not, start one. """ if cls.edm_server_proc is False: return if is_pydm_app(): if cls.edm_server_proc is None or cls.edm_server_proc.poll( ) is not None: LOGGER.info( "Starting EDM server process with command '{}'".format( " ".join(cls.edm_command))) try: if not cls.wmctrl_available or not hasattr( wmctrl.Window, 'set_always_on_bottom'): cls.edm_server_proc = subprocess.Popen(cls.edm_command) LOGGER.debug("EDM server process launched.") else: # If wmctrl is availabe, and knows how to send a window to the bottom, # we look for the stupid EDM postage stamp window, and if we find it, # we send it to the bottom so that it doesn't overlap with PyDM. cls.edm_server_proc = subprocess.Popen(cls.edm_command) LOGGER.debug("EDM server process launched.") t = threading.Thread(target=cls.initialize_edm_window) t.start() except FileNotFoundError as e: LOGGER.info("EDM was not found. Disabling EDM buttons.") cls.edm_server_proc = False LOGGER.debug("EDMButton: ensure_server_is_available complete.")
def open_template_file(self, variables=None): """ Opens the widget specified in the templateFilename property. Parameters ---------- variables : dict A dictionary of macro variables to apply when loading, in addition to all the macros specified on the template repeater widget. Returns ------- display : QWidget """ if not variables: variables = {} # Expand user (~ or ~user) and environment variables. fname = os.path.expanduser(os.path.expandvars(self.templateFilename)) if is_pydm_app(): if not self._cached_template: self._cached_template = self.app.open_template(fname) return self.app.widget_from_template(self._cached_template, variables) else: try: f = macro.substitute_in_file(fname, variables) return uic.loadUi(f) except Exception as e: logger.exception("Exception while opening template file.") return None
def dataSource(self, data_source): """ Sets the path to the JSON file to fill in each instance of the template. For example, if you build a template that contains two macro variables, ${NAME} and ${UNIT}, your JSON file should be a list of dictionaries, each with keys for NAME and UNIT, like this: [{"NAME": "First Device", "UNIT": 1}, {"NAME": "Second Device", "UNIT": 2}] Parameters ------- data_source : str """ if data_source != self._data_source: self._data_source = data_source if self._data_source: try: # Expand user (~ or ~user) and environment variables. fname = os.path.expanduser(os.path.expandvars(self._data_source)) if is_pydm_app(): # If we're running this inside the PyDM app, we can # make sure the path is relative to the currently loaded # display (.ui or .py file). fname = self.app.get_path(fname) with open(fname) as f: self.data = json.load(f) except IOError as e: self.data = [] else: self.clear()
def dataSource(self, data_source): """ Sets the path to the JSON file to fill in each instance of the template. For example, if you build a template that contains two macro variables, ${NAME} and ${UNIT}, your JSON file should be a list of dictionaries, each with keys for NAME and UNIT, like this: [{"NAME": "First Device", "UNIT": 1}, {"NAME": "Second Device", "UNIT": 2}] Parameters ------- data_source : str """ if data_source != self._data_source: self._data_source = data_source if self._data_source: try: # Expand user (~ or ~user) and environment variables. fname = os.path.expanduser( os.path.expandvars(self._data_source)) if is_pydm_app(): # If we're running this inside the PyDM app, we can # make sure the path is relative to the currently loaded # display (.ui or .py file). fname = self.app.get_path(fname) with open(fname) as f: self.data = json.load(f) except IOError as e: self.data = [] else: self.clear()
def ensure_server_is_available(cls): """ Check if the class-wide EDM server is running. If not, start one. """ if cls.edm_server_proc is False: return if is_pydm_app(): if cls.edm_server_proc is None or cls.edm_server_proc.poll() is not None: LOGGER.info("Starting EDM server process with command '{}'".format(" ".join(cls.edm_command))) try: if not wmctrl or not hasattr(wmctrl.Window, 'set_always_on_bottom'): cls.edm_server_proc = subprocess.Popen(cls.edm_command) else: # If wmctrl is availabe, and knows how to send a window to the bottom, # we look for the stupid EDM postage stamp window, and if we find it, # we send it to the bottom so that it doesn't overlap with PyDM. before_list = {w.id: w for w in wmctrl.Window.list()} cls.edm_server_proc = subprocess.Popen(cls.edm_command) new_window = None start_time = time.time() while new_window is None: after_list = wmctrl.Window.list() for win in after_list: if win.id not in before_list and win.wm_class == 'edm.edm' and win.wm_name.startswith('edm'): new_window = win break end_time = time.time() if end_time - start_time > 5.0: break if new_window: new_window.set_always_on_bottom() except FileNotFoundError as e: LOGGER.info("EDM was not found. Disabling EDM buttons.") cls.edm_server_proc = False
def put_value(self, new_val): if is_pydm_app() and self.app.is_read_only(): return try: self.data_thread.write(new_val) except Exception as e: logger.error("Unable to put %s to %s. Exception: %s", new_val, self.address, str(e))
def put_value(self, new_val): if is_pydm_app() and self.app.is_read_only(): return if self.pv.write_access: try: self.pv.put(new_val) except Exception as e: logger.exception("Unable to put %s to %s. Exception: %s", new_val, self.pv.pvname, str(e))
def __init__(self, parent=None, init_channel=None): QLabel.__init__(self, parent) PyDMWidget.__init__(self, init_channel=init_channel) self.app = QApplication.instance() self.setTextFormat(Qt.PlainText) self.setTextInteractionFlags(Qt.NoTextInteraction) self.setText("PyDMLabel") self._display_format_type = self.DisplayFormat.Default self._string_encoding = "utf_8" if is_pydm_app(): self._string_encoding = self.app.get_string_encoding()
def __init__(self, parent=None, init_channel=None): QLabel.__init__(self, parent) PyDMWidget.__init__(self, init_channel=init_channel) if 'Text' not in PyDMLabel.RULE_PROPERTIES: PyDMLabel.RULE_PROPERTIES = PyDMWidget.RULE_PROPERTIES.copy() PyDMLabel.RULE_PROPERTIES.update({'Text': ['value_changed', str]}) self.app = QApplication.instance() self.setTextFormat(Qt.PlainText) self.setTextInteractionFlags(Qt.NoTextInteraction) self.setText("PyDMLabel") self._display_format_type = self.DisplayFormat.Default self._string_encoding = "utf_8" if is_pydm_app(): self._string_encoding = self.app.get_string_encoding()
def __init__(self, parent=None, init_channel=None): QLabel.__init__(self, parent) PyDMWidget.__init__(self, init_channel=init_channel) if 'Text' not in PyDMLabel.RULE_PROPERTIES: PyDMLabel.RULE_PROPERTIES = PyDMWidget.RULE_PROPERTIES.copy() PyDMLabel.RULE_PROPERTIES.update( {'Text': ['value_changed', str]}) self.app = QApplication.instance() self.setTextFormat(Qt.PlainText) self.setTextInteractionFlags(Qt.NoTextInteraction) self.setText("PyDMLabel") self._display_format_type = self.DisplayFormat.Default self._string_encoding = "utf_8" if is_pydm_app(): self._string_encoding = self.app.get_string_encoding()
def check_enable_state(self): """ Checks whether or not the widget should be disable. This method also disables the widget and add a Tool Tip with the reason why it is disabled. """ status = self._write_access and self._connected and self._has_enums tooltip = "" if not self._connected: tooltip += "PV is disconnected." elif not self._write_access: if is_pydm_app() and self.app.is_read_only(): tooltip += "Running PyDM on Read-Only mode." else: tooltip += "Access denied by Channel Access Security." elif not self._has_enums: tooltip += "Enums not available." self.setToolTip(tooltip) self.setEnabled(status)
def __init__(self, channel, address, protocol=None, parent=None): super(RogueConnection, self).__init__(channel, address, protocol, parent) self.app = QApplication.instance() self._host, self._port, self._path, self._mode = parseAddress(address) self._cmd = False self._int = False self._node = None self._enum = None self._notDev = False self._address = address if utilities.is_pydm_app(): self._client = pyrogue.interfaces.VirtualClient( self._host, self._port) self._node = self._client.root.getNode(self._path) if self._node is not None and not self._node.isinstance( pyrogue.Device): self._node.addListener(self._updateVariable) self._notDev = True if self._node.isinstance(pyrogue.BaseCommand): self._cmd = True if self._node.disp == 'enum' and self._node.enum is not None and self._node.mode != 'RO': self._enum = list(self._node.enum.values()) elif self._mode == 'value' and ('Int' in self._node.typeStr or self._node.typeStr == 'int'): self._int = True self.add_listener(channel) self._client.addLinkMonitor(self.linkState)
def send_access_state(self, read_access, write_access): if is_pydm_app() and self.app.is_read_only(): self.write_access_signal.emit(False) return self.write_access_signal.emit(write_access)
def emit_access_state(self): no_access = ((is_pydm_app() and self.app.is_read_only()) or not self.poller.writable) self.write_access_signal.emit(not no_access)
def emit_access_state(self): if is_pydm_app() and self.app.is_read_only(): self.write_access_signal.emit(False) return self.write_access_signal.emit(True)