Esempio n. 1
0
    def rebuild(self):
        """ Clear out all existing widgets, and populate the list using the
        template file and data source."""
        self.clear()
        if (not self.templateFilename) or (not self.data):
            return
        self.setUpdatesEnabled(False)

        layout_class = layout_class_for_type[self.layoutType]
        if type(self.layout()) != layout_class:
            if self.layout() is not None:
                # Trick to remove the existing layout by re-parenting it in an empty widget.
                QWidget().setLayout(self.layout())
            l = layout_class(self)
            self.setLayout(l)
        with pydm.data_plugins.connection_queue(defer_connections=True):
            for i, variables in enumerate(self.data):
                if is_qt_designer() and i > self.countShownInDesigner - 1:
                    break
                w = self.open_template_file(variables)
                if w is None:
                    w = QLabel()
                    w.setText(
                        "No Template Loaded.  Data: {}".format(variables))
                w.setParent(self)
                self.layout().addWidget(w)
        self.setUpdatesEnabled(True)
        pydm.data_plugins.establish_queued_connections()
Esempio n. 2
0
 def rebuild(self):
     """ Clear out all existing widgets, and populate the list using the
     template file and data source."""
     self.clear()
     if (not self.templateFilename) or (not self.data):
         return
     self.setUpdatesEnabled(False)
     
     layout_class = layout_class_for_type[self.layoutType]
     if type(self.layout()) != layout_class:
         if self.layout() is not None:
             # Trick to remove the existing layout by re-parenting it in an empty widget.
             QWidget().setLayout(self.layout())
         l = layout_class(self)
         self.setLayout(l)
     with pydm.data_plugins.connection_queue():
         for i, variables in enumerate(self.data):
             if is_qt_designer() and i > self.countShownInDesigner - 1:
                 break
             w = self.open_template_file(variables)
             if w is None:
                 w = QLabel()
                 w.setText("No Template Loaded.  Data: {}".format(variables))
             w.setParent(self)
             self.layout().addWidget(w)
     self.setUpdatesEnabled(True)
Esempio n. 3
0
 def displayFormat(self, new_type):
     if self._display_format_type == new_type:
         return
     self._display_format_type = new_type
     if not is_qt_designer() or config.DESIGNER_ONLINE:
         # Trigger the update of display format
         self.value_changed(self.value)
Esempio n. 4
0
 def initial_sort_header(self, header: str):
     self._initial_sort_header = header
     if not is_qt_designer():
         # Do a sort after a short timer
         # HACK: this is because it doesn't work if done immediately
         # This is due to some combination of qt designer properties being
         # applied in some random order post-__init__ combined with it
         # taking a short bit of time for the items to be ready to sort.
         # Some items will never connect and never be ready to sort,
         # so for now we'll do a best-effort one-second wait.
         timer = QtCore.QTimer(parent=self)
         timer.singleShot(1000, self.initial_sort)
Esempio n. 5
0
 def disconnect(self, destroying=False):
     """
     Disconnect a PyDMChannel
     """
     if is_qt_designer() and not config.DESIGNER_ONLINE:
         return
     try:
         plugin = plugin_for_address(self.address)
         if not plugin:
             return
         plugin.remove_connection(self, destroying=destroying)
     except Exception as exc:
         logger.exception("Unable to remove connection " "for %r", self)
Esempio n. 6
0
 def connect(self):
     """
     Connect a PyDMChannel to the proper PyDMPlugin
     """
     if is_qt_designer() and not config.DESIGNER_ONLINE:
         return
     logger.debug("Connecting %r", self.address)
     # Connect to proper PyDMPlugin
     try:
         pydm.data_plugins.establish_connection(self)
     except Exception:
         logger.exception("Unable to make proper connection "
                          "for %r", self)
Esempio n. 7
0
 def disconnect(self, destroying=False):
     """
     Disconnect a PyDMChannel
     """
     if is_qt_designer() and not config.DESIGNER_ONLINE:
         return
     try:
         plugin = pydm.data_plugins.plugin_for_address(self.address)
         if not plugin:
             return
         plugin.remove_connection(self, destroying=destroying)
     except Exception as exc:
         logger.exception("Unable to remove connection "
                          "for %r", self)
Esempio n. 8
0
 def connect(self):
     """
     Connect a PyDMChannel to the proper PyDMPlugin
     """
     if not self.address:
         return
     if is_qt_designer() and not config.DESIGNER_ONLINE:
         return
     logger.debug("Connecting %r", self.address)
     # Connect to proper PyDMPlugin
     try:
         pydm.data_plugins.establish_connection(self)
     except Exception:
         logger.exception("Unable to make proper connection "
                          "for %r", self)
Esempio n. 9
0
    def dataSource(self, data_source):
        """
        Sets the path to the JSON file or a valid JSON string 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:
                is_json, data = self._is_json(data_source)
                if is_json:
                    logger.debug('TemplateRepeater dataSource is a valid JSON.')
                    self.data = data
                else:
                    logger.debug('TemplateRepeater dataSource is not a valid JSON. Assuming it is a file path.')
                    try:
                        parent_display = self.find_parent_display()
                        base_path = None
                        if parent_display:
                            base_path = os.path.dirname(
                                parent_display.loaded_file())
                        fname = find_file(self._data_source, base_path=base_path)

                        if not fname:
                            if not is_qt_designer():
                                logger.error('Cannot locate data source file {} for PyDMTemplateRepeater.'.format(fname))
                            self.data = []
                        else:
                            with open(fname) as f:
                                try:
                                    self.data = json.load(f)
                                except ValueError:
                                    logger.error('Failed to parse data source file {} for PyDMTemplateRepeater.'.format(fname))
                                    self.data = []
                    except IOError as e:
                        self.data = []
            else:
                self.clear()
Esempio n. 10
0
    def add_connection(self, channel):
        from pydm.utilities import is_qt_designer
        with self.lock:
            address = self.get_address(channel)
            # If this channel is already connected to this plugin lets ignore
            if channel in self.channels:
                return

            if (is_qt_designer() and not config.DESIGNER_ONLINE
                    and not self.designer_online_by_default):
                return

            self.channels.add(channel)
            if address in self.connections:
                self.connections[address].add_listener(channel)
            else:
                self.connections[address] = self.connection_class(
                    channel, address, self.protocol)
Esempio n. 11
0
 def __init__(self, parent=None):
     self._brush = QBrush(QColor(0, 255, 0), Qt.SolidPattern)
     self._original_brush = None
     self._rotation = 0
     self._pen_style = Qt.SolidLine
     self._pen = QPen(self._pen_style)
     self._pen.setCosmetic(True)
     self._pen_width = 1.0
     self._pen_color = QColor(0, 0, 0)
     self._pen.setWidthF(self._pen_width)
     self._pen.setColor(self._pen_color)
     self._original_pen_style = self._pen_style
     self._original_pen_color = self._pen_color
     super(BaseSymbolIcon, self).__init__(parent=parent)
     self.setObjectName("icon")
     if not is_qt_designer():
         # We should  install the Event Filter only if we are running
         # and not at the Designer
         self.installEventFilter(self)
Esempio n. 12
0
 def countShownInDesigner(self, new_count):
     """
     The number of instances to show in Qt Designer.  This property has no
     effect outside of Designer.
     
     Parameters
     ----------
     new_count : int
     """
     if not is_qt_designer():
         return
     try:
         new_count = int(new_count)
     except ValueError:
         logger.exception("Couldn't convert {} to integer.".format(new_count))
         return
     new_count = max(new_count, 0)
     if new_count != self._count_shown_in_designer:
         self._count_shown_in_designer = new_count
         self.rebuild()
Esempio n. 13
0
    def rebuild(self):
        """ Clear out all existing widgets, and populate the list using the
        template file and data source."""
        self.clear()
        if (not self.templateFilename) or (not self.data):
            return
        self.setUpdatesEnabled(False)

        layout_class = layout_class_for_type[self.layoutType]
        if type(self.layout()) != layout_class:
            if self.layout() is not None:
                # Trick to remove the existing layout by re-parenting it in an empty widget.
                QWidget().setLayout(self.layout())
            l = layout_class(self)
            self.setLayout(l)
            self.layout().setSpacing(self._temp_layout_spacing)
        try:
            with pydm.data_plugins.connection_queue(defer_connections=True):
                for i, variables in enumerate(self.data):
                    if is_qt_designer() and i > self.countShownInDesigner - 1:
                        break
                    w = self.open_template_file(variables)
                    if w is None:
                        w = QLabel()
                        w.setText(
                            "No Template Loaded.  Data: {}".format(variables))
                    w.setParent(self)
                    self.layout().addWidget(w)
        except:
            logger.exception('Template repeater failed to rebuild.')
        finally:
            # If issues happen during the rebuild we should still enable
            # updates and establish connection for the widgets added.
            # Moreover, if we dont call establish_queued_connections
            # the queue will never be emptied and new connections will be
            # staled.
            self.setUpdatesEnabled(True)
            pydm.data_plugins.establish_queued_connections()
Esempio n. 14
0
 def preload(self, exec_preload):
     self._preload = exec_preload
     if self._preload and self._suite is None and not is_qt_designer():
         self.create_suite()