예제 #1
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()
예제 #2
0
    def rebuild_selected_packages_list_widget(self):
        # remove all items
        self.selected_packages_list_widget.clear()

        for f in self.file_paths:
            file_item = QListWidgetItem()
            file_item.setText(f)
            self.selected_packages_list_widget.addItem(file_item)
예제 #3
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()
        icons_map = {CompletionItemKind.TEXT: 'text',
                     CompletionItemKind.METHOD: 'method',
                     CompletionItemKind.FUNCTION: 'function',
                     CompletionItemKind.CONSTRUCTOR: 'constructor',
                     CompletionItemKind.FIELD: 'field',
                     CompletionItemKind.VARIABLE: 'variable',
                     CompletionItemKind.CLASS: 'class',
                     CompletionItemKind.INTERFACE: 'interface',
                     CompletionItemKind.MODULE: 'module',
                     CompletionItemKind.PROPERTY: 'property',
                     CompletionItemKind.UNIT: 'unit',
                     CompletionItemKind.VALUE: 'value',
                     CompletionItemKind.ENUM: 'enum',
                     CompletionItemKind.KEYWORD: 'keyword',
                     CompletionItemKind.SNIPPET: 'snippet',
                     CompletionItemKind.COLOR: 'color',
                     CompletionItemKind.FILE: 'filenew',
                     CompletionItemKind.REFERENCE: 'reference',
                     }

        height = self.item_height
        width = self.item_width

        for completion in self.completion_list:
            if not self.is_internal_console:
                completion_label = completion['filterText']
                icon = icons_map.get(completion['kind'], 'no_match')
                completion_data = completion['insertText']
                completion_text = self.get_html_item_representation(
                    completion_data, icon, height=height, width=width)
                item = QListWidgetItem(ima.icon(icon),
                                       completion_text)
                item.setData(Qt.UserRole, completion_data)
            else:
                completion_label = completion[0]
                completion_text = self.get_html_item_representation(
                    completion_label, '', 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)

        if self.count() > 0:
            self.setCurrentRow(0)
            self.scrollTo(self.currentIndex(),
                          QAbstractItemView.PositionAtTop)
        else:
            self.hide()
예제 #4
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))
예제 #5
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()
예제 #6
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))
예제 #7
0
    def update_list(self, current_word, new=True):
        """
        Update the displayed list by filtering self.completion_list based on
        the current_word under the cursor (see check_can_complete).

        If we're not updating the list with new completions, we filter out
        textEdit completions, since it's difficult to apply them correctly
        after the user makes edits.

        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:
                if not new and 'textEdit' in completion:
                    continue
                completion_label = completion['filterText']
            else:
                completion_label = completion[0]

            if not self.check_can_complete(completion_label, current_word):
                continue
            item = QListWidgetItem()

            if not self.is_internal_console:
                self.set_item_display(item,
                                      completion,
                                      height=height,
                                      width=width)
                item.setData(Qt.UserRole, completion)
            else:
                completion_text = self.get_html_item_representation(
                    completion_label, '', height=height, width=width)
                item.setData(Qt.UserRole, completion_label)
                item.setText(completion_text)

            self.addItem(item)
            self.display_index.append(i)

        if self.count() == 0:
            self.hide()
예제 #8
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))
예제 #9
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)
예제 #10
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