How to use the pydm.utilities function in pydm

To help you get started, we’ve selected a few pydm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pcdshub / typhon / tests / test_widgets.py View on Github external
def test_line_edit_history(qtbot, motor):
    widget = widgets.TyphosLineEdit()
    qtbot.addWidget(widget)

    widget.channel = 'sig://' + ophyd.sim.motor.setpoint.name
    widget.channeltype = int  # hack
    pydm.utilities.establish_widget_connections(widget)

    items = list(range(10))
    for i in items:
        widget.setText(str(i))
        widget.send_value()

    expected = items[-widget.setpointHistoryCount:]
    assert list(widget.setpoint_history) == [str(s) for s in expected]

    # Smoke test menu creation
    menu = widget.widget_ctx_menu()
    qtbot.addWidget(menu)
github pcdshub / typhon / tests / test_panel.py View on Github external
def test_typhos_panel(qapp, client, qtbot, typhos_signal_panel):
    panel = typhos_signal_panel

    # Setting Kind without device doesn't explode
    panel.showConfig = False
    panel.showConfig = True
    # Add a device channel
    panel.channel = 'happi://test_device'
    assert panel.channel == 'happi://test_device'
    # Reset channel and no smoke comes out
    panel.channel = 'happi://test_motor'
    pydm.utilities.establish_widget_connections(panel)

    def have_device():
        assert len(panel.devices) == 1

    qtbot.wait_until(have_device)

    device = panel.devices[0]
    num_hints = len(device.hints['fields'])
    num_read = len(device.read_attrs)

    def get_visible_signals():
        return panel.layout().visible_signals

    # Check we got all our signals
    assert len(get_visible_signals()) == len(device.component_names)
github slaclab / rogue / python / pyrogue / pydm / customwidgets / displays / syslog.py View on Github external
def _build(self):
        if (not self._en) or (not utilities.is_pydm_app()) or self.channel is None:
            return

        self._addr, self._port, path, disp = ParseAddress(self.channel)
        cpath = 'rogue://{}:{}/{}.ClearLog'.format(self._addr,self._port,path.split('.')[0])

        vb = QVBoxLayout()
        self.setLayout(vb)

        gb = QGroupBox('System Log')
        vb.addWidget(gb)

        vb = QVBoxLayout()
        gb.setLayout(vb)

        self._systemLog = QTreeWidget()
        vb.addWidget(self._systemLog)
github slaclab / pydm / pydm / widgets / line_edit.py View on Github external
def __init__(self, parent=None, init_channel=None):
        QLineEdit.__init__(self, parent)
        PyDMWritableWidget.__init__(self, init_channel=init_channel)
        self.app = QApplication.instance()
        self._display = None
        self._scale = 1

        self.returnPressed.connect(self.send_value)
        self.unitMenu = QMenu('Convert Units', self)
        self.create_unit_options()
        self._display_format_type = self.DisplayFormat.Default
        self._string_encoding = "utf_8"
        if utilities.is_pydm_app():
            self._string_encoding = self.app.get_string_encoding()
github slaclab / rogue / python / pyrogue / pydm / customwidgets / displays / command_tree.py View on Github external
def _build(self):
        if (not self._en) or (not utilities.is_pydm_app()) or self.channel is None:
            return

        self._addr, self._port, path, disp = ParseAddress(self.channel)

        self._client = pyrogue.interfaces.VirtualClient(self._addr, self._port)
        self._node = self._client.root.getNode(path)

        vb = QVBoxLayout()
        self.setLayout(vb)

        gb = QGroupBox('Command Tree')
        vb.addWidget(gb)

        vb = QVBoxLayout()
        gb.setLayout(vb)
        self._tree = QTreeWidget()
github slaclab / rogue / python / pyrogue / pydm / customwidgets / displays / variable_tree.py View on Github external
def _build(self):
        if (not self._en) or (not utilities.is_pydm_app()) or self.channel is None:
            return

        self._addr, self._port, path, disp = ParseAddress(self.channel)

        self._client = pyrogue.interfaces.VirtualClient(self._addr, self._port)
        self._node   = self._client.root.getNode(path)

        vb = QVBoxLayout()
        self.setLayout(vb)

        gb = QGroupBox('Variable Tree')
        vb.addWidget(gb)

        vb = QVBoxLayout()
        gb.setLayout(vb)
        self._tree = QTreeWidget()
github slaclab / pydm / pydm / widgets / baseplot.py View on Github external
def addCurve(self, plot_item, curve_color=None):
        if curve_color is None:
            curve_color = utilities.colors.default_colors[
                    len(self._curves) % len(utilities.colors.default_colors)]
            plot_item.color_string = curve_color
        self._curves.append(plot_item)
        self.addItem(plot_item)
        self.redraw_timer.start()
        # Connect channels
        for chan in plot_item.channels():
            if chan:
                chan.connect()
        # self._legend.addItem(plot_item, plot_item.curve_name)
github slaclab / pydm / pydm / widgets / line_edit.py View on Github external
Convert the current unit to a different one

        This function will attempt to find a scalar to convert the current
        unit type to the desired one and reset the display with the new
        conversion.

        Parameters
        ----------
        unit : str
            String name of desired units
        """
        if not self._unit:
            logger.warning("Warning: Attempting to convert PyDMLineEdit unit, but no initial units supplied.")
            return None

        scale = utilities.convert(str(self._unit), unit)
        if scale:
            self._scale = scale * float(self._scale)
            self._unit = unit
            self.update_format_string()
            self.clearFocus()
            self.set_display()
        else:
            logging.warning("Warning: Attempting to convert PyDMLineEdit unit, but '{0}' can not be converted to '{1}'."
                            .format(self._unit, unit))
github slaclab / pydm / pydm / widgets / line_edit.py View on Github external
def create_unit_options(self):
        """
        Create the menu for displaying possible unit values

        The menu is filled with possible unit conversions based on the
        current PyDMLineEdit. If either the unit is not found in the by
        the :func:`utilities.find_unit_options` function, or, the
        :attr:`.showUnits` attribute is set to False, the menu will tell
        the user that there are no available conversions
        """
        self.unitMenu.clear()
        units = utilities.find_unit_options(self._unit)
        if units and self._show_units:
            for choice in units:
                self.unitMenu.addAction(choice,
                                        partial(
                                            self.apply_conversion,
                                            choice
                                            )
                                        )
        else:
            self.unitMenu.addAction('No Unit Conversions found')
github pcdshub / typhon / typhos / display.py View on Github external
def get_icon(cls, icon=None):
        """
        Get a QIcon, if specified, or fall back to the default.

        Parameters
        ----------
        icon : str or QtGui.QIcon
            If a string, assume it is from fontawesome.
            Otherwise, use the icon instance as-is.
        """
        icon = icon or cls.DEFAULT_ICON
        if isinstance(icon, str):
            return pydm.utilities.IconFont().icon(icon)
        return icon