当前位置: 首页>>代码示例>>Python>>正文


Python Qt.QTreeWidget类代码示例

本文整理汇总了Python中PyQt5.Qt.QTreeWidget的典型用法代码示例。如果您正苦于以下问题:Python QTreeWidget类的具体用法?Python QTreeWidget怎么用?Python QTreeWidget使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了QTreeWidget类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

 def __init__(self, storage, show_files=False, item_func=browser_item):
     QTreeWidget.__init__(self)
     self.item_func = item_func
     self.show_files = show_files
     self.create_children(storage, self)
     self.name = storage.name
     self.object_id = storage.persistent_id
     self.setMinimumHeight(350)
     self.setHeaderHidden(True)
     self.storage = storage
开发者ID:davidfor,项目名称:calibre,代码行数:10,代码来源:mtp_folder_browser.py

示例2: selectedIndexes

 def selectedIndexes(self):
     ans = QTreeWidget.selectedIndexes(self)
     if self.ordered_selected_indexes:
         # The reverse is needed because Qt's implementation of dropEvent
         # reverses the selectedIndexes when dropping.
         ans = list(sorted(ans, key=lambda idx:idx.row(), reverse=True))
     return ans
开发者ID:,项目名称:,代码行数:7,代码来源:

示例3: __init__

    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        self.l = l = QGridLayout(self)
        self.toc_title = None
        self.setLayout(l)
        l.setContentsMargins(0, 0, 0, 0)

        self.view = QTreeWidget(self)
        self.delegate = Delegate(self.view)
        self.view.setItemDelegate(self.delegate)
        self.view.setHeaderHidden(True)
        self.view.setAnimated(True)
        self.view.setContextMenuPolicy(Qt.CustomContextMenu)
        self.view.customContextMenuRequested.connect(self.show_context_menu, type=Qt.QueuedConnection)
        self.view.itemActivated.connect(self.emit_navigate)
        self.view.itemPressed.connect(self.item_pressed)
        pi = plugins['progress_indicator'][0]
        if hasattr(pi, 'set_no_activate_on_click'):
            pi.set_no_activate_on_click(self.view)
        self.view.itemDoubleClicked.connect(self.emit_navigate)
        l.addWidget(self.view)

        self.refresh_action = QAction(QIcon(I('view-refresh.png')), _('&Refresh'), self)
        self.refresh_action.triggered.connect(self.refresh)
        self.refresh_timer = t = QTimer(self)
        t.setInterval(1000), t.setSingleShot(True)
        t.timeout.connect(self.auto_refresh)
        self.toc_name = None
        self.currently_editing = None
开发者ID:JimmXinu,项目名称:calibre,代码行数:29,代码来源:toc.py

示例4: __init__

 def __init__(self, parent=None):
     super(ServicesQWidget, self).__init__(parent)
     # Fields
     self.services = None
     self.services_tree_widget = QTreeWidget()
     self.services_list_widget = QListWidget()
     self.service_data_widget = ServiceDataQWidget()
     self.services_dashboard = ServicesDashboardQWidget()
开发者ID:Alignak-monitoring-contrib,项目名称:alignak-app,代码行数:8,代码来源:services.py

示例5: __init__

 def __init__(self, parent):
     QTreeWidget.__init__(self, parent)
     self.setHeaderLabel(_('Table of Contents'))
     self.setIconSize(QSize(ICON_SIZE, ICON_SIZE))
     self.setDragEnabled(True)
     self.setSelectionMode(self.ExtendedSelection)
     self.viewport().setAcceptDrops(True)
     self.setDropIndicatorShown(True)
     self.setDragDropMode(self.InternalMove)
     self.setAutoScroll(True)
     self.setAutoScrollMargin(ICON_SIZE*2)
     self.setDefaultDropAction(Qt.MoveAction)
     self.setAutoExpandDelay(1000)
     self.setAnimated(True)
     self.setMouseTracking(True)
     self.in_drop_event = False
     self.root = self.invisibleRootItem()
     self.setContextMenuPolicy(Qt.CustomContextMenu)
     self.customContextMenuRequested.connect(self.show_context_menu)
开发者ID:AtulKumar2,项目名称:calibre,代码行数:19,代码来源:main.py

示例6: __init__

 def __init__(self, parent=None):
     QTreeWidget.__init__(self, parent)
     self.categories = {}
     self.ordered_selected_indexes = False
     pi = plugins["progress_indicator"][0]
     if hasattr(pi, "set_no_activate_on_click"):
         pi.set_no_activate_on_click(self)
     self.current_edited_name = None
     self.delegate = ItemDelegate(self)
     self.delegate.rename_requested.connect(self.rename_requested)
     self.setTextElideMode(Qt.ElideMiddle)
     self.setItemDelegate(self.delegate)
     self.setIconSize(QSize(16, 16))
     self.header().close()
     self.setDragEnabled(True)
     self.setEditTriggers(self.EditKeyPressed)
     self.setSelectionMode(self.ExtendedSelection)
     self.viewport().setAcceptDrops(True)
     self.setDropIndicatorShown(True)
     self.setDragDropMode(self.InternalMove)
     self.setAutoScroll(True)
     self.setAutoScrollMargin(TOP_ICON_SIZE * 2)
     self.setDefaultDropAction(Qt.MoveAction)
     self.setAutoExpandDelay(1000)
     self.setAnimated(True)
     self.setMouseTracking(True)
     self.setContextMenuPolicy(Qt.CustomContextMenu)
     self.customContextMenuRequested.connect(self.show_context_menu)
     self.root = self.invisibleRootItem()
     self.emblem_cache = {}
     self.rendered_emblem_cache = {}
     self.top_level_pixmap_cache = {
         name: QPixmap(I(icon)).scaled(TOP_ICON_SIZE, TOP_ICON_SIZE, transformMode=Qt.SmoothTransformation)
         for name, icon in {
             "text": "keyboard-prefs.png",
             "styles": "lookfeel.png",
             "fonts": "font.png",
             "misc": "mimetypes/dir.png",
             "images": "view-image.png",
         }.iteritems()
     }
     self.itemActivated.connect(self.item_double_clicked)
开发者ID:Xliff,项目名称:calibre,代码行数:42,代码来源:file_list.py

示例7: __init__

 def __init__(self, parent = None):
     super().__init__(parent)
     self.tree = QTreeWidget()
     self.tree.setHeaderHidden(True)
     layout = QVBoxLayout()
     layout.addWidget(self.tree)
     self.setLayout(layout)
     self.tree.setIndentation(0)
     self.sections = []
     self.section_dic = {}
     self.define_sections()
     self.add_sections()
开发者ID:DKMS-LSL,项目名称:typeloader,代码行数:12,代码来源:GUI_forms.py

示例8: keyPressEvent

 def keyPressEvent(self, ev):
     if ev.key() in (Qt.Key_Delete, Qt.Key_Backspace):
         ev.accept()
         self.request_delete()
     else:
         return QTreeWidget.keyPressEvent(self, ev)
开发者ID:,项目名称:,代码行数:6,代码来源:

示例9: commitData

 def commitData(self, editor):
     self.push_history()
     return QTreeWidget.commitData(self, editor)
开发者ID:j-howell,项目名称:calibre,代码行数:3,代码来源:main.py

示例10: mimeData

 def mimeData(self, indices):
     ans = QTreeWidget.mimeData(self, indices)
     names = (idx.data(0, NAME_ROLE) for idx in indices if idx.data(0, MIME_ROLE))
     ans.setData(CONTAINER_DND_MIMETYPE, '\n'.join(filter(None, names)).encode('utf-8'))
     return ans
开发者ID:jelly,项目名称:calibre,代码行数:5,代码来源:file_list.py

示例11: mimeTypes

 def mimeTypes(self):
     ans = QTreeWidget.mimeTypes(self)
     ans.append(CONTAINER_DND_MIMETYPE)
     return ans
开发者ID:jelly,项目名称:calibre,代码行数:4,代码来源:file_list.py

示例12: TOCViewer

class TOCViewer(QWidget):

    navigate_requested = pyqtSignal(object, object)
    refresh_requested = pyqtSignal()

    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        self.l = l = QGridLayout(self)
        self.toc_title = None
        self.setLayout(l)
        l.setContentsMargins(0, 0, 0, 0)

        self.view = QTreeWidget(self)
        self.delegate = Delegate(self.view)
        self.view.setItemDelegate(self.delegate)
        self.view.setHeaderHidden(True)
        self.view.setAnimated(True)
        self.view.setContextMenuPolicy(Qt.CustomContextMenu)
        self.view.customContextMenuRequested.connect(self.show_context_menu, type=Qt.QueuedConnection)
        self.view.itemActivated.connect(self.emit_navigate)
        self.view.itemPressed.connect(self.item_pressed)
        pi = plugins['progress_indicator'][0]
        if hasattr(pi, 'set_no_activate_on_click'):
            pi.set_no_activate_on_click(self.view)
        self.view.itemDoubleClicked.connect(self.emit_navigate)
        l.addWidget(self.view)

        self.refresh_action = QAction(QIcon(I('view-refresh.png')), _('&Refresh'), self)
        self.refresh_action.triggered.connect(self.refresh)
        self.refresh_timer = t = QTimer(self)
        t.setInterval(1000), t.setSingleShot(True)
        t.timeout.connect(self.auto_refresh)
        self.toc_name = None
        self.currently_editing = None

    def start_refresh_timer(self, name):
        if self.isVisible() and self.toc_name == name:
            self.refresh_timer.start()

    def auto_refresh(self):
        if self.isVisible():
            try:
                self.refresh()
            except Exception:
                # ignore errors during live refresh of the toc
                import traceback
                traceback.print_exc()

    def refresh(self):
        self.refresh_requested.emit()  # Give boss a chance to commit dirty editors to the container
        self.build()

    def item_pressed(self, item):
        if QApplication.mouseButtons() & Qt.LeftButton:
            QTimer.singleShot(0, self.emit_navigate)

    def show_context_menu(self, pos):
        menu = QMenu(self)
        menu.addAction(actions['edit-toc'])
        menu.addAction(_('&Expand all'), self.view.expandAll)
        menu.addAction(_('&Collapse all'), self.view.collapseAll)
        menu.addAction(self.refresh_action)
        menu.exec_(self.view.mapToGlobal(pos))

    def iter_items(self, parent=None):
        if parent is None:
            parent = self.invisibleRootItem()
        for i in range(parent.childCount()):
            child = parent.child(i)
            yield child
            for gc in self.iter_items(parent=child):
                yield gc

    def emit_navigate(self, *args):
        item = self.view.currentItem()
        if item is not None:
            dest = unicode_type(item.data(0, DEST_ROLE) or '')
            frag = unicode_type(item.data(0, FRAG_ROLE) or '')
            if not frag:
                frag = TOP
            self.navigate_requested.emit(dest, frag)

    def build(self):
        c = current_container()
        if c is None:
            return
        toc = get_toc(c, verify_destinations=False)
        self.toc_name = getattr(toc, 'toc_file_name', None)
        self.toc_title = toc.toc_title

        def process_node(toc, parent):
            for child in toc:
                node = QTreeWidgetItem(parent)
                node.setText(0, child.title or '')
                node.setData(0, DEST_ROLE, child.dest or '')
                node.setData(0, FRAG_ROLE, child.frag or '')
                tt = _('File: {0}\nAnchor: {1}').format(
                    child.dest or '', child.frag or _('Top of file'))
                node.setData(0, Qt.ToolTipRole, tt)
                process_node(child, node)
#.........这里部分代码省略.........
开发者ID:JimmXinu,项目名称:calibre,代码行数:101,代码来源:toc.py

示例13: ServicesQWidget

class ServicesQWidget(QWidget):
    """
        Class wo create services QWidget
    """

    def __init__(self, parent=None):
        super(ServicesQWidget, self).__init__(parent)
        # Fields
        self.services = None
        self.services_tree_widget = QTreeWidget()
        self.services_list_widget = QListWidget()
        self.service_data_widget = ServiceDataQWidget()
        self.services_dashboard = ServicesDashboardQWidget()

    def initialize(self):
        """
        Initialize QWidget

        """

        layout = QGridLayout()
        self.setLayout(layout)
        layout.setContentsMargins(0, 0, 0, 0)

        # Services dashboard
        self.services_dashboard.initialize()
        for state in self.services_dashboard.states_btns:
            self.services_dashboard.states_btns[state].clicked.connect(
                lambda _, s=state: self.filter_services(state=s)
            )
        layout.addWidget(self.services_dashboard, 0, 0, 1, 2)
        layout.addWidget(get_frame_separator(), 1, 0, 1, 2)

        # Services QTreeWidget
        self.services_tree_widget.setIconSize(QSize(32, 32))
        self.services_tree_widget.setAlternatingRowColors(True)
        self.services_tree_widget.header().close()
        layout.addWidget(self.services_tree_widget, 2, 0, 1, 1)

        # Services QListWidget
        self.services_list_widget.clicked.connect(self.update_service_data)
        self.services_list_widget.hide()
        layout.addWidget(self.services_list_widget, 2, 0, 1, 1)

        # Service DataWidget
        self.service_data_widget.initialize()
        layout.addWidget(self.service_data_widget, 2, 1, 1, 1)

    def filter_services(self, state):
        """
        Filter services with the wanted state

        :param state: state of service: OK, WARNING, NOT_MONITORED, DOWNTIME
        :return:
        """

        # Clear QListWidget and update filter buttons of services dashboard
        self.services_list_widget.clear()
        for btn_state in self.services_dashboard.states_btns:
            if btn_state != state:
                self.services_dashboard.states_btns[btn_state].setChecked(False)

        # Update QWidgets
        if self.sender().isChecked():
            self.set_filter_items(state)
            self.services_tree_widget.hide()
            self.services_list_widget.show()
        else:
            self.services_tree_widget.show()
            self.services_list_widget.hide()

    def set_filter_items(self, state):
        """
        Add filter items to QListWidget corresponding to "state"

        :param state: state of service to filter
        :type state: str
        """

        services_added = False
        if state in 'NOT_MONITORED':
            for service in self.services:
                if not service.data['active_checks_enabled'] and \
                        not service.data['passive_checks_enabled']and \
                        not service.data['ls_downtimed'] and \
                        not service.data['ls_acknowledged']:
                    self.add_filter_item(service)
                    services_added = True
        elif state in 'DOWNTIME':
            for service in self.services:
                if service.data['ls_downtimed']:
                    self.add_filter_item(service)
                    services_added = True
        elif state in 'ACKNOWLEDGE':
            for service in self.services:
                if service.data['ls_acknowledged']:
                    self.add_filter_item(service)
                    services_added = True
        else:
            for service in self.services:
#.........这里部分代码省略.........
开发者ID:Alignak-monitoring-contrib,项目名称:alignak-app,代码行数:101,代码来源:services.py

示例14: CheckLibraryDialog

class CheckLibraryDialog(QDialog):

    def __init__(self, parent, db):
        QDialog.__init__(self, parent)
        self.db = db

        self.setWindowTitle(_('Check Library -- Problems Found'))
        self.setWindowIcon(QIcon(I('debug.png')))

        self._tl = QHBoxLayout()
        self.setLayout(self._tl)
        self.splitter = QSplitter(self)
        self.left = QWidget(self)
        self.splitter.addWidget(self.left)
        self.helpw = QTextEdit(self)
        self.splitter.addWidget(self.helpw)
        self._tl.addWidget(self.splitter)
        self._layout = QVBoxLayout()
        self.left.setLayout(self._layout)
        self.helpw.setReadOnly(True)
        self.helpw.setText(_('''\
        <h1>Help</h1>

        <p>calibre stores the list of your books and their metadata in a
        database. The actual book files and covers are stored as normal
        files in the calibre library folder. The database contains a list of the files
        and covers belonging to each book entry. This tool checks that the
        actual files in the library folder on your computer match the
        information in the database.</p>

        <p>The result of each type of check is shown to the left. The various
        checks are:
        </p>
        <ul>
        <li><b>Invalid titles</b>: These are files and folders appearing
        in the library where books titles should, but that do not have the
        correct form to be a book title.</li>
        <li><b>Extra titles</b>: These are extra files in your calibre
        library that appear to be correctly-formed titles, but have no corresponding
        entries in the database</li>
        <li><b>Invalid authors</b>: These are files appearing
        in the library where only author folders should be.</li>
        <li><b>Extra authors</b>: These are folders in the
        calibre library that appear to be authors but that do not have entries
        in the database</li>
        <li><b>Missing book formats</b>: These are book formats that are in
        the database but have no corresponding format file in the book's folder.
        <li><b>Extra book formats</b>: These are book format files found in
        the book's folder but not in the database.
        <li><b>Unknown files in books</b>: These are extra files in the
        folder of each book that do not correspond to a known format or cover
        file.</li>
        <li><b>Missing cover files</b>: These represent books that are marked
        in the database as having covers but the actual cover files are
        missing.</li>
        <li><b>Cover files not in database</b>: These are books that have
        cover files but are marked as not having covers in the database.</li>
        <li><b>Folder raising exception</b>: These represent folders in the
        calibre library that could not be processed/understood by this
        tool.</li>
        </ul>

        <p>There are two kinds of automatic fixes possible: <i>Delete
        marked</i> and <i>Fix marked</i>.</p>
        <p><i>Delete marked</i> is used to remove extra files/folders/covers that
        have no entries in the database. Check the box next to the item you want
        to delete. Use with caution.</p>

        <p><i>Fix marked</i> is applicable only to covers and missing formats
        (the three lines marked 'fixable'). In the case of missing cover files,
        checking the fixable box and pushing this button will tell calibre that
        there is no cover for all of the books listed. Use this option if you
        are not going to restore the covers from a backup. In the case of extra
        cover files, checking the fixable box and pushing this button will tell
        calibre that the cover files it found are correct for all the books
        listed. Use this when you are not going to delete the file(s). In the
        case of missing formats, checking the fixable box and pushing this
        button will tell calibre that the formats are really gone. Use this if
        you are not going to restore the formats from a backup.</p>

        '''))

        self.log = QTreeWidget(self)
        self.log.itemChanged.connect(self.item_changed)
        self.log.itemExpanded.connect(self.item_expanded_or_collapsed)
        self.log.itemCollapsed.connect(self.item_expanded_or_collapsed)
        self._layout.addWidget(self.log)

        self.check_button = QPushButton(_('&Run the check again'))
        self.check_button.setDefault(False)
        self.check_button.clicked.connect(self.run_the_check)
        self.copy_button = QPushButton(_('Copy &to clipboard'))
        self.copy_button.setDefault(False)
        self.copy_button.clicked.connect(self.copy_to_clipboard)
        self.ok_button = QPushButton(_('&Done'))
        self.ok_button.setDefault(True)
        self.ok_button.clicked.connect(self.accept)
        self.mark_delete_button = QPushButton(_('Mark &all for delete'))
        self.mark_delete_button.setToolTip(_('Mark all deletable subitems'))
        self.mark_delete_button.setDefault(False)
#.........这里部分代码省略.........
开发者ID:Aliminator666,项目名称:calibre,代码行数:101,代码来源:check_library.py

示例15: selectedIndexes

 def selectedIndexes(self):
     ans = QTreeWidget.selectedIndexes(self)
     if self.ordered_selected_indexes:
         ans = list(sorted(ans, key=lambda idx:idx.row()))
     return ans
开发者ID:jelly,项目名称:calibre,代码行数:5,代码来源:file_list.py


注:本文中的PyQt5.Qt.QTreeWidget类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。