예제 #1
0
    def load_project_list(self):
        """
        Populate the project selection list.
        """
        self.list_projects.clear()

        for path in self.projects_dict:
            project = self.projects_dict[path]
            name = project.name

            item = QListWidgetItem(name)

            if getattr(project, 'icon', None):
                icon = self.api.load_icon(path, project)
            else:
                icon = qta.icon('fa.cog')

            item.setIcon(icon)
            item.project = project
            item.path = path
            if project.commands:
                item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsUserCheckable
                              | Qt.ItemIsEnabled)
                if project.is_app:
                    item.setCheckState(Qt.Checked)
                else:
                    item.setCheckState(Qt.Unchecked)

            self.list_projects.addItem(item)
            self.toogle_dev_tools(visible=self.dev_tool_visible)

        for i in range(self.list_projects.count()):
            item = self.list_projects.item(i)
            item.setSizeHint(QSize(item.sizeHint().width(), self._height()))
예제 #2
0
    def submit(self):
        """Put a new command on the queue for later execution.
        """
        # put the new command on the queue
        cmd = str(self.mdi_entry_widget.text()).strip()
        row_item = QListWidgetItem()
        row_item.setText(cmd)
        row_item.setData(MDIHistory.MDQQ_ROLE, MDIHistory.MDIQ_TODO)
        row_item.setIcon(self.icon_waiting)
        if self.mdi_listorder_natural:
            self.addItem(row_item)
        else:
            self.insertItem(0, row_item)

        # Set the recently added item as the "current" item
        # if the queue is not paused this will quickly get overridden
        # to the executing item highlight mode
        self.clearSelection()
        self.setCurrentItem(row_item)

        # put the command onto the status channel mdi history
        # This always adds this item at position Zero on the channel
        STATUS.mdi_history.setValue(cmd)

        # now clear down the mdi entry text ready for new input
        self.mdi_entry_widget.clear()
예제 #3
0
 def __grounded(self) -> None:
     """Grounded combinations."""
     current_item = self.collection_list.currentItem()
     self.collections_grounded.clear()
     self.grounded_list.clear()
     g = self.collections[self.collection_list.row(current_item)]
     item = QListWidgetItem("Released")
     icon = graph2icon(g,
                       self.grounded_list.iconSize().width(),
                       self.graph_link_as_node.isChecked(),
                       self.graph_show_label.isChecked(),
                       self.prefer.monochrome_option,
                       pos=self.ground_engine)
     item.setIcon(icon)
     self.collections_grounded.append(g)
     self.grounded_list.addItem(item)
     for node, graph_ in labeled_enumerate(g):
         item = QListWidgetItem(f"link_{node}")
         icon = graph2icon(g,
                           self.grounded_list.iconSize().width(),
                           self.graph_link_as_node.isChecked(),
                           self.graph_show_label.isChecked(),
                           self.prefer.monochrome_option,
                           except_node=node,
                           pos=self.ground_engine)
         item.setIcon(icon)
         self.collections_grounded.append(graph_)
         self.grounded_list.addItem(item)
예제 #4
0
 def update_list(self):
     """Update path list"""
     self.listwidget.clear()
     for name in self.pathlist + self.ro_pathlist:
         item = QListWidgetItem(name)
         item.setIcon(ima.icon('DirClosedIcon'))
         if name in self.ro_pathlist:
             item.setFlags(Qt.NoItemFlags)
         self.listwidget.addItem(item)
     self.refresh()
예제 #5
0
 def update_list(self):
     """Update path list"""
     self.listwidget.clear()
     for name in self.pathlist+self.ro_pathlist:
         item = QListWidgetItem(name)
         item.setIcon(ima.icon('DirClosedIcon'))
         if name in self.ro_pathlist:
             item.setFlags(Qt.NoItemFlags)
         self.listwidget.addItem(item)
     self.refresh()
예제 #6
0
파일: dialogs.py 프로젝트: ezcad-dev/ezcad
 def add_page(self, widget):
     scrollarea = QScrollArea(self)
     scrollarea.setWidgetResizable(True)
     scrollarea.setWidget(widget)
     self.pages_widget.addWidget(scrollarea)
     item = QListWidgetItem(self.contents_widget)
     try:
         item.setIcon(widget.get_icon())
     except TypeError:
         pass
     item.setText(widget.get_name())
     item.setFlags(Qt.ItemIsSelectable|Qt.ItemIsEnabled)
     item.setSizeHint(QSize(0, 25))
예제 #7
0
    def update_list(self, filter_text):
        """
        Update the displayed list by filtering self.completion_list.

        If no items are left on the list the autocompletion should stop
        """
        self.clear()

        self.display_index = []
        height = self.item_height
        width = self.item_width

        for i, completion in enumerate(self.completion_list):
            if not self.is_internal_console:
                code_snippets_enabled = getattr(self.textedit, 'code_snippets',
                                                False)
                completion_label = completion['filterText']
                completion_text = completion['insertText']
                if not code_snippets_enabled:
                    completion_label = completion['insertText']
                icon = self.ICONS_MAP.get(completion['kind'], 'no_match')
                item = QListWidgetItem()
                item.setIcon(ima.icon(icon))
                self.set_item_text(item,
                                   completion,
                                   height=height,
                                   width=width)
                item.setData(Qt.UserRole, completion_text)
            else:
                completion_label = completion[0]
                completion_text = self.get_html_item_representation(
                    completion_label,
                    '',
                    icon_provider=None,
                    size=0,
                    height=height,
                    width=width)
                item = QListWidgetItem()
                item.setData(Qt.UserRole, completion_label)
                item.setText(completion_text)

            if self.check_can_complete(completion_label, filter_text):
                self.addItem(item)
                self.display_index.append(i)

        if self.count() > 0:
            self.setCurrentRow(0)
            self.scrollTo(self.currentIndex(), QAbstractItemView.PositionAtTop)
        else:
            self.hide()
예제 #8
0
    def _create_item(self, path):
        """Helper to create a new list item."""
        item = QListWidgetItem(path)
        item.setIcon(ima.icon('DirClosedIcon'))

        if path in self.read_only_path:
            item.setFlags(Qt.NoItemFlags | Qt.ItemIsUserCheckable)
            item.setCheckState(Qt.Checked)
        elif path in self.not_active_path:
            item.setFlags(item.flags() | Qt.ItemIsUserCheckable)
            item.setCheckState(Qt.Unchecked)
        else:
            item.setFlags(item.flags() | Qt.ItemIsUserCheckable)
            item.setCheckState(Qt.Checked)

        return item
예제 #9
0
 def __draw_atlas(self, i: int, g: Graph) -> bool:
     """Draw atlas and return True if done."""
     item = QListWidgetItem(f"No. {i + 1}")
     item.setIcon(
         graph2icon(g,
                    self.structure_list.iconSize().width(),
                    self.graph_engine.currentText(),
                    self.graph_link_as_node.isChecked(),
                    self.graph_show_label.isChecked(),
                    self.prefer.monochrome_option))
     item.setToolTip(
         f"Edge Set: {list(g.edges)}\n"
         f"Link assortment: {link_assortment(g)}\n"
         f"Contracted Link assortment: {contracted_link_assortment(g)}")
     self.structure_list.addItem(item)
     return True
예제 #10
0
 def add_page(self, widget):
     self.check_settings.connect(widget.check_settings)
     widget.show_this_page.connect(lambda row=self.contents_widget.count():
                                   self.contents_widget.setCurrentRow(row))
     widget.apply_button_enabled.connect(self.apply_btn.setEnabled)
     scrollarea = QScrollArea(self)
     scrollarea.setWidgetResizable(True)
     scrollarea.setWidget(widget)
     self.pages_widget.addWidget(scrollarea)
     item = QListWidgetItem(self.contents_widget)
     try:
         item.setIcon(widget.get_icon())
     except TypeError:
         pass
     item.setText(widget.get_name())
     item.setFlags(Qt.ItemIsSelectable|Qt.ItemIsEnabled)
     item.setSizeHint(QSize(0, 25))
예제 #11
0
 def add_page(self, widget):
     self.check_settings.connect(widget.check_settings)
     widget.show_this_page.connect(lambda row=self.contents_widget.count():
                                   self.contents_widget.setCurrentRow(row))
     widget.apply_button_enabled.connect(self.apply_btn.setEnabled)
     scrollarea = QScrollArea(self)
     scrollarea.setWidgetResizable(True)
     scrollarea.setWidget(widget)
     self.pages_widget.addWidget(scrollarea)
     item = QListWidgetItem(self.contents_widget)
     try:
         item.setIcon(widget.get_icon())
     except TypeError:
         pass
     item.setText(widget.get_name())
     item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)
     item.setSizeHint(QSize(0, 25))
예제 #12
0
    def __reload_atlas(self) -> None:
        """Reload atlas with the engine."""
        current_pos = self.collection_list.currentRow()
        self.collections_layouts.clear()
        self.collection_list.clear()
        self.__clear_selection()
        if not self.collections:
            return

        dlg = QProgressDialog(
            "Drawing atlas...",
            "Cancel",
            0,
            len(self.collections),
            self
        )
        dlg.setWindowTitle("Type synthesis")
        dlg.resize(400, dlg.height())
        dlg.setModal(True)
        dlg.show()
        engine_str = self.graph_engine.currentText()
        for i, g in enumerate(self.collections):
            QCoreApplication.processEvents()
            if dlg.wasCanceled():
                dlg.deleteLater()
                return

            item = QListWidgetItem(f"No. {i + 1}")
            engine = engine_picker(g, engine_str, self.graph_link_as_node.isChecked())
            item.setIcon(graph2icon(
                g,
                self.collection_list.iconSize().width(),
                engine,
                self.graph_link_as_node.isChecked(),
                self.graph_show_label.isChecked(),
                self.prefer.monochrome_option
            ))
            self.collections_layouts.append(engine)
            item.setToolTip(f"{g.edges}")
            self.collection_list.addItem(item)
            dlg.setValue(i + 1)

        dlg.deleteLater()
        if current_pos > -1:
            self.collection_list.setCurrentRow(current_pos)
            self.__set_selection(self.collection_list.currentItem())
예제 #13
0
    def __set_selection(self, item: QListWidgetItem) -> None:
        """Show the data of collection.

        Save the layout position to keep the graphs
        will be in same appearance.
        """
        for button in (
            self.delete_button,
            self.configure_button,
            self.duplicate_button,
        ):
            button.setEnabled(item is not None)
        self.selection_window.clear()
        if item is None:
            return

        # Preview item
        link_is_node = self.graph_link_as_node.isChecked()
        item_preview = QListWidgetItem(item.text())
        row = self.collection_list.row(item)
        g = self.collections[row]
        self.ground_engine = self.collections_layouts[row]
        item_preview.setIcon(graph2icon(
            g,
            self.selection_window.iconSize().width(),
            self.ground_engine,
            link_is_node,
            self.graph_show_label.isChecked(),
            self.prefer.monochrome_option
        ))
        self.selection_window.addItem(item_preview)

        # Set attributes
        self.edges_text.setText(str(list(g.edges)))
        self.nl_label.setText(str(len(g.nodes)))
        self.nj_label.setText(str(len(g.edges)))
        self.dof_label.setText(str(g.dof()))
        self.is_degenerate_label.setText(str(g.is_degenerate()))
        self.link_assortment_label.setText(str(link_assortment(g)))
        self.contracted_link_assortment_label.setText(str(contracted_link_assortment(g)))

        self.duplicate_button.setEnabled(link_is_node)
        self.configure_button.setEnabled(not link_is_node)
        self.merge_button.setEnabled(not link_is_node)

        self.__grounded()
예제 #14
0
 def update_list(self):
     """Update path list"""
     self.listwidget.clear()
     for name in self.pathlist + self.ro_pathlist:
         item = QListWidgetItem(name)
         item.setIcon(ima.icon('DirClosedIcon'))
         if name in self.ro_pathlist:
             item.setFlags(Qt.NoItemFlags | Qt.ItemIsUserCheckable)
             item.setCheckState(Qt.Checked)
         elif name in self.not_active_pathlist:
             item.setFlags(item.flags() | Qt.ItemIsUserCheckable)
             item.setCheckState(Qt.Unchecked)
         else:
             item.setFlags(item.flags() | Qt.ItemIsUserCheckable)
             item.setCheckState(Qt.Checked)
         self.listwidget.addItem(item)
     self.refresh()
예제 #15
0
 def update_list(self):
     """Update path list"""
     self.listwidget.clear()
     for name in self.pathlist+self.ro_pathlist:
         item = QListWidgetItem(name)
         item.setIcon(ima.icon('DirClosedIcon'))
         if name in self.ro_pathlist:
             item.setFlags(Qt.NoItemFlags | Qt.ItemIsUserCheckable)
             item.setCheckState(Qt.Checked)
         elif name in self.not_active_pathlist:
             item.setFlags(item.flags() | Qt.ItemIsUserCheckable)
             item.setCheckState(Qt.Unchecked)
         else:
             item.setFlags(item.flags() | Qt.ItemIsUserCheckable)
             item.setCheckState(Qt.Checked)
         self.listwidget.addItem(item)
     self.refresh()
예제 #16
0
 def __add_result(self, result: Dict[str, Any]) -> None:
     """Add result items, except add to the list."""
     item = QListWidgetItem(result['algorithm'])
     interrupt = result['interrupted']
     if interrupt == 'False':
         interrupt_icon = "task_completed.png"
     elif interrupt == 'N/A':
         interrupt_icon = "question.png"
     else:
         interrupt_icon = "interrupted.png"
     item.setIcon(QIcon(QPixmap(f":/icons/{interrupt_icon}")))
     if interrupt == 'False':
         interrupt_text = "No interrupt."
     else:
         interrupt_text = f"Interrupt at: {interrupt}"
     text = f"{result['algorithm']} ({interrupt_text})"
     if interrupt == 'N/A':
         text += "\n※Completeness is unknown."
     item.setToolTip(text)
     self.result_list.addItem(item)
예제 #17
0
    def setHistory(self, items_list):
        """Clear and reset the history in the list.
        item_list is a list of strings."""
        print('Clear and load history to list')
        self.clear()

        # check that there is anything do to
        if len(items_list) == 0:
            return

        # load the history based on natural order or not
        if self.mdi_listorder_natural:
            items_list.reverse()

        for item in items_list:
            row_item = QListWidgetItem()
            row_item.setText(item)
            row_item.setData(MDIHistory.MDQQ_ROLE, MDIHistory.MDIQ_DONE)
            row_item.setIcon(QIcon())
            self.addItem(row_item)
예제 #18
0
 def undo(self) -> None:
     """Create a new item and recover expression."""
     item = QListWidgetItem(self.name)
     item.expr = self.mechanism
     item.setIcon(QIcon(QPixmap("icons:mechanism.png")))
     self.widget.insertItem(self.row, item)
예제 #19
0
 def _generate_list_item(self, key_frame):
     """Generate a QListWidgetItem from a key-frame"""
     item = QListWidgetItem(f"key-frame {self._frame_count}")
     item.setIcon(self._icon_from_key_frame(key_frame))
     return item
예제 #20
0
    def scan_devices_update_list_view(self):
        """
        Scan for new devices; and update the list view
        :return:
        """
        # self.devices_view.clear()
        device_exists_in_view = False
        paired_devices = []
        for index in range(self.devices_view.count()):
            paired_devices.append(self.devices_view.item(index))

        __devices = self.adb.devices_detailed()
        log(__devices)
        for i in __devices:
            device_is_wifi = \
                i['identifier'].count('.') >= 3 and (':' in i['identifier'])

            if i['identifier'] not in self.config['device'].keys():
                device_paired_and_exists = False
                self.config['device'][i['identifier']] = {'rotation': 0}
            else:
                device_paired_and_exists = True

            if device_is_wifi:
                _icon_suffix = '_wifi'
            else:
                _icon_suffix = '_usb'

            icon = ':/icons/icons/portrait_mobile_white{}.svg'.format(
                _icon_suffix)

            if i['status'] == 'offline':
                icon = ':/icons/icons/portrait_mobile_error.svg'
            elif i['status'] == 'unauthorized':
                icon = ':/icons/icons/portrait_mobile_warning.svg'

            if i['status'] == 'no_permission':
                log("pairfilter: 5")
                # https://stackoverflow.com/questions/
                # 53887322/adb-devices-no-permissions-user-in-
                # plugdev-group-are-your-udev-rules-wrong
                udev_error = "Error connecting to device. Your udev rules are"\
                    " incorrect. See https://stackoverflow.com/questions"\
                    "/53887322/adb-devices-no-permissions-user-in-plugdev-"\
                    "group-are-your-udev-rules-wrong"
                self.display_public_message(udev_error)
                print(udev_error)
                return []
            # Check if device is unauthorized
            elif i['status'] == "unauthorized":
                log("unauthorized device detected: Click Allow on your device")
                log("pairfilter: 4")
                # The device is connected; and might/might't paired in the past
                # And is connected to the same IP address
                # It is possibly a bug with the connection;
                # Temporarily create a new QListItem to display the
                # device with the error
                paired = False
                device_paired_and_exists = False
                self.display_public_message(
                    f"{i['identifier']} is unauthorized. Please click allow "
                    f"on your device.")
                # Remove other devices with the same id and offline and
                # unauthorized
                self.remove_device_device_view(
                    i['identifier'], statuses=['offline', 'unauthorized'])
                # Unauthorized device cannot be considered as a paired device
                devices_view_list_item = QListWidgetItem()
            else:
                # check if device is paired
                # if yes, just update the list item
                if not device_paired_and_exists:
                    paired = False
                    devices_view_list_item = QListWidgetItem()
                else:
                    for paired_device in paired_devices:
                        if paired_device.text().split()[0] == i['model']:
                            log("pairfilter: 1")
                            paired = True
                            devices_view_list_item = paired_device
                            # as we have found a paired device
                            # we know by assumption; there cannot be two
                            # devices with the same local IP address;
                            # lets scan the devices_view once more in a loop
                            # to check for any device with the same
                            # identifier and remove them; based on this same
                            # assumption
                            self.remove_device_device_view(
                                i['identifier'],
                                statuses=['offline', 'unauthorized'])
                            break
                        elif paired_device.text().split()[1] ==\
                                i['identifier']:
                            log("pairfilter: 2")
                            self.remove_device_device_view(
                                i['identifier'],
                                statuses=['offline', 'unauthorized'])
                            devices_view_list_item = QListWidgetItem()
                            paired = False
                            break
                    else:
                        log("pairfilter: 3")
                        paired = False
                        devices_view_list_item = QListWidgetItem()

            devices_view_list_item.setIcon(QIcon(icon))

            devices_view_list_item.setText("{device}\n{mode}\n{status}".format(
                device=i['model'], mode=i['identifier'], status=i['status']))
            __sha_shift = self.config.get('sha_shift', 5)
            __sha = hashlib.sha256(str(i['identifier']).encode()).hexdigest(
            )[__sha_shift:__sha_shift + 6]
            devices_view_list_item.setToolTip(
                "Device: "
                "<span style='color: #{inv_color};background-color: #{color}'>"
                "<b>{d}</b></span>\n"
                "<br>"
                "Model: {m}\n<br>"
                "Alias: {a}\n<br>"
                "Status: {s}\n<br>"
                "Transport ID: {t}\n<br>"
                "Paired: {p}".format(d=i['identifier'],
                                     m=i['model'],
                                     a=i['product'],
                                     s=i['status'],
                                     t=i['transport_id'],
                                     p=paired,
                                     color=__sha,
                                     inv_color=str(
                                         hex(0xFFFFFF - int(__sha, 16))[2:])))

            devices_view_list_item.setFont(QFont('Noto Sans', 8))
            log(f"Pairing status: {device_paired_and_exists}")
            if device_paired_and_exists and device_is_wifi:
                # we need to only neglect wifi devices
                # paired usb device need to still show in the display
                continue
            elif device_exists_in_view:
                # devices exists in the list with the same status and
                # we should not add the new detected list item
                continue
            # If and only if the device doesn't exist; add it
            self.devices_view.addItem(devices_view_list_item)
        return __devices
예제 #21
0
 def redo(self) -> None:
     """Add mechanism expression to 'expr' attribute."""
     item = QListWidgetItem(self.name)
     item.expr = self.mechanism
     item.setIcon(QIcon(QPixmap("icons:mechanism.png")))
     self.widget.addItem(item)