Python PyQt5.QtGui.QStandardItem() Examples

The following are 30 code examples of PyQt5.QtGui.QStandardItem(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module PyQt5.QtGui , or try the search function .
Example #1
Source File: modelviewserver.py    From PyQt with GNU General Public License v3.0 6 votes vote down vote up
def addChild(numChildren, nestingLevel):
    result = []

    if nestingLevel == 0:
        return result

    for i in range(numChildren):
        child = QStandardItem(
                "Child num {}, nesting level {}".format(i + 1, nestingLevel))

        if i == 0:
            child.appendRow(addChild(numChildren, nestingLevel - 1))

        result.append(child)

    return result 
Example #2
Source File: dockwidgets.py    From Lector with GNU General Public License v3.0 6 votes vote down vote up
def generate_annotation_model(self):
        # TODO
        # Annotation previews will require creation of a
        # QStyledItemDelegate

        saved_annotations = self.parent.main_window.settings['annotations']
        if not saved_annotations:
            return

        # Create annotation model
        for i in saved_annotations:
            item = QtGui.QStandardItem()
            item.setText(i['name'])
            item.setData(i, QtCore.Qt.UserRole)
            self.parent.annotationModel.appendRow(item)
        self.annotationListView.setModel(self.parent.annotationModel) 
Example #3
Source File: listcategory.py    From qutebrowser with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self,
                 name: str,
                 items: typing.Iterable[_ItemType],
                 sort: bool = True,
                 delete_func: util.DeleteFuncType = None,
                 parent: QWidget = None):
        super().__init__(parent)
        self.name = name
        self.srcmodel = QStandardItemModel(parent=self)
        self._pattern = ''
        # ListCategory filters all columns
        self.columns_to_filter = [0, 1, 2]
        self.setFilterKeyColumn(-1)
        for item in items:
            self.srcmodel.appendRow([QStandardItem(x) for x in item])
        self.setSourceModel(self.srcmodel)
        self.delete_func = delete_func
        self._sort = sort 
Example #4
Source File: detection.py    From detection with GNU General Public License v2.0 6 votes vote down vote up
def populateTree(self, node, parent):
        """Create a QTreeView node under 'parent'.
        """
        item = QtGui.QStandardItem(node)
        h, s, v = Detector.getDefaultHSVColor(node)
        color = QColor()
        color.setHsvF(h, s, v)
        item.setIcon(self.getIcon(color))
        # Unique hash for QStandardItem
        key = hash(item)
        while key in self.classifiersParameters:
            key += 1
        item.setData(key)
        cp = ClassifierParameters(item.data(), node, node, color,
                                  self.SHAPE_RECT, self.FILL_OUTLINE)
        self.classifiersParameters[key] = cp
        parent.appendRow(item)
        return item 
Example #5
Source File: widgets.py    From Lector with GNU General Public License v3.0 6 votes vote down vote up
def generate_toc_model(self):
        # The toc list is:
        # 0: Level
        # 1: Title
        # 2: Chapter content / page number
        # pprint it out to get a better idea of structure

        toc = self.metadata['toc']
        parent_list = []
        for i in toc:
            item = QtGui.QStandardItem()
            item.setText(i[1])
            item.setData(i[2], QtCore.Qt.UserRole)
            item.setData(i[1], QtCore.Qt.UserRole + 1)

            current_level = i[0]
            if current_level == 1:
                self.tocModel.appendRow(item)
                parent_list.clear()
                parent_list.append(item)
            else:
                parent_list[current_level - 2].appendRow(item)
                try:
                    next_level = toc[toc.index(i) + 1][0]
                    if next_level > current_level:
                        parent_list.append(item)

                    if next_level < current_level:
                        level_difference = current_level - next_level
                        parent_list = parent_list[:-level_difference]
                except IndexError:
                    pass

        # This is needed to be able to have the toc Combobox
        # jump to the correct position in the book when it is
        # first opened
        self.main_window.bookToolBar.tocBox.setModel(self.tocModel)
        self.main_window.bookToolBar.tocTreeView.expandAll() 
Example #6
Source File: refnodesets_widget.py    From opcua-modeler with GNU General Public License v3.0 6 votes vote down vote up
def import_nodeset(self, path):
        print("IMPORT", path)
        name = os.path.basename(path)
        if name in self.nodesets:
            return
        try:
            self.server_mgr.import_xml(path)
        except Exception as ex:
            self.error.emit(ex)
            raise

        item = QStandardItem(name)
        self.model.appendRow([item])
        self.nodesets.append(name)
        self.view.expandAll()
        self.nodeset_added.emit(path) 
Example #7
Source File: FunctionViewEx.py    From DIE with MIT License 6 votes vote down vote up
def _make_nonexec_function_time(self, function_name):
        """
        Build a tree item for a function name (for a non-executed function)
        @type: String
        @param function_name: Function name
        @return:
        """

        item_function = QtGui.QStandardItem(self.die_icons.icon_function, function_name)
        item_function_count = QtGui.QStandardItem("0")

        item_function_count.setEditable(False)
        item_function.setEditable(False)

        item_list = [item_function, item_function_count]

        return item_list 
Example #8
Source File: puzzle.py    From Miyamoto with GNU General Public License v3.0 6 votes vote down vote up
def addObj(self):
        global Tileset

        Tileset.addObject(new=True)

        pix = QtGui.QPixmap(24, 24)
        pix.fill(Qt.transparent)

        painter = QtGui.QPainter(pix)
        painter.drawPixmap(0, 0, Tileset.tiles[0].image.scaledToWidth(24, Qt.SmoothTransformation))
        painter.end()
        del painter

        count = len(Tileset.objects)
        item = QtGui.QStandardItem(QtGui.QIcon(pix), 'Object {0}'.format(count-1))
        item.setFlags(item.flags() & ~Qt.ItemIsEditable)
        window.objmodel.appendRow(item)
        index = window.objectList.currentIndex()
        window.objectList.setCurrentIndex(index)
        self.setObject(index)

        window.objectList.update()
        self.update() 
Example #9
Source File: ontology_explorer.py    From eddy with GNU General Public License v3.0 6 votes vote down vote up
def doAddNode(self, diagram, node):
        """
        Add a node in the tree view.
        :type diagram: QGraphicsScene
        :type node: AbstractItem
        """
        if node.type() in {Item.ConceptNode, Item.RoleNode, Item.AttributeNode, Item.IndividualNode}:
            parent = self.parentFor(node)
            if not parent:
                parent = QtGui.QStandardItem(self.parentKey(node))
                parent.setIcon(self.iconFor(node))
                self.model.appendRow(parent)
                self.proxy.sort(0, QtCore.Qt.AscendingOrder)
            child = QtGui.QStandardItem(self.childKey(diagram, node))
            child.setData(node)
            parent.appendRow(child)
            self.proxy.sort(0, QtCore.Qt.AscendingOrder) 
Example #10
Source File: mainwindow.py    From opcua-client-gui with GNU General Public License v3.0 6 votes vote down vote up
def _subscribe(self, node=None):
        if not isinstance(node, Node):
            node = self.window.get_current_node()
            if node is None:
                return
        if node in self._subscribed_nodes:
            logger.warning("allready subscribed to node: %s ", node)
            return
        self.model.setHorizontalHeaderLabels(["DisplayName", "Value", "Timestamp"])
        text = str(node.get_display_name().Text)
        row = [QStandardItem(text), QStandardItem("No Data yet"), QStandardItem("")]
        row[0].setData(node)
        self.model.appendRow(row)
        self._subscribed_nodes.append(node)
        self.window.ui.subDockWidget.raise_()
        try:
            self.uaclient.subscribe_datachange(node, self._subhandler)
        except Exception as ex:
            self.window.show_error(ex)
            idx = self.model.indexFromItem(row[0])
            self.model.takeRow(idx.row())
            raise 
Example #11
Source File: EasyInstall.py    From Resetter with GNU General Public License v3.0 6 votes vote down vote up
def addItems(self):
        package = str(self.EditText.text())
        try:
            pkg = self.cache[package.strip()]
            n = pkg.shortname
            v = pkg.versions[0].version
            desc = pkg.versions[0].description
            name = "{}: {}".format(n, v)
            if len(package) > 0 and pkg.is_installed is False:
                item = QtGui.QStandardItem(name)
                item.setCheckable(True)
                item.setSelectable(True)
                item.setToolTip((textwrap.fill(desc, 70)))
                item.setCheckState(QtCore.Qt.Unchecked)
                self.model.appendRow(item)
                self.list_view.setModel(self.model)
            else:
                self.alreadyInstalled(name)
            self.EditText.clear()
        except KeyError:
            self.showMessage(package) 
Example #12
Source File: panel_search.py    From Dwarf with GNU General Public License v3.0 6 votes vote down vote up
def _on_show_results(self):
        if self._search_results:
            self.results.clear()
            if self._app_window.debug_panel.memory_panel:
                self._app_window.debug_panel.memory_panel.remove_highlights('search')
            selected_index = self.ranges.selectionModel().currentIndex().row()
            if selected_index is not None:
                item_txt = self._ranges_model.item(selected_index, 3).text()
                if item_txt == '':
                    return

                for result in self._search_results[selected_index]:
                    self._result_model.appendRow(
                        QStandardItem(result['address']))

                    # TODO: fix hexview highlights performance
                    """
                    if self._app_window.memory_panel:
                        try:
                            self._app_window.memory_panel.add_highlight(
                                HighLight('search', utils.parse_ptr(result['address']), self._pattern_length))
                        except HighlightExistsError:
                            pass""" 
Example #13
Source File: CustomWidgetItem.py    From PyQt with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(ListView, self).__init__(*args, **kwargs)
        # 模型
        self._model = QStandardItemModel(self)
        self.setModel(self._model)

        # 循环生成10个自定义控件
        for i in range(10):
            item = QStandardItem()
            self._model.appendRow(item)  # 添加item

            # 得到索引
            index = self._model.indexFromItem(item)
            widget = CustomWidget(str(i))
            item.setSizeHint(widget.sizeHint())  # 主要是调整item的高度
            # 设置自定义的widget
            self.setIndexWidget(index, widget) 
Example #14
Source File: list_view.py    From Dwarf with GNU General Public License v3.0 5 votes vote down vote up
def get_item_text(self, index, col):
        """ returns text in index, col
        """
        if self.model() is not None:
            if index < self.model().rowCount():
                if col < self.model().columnCount():
                    item = self.model().item(index, col)
                    if isinstance(item, QStandardItem):
                        return self.model().item(index, col).text()

        return None 
Example #15
Source File: panel_java_trace.py    From Dwarf with GNU General Public License v3.0 5 votes vote down vote up
def class_list_double_click(self, model_index):
        class_name = self.class_list_model.item(model_index.row(), 0).text()
        if class_name:
            for i in range(self.trace_list_model.rowCount()):
                if self.trace_list_model.item(i, 0).text() == class_name:
                    return

            self.trace_list_model.appendRow([QtGui.QStandardItem(class_name)])
            self.trace_list_model.sort(0, QtCore.Qt.AscendingOrder) 
Example #16
Source File: panel_java_inspector.py    From Dwarf with GNU General Public License v3.0 5 votes vote down vote up
def _on_method_enumeration_complete(self, data):
        self._java_methods.clear()
        _class, methods = data
        for method in methods:
            _method_name = QStandardItem()
            _method_name.setText(method)
            self._javamethod_model.appendRow(_method_name) 
Example #17
Source File: panel_java_inspector.py    From Dwarf with GNU General Public License v3.0 5 votes vote down vote up
def _on_class_enumeration_match(self, java_class):
        _class_name = QStandardItem()
        _class_name.setText(java_class)
        self._javaclass_model.appendRow(_class_name) 
Example #18
Source File: settingsdialog.py    From Lector with GNU General Public License v3.0 5 votes vote down vote up
def generate_annotations(self):
        saved_annotations = self.main_window.settings['annotations']

        for i in saved_annotations:
            item = QtGui.QStandardItem()
            item.setText(i['name'])
            item.setData(i, QtCore.Qt.UserRole)
            self.annotationModel.appendRow(item)

        self.annotationsList.setModel(self.annotationModel) 
Example #19
Source File: process_list.py    From Dwarf with GNU General Public License v3.0 5 votes vote down vote up
def _on_add_proc(self, item):
        model = self.process_list.model()
        pid = QStandardItem()
        pid.setText(str(item['pid']))
        pid.setTextAlignment(Qt.AlignCenter)
        name = QStandardItem()
        name.setText(item['name'])
        model.appendRow([pid, name]) 
Example #20
Source File: panel_objc_inspector.py    From Dwarf with GNU General Public License v3.0 5 votes vote down vote up
def add_module(self, module):
        _module_name = QStandardItem()
        _module_name.setText(module)
        self._ObjCmodule_model.appendRow(_module_name) 
Example #21
Source File: panel_objc_inspector.py    From Dwarf with GNU General Public License v3.0 5 votes vote down vote up
def _on_method_enumeration_match(self, ObjC_method):
        _method_name = QStandardItem()
        _method_name.setText(ObjC_method)
        self._ObjCmethod_model.appendRow(_method_name) 
Example #22
Source File: panel_objc_inspector.py    From Dwarf with GNU General Public License v3.0 5 votes vote down vote up
def _on_class_enumeration_match(self, ObjC_class):
        _class_name = QStandardItem()
        _class_name.setText(ObjC_class)
        self._ObjCclass_model.appendRow(_class_name) 
Example #23
Source File: panel_java_explorer.py    From Dwarf with GNU General Public License v3.0 5 votes vote down vote up
def _add_field(self, name, value, handle=None, handle_class=None, is_native=False):
        if handle:
            handle = {'handle': handle, 'handle_class': handle_class}
            handle_item = QStandardItem(name)
            handle_item.setData(handle, Qt.UserRole + 1)
        else:
            handle_item = QStandardItem(name)

        if not is_native:
            self._fields_model.appendRow(
                [handle_item, QStandardItem(str(value))])
        else:
            self._native_fields_model.appendRow(
                [handle_item, QStandardItem(str(value))]) 
Example #24
Source File: panel_java_explorer.py    From Dwarf with GNU General Public License v3.0 5 votes vote down vote up
def _add_method(self, name, ref):
        ref_overloads = ref['overloads']
        for _, ref_overload in enumerate(ref_overloads):
            args = []

            if 'args' in ref_overload:
                for arg in ref_overload['args']:
                    if 'className' in arg:
                        args.append(arg['className'])

            self._methods_model.appendRow([
                QStandardItem(name),
                QStandardItem(ref_overload['return']['className']),
                QStandardItem('(%s)' % ', '.join(args)),
            ]) 
Example #25
Source File: ui.py    From Quantdom with Apache License 2.0 5 votes vote down vote up
def on_symbols_loaded(self, symbols):
        self.shares_symbol_list.clear()
        self.shares_symbol_list.setEnabled(True)
        # self.symbols = ['%s/%s' % (ticker, name) for ticker, name in symbols]
        # self.shares_symbol_list.addItems(self.symbols)
        model = QtGui.QStandardItemModel()
        model.setHorizontalHeaderLabels(SYMBOL_COLUMNS)
        for irow, (ticker, name) in enumerate(symbols):
            model.setItem(irow, 0, QtGui.QStandardItem(ticker))
            model.setItem(irow, 1, QtGui.QStandardItem(name))

        table_view = QtGui.QTableView()
        table_view.setModel(model)
        table_view.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
        table_view.verticalHeader().setVisible(False)
        table_view.setAutoScroll(False)
        table_view.setShowGrid(False)
        table_view.resizeRowsToContents()
        table_view.setColumnWidth(0, 60)
        table_view.setColumnWidth(1, 240)
        table_view.setMinimumWidth(300)

        completer = QtGui.QCompleter(model)
        completer.setCaseSensitivity(QtCore.Qt.CaseInsensitive)
        completer.setModel(model)

        self.symbols = symbols
        self.shares_symbol_list.setModel(model)
        self.shares_symbol_list.setView(table_view)
        self.shares_symbol_list.setCompleter(completer)

        # set default symbol
        self.shares_symbol_list.setCurrentIndex(
            self.shares_symbol_list.findText(DEFAULT_TICKER)
        ) 
Example #26
Source File: Q_dict_tree_view.py    From pyNMS with GNU General Public License v3.0 5 votes vote down vote up
def populate_tree(self, children, parent=None):
        if not parent:
            parent = self.root_model.invisibleRootItem()
        for child in sorted(children):
            child_item = QStandardItem(child)
            parent.appendRow(child_item)
            if isinstance(children, dict) and bool(list(children)):
                self.populate_tree(children[child], child_item) 
Example #27
Source File: Sources.py    From Resetter with GNU General Public License v3.0 5 votes vote down vote up
def editSources(self, title, tip):
        self.setWindowTitle(title)
        list_view = QListView(self)
        self.model = QtGui.QStandardItemModel(list_view)
        self.model.itemChanged.connect(self.setItems)
        self.setToolTip(tip)
        verticalLayout = QVBoxLayout(self)
        verticalLayout.addWidget(self.searchEditText)
        verticalLayout.addWidget(list_view)
        horizontalLayout = QHBoxLayout()
        horizontalLayout.setAlignment(QtCore.Qt.AlignRight)
        horizontalLayout.addWidget(self.label)
        horizontalLayout.addWidget(self.btDisable)
        horizontalLayout.addWidget(self.btnEnable)
        horizontalLayout.addWidget(self.btnRemove)
        horizontalLayout.addWidget(self.btnClose)
        verticalLayout.addLayout(horizontalLayout)
        mode = 0
        args = (self.model, list_view,  self.label, self.font, self.font2, mode)
        self.searchEditText.textChanged.connect(lambda: UsefulTools().searchItem(*args, self.searchEditText.text()))

        for dirpath, dirs, files in os.walk('/etc/apt/'):
            word = 'deb'
            for filename in fnmatch.filter(files, "*.list"):
                source_list = os.path.join(dirpath, filename)
                self.sourceslists.append(source_list)
                with open(source_list, "r") as sources:
                    for line in sources:
                        if line.startswith(word) or line.startswith('#') \
                                and line[2:].split(' ')[0][:3] == word:
                                item = QtGui.QStandardItem(line.strip())
                                item.setCheckable(True)
                                item.setCheckState(QtCore.Qt.Unchecked)
                                self.model.appendRow(item)
                    list_view.setModel(self.model) 
Example #28
Source File: EasyInstall.py    From Resetter with GNU General Public License v3.0 5 votes vote down vote up
def openBackup(self):
        try:
            dpath = os.path.abspath(os.path.join('Backup', '../../../'))
            backup = QFileDialog.getOpenFileName(self, 'Choose Backup', dpath, '(*.rbf)')
            if os.path.isfile(backup):
                with open(backup, 'r') as bk:
                    for line in bk:
                        try:
                            pkg = self.cache[line.strip()]
                            n = pkg.shortname
                            v = pkg.versions[0].version
                            desc = pkg.versions[0].raw_description
                            name = "{}: {}".format(n, v)
                            if len(line) > 0 and pkg.is_installed is False:
                                item = QtGui.QStandardItem(name)
                                item.setCheckable(True)
                                item.setSelectable(True)
                                item.setToolTip((textwrap.fill(desc, 70)))
                                item.setCheckState(QtCore.Qt.Unchecked)
                                self.model.appendRow(item)
                                self.list_view.setModel(self.model)
                            self.EditText.clear()
                        except KeyError:
                            continue
        except IOError:
            pass 
Example #29
Source File: first.py    From FIRST-plugin-ida with GNU General Public License v2.0 5 votes vote down vote up
def make_model_headers(model, full=True, check_all=True):
            '''
            Set the model horizontal header data
            @param model: the QStandardItemModel which headers should be set

            When full is set to False this mean the headers are for the user
            to review metadata they've created.
            '''
            center_align = ['Rank', 'Similarity', 'i', 'Matches']
            headers = [ ('Function', 'function name'),
                        ('Rank', 'number of times metadata has been applied'),
                        ('Prototype', 'function prototype')]

            if full:
                full_headers = [headers[0]]
                if check_all:
                    full_headers.append(('Matches', 'number of unique matches'))

                full_headers += [
                            headers[1],
                            ('Similarity', 'percent of how similary the match is to the function'),
                            headers[2],
                            ('i', 'full prototype information'),
                            ('Engines', 'engines that matched on this function'),
                            ('i', 'detailed engine information'),
                            ('User', 'creator of the metadata')
                                ]

                headers = full_headers

            i = 0
            for display_name, tooltip in headers:
                item_header = QtGui.QStandardItem(display_name)
                item_header.setToolTip(tooltip)

                if display_name in center_align:
                    item_header.setTextAlignment(Qt.AlignCenter)

                model.setHorizontalHeaderItem(i, item_header)

                i += 1 
Example #30
Source File: CColorItems.py    From CustomWidgets with GNU General Public License v3.0 5 votes vote down vote up
def addColor(self, color):
        item = QStandardItem('')
        item.setData(QColor(color))
        item.setSizeHint(QSize(20, 20))
        item.setToolTip(color)
        self._model.appendRow(item)