예제 #1
0
    def __init__(self, settings: BaseSettings, parent=None):
        super().__init__(parent)
        self.settings = settings
        self.file_list = QListWidget()
        self.file_list.setSelectionMode(QAbstractItemView.ExtendedSelection)
        self.cancel_btn = QPushButton("Cancel", clicked=self.reject)
        self.load_btn = QPushButton("Load", clicked=self.accept)

        for name_list, method in settings.get_last_files_multiple():
            entry = f"{name_list[0]} {method}"
            item = QListWidgetItem(entry, self.file_list)
            item.setData(Qt.UserRole, (name_list, method))

        last_set = {(tuple(x), y)
                    for x, y in settings.get_last_files_multiple()}
        for name_list, method in settings.get_last_files():
            if (tuple(name_list), method) in last_set:
                continue
            entry = f"{name_list[0]} {method}"
            item = QListWidgetItem(entry, self.file_list)
            item.setData(Qt.UserRole, (name_list, method))

        layout = QGridLayout()
        layout.addWidget(QLabel("Select files"))
        layout.addWidget(self.file_list, 1, 0, 1, 2)
        layout.addWidget(self.cancel_btn, 2, 0)
        layout.addWidget(self.load_btn, 2, 1)

        self.setLayout(layout)
        self.resize(
            *self.settings.get_from_profile("multiple_files_dialog_size", (
                self.size().width(), self.size().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 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()
 def update(self, files):
     self.clear()
     for i, fname in enumerate(files):
         fname = fname.encode('utf-8')
         text = os.path.basename(fname)
         icon = QIcon(FILE_ICON)
         item = QListWidgetItem(icon, text)
         item.setData(Qt.UserRole, fname)
         self.addItem(item)
예제 #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_data_item(self, data):
        """
        Adds a `Data` object to the loaded data list widget.

        Parameters
        ----------
        data : specutils.core.generic.Spectrum1DRef
            The `Data` object to add to the list widget.
        """
        new_item = QListWidgetItem(data.name, self.contents.list_widget_data_list)
        new_item.setFlags(new_item.flags() | Qt.ItemIsEditable)

        new_item.setData(Qt.UserRole, data)

        self.contents.list_widget_data_list.setCurrentItem(new_item)
예제 #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 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)