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


Python QTreeWidget.currentIndex方法代码示例

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


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

示例1: SessionsManager

# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import currentIndex [as 别名]

#.........这里部分代码省略.........
        btn_layout.addWidget(btn_activate)
        btn_layout.addWidget(btn_update)
        btn_layout.addWidget(btn_delete)
        btn_layout.addStretch()
        btn_layout.addWidget(btn_details)
        # Add widgets and layouts to the main layout
        main_layout.addLayout(main_hbox)
        main_hbox.addLayout(session_layout)
        main_hbox.addWidget(line_frame)
        main_hbox.addLayout(btn_layout)
        main_hbox.setSizeConstraint(QLayout.SetFixedSize)
        btn_details.toggled[bool].connect(content_frame.setVisible)
        # Connections
        self._session_list.itemSelectionChanged.connect(
            self.load_session_content)
        btn_activate.clicked.connect(self.open_session)
        btn_update.clicked.connect(self.save_session)
        btn_create.clicked.connect(self.create_session)
        btn_delete.clicked.connect(self.delete_session)

    def __load_sessions(self):
        for session_name in self._manager.sessions:
            item = QTreeWidgetItem()
            item.setText(0, session_name)
            item.setText(1, "FIXME: manage this!")
            self._session_list.addTopLevelItem(item)
        self._session_list.setCurrentItem(
            self._session_list.topLevelItem(0))

    def load_session_content(self):
        """Load the selected session, replacing the current session."""
        item = self._session_list.currentItem()
        self._content_list.clear()
        if item is not None:
            key = item.text(0)
            files, projects = self._manager.get_session(key)
            files_parent = QTreeWidgetItem(
                self._content_list, [translations.TR_FILES])
            for ffile in files:
                QTreeWidgetItem(files_parent, [ffile[0]])
            projects_parent = QTreeWidgetItem(
                self._content_list, [translations.TR_PROJECT])
            for project in projects:
                QTreeWidgetItem(projects_parent, [project])

            files_parent.setExpanded(True)
            projects_parent.setExpanded(True)

    def create_session(self):
        """Create a new Session."""
        session_info = QInputDialog.getText(
            None, translations.TR_SESSIONS_CREATE_TITLE,
            translations.TR_SESSIONS_CREATE_BODY)
        if session_info[1]:
            session_name = session_info[0]
            if not session_name or session_name in settings.SESSIONS:
                QMessageBox.information(
                    self,
                    translations.TR_SESSIONS_MESSAGE_TITLE,
                    translations.TR_SESSIONS_MESSAGE_BODY)
                return
            self._manager.save_session_data(session_name)
        self.close()

    def save_session(self):
        """Save current session"""
        if self._session_list.currentItem():
            session_name = self._session_list.currentItem().text(0)
            self._manager.save_session_data(session_name)
            self._ninja.show_message(
                translations.TR_SESSIONS_UPDATED_NOTIF.format(session_name))
            self.load_session_content()

    def open_session(self):
        """Open a saved session"""
        if self._session_list.currentItem():
            session_name = self._session_list.currentItem().text(0)
            self._manager.load_session(session_name)
            self._manager.set_current_session(session_name)
            self.close()

    def delete_session(self):
        """Delete a session"""
        if self._session_list.currentItem():
            key = self._session_list.currentItem().text(0)
            self._manager.delete_session(key)
            self._session_list.takeTopLevelItem(
                self._session_list.currentIndex().row())

    @property
    def current_session(self):
        return self._manager.current_session()

    def showEvent(self, event):
        super().showEvent(event)
        self.__load_sessions()

    def hideEvent(self, event):
        super().hideEvent(event)
        self._session_list.clear()
开发者ID:ninja-ide,项目名称:ninja-ide,代码行数:104,代码来源:session_manager.py


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