Пример #1
0
    def add_catalogs(self):
        config_file_to_broker = defaultdict(list)
        catalog_names = list(catalog)

        for name in catalog_names:
            broker = Broker.named(name)
            if getattr(broker, 'v2', None) is None:
                msg.logMessage(
                    f'The broker named {name} cannot be cast to a v2 Broker.',
                    msg.WARNING)
                continue
            # catalog_dir might be in the metadata; if not, let's try to find it
            if 'catalog_dir' in broker.v2.metadata:
                config_file = broker.v2.metadata["catalog_dir"]
            else:
                config_file = find_catalog(name)

            config_file_to_broker[config_file].append(broker)

        for config_file, brokers in config_file_to_broker.items():
            config_file_item = QStandardItem()
            config_file_item.setData(config_file, Qt.DisplayRole)
            self.appendRow(config_file_item)
            for broker in brokers:
                broker_item = QStandardItem()
                broker_item.setData(broker.name, Qt.DisplayRole)
                broker_item.setData(broker, self.broker_role)
                config_file_item.appendRow(broker_item)
Пример #2
0
    def add_model(self, model):
        """
        Adds a model to the internal Qt model.

        Parameters
        ----------
        model : :class:`astropy.modeling.FittableModel`
            The model instance to add.

        Returns
        -------
        :class:`qtpy.QtCore.QModelIndex`
            The index in the Qt model where the new model been added.
        """
        model_name = model.name or model.__class__.name

        model_count = len([self.item(idx) for idx in range(self.rowCount())
                           if model_name in self.item(idx).text()])

        model_name = model_name + "_" + str(model_count) \
            if model_count > 0 else model_name

        model_item = QStandardItem(model_name)
        model_item.setData(model, Qt.UserRole + 1)

        for para_name in model.param_names:
            # Retrieve the parameter object from the model
            parameter = getattr(model, para_name)

            # Store the name value
            param_name = QStandardItem(parameter.name)
            param_name.setData(parameter.name, Qt.UserRole + 1)
            param_name.setEditable(False)

            # Store the data value of the parameter
            param_value = QStandardItem("{:.5g}".format(parameter.value))
            param_value.setData(parameter.value, Qt.UserRole + 1)

            # Store the unit information
            # param_unit = QStandardItem("{}".format(parameter.unit))
            param_unit = QStandardItem("Plot Units")
            param_unit.setData(parameter.unit, Qt.UserRole + 1)
            param_unit.setEditable(False)

            # Store the fixed state of the unit
            param_fixed = QStandardItem()
            param_fixed.setData(parameter.fixed, Qt.UserRole + 1)
            param_fixed.setCheckable(True)
            param_fixed.setEditable(False)

            model_item.appendRow([param_name, param_value, param_unit, param_fixed])

        self.appendRow([model_item, None, None, None])

        # Add this model to the model equation string. By default, all models
        # are simply added together
        self._equation += " + {}".format(model_name) \
            if len(self._equation) > 0 else "{}".format(model_name)

        return model_item.index()
Пример #3
0
 def load_kpis(self, rootIndex, topology):
     kpis = QStandardItem('kpis')
     item = self.itemFromIndex(rootIndex)
     item.appendRow(kpis)
     for conn_key, conn in topology.connections.items():
         conn_item = QStandardItem(conn_key)
         kpis.appendRow(conn_item)
         for kpi_key, kpi in conn.kpis.items():
             kpi_item = QStandardItem(kpi_key)
             kpi_item.setData('kpi', self.TYPE_ROLE)
             kpi_item.setData(kpi, self.MODEL_ROLE)
             conn_item.appendRow(kpi_item)
Пример #4
0
    def add_model(self, model):
        model_name = model.__class__.name

        model_count = len([
            self.item(idx) for idx in range(self.rowCount())
            if model.__class__.name in self.item(idx).text()
        ])

        model_name = model_name + str(
            model_count) if model_count > 0 else model_name

        model_item = QStandardItem(model_name)
        model_item.setData(model, Qt.UserRole + 1)

        for para_name in model.param_names:
            # Retrieve the parameter object from the model
            parameter = getattr(model, para_name)

            # Store the name value
            param_name = QStandardItem(parameter.name)
            param_name.setData(parameter.name, Qt.UserRole + 1)
            param_name.setEditable(False)

            # Store the data value of the parameter
            param_value = QStandardItem("{:.5g}".format(parameter.value))
            param_value.setData(parameter.value, Qt.UserRole + 1)

            # Store the unit information
            # param_unit = QStandardItem("{}".format(parameter.unit))
            param_unit = QStandardItem("Plot Units")
            param_unit.setData(parameter.unit, Qt.UserRole + 1)
            param_unit.setEditable(False)

            # Store the fixed state of the unit
            param_fixed = QStandardItem()
            param_fixed.setData(parameter.fixed, Qt.UserRole + 1)
            param_fixed.setCheckable(True)
            param_fixed.setEditable(False)

            model_item.appendRow(
                [param_name, param_value, param_unit, param_fixed])

        self.appendRow([model_item, None, None, None])

        # Add this model to the model equation string. By default, all models
        # are simply added together
        self._equation += " + {}".format(model_name) \
            if len(self._equation) > 0 else "{}".format(model_name)

        return model_item.index()
Пример #5
0
    def refresh(self):
        self.clear()

        if not self._proc_interface:
            logger.warning('cannot refresh without a procInterface')
            return

        eprocs = self._proc_interface.eprocs
        for device in eprocs.keys():
            device_item = QStandardItem(device)
            self.appendRow(device_item)
            for eproc in eprocs[device]:
                eproc_item = QStandardItem(eproc)
                device_item.appendRow(eproc_item)
Пример #6
0
    def add_catalogs(self):
        config_file_to_broker = defaultdict(list)
        catalog_names = list(catalog)

        for name in catalog_names:
            broker = Broker.named(name)
            config_file = broker.v2.metadata["catalog_dir"]
            config_file_to_broker[config_file].append(broker)

        for config_file, brokers in config_file_to_broker.items():
            config_file_item = QStandardItem()
            config_file_item.setData(config_file, Qt.DisplayRole)
            self.appendRow(config_file_item)
            for broker in brokers:
                broker_item = QStandardItem()
                broker_item.setData(broker.name, Qt.DisplayRole)
                broker_item.setData(broker, self.broker_role)
                config_file_item.appendRow(broker_item)
Пример #7
0
    def update_list(self):
        self.model.clear()

        packages = {}  # {NodePackage: [Node]}
        for node, node_package in self.main_window.node_packages.items():
            if node_package in packages.keys():
                packages[node_package].append(node)
            else:
                packages[node_package] = [node]

        for node_package, nodes in packages.items():
            package_item = QStandardItem(node_package.name)
            package_item.setEditable(False)
            for n in nodes:
                node_item = NodeItem(n)
                # node_item.setEditable(False)
                # node_item.setDragEnabled(True)
                package_item.appendRow(node_item)
            self.model.appendRow(package_item)
Пример #8
0
    def populatePortList(self, model, tv, ports):
        tv.setModel(model)
        root = model.invisibleRootItem()

        portsdict = {}
        for port in ports:
            if port.client not in portsdict:
                portsdict[port.client] = []
            portsdict[port.client].append(port)

        for client in humansorted(portsdict):
            clientitem = QStandardItem(client)

            for port in humansorted(portsdict[client],
                                    key=attrgetter("group", "order", "name")):
                portspec = (port.client, port.name)
                if port.pretty_name:
                    label = "%s (%s)" % (port.pretty_name, port.name)
                else:
                    label = port.name

                portitem = QStandardItem(label)
                portitem.setData(portspec)
                portitem.setCheckable(True)
                portitem.setUserTristate(False)
                # Check box toggling is done in the treeview clicked handler "on_port_clicked"
                portitem.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)

                portitem.setToolTip(self.makePortTooltip(port))

                if portspec in self.rec_sources:
                    portitem.setCheckState(2)

                clientitem.appendRow(portitem)

            root.appendRow(clientitem)

        tv.expandAll()
Пример #9
0
    def load(self, type_, data, positions):
        self.clear()
        if type_ == 'position':
            if data != 'dict..':
                class_, preset_, transforms_ = presets.get_elements(
                    'positions', data)
                class_ = class_.lower()
                classes = list(presets.positions.keys())
                # Build the 'class' combobox
                class_item_val = QStandardItem(class_)
                class_item_val.setData('class_combo', self.TYPE_ROLE)
                self.appendRow([QStandardItem('class'), class_item_val])

                # Build the 'preset' combobox
                presets_ = list(presets.positions[class_].keys())
                preset_item_val = QStandardItem(preset_)
                preset_item_val.setData('preset_combo', self.TYPE_ROLE)
                self.appendRow([QStandardItem('preset'), preset_item_val])

                # Build the 'transforms' subtree
                # NOTE: self.tr is a Qt func that helps for the translation to another language
                transforms = QStandardItem(self.tr('Transformations'))
                transforms.setData(positions, self.MODEL_ROLE)
                self.appendRow(transforms)
                # Scale -> spinbox
                scale_item = QStandardItem(str(positions.absolute_scale))
                scale_item.setData('spin_scale', self.TYPE_ROLE)
                scale_item.setData(positions.absolute_scale, self.DATA_ROLE)
                transforms.appendRow([QStandardItem('Scale'), scale_item])
                # Rotate -> slider
                rotate_item = QStandardItem(str(positions.angle))
                rotate_item.setData('rotate_slider', self.TYPE_ROLE)
                rotate_item.setData(positions.angle, self.DATA_ROLE)
                transforms.appendRow([QStandardItem('Rotate'), rotate_item])
                # Translate -> 2 spinboxes
                translate_item = QStandardItem('Translation')
                x_item = QStandardItem(str(positions.translation["x"]))
                x_item.setData('spin_x', self.TYPE_ROLE)
                x_item.setData(positions.translation["x"], self.DATA_ROLE)
                y_item = QStandardItem(str(positions.translation["y"]))
                y_item.setData('spin_y', self.TYPE_ROLE)
                y_item.setData(positions.translation["y"], self.DATA_ROLE)
                translate_item.appendRow([QStandardItem('x:'), x_item])
                translate_item.appendRow([QStandardItem('y:'), y_item])
                transforms.appendRow(translate_item)

        elif type_ == 'motion':
            pass
Пример #10
0
    window = QMainWindow()
    layout = QVBoxLayout()
    model = DerivedDataModel()

    from xicam.plugins.hints import PlotHint, ImageHint, CoPlotHint
    parentItem = QStandardItem("blah")
    parentItem.setCheckable(True)
    import numpy as np
    for i in range(3):
        hint = PlotHint(np.arange(10),
                        np.random.random((10, )),
                        name=f"1-Time")
        item = QStandardItem(hint.group)
        item.setData(hint, Qt.UserRole)
        item.setCheckable(True)
        parentItem.appendRow(item)
    hint = ImageHint(np.random.random((100, 100)),
                     xlabel="x",
                     ylabel="y",
                     name="2-Time")
    item = QStandardItem(hint.group)
    item.setData(hint, Qt.UserRole)
    item.setCheckable(True)
    parentItem.appendRow(item)
    model.appendRow(parentItem)

    workflowItem = QStandardItem("A Workflow Result")
    workflowItem.setCheckable(True)
    hints = []
    for i in range(2):
        if i == 0:
Пример #11
0
 def add_device(self, client_item: QStandardItem, device: Device):
     device_item = QStandardItem(device.name)
     device_item.setData(device, self.happiItemRole)
     client_item.appendRow(device_item)
Пример #12
0
    def refresh(self):
        self.clear()

        if not self._app_interface:
            logger.warning('cannot refresh without an appInterface')
            return

        proclog = self._app_interface.proclog
        previous_level = 0
        item_stack = deque([self])
        for i, log in enumerate(proclog):
            level = 0
            name = ''
            info = {}
            for item in log:
                if item == '->':
                    level += 1
                else:
                    name = item['name']
                    info = item['information']
            item = QStandardItem(name)
            item.setData(True, self.IsProcedureRole)
            item.setData('', self.ValueRole)
            item.setData(i + 1, self.IdRole)
            if isinstance(info, dict) and len(info):
                data_item = QStandardItem(self.tr('data'))
                data_item.setData(False, self.IsProcedureRole)
                data_item.setData('', self.ValueRole)
                for k, v in info.items():
                    entry_item = QStandardItem(k)
                    if isinstance(v, dict) and 'address' in v and 'value' in v:
                        value_item = QStandardItem('value')
                        value_item.setData(str(v['value']), self.ValueRole)
                        value_item.setData(False, self.IsProcedureRole)
                        entry_item.appendRow(value_item)
                        value_item = QStandardItem('address')
                        value_item.setData(str(v['address']), self.ValueRole)
                        value_item.setData(False, self.IsProcedureRole)
                        entry_item.appendRow(value_item)
                        value = ''
                    else:
                        value = str(v)
                    entry_item.setData(value, self.ValueRole)
                    entry_item.setData(False, self.IsProcedureRole)
                    data_item.appendRow(entry_item)
                item.appendRow(data_item)
            elif isinstance(info, str):
                data_item = QStandardItem(self.tr('info'))
                data_item.setData(False, self.IsProcedureRole)
                data_item.setData(info, self.ValueRole)
                item.appendRow(data_item)

            if level > previous_level:
                previous_level = level
            elif level == previous_level:
                item_stack.pop()
            else:
                item_stack.pop()
                while previous_level > level and previous_level > 0:
                    item_stack.pop()
                    previous_level -= 1
            item_stack[-1].appendRow(item)
            item_stack.append(item)
Пример #13
0
    def load(self):
        self.clear()
        """Walk the tree starting from topology"""
        for el, val in presets.topology.items():
            item = QStandardItem(el)
            self.appendRow(item)
            nodes = QStandardItem('nodes')
            item.appendRow(nodes)
            # Walk the nodes
            for node_name, nvals in val['nodes'].items():
                n = QStandardItem(node_name)
                nodes.appendRow(n)
                for nval in nvals:
                    node_layout = QStandardItem('')
                    n.appendRow(node_layout)
                    p = nval.get('position')
                    if isinstance(p, dict):
                        p = 'dict..'
                    pos = QStandardItem(p)
                    pos.setData('position', self.TYPE_ROLE)
                    node_layout.appendRow([QStandardItem('position'), pos])

                    m = nval.get('motion')
                    if isinstance(m, dict):
                        m = 'dict..'
                    mot = QStandardItem(m)
                    mot.setData('motion', self.TYPE_ROLE)
                    node_layout.appendRow([QStandardItem('motion'), mot])

                    mdl = QStandardItem(nval.get('model'))
                    node_layout.appendRow([QStandardItem('model'), mdl])
            
            connections = QStandardItem('connections')
            item.appendRow(connections)
            # Walk the connections
            for conn in val['connections']:
                c = QStandardItem('')
                connections.appendRow(c)
                src = QStandardItem('Source:')
                src_val = QStandardItem(conn['source'])
                src_val.setData('combo', self.TYPE_ROLE)
                c.appendRow([src, src_val])

                snk = QStandardItem('Sink:')
                snk_val = QStandardItem(conn['sink'])
                snk_val.setData('combo', self.TYPE_ROLE)
                c.appendRow([snk, snk_val])

                mdl = QStandardItem('Model:')
                mdl_val = QStandardItem(conn['model'])
                c.appendRow([mdl, mdl_val])