我们从Python开源项目中,提取了以下25个代码示例,用于说明如何使用PyQt5.QtWidgets.QTreeWidget()。
def setupUi(self, Window): Window.setObjectName("Window") Window.resize(800, 600) self.centralwidget = QtWidgets.QWidget(Window) self.centralwidget.setObjectName("centralwidget") self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.centralwidget) self.verticalLayout_2.setContentsMargins(-1, 4, -1, 4) self.verticalLayout_2.setObjectName("verticalLayout_2") self.webView = QtWebKitWidgets.QWebView(self.centralwidget) self.webView.setUrl(QtCore.QUrl("http://qt.nokia.com/")) self.webView.setObjectName("webView") self.verticalLayout_2.addWidget(self.webView) Window.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(Window) self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 27)) self.menubar.setObjectName("menubar") Window.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(Window) self.statusbar.setObjectName("statusbar") Window.setStatusBar(self.statusbar) self.dockWidget = QtWidgets.QDockWidget(Window) self.dockWidget.setAllowedAreas(QtCore.Qt.LeftDockWidgetArea|QtCore.Qt.RightDockWidgetArea) self.dockWidget.setObjectName("dockWidget") self.dockWidgetContents = QtWidgets.QWidget() self.dockWidgetContents.setObjectName("dockWidgetContents") self.verticalLayout = QtWidgets.QVBoxLayout(self.dockWidgetContents) self.verticalLayout.setContentsMargins(4, 4, 4, 4) self.verticalLayout.setObjectName("verticalLayout") self.treeWidget = QtWidgets.QTreeWidget(self.dockWidgetContents) self.treeWidget.setObjectName("treeWidget") self.treeWidget.headerItem().setText(0, "1") self.treeWidget.header().setVisible(False) self.verticalLayout.addWidget(self.treeWidget) self.dockWidget.setWidget(self.dockWidgetContents) Window.addDockWidget(QtCore.Qt.DockWidgetArea(1), self.dockWidget) self.retranslateUi(Window) QtCore.QMetaObject.connectSlotsByName(Window)
def main(): app = QApplication (sys.argv) tree = QTreeWidget () headerItem = QTreeWidgetItem() item = QTreeWidgetItem() for i in range(3): parent = QTreeWidgetItem(tree) parent.setText(0, "Parent {}".format(i)) parent.setFlags(parent.flags() | Qt.ItemIsTristate | Qt.ItemIsUserCheckable) for x in range(5): child = QTreeWidgetItem(parent) child.setFlags(child.flags() | Qt.ItemIsUserCheckable) child.setText(0, "Child {}".format(x)) child.setCheckState(0, Qt.Unchecked) tree.show() sys.exit(app.exec_())
def OnCreate(self, form): '''Called when the plugin form is created''' self.parent = self.FormToPyQtWidget(form) self.tree = QtWidgets.QTreeWidget() self.tree.setColumnCount(len(self.cols.names)) self.tree.setHeaderLabels(self.cols.names) self.tree.itemDoubleClicked.connect(self.dblclick) layout = QtWidgets.QVBoxLayout() layout.addWidget(self.tree) layout.setSpacing(0) layout.setContentsMargins(0, 0, 0, 0) self.populate_tree() self.tree.setColumnWidth(0, 512) for index in xrange(6, len(self.cols.names)): self.tree.setColumnWidth(index, 32) self.tree.setAlternatingRowColors(True) self.parent.setLayout(layout)
def setupUi(self, Master): Master.setObjectName("Master") Master.resize(718, 477) self.verticalLayout = QtWidgets.QVBoxLayout(Master) self.verticalLayout.setObjectName("verticalLayout") self.splitter = QtWidgets.QSplitter(Master) self.splitter.setOrientation(QtCore.Qt.Vertical) self.splitter.setObjectName("splitter") self.tab_widget = QtWidgets.QTabWidget(self.splitter) self.tab_widget.setObjectName("tab_widget") self.docker = QtWidgets.QDockWidget(self.splitter) self.docker.setObjectName("docker") self.docker.setAllowedAreas(QtCore.Qt.BottomDockWidgetArea) self.log_widget = QtWidgets.QTreeWidget(self.docker) self.log_widget.setHeaderItem(QtWidgets.QTreeWidgetItem(["date", "origin", "type", "message"])) self.docker.setWidget(self.log_widget) self.verticalLayout.addWidget(self.splitter) self.tab_widget.setCurrentIndex(-1) QtCore.QMetaObject.connectSlotsByName(Master) Master.setWindowTitle("IDASec")
def setupUi(self, Form): Form.setObjectName("Form") Form.resize(241, 367) self.gridLayout = QtWidgets.QGridLayout(Form) self.gridLayout.setSpacing(0) self.gridLayout.setObjectName("gridLayout") self.label = QtWidgets.QLabel(Form) self.label.setObjectName("label") self.gridLayout.addWidget(self.label, 0, 0, 1, 3) self.itemTree = QtWidgets.QTreeWidget(Form) self.itemTree.setObjectName("itemTree") self.itemTree.headerItem().setText(0, "1") self.itemTree.header().setVisible(False) self.gridLayout.addWidget(self.itemTree, 1, 0, 1, 3) self.label_2 = QtWidgets.QLabel(Form) self.label_2.setObjectName("label_2") self.gridLayout.addWidget(self.label_2, 2, 0, 1, 3) self.formatList = QtWidgets.QListWidget(Form) self.formatList.setObjectName("formatList") self.gridLayout.addWidget(self.formatList, 3, 0, 1, 3) self.exportBtn = QtWidgets.QPushButton(Form) self.exportBtn.setObjectName("exportBtn") self.gridLayout.addWidget(self.exportBtn, 6, 1, 1, 1) self.closeBtn = QtWidgets.QPushButton(Form) self.closeBtn.setObjectName("closeBtn") self.gridLayout.addWidget(self.closeBtn, 6, 2, 1, 1) self.paramTree = ParameterTree(Form) self.paramTree.setObjectName("paramTree") self.paramTree.headerItem().setText(0, "1") self.paramTree.header().setVisible(False) self.gridLayout.addWidget(self.paramTree, 5, 0, 1, 3) self.label_3 = QtWidgets.QLabel(Form) self.label_3.setObjectName("label_3") self.gridLayout.addWidget(self.label_3, 4, 0, 1, 3) self.copyBtn = QtWidgets.QPushButton(Form) self.copyBtn.setObjectName("copyBtn") self.gridLayout.addWidget(self.copyBtn, 6, 0, 1, 1) self.retranslateUi(Form) QtCore.QMetaObject.connectSlotsByName(Form)
def setupUi(self, DownloaderDlg): DownloaderDlg.setObjectName("DownloaderDlg") DownloaderDlg.resize(524, 443) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(DownloaderDlg.sizePolicy().hasHeightForWidth()) DownloaderDlg.setSizePolicy(sizePolicy) self.downloads_buttonBox = QtWidgets.QDialogButtonBox(DownloaderDlg) self.downloads_buttonBox.setGeometry(QtCore.QRect(350, 400, 161, 32)) self.downloads_buttonBox.setOrientation(QtCore.Qt.Horizontal) self.downloads_buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Close | QtWidgets.QDialogButtonBox.Ok) self.downloads_buttonBox.setCenterButtons(False) self.downloads_buttonBox.setObjectName("downloads_buttonBox") self.downloads_treeWidget = QtWidgets.QTreeWidget(DownloaderDlg) self.downloads_treeWidget.setGeometry(QtCore.QRect(10, 10, 501, 381)) self.downloads_treeWidget.setObjectName("downloads_treeWidget") self.downloads_treeWidget.headerItem().setText(0, "1") self.statusLabel = QtWidgets.QLabel(DownloaderDlg) self.statusLabel.setGeometry(QtCore.QRect(20, 400, 321, 31)) self.statusLabel.setText("") self.statusLabel.setObjectName("statusLabel") self.retranslateUi(DownloaderDlg) self.downloads_buttonBox.accepted.connect(DownloaderDlg.accept) self.downloads_buttonBox.rejected.connect(DownloaderDlg.reject) QtCore.QMetaObject.connectSlotsByName(DownloaderDlg)
def setupUi(self, GroupWidget): GroupWidget.setObjectName("GroupWidget") GroupWidget.resize(640, 478) self.verticalLayout = QtWidgets.QVBoxLayout(GroupWidget) self.verticalLayout.setContentsMargins(0, 0, 0, 0) self.verticalLayout.setObjectName("verticalLayout") self.tree_groups = QtWidgets.QTreeWidget(GroupWidget) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.tree_groups.sizePolicy().hasHeightForWidth()) self.tree_groups.setSizePolicy(sizePolicy) self.tree_groups.setVerticalScrollMode(QtWidgets.QAbstractItemView.ScrollPerPixel) self.tree_groups.setRootIsDecorated(True) self.tree_groups.setAnimated(True) self.tree_groups.setObjectName("tree_groups") self.tree_groups.header().setVisible(False) self.verticalLayout.addWidget(self.tree_groups) self.gridLayout = QtWidgets.QGridLayout() self.gridLayout.setObjectName("gridLayout") self.button_add_group = QtWidgets.QPushButton(GroupWidget) self.button_add_group.setObjectName("button_add_group") self.gridLayout.addWidget(self.button_add_group, 0, 1, 1, 1) self.button_remove_group = QtWidgets.QPushButton(GroupWidget) self.button_remove_group.setObjectName("button_remove_group") self.gridLayout.addWidget(self.button_remove_group, 1, 2, 1, 1) self.button_edit_group = QtWidgets.QPushButton(GroupWidget) self.button_edit_group.setObjectName("button_edit_group") self.gridLayout.addWidget(self.button_edit_group, 1, 1, 1, 1) self.verticalLayout.addLayout(self.gridLayout) self.verticalLayout.setStretch(0, 1) self.retranslateUi(GroupWidget) QtCore.QMetaObject.connectSlotsByName(GroupWidget)
def __init__(self): super().__init__("Sheets") # Create main widget for content and layout of Dockwidget self.mainWidget = QWidget() self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) self.mainWidgetLayout = QGridLayout(self.mainWidget) self.mainWidgetLayout.setSizeConstraint(QGridLayout.SetDefaultConstraint) # - Create frame for button and entry self.newSheetWidget = QWidget(self.mainWidget) self.newSheetWidget.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) self.newSheetWidgetLayout = QFormLayout(self.newSheetWidget) self.newSheetWidgetLayout.setContentsMargins(0, 0, 0, 0) self.newSheetButton = QPushButton(self.newSheetWidget) self.newSheetButton.setText("Create") self.newSheetButton.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed) self.newSheetWidgetLayout.setWidget(0, QFormLayout.LabelRole, self.newSheetButton) self.newSheetLineedit = QLineEdit(self.newSheetWidget) #self.newSheetLineedit.setEditable(True) self.newSheetLineedit.setToolTip("Enter name for new sheet") self.newSheetLineedit.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed) self.newSheetWidgetLayout.setWidget(0, QFormLayout.FieldRole, self.newSheetLineedit) self.mainWidgetLayout.addWidget(self.newSheetWidget, 0, 0, 1, 1) # - Add worker treeview to content self.sheetTree = QTreeWidget(self.mainWidget) self.sheetTree.setColumnCount(1) self.sheetTree.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.mainWidgetLayout.addWidget(self.sheetTree, 1, 0, 1, 1) # Set dockwidget content to main widget self.setWidget(self.mainWidget)
def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(704, 545) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.gridLayout = QtWidgets.QGridLayout(self.centralwidget) self.gridLayout.setObjectName("gridLayout") self.splitter = QtWidgets.QSplitter(self.centralwidget) self.splitter.setOrientation(QtCore.Qt.Horizontal) self.splitter.setObjectName("splitter") self.treeWidget_InstructionInfo = QtWidgets.QTreeWidget(self.splitter) self.treeWidget_InstructionInfo.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers) self.treeWidget_InstructionInfo.setObjectName("treeWidget_InstructionInfo") self.treeWidget_InstructionInfo.headerItem().setText(0, "1") self.treeWidget_InstructionInfo.header().setVisible(False) self.textBrowser_RegisterInfo = QtWidgets.QTextBrowser(self.splitter) self.textBrowser_RegisterInfo.setObjectName("textBrowser_RegisterInfo") self.gridLayout.addWidget(self.splitter, 0, 0, 1, 1) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 704, 22)) self.menubar.setObjectName("menubar") self.menuFile = QtWidgets.QMenu(self.menubar) self.menuFile.setObjectName("menuFile") MainWindow.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.actionOpen = QtWidgets.QAction(MainWindow) self.actionOpen.setObjectName("actionOpen") self.actionSave = QtWidgets.QAction(MainWindow) self.actionSave.setObjectName("actionSave") self.actionSave_as_a_text_file = QtWidgets.QAction(MainWindow) self.actionSave_as_a_text_file.setObjectName("actionSave_as_a_text_file") self.menuFile.addAction(self.actionOpen) self.menuFile.addAction(self.actionSave) self.menubar.addAction(self.menuFile.menuAction()) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow)
def setLang(self, langName): lang_data = self.memoData['lang'][langName] for ui_name in lang_data.keys(): if ui_name in self.uiList.keys() and lang_data[ui_name] != '': ui_element = self.uiList[ui_name] # '' means no translation availdanle in that data file if isinstance(ui_element, (QtWidgets.QLabel, QtWidgets.QPushButton, QtWidgets.QAction, QtWidgets.QCheckBox) ): # uiType: QLabel, QPushButton, QAction(menuItem), QCheckBox ui_element.setText(lang_data[ui_name]) elif isinstance(ui_element, (QtWidgets.QGroupBox, QtWidgets.QMenu) ): # uiType: QMenu, QGroupBox ui_element.setTitle(lang_data[ui_name]) elif isinstance(ui_element, QtWidgets.QTabWidget): # uiType: QTabWidget tabCnt = ui_element.count() tabNameList = lang_data[ui_name].split(';') if len(tabNameList) == tabCnt: for i in range(tabCnt): if tabNameList[i] != '': ui_element.setTabText(i,tabNameList[i]) elif isinstance(ui_element, QtWidgets.QComboBox): # uiType: QComboBox itemCnt = ui_element.count() itemNameList = lang_data[ui_name].split(';') ui_element.clear() ui_element.addItems(itemNameList) elif isinstance(ui_element, QtWidgets.QTreeWidget): # uiType: QTreeWidget labelCnt = ui_element.headerItem().columnCount() labelList = lang_data[ui_name].split(';') ui_element.setHeaderLabels(labelList) elif isinstance(ui_element, QtWidgets.QTableWidget): # uiType: QTableWidget colCnt = ui_element.columnCount() headerList = lang_data[ui_name].split(';') cur_table.setHorizontalHeaderLabels( headerList ) elif isinstance(ui_element, (str, unicode) ): # uiType: string for msg self.uiList[ui_name] = lang_data[ui_name]
def __init__(self): super().__init__("Workers") # Create main widget for content and layout of Dockwidget self.mainWidget = QWidget() self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) self.mainWidgetLayout = QGridLayout(self.mainWidget) self.mainWidgetLayout.setSizeConstraint(QGridLayout.SetDefaultConstraint) # - Create frame for button and entry self.newConnWidget = QWidget(self.mainWidget) self.newConnWidget.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) self.newConnWidgetLayout = QFormLayout(self.newConnWidget) self.newConnWidgetLayout.setContentsMargins(0, 0, 0, 0) self.newConnButton = QPushButton(self.newConnWidget) self.newConnButton.setText("Connect") self.newConnButton.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed) self.newConnWidgetLayout.setWidget(0, QFormLayout.LabelRole, self.newConnButton) self.newConnCombobox = QComboBox(self.newConnWidget) self.newConnCombobox.setEditable(True) self.newConnCombobox.setToolTip("Enter ip to connect to.\nEntry format: ip:port\n(if port is omitted, default is used)") self.newConnCombobox.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed) self.newConnWidgetLayout.setWidget(0, QFormLayout.FieldRole, self.newConnCombobox) self.mainWidgetLayout.addWidget(self.newConnWidget, 0, 0, 1, 1) # - Add monitor controls self.controlsWidget = QWidget(self.mainWidget) self.controlsWidget.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) self.controlsWidgetLayout = QGridLayout(self.controlsWidget) self.controlsWidgetLayout.setContentsMargins(0, 0, 0, 0) self.startRepeatButton = QPushButton(self.controlsWidget) self.startRepeatButton.setIcon(QIcon("resources/icons/control_play.png")) self.startRepeatButton.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed) self.startRepeatButton.setEnabled(False) self.controlsWidgetLayout.addWidget(self.startRepeatButton, 0, 0, 1, 1) self.stopButton = QPushButton(self.controlsWidget) self.stopButton.setIcon(QIcon("resources/icons/control_stop.png")) self.stopButton.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed) self.stopButton.setEnabled(False) self.controlsWidgetLayout.addWidget(self.stopButton, 0, 1, 1, 1) self.controlsSpacer = QSpacerItem(20, 40, QSizePolicy.Expanding, QSizePolicy.Fixed) self.controlsWidgetLayout.addItem(self.controlsSpacer, 0, 2, 1, 1) self.mainWidgetLayout.addWidget(self.controlsWidget, 1, 0, 1, 1) # - Add worker treeview to content self.workerTree = QTreeWidget(self.mainWidget) self.workerTree.setColumnCount(1) self.workerTree.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.mainWidgetLayout.addWidget(self.workerTree, 2, 0, 1, 1) # Set dockwidget content to main widget self.setWidget(self.mainWidget)
def __init__(self): QWidget.__init__(self) self.main_vbox=QVBoxLayout() self.save_function=None self.setWindowIcon(QIcon_load("scan")) self.setWindowTitle(_("Dump File Selector")+" (https://www.gpvdm.com)") self.tab = QTreeWidget() self.tab.header().hide() #self.tab.setHeaderItem("Scan items") self.font = QFont() # self.font.setFamily('DejaVu Sans') # self.font.setBold(True) # self.font.setStyleHint(QFont.Monospace) # self.font.setFixedPitch(True) self.font.setPointSize(int(20)) self.tab.setFont(self.font) toolbar=QToolBar() toolbar.setIconSize(QSize(32, 32)) self.refresh = QAction(QIcon_load("view-refresh"), _("Refresh"), self) self.refresh.triggered.connect(self.callback_refresh) toolbar.addAction(self.refresh) self.main_vbox.addWidget(toolbar) self.main_vbox.addWidget(self.tab) self.setLayout(self.main_vbox) #okButton.clicked.connect(self.tree_apply_click) #cancelButton.clicked.connect(self.close) #self.tab.header().close() self.update() self.save() self.tab.itemChanged.connect(self.callback_tree_checked) self.tab.itemClicked.connect(self.tree_callback_clicked) return
def __init__(self, parent=None, mode=0): QtWidgets.QMainWindow.__init__(self, parent) #------------------------------ # class variables #------------------------------ self.version = '0.1' self.date = '2017.01.01' self.log = 'no version log in user class' self.help = 'no help guide in user class' self.uiList={} # for ui obj storage self.memoData = {} # key based variable data storage self.memoData['font_size_default'] = QtGui.QFont().pointSize() self.memoData['font_size'] = self.memoData['font_size_default'] self.memoData['last_export'] = '' self.memoData['last_import'] = '' self.name = self.__class__.__name__ self.location = '' if getattr(sys, 'frozen', False): # frozen - cx_freeze self.location = sys.executable else: # unfrozen self.location = os.path.realpath(sys.modules[self.__class__.__module__].__file__) self.iconPath = os.path.join(os.path.dirname(self.location),'icons',self.name+'.png') self.iconPix = QtGui.QPixmap(self.iconPath) self.icon = QtGui.QIcon(self.iconPath) self.fileType='.{0}_EXT'.format(self.name) #------------------------------ # core function variable #------------------------------ self.qui_core_dict = { 'vbox': 'QVBoxLayout','hbox':'QHBoxLayout','grid':'QGridLayout', 'form':'QFormLayout', 'split': 'QSplitter', 'grp':'QGroupBox', 'tab':'QTabWidget', 'btn':'QPushButton', 'btnMsg':'QPushButton', 'label':'QLabel', 'input':'QLineEdit', 'check':'QCheckBox', 'choice':'QComboBox', 'txt': 'QTextEdit', 'list': 'QListWidget', 'tree': 'QTreeWidget', 'table': 'QTableWidget', 'space': 'QSpacerItem', 'menu' : 'QMenu', 'menubar' : 'QMenuBar', } self.qui_user_dict = {}
def __init__(self, parent=None, mode=0): super_class.__init__(self, parent) #------------------------------ # class variables #------------------------------ self.version = "0.1" self.date = '2017.01.01' self.log = 'no version log in user class' self.help = 'no help guide in user class' self.uiList={} # for ui obj storage self.memoData = {} # key based variable data storage self.memoData['font_size_default'] = QtGui.QFont().pointSize() self.memoData['font_size'] = self.memoData['font_size_default'] self.memoData['last_export'] = '' self.memoData['last_import'] = '' self.location = "" if getattr(sys, 'frozen', False): # frozen - cx_freeze self.location = sys.executable else: # unfrozen self.location = os.path.realpath(sys.modules[self.__class__.__module__].__file__) self.name = self.__class__.__name__ self.iconPath = os.path.join(os.path.dirname(self.location),'icons',self.name+'.png') self.iconPix = QtGui.QPixmap(self.iconPath) self.icon = QtGui.QIcon(self.iconPath) self.fileType='.{0}_EXT'.format(self.name) #------------------------------ # core function variable #------------------------------ self.qui_core_dict = { 'vbox': 'QVBoxLayout','hbox':'QHBoxLayout','grid':'QGridLayout', 'form':'QFormLayout', 'split': 'QSplitter', 'grp':'QGroupBox', 'tab':'QTabWidget', 'btn':'QPushButton', 'btnMsg':'QPushButton', 'label':'QLabel', 'input':'QLineEdit', 'check':'QCheckBox', 'choice':'QComboBox', 'txt': 'QTextEdit', 'list': 'QListWidget', 'tree': 'QTreeWidget', 'table': 'QTableWidget', 'space': 'QSpacerItem', 'menu' : 'QMenu', 'menubar' : 'QMenuBar', } self.qui_user_dict = {} #------------------------------
def __init__(self, parent=None, mode=0): super_class.__init__(self, parent) #------------------------------ # class variables #------------------------------ self.version="0.1" self.help = "How to Use:\n1. Put source info in\n2. Click Process button\n3. Check result output\n4. Save memory info into a file." self.uiList={} # for ui obj storage self.memoData = {} # key based variable data storage self.location = "" if getattr(sys, 'frozen', False): # frozen - cx_freeze self.location = sys.executable else: # unfrozen self.location = os.path.realpath(sys.modules[self.__class__.__module__].__file__) self.name = self.__class__.__name__ self.iconPath = os.path.join(os.path.dirname(self.location),'icons',self.name+'.png') self.iconPix = QtGui.QPixmap(self.iconPath) self.icon = QtGui.QIcon(self.iconPath) self.fileType='.{0}_EXT'.format(self.name) #------------------------------ # core function variable #------------------------------ self.qui_core_dict = { 'vbox': 'QVBoxLayout','hbox':'QHBoxLayout','grid':'QGridLayout', 'form':'QFormLayout', 'split': 'QSplitter', 'grp':'QGroupBox', 'tab':'QTabWidget', 'btn':'QPushButton', 'btnMsg':'QPushButton', 'label':'QLabel', 'input':'QLineEdit', 'check':'QCheckBox', 'choice':'QComboBox', 'txt': 'QTextEdit', 'list': 'QListWidget', 'tree': 'QTreeWidget', 'table': 'QTableWidget', 'space': 'QSpacerItem', } self.qui_user_dict = {} #------------------------------
def qui(self, ui_list_string, parentObject_string='', opt=''): # pre-defined user short name syntax type_dict = { 'vbox': 'QVBoxLayout','hbox':'QHBoxLayout','grid':'QGridLayout', 'form':'QFormLayout', 'split': 'QSplitter', 'grp':'QGroupBox', 'tab':'QTabWidget', 'btn':'QPushButton', 'btnMsg':'QPushButton', 'label':'QLabel', 'input':'QLineEdit', 'check':'QCheckBox', 'choice':'QComboBox', 'txt': 'QTextEdit', 'list': 'QListWidget', 'tree': 'QTreeWidget', 'table': 'QTableWidget', 'space': 'QSpacerItem', } # get ui_list, creation or existing ui object ui_list = [x.strip() for x in ui_list_string.split('|')] for i in range(len(ui_list)): if ui_list[i] in self.uiList: # - exisiting object ui_list[i] = self.uiList[ui_list[i]] else: # - string creation: # get part info partInfo = ui_list[i].split(';',1) uiName = partInfo[0].split('@')[0] uiType = uiName.rsplit('_',1)[-1] if uiType in type_dict: uiType = type_dict[uiType] # set quickUI string format ui_list[i] = partInfo[0]+';'+uiType if len(partInfo)==1: # give empty button and label a place holder name if uiType in ('btn', 'btnMsg', 'QPushButton','label', 'QLabel'): ui_list[i] = partInfo[0]+';'+uiType + ';'+uiName elif len(partInfo)==2: ui_list[i]=ui_list[i]+";"+partInfo[1] # get parentObject or exisiting object parentObject = parentObject_string if parentObject in self.uiList: parentObject = self.uiList[parentObject] # process quickUI self.quickUI(ui_list, parentObject, opt)
def __init__(self, fpath): super(JsonView, self).__init__() self.find_box = None self.tree_widget = None self.text_to_titem = TextToTreeItem() self.find_str = "" self.found_titem_list = [] self.found_idx = 0 jfile = open(fpath) jdata = json.load(jfile, object_pairs_hook=collections.OrderedDict) # Find UI find_layout = self.make_find_ui() # Tree self.tree_widget = QtWidgets.QTreeWidget() self.tree_widget.setHeaderLabels(["Key", "Value"]) self.tree_widget.header().setSectionResizeMode(QtWidgets.QHeaderView.Stretch) root_item = QtWidgets.QTreeWidgetItem(["Root"]) self.recurse_jdata(jdata, root_item) self.tree_widget.addTopLevelItem(root_item) # Add table to layout layout = QtWidgets.QHBoxLayout() layout.addWidget(self.tree_widget) # Group box gbox = QtWidgets.QGroupBox(fpath) gbox.setLayout(layout) layout2 = QtWidgets.QVBoxLayout() layout2.addLayout(find_layout) layout2.addWidget(gbox) self.setLayout(layout2)