def convert(name, editor, to_collapse): ti = QtWidgets.QTreeWidgetItem() ti.setText(0, name.name) if isinstance(name.icon, list): icon = QtGui.QIcon.fromTheme(name.icon[0], QtGui.QIcon(name.icon[1])) else: icon = QtGui.QIcon(name.icon) ti.setIcon(0, icon) name.block = editor.document().findBlockByNumber(name.line) ti.setData(0, QtCore.Qt.UserRole, name) ti.setToolTip(0, name.description) name.tree_item = ti block_data = name.block.userData() if block_data is None: block_data = TextBlockUserData() name.block.setUserData(block_data) block_data.tree_item = ti if to_collapse is not None and \ TextBlockHelper.is_collapsed(name.block): to_collapse.append(ti) for ch in name.children: ti_ch, to_collapse = convert(ch, editor, to_collapse) if ti_ch: ti.addChild(ti_ch) return ti, to_collapse
def _on_changed(self): """ Update the tree items """ self._updating = True to_collapse = [] self.clear() if self._editor and self._outline_mode and self._folding_panel: items, to_collapse = self.to_tree_widget_items( self._outline_mode.definitions, to_collapse=to_collapse) if len(items): self.addTopLevelItems(items) self.expandAll() for item in reversed(to_collapse): self.collapseItem(item) self._updating = False return # no data root = QtWidgets.QTreeWidgetItem() root.setText(0, 'No data') root.setIcon( 0, icons.icon('dialog-information', ':/pyqode-icons/rc/dialog-info.png', 'fa.info-circle')) self.addTopLevelItem(root) self._updating = False self.sync()
def _on_changed(self): """ Update the tree items """ self._updating = True to_collapse = [] self.clear() if self._editor and self._analyser and self._folding_panel: items, to_collapse = self._analyser.to_tree_widget_items( to_collapse=to_collapse) if len(items): self.addTopLevelItems(items) self.expandAll() for item in reversed(to_collapse): self.collapseItem(item) self._updating = False return # no data root = QtWidgets.QTreeWidgetItem() root.setText(0, 'No data') root.setIcon( 0, QtGui.QIcon.fromTheme( 'dialog-information', QtGui.QIcon(':/pyqode-icons/rc/dialog-info.png'))) self.addTopLevelItem(root) self._updating = False
def __init__(self, parent): super(DeviceFilesWidget, self).__init__(i18n('Device files'), parent) self.setWindowTitle(i18n("Device files")) widget = QtWidgets.QWidget(self) vlayout = QtWidgets.QVBoxLayout() self.toolbar = QtWidgets.QToolBar(self) self.toolbar.addAction(i18n("Refresh"), self.loadRemoteFiles) self.toolbar.addAction(icon("download"), i18n("Download to Device"), self.downloadFile) self.filesView = QtWidgets.QTreeWidget(self) self.filesView.header().close() self.deviceItem = QtWidgets.QTreeWidgetItem(0) self.deviceItem.setText(0,i18n("Device")) self.filesView.addTopLevelItem(self.deviceItem) vlayout.addWidget(self.toolbar) vlayout.addWidget(self.filesView) widget.setLayout(vlayout) self.setWidget(widget)
def convert(name, editor, to_collapse): ti = QtWidgets.QTreeWidgetItem() ti.setText(0, name.name) ti.setIcon(0, QtGui.QIcon(name.icon)) name.block = editor.document().findBlockByNumber(name.line) ti.setData(0, QtCore.Qt.UserRole, name) block_data = name.block.userData() if block_data is None: block_data = TextBlockUserData() name.block.setUserData(block_data) block_data.tree_item = ti if to_collapse is not None and \ TextBlockHelper.get_fold_trigger_state(name.block): to_collapse.append(ti) for ch in name.children: ti_ch, to_collapse = convert(ch, editor, to_collapse) if ti_ch: ti.addChild(ti_ch) return ti, to_collapse
def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(933, 539) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(":/icons/Preferences-system.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) Dialog.setWindowIcon(icon) self.verticalLayout = QtWidgets.QVBoxLayout(Dialog) self.verticalLayout.setObjectName("verticalLayout") self.horizontalLayout = QtWidgets.QHBoxLayout() self.horizontalLayout.setContentsMargins(-1, -1, 0, -1) self.horizontalLayout.setObjectName("horizontalLayout") self.categories = QtWidgets.QTreeWidget(Dialog) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.categories.sizePolicy().hasHeightForWidth()) self.categories.setSizePolicy(sizePolicy) self.categories.setMinimumSize(QtCore.QSize(250, 0)) self.categories.setObjectName("categories") item_0 = QtWidgets.QTreeWidgetItem(self.categories) icon = QtGui.QIcon.fromTheme("preferences-system") item_0.setIcon(0, icon) item_0 = QtWidgets.QTreeWidgetItem(self.categories) icon = QtGui.QIcon.fromTheme("accessories-text-editor") item_0.setIcon(0, icon) item_1 = QtWidgets.QTreeWidgetItem(item_0) icon = QtGui.QIcon.fromTheme("applications-graphics") item_1.setIcon(0, icon) item_1 = QtWidgets.QTreeWidgetItem(item_0) icon = QtGui.QIcon.fromTheme("network-wired") item_1.setIcon(0, icon) item_0 = QtWidgets.QTreeWidgetItem(self.categories) icon1 = QtGui.QIcon() icon1.addPixmap(QtGui.QPixmap(":/icons/interpreter-sys.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) item_0.setIcon(0, icon1) self.categories.header().setVisible(False) self.horizontalLayout.addWidget(self.categories) self.line = QtWidgets.QFrame(Dialog) self.line.setFrameShape(QtWidgets.QFrame.VLine) self.line.setFrameShadow(QtWidgets.QFrame.Sunken) self.line.setObjectName("line") self.horizontalLayout.addWidget(self.line) self.pages = QtWidgets.QStackedWidget(Dialog) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.pages.sizePolicy().hasHeightForWidth()) self.pages.setSizePolicy(sizePolicy) self.pages.setObjectName("pages") self.pageNotFound = QtWidgets.QWidget() self.pageNotFound.setObjectName("pageNotFound") self.gridLayout = QtWidgets.QGridLayout(self.pageNotFound) self.gridLayout.setObjectName("gridLayout") self.label = QtWidgets.QLabel(self.pageNotFound) self.label.setAlignment(QtCore.Qt.AlignCenter) self.label.setObjectName("label") self.gridLayout.addWidget(self.label, 0, 0, 1, 1) self.pages.addWidget(self.pageNotFound) self.horizontalLayout.addWidget(self.pages) self.verticalLayout.addLayout(self.horizontalLayout) self.buttons = QtWidgets.QDialogButtonBox(Dialog) self.buttons.setOrientation(QtCore.Qt.Horizontal) self.buttons.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok|QtWidgets.QDialogButtonBox.Reset|QtWidgets.QDialogButtonBox.RestoreDefaults) self.buttons.setObjectName("buttons") self.verticalLayout.addWidget(self.buttons) self.retranslateUi(Dialog) self.buttons.accepted.connect(Dialog.accept) self.buttons.rejected.connect(Dialog.reject) QtCore.QMetaObject.connectSlotsByName(Dialog)