Python PyQt5.QtCore 模块,QStringListModel() 实例源码

我们从Python开源项目中,提取了以下21个代码示例,用于说明如何使用PyQt5.QtCore.QStringListModel()

项目:uPyLoader    作者:BetaRavener    | 项目源码 | 文件源码
def list_mcu_files(self):
        file_list = []
        try:
            file_list = self._connection.list_files()
        except OperationError:
            QMessageBox().critical(self, "Operation failed", "Could not list files.", QMessageBox.Ok)
            return

        self._mcu_files_model = QStringListModel()

        for file in file_list:
            idx = self._mcu_files_model.rowCount()
            self._mcu_files_model.insertRow(idx)
            self._mcu_files_model.setData(self._mcu_files_model.index(idx), file)

        self.mcuFilesListView.setModel(self._mcu_files_model)
        self.mcu_file_selection_changed()
项目:Pext    作者:Pext    | 项目源码 | 文件源码
def __init__(self) -> None:
        """Initialize ViewModel."""
        # Temporary values to allow binding. These will be properly set when
        # possible and relevant.
        self.command_list = []  # type: List
        self.entry_list = []  # type: List
        self.filtered_entry_list = []  # type: List
        self.filtered_command_list = []  # type: List
        self.result_list_model_list = QStringListModel()
        self.result_list_model_max_index = -1
        self.result_list_model_command_mode = False
        self.result_list_model_command_mode_new = True
        self.selection = []  # type: List[Dict[SelectionType, str]]
        self.last_search = ""
        self.context_menu_model_list = QStringListModel()
        self.extra_info_entries = {}  # type: Dict[str, str]
        self.extra_info_commands = {}  # type: Dict[str, str]
        self.context_menu_entries = {}  # type: Dict[str, List[str]]
        self.context_menu_commands = {}  # type: Dict[str, List[str]]
        self.context_menu_base = []  # type: List[str]
        self.context_menu_base_open = False
        self.extra_info_last_entry = ""
        self.extra_info_last_entry_type = None
        self.selection_thread = None  # type: threading.Thread
项目:tahoe-gui    作者:LeastAuthority    | 项目源码 | 文件源码
def __init__(self, parent=None):
        super(self.__class__, self).__init__()
        self.parent = parent
        font = QFont()
        font.setPointSize(16)
        model = QStringListModel()
        model.setStringList(wordlist)
        completer = Completer()
        completer.setModel(model)
        self.setFont(font)
        self.setCompleter(completer)
        self.setAlignment(Qt.AlignCenter)
        #self.setPlaceholderText("Enter invite code")
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
def setupModel(self):
        items = ("Home", "Work", "Other")
        self.typeModel = QStringListModel(items, self)

        self.model = QStandardItemModel(5, 3, self)

        names = ("Alice", "Bob", "Carol", "Donald", "Emma")
        addresses = ("<qt>123 Main Street<br/>Market Town</qt>",
                     "<qt>PO Box 32<br/>Mail Handling Service"
                     "<br/>Service City</qt>",
                     "<qt>The Lighthouse<br/>Remote Island</qt>",
                     "<qt>47338 Park Avenue<br/>Big City</qt>",
                     "<qt>Research Station<br/>Base Camp<br/>Big Mountain</qt>")
        types = ("0", "1", "2", "0", "2")

        for row, name in enumerate(names):
            item = QStandardItem(name)
            self.model.setItem(row, 0, item)
            item = QStandardItem(addresses[row])
            self.model.setItem(row, 1, item)
            item = QStandardItem(types[row])
            self.model.setItem(row, 2, item)
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
def modelFromFile(self, fileName):
        f = QFile(fileName)
        if not f.open(QFile.ReadOnly):
            return QStringListModel(self.completer)

        QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))

        words = []
        while not f.atEnd():
            line = f.readLine().trimmed()
            if line.length() != 0:
                try:
                    line = str(line, encoding='ascii')
                except TypeError:
                    line = str(line)

                words.append(line)

        QApplication.restoreOverrideCursor()

        return QStringListModel(words, self.completer)
项目:examples    作者:pyqt    | 项目源码 | 文件源码
def setupModel(self):
        items = ("Home", "Work", "Other")
        self.typeModel = QStringListModel(items, self)

        self.model = QStandardItemModel(5, 3, self)

        names = ("Alice", "Bob", "Carol", "Donald", "Emma")
        addresses = ("<qt>123 Main Street<br/>Market Town</qt>",
                     "<qt>PO Box 32<br/>Mail Handling Service"
                     "<br/>Service City</qt>",
                     "<qt>The Lighthouse<br/>Remote Island</qt>",
                     "<qt>47338 Park Avenue<br/>Big City</qt>",
                     "<qt>Research Station<br/>Base Camp<br/>Big Mountain</qt>")
        types = ("0", "1", "2", "0", "2")

        for row, name in enumerate(names):
            item = QStandardItem(name)
            self.model.setItem(row, 0, item)
            item = QStandardItem(addresses[row])
            self.model.setItem(row, 1, item)
            item = QStandardItem(types[row])
            self.model.setItem(row, 2, item)
项目:examples    作者:pyqt    | 项目源码 | 文件源码
def modelFromFile(self, fileName):
        f = QFile(fileName)
        if not f.open(QFile.ReadOnly):
            return QStringListModel(self.completer)

        QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))

        words = []
        while not f.atEnd():
            line = f.readLine().trimmed()
            if line.length() != 0:
                try:
                    line = str(line, encoding='ascii')
                except TypeError:
                    line = str(line)

                words.append(line)

        QApplication.restoreOverrideCursor()

        return QStringListModel(words, self.completer)
项目:OpenTutorials_PyQt    作者:RavenKyu    | 项目源码 | 文件源码
def init_widget(self):
        """
        ?? ??? ???? ???
        """
        self.setWindowTitle("QLineEdit Widget")
        form_lbx = QBoxLayout(QBoxLayout.TopToBottom, parent=self)
        self.setLayout(form_lbx)

        lb = QLabel()
        le = QLineEdit()

        model = QStringListModel()
        model.setStringList(["Hello", "Hi", "Bye", "Good", "Seoul"])

        completer = QCompleter()
        completer.setModel(model)
        le.setCompleter(completer)

        le.textChanged.connect(lb.setText)

        form_lbx.addWidget(lb)
        form_lbx.addWidget(le)
项目:pyqt5-example    作者:guinslym    | 项目源码 | 文件源码
def setupModel(self):
        items = ("Home", "Work", "Other")
        self.typeModel = QStringListModel(items, self)

        self.model = QStandardItemModel(5, 3, self)

        names = ("Alice", "Bob", "Carol", "Donald", "Emma")
        addresses = ("<qt>123 Main Street<br/>Market Town</qt>",
                     "<qt>PO Box 32<br/>Mail Handling Service"
                     "<br/>Service City</qt>",
                     "<qt>The Lighthouse<br/>Remote Island</qt>",
                     "<qt>47338 Park Avenue<br/>Big City</qt>",
                     "<qt>Research Station<br/>Base Camp<br/>Big Mountain</qt>")
        types = ("0", "1", "2", "0", "2")

        for row, name in enumerate(names):
            item = QStandardItem(name)
            self.model.setItem(row, 0, item)
            item = QStandardItem(addresses[row])
            self.model.setItem(row, 1, item)
            item = QStandardItem(types[row])
            self.model.setItem(row, 2, item)
项目:pyqt5-example    作者:guinslym    | 项目源码 | 文件源码
def modelFromFile(self, fileName):
        f = QFile(fileName)
        if not f.open(QFile.ReadOnly):
            return QStringListModel(self.completer)

        QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))

        words = []
        while not f.atEnd():
            line = f.readLine().trimmed()
            if line.length() != 0:
                try:
                    line = str(line, encoding='ascii')
                except TypeError:
                    line = str(line)

                words.append(line)

        QApplication.restoreOverrideCursor()

        return QStringListModel(words, self.completer)
项目:gui_tool    作者:UAVCAN    | 项目源码 | 文件源码
def _make_expression_completer(owner, data_type):
    model = QStringListModel()
    comp = QCompleter(owner)
    comp.setCaseSensitivity(Qt.CaseSensitive)

    if isinstance(data_type, str):
        data_type = uavcan.TYPENAMES[data_type]

    # TODO: implement proper completion, requires Python lexer
    # TODO: IPython/Jupyter solves the same task splendidly, might make sense to take a closer look at their code
    def make_suggestions(t):
        """Builds a flat list of fields in a given data type"""
        if t.category == t.CATEGORY_COMPOUND:
            out = []
            for a in t.fields + t.constants:
                if (a.type.category != a.type.CATEGORY_COMPOUND) and \
                   (a.type.category != a.type.CATEGORY_VOID) and \
                   (a.type.category != a.type.CATEGORY_ARRAY or
                            a.type.value_type.category == a.type.value_type.CATEGORY_PRIMITIVE):
                    out.append(a.name)
                out += [(a.name + x) for x in make_suggestions(a.type)]
            return [('.' + x) for x in out]
        elif t.category == t.CATEGORY_ARRAY:
            base = '[0]'
            if t.value_type.category == t.CATEGORY_COMPOUND:
                return [(base + x) for x in make_suggestions(t.value_type)]
            else:
                return [base]
        return []

    suggestions = [(EXPRESSION_VARIABLE_FOR_MESSAGE + x) for x in make_suggestions(data_type)]

    model.setStringList(suggestions)
    comp.setModel(model)
    return comp
项目:gui_tool    作者:UAVCAN    | 项目源码 | 文件源码
def __init__(self, parent):
        super(FilterBar, self).__init__(parent)

        self.add_filter_button = make_icon_button('filter', 'Add filter', self, on_clicked=self._on_add_filter)

        self.on_filter = lambda *_: None

        self._filters = []

        self._pattern_completion_model = QStringListModel(self)

        self._layout = QVBoxLayout(self)
        self._layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(self._layout)
        self.setVisible(False)
项目:uPyLoader    作者:BetaRavener    | 项目源码 | 文件源码
def execute_mcu_code(self):
        idx = self.mcuFilesListView.currentIndex()
        assert isinstance(idx, QModelIndex)
        model = self.mcuFilesListView.model()
        assert isinstance(model, QStringListModel)
        file_name = model.data(idx, Qt.EditRole)
        self._connection.run_file(file_name)
项目:uPyLoader    作者:BetaRavener    | 项目源码 | 文件源码
def remove_file(self):
        idx = self.mcuFilesListView.currentIndex()
        assert isinstance(idx, QModelIndex)
        model = self.mcuFilesListView.model()
        assert isinstance(model, QStringListModel)
        file_name = model.data(idx, Qt.EditRole)
        try:
            self._connection.remove_file(file_name)
        except OperationError:
            QMessageBox().critical(self, "Operation failed", "Could not remove the file.", QMessageBox.Ok)
            return
        self.list_mcu_files()
项目:uPyLoader    作者:BetaRavener    | 项目源码 | 文件源码
def read_mcu_file(self, idx):
        assert isinstance(idx, QModelIndex)
        model = self.mcuFilesListView.model()
        assert isinstance(model, QStringListModel)
        file_name = model.data(idx, Qt.EditRole)
        if not file_name.endswith(".py"):
            QMessageBox.information(self, "Unknown file", "Files without .py ending won't open"
                                                          " in editor, but can still be transferred.")
            return

        progress_dlg = FileTransferDialog(FileTransferDialog.DOWNLOAD)
        progress_dlg.finished.connect(lambda: self.finished_read_mcu_file(file_name, progress_dlg.transfer))
        progress_dlg.show()
        self._connection.read_file(file_name, progress_dlg.transfer)
项目:uPyLoader    作者:BetaRavener    | 项目源码 | 文件源码
def transfer_to_pc(self):
        idx = self.mcuFilesListView.currentIndex()
        assert isinstance(idx, QModelIndex)
        model = self.mcuFilesListView.model()
        assert isinstance(model, QStringListModel)
        remote_path = model.data(idx, Qt.EditRole)
        local_path = self.localPathEdit.text() + "/" + remote_path

        progress_dlg = FileTransferDialog(FileTransferDialog.DOWNLOAD)
        progress_dlg.finished.connect(lambda: self.finished_transfer_to_pc(local_path, progress_dlg.transfer))
        progress_dlg.show()
        self._connection.read_file(remote_path, progress_dlg.transfer)
项目:defconQt    作者:trufont    | 项目源码 | 文件源码
def splitPath(self, path):
        # hack around the splitPath() function to feed custom results to the
        # QCompleter, see: http://stackoverflow.com/a/28286322/2037879
        match, replace = _search(path, self._font)
        if replace:
            comboBox = self.widget()
            comboBox.setCurrentText(match)
            comboBox.lineEdit().selectAll()
            match = None
        if match is None:
            model = QStringListModel()
        else:
            model = QStringListModel([match])
        self.setModel(model)
        return [path]
项目:uitester    作者:IfengAutomation    | 项目源码 | 文件源码
def __init__(self, string_list, parent=None):
        super(TagCompleter, self).__init__(parent)
        self.string_list = string_list
        self.setModel(QStringListModel())
项目:uitester    作者:IfengAutomation    | 项目源码 | 文件源码
def __init__(self, string_list, parent=None):
        super(TagCompleter, self).__init__(parent)
        self.string_list = string_list
        self.setModel(QStringListModel())
项目:solar-sails    作者:metrasynth    | 项目源码 | 文件源码
def setup_model(self):
        self.midi_in_model = QStringListModel()
        self.midi_in_model.setStringList(mido.backend.get_input_names())
        self.midi_in_listview.setModel(self.midi_in_model)
        self.midi_in_listview.selectionModel().selectionChanged.connect(
            self.on_midi_in_selection_changed)
        self.load_midi_in_selection()
项目:DicomBrowser    作者:ericspod    | 项目源码 | 文件源码
def __init__(self,args,parent=None):
        QtGui.QMainWindow.__init__(self,parent)

        self.srclist=[] # list of source directories
        self.imageIndex=0 # index of selected image
        self.seriesMap=OrderedDict() # maps series table row tuples to DicomSeries object it was generated from
        self.seriesColumns=list(seriesListColumns) # keywords for columns
        self.selectedRow=-1 # selected series row
        self.lastDir='.' # last loaded directory root
        self.filterRegex='' # regular expression to filter tags by

        # create the directory queue and loading thread objects
        self.dirQueue=Queue() # queue of directories to load
        self.loadDirThread=threading.Thread(target=self._loadDirsThread)
        self.loadDirThread.daemon=True # clean shutdown possible with daemon threads
        self.loadDirThread.start() # start the thread now, it will wait until something is put on self.dirQueue

        # setup ui
        self.setupUi(self) # create UI elements based on the loaded .ui file
        self.setWindowTitle('DicomBrowser v%s (FOR RESEARCH ONLY)'%(__version__))
        self.setStatus('')

        # connect signals
        self.importButton.clicked.connect(self._openDirDialog)
        self.statusSignal.connect(self.setStatus)
        self.updateSignal.connect(self._updateSeriesTable)
        self.filterLine.textChanged.connect(self._setFilterString)
        self.imageSlider.valueChanged.connect(self.setSeriesImage)
        self.seriesView.clicked.connect(self._seriesTableClicked)

        # setup the list and table models
        self.srcmodel=QStringListModel()
        self.seriesmodel=SeriesTableModel(self.seriesColumns)
        self.seriesmodel.layoutChanged.connect(self._seriesTableResize)
        self.tagmodel=QtGui.QStandardItemModel()

        # assign models to views
        self.sourceListView.setModel(self.srcmodel)
        self.seriesView.setModel(self.seriesmodel)
        self.tagView.setModel(self.tagmodel)

        # create the pyqtgraph object for viewing images
        self.imageview=pg.ImageView()
        layout=QtGui.QGridLayout(self.view2DGroup)
        layout.addWidget(self.imageview)

        # load the empty image placeholder into a ndarray
        qimg=QtGui.QImage(':/icons/noimage.png')
        bytedata=qimg.constBits().asstring(qimg.width()*qimg.height())
        self.noimg=np.ndarray((qimg.width(),qimg.height()),dtype=np.ubyte,buffer=bytedata)

        # add the directories passed as arguments to the directory queue to start loading
        for i in args:
            if os.path.isdir(i):
                self.addSourceDir(i)