def testConn(self): url = self.lineEdit.text() passWord = self.lineEdit_2.text() try: if self.checkBox.isChecked(): useRSA = '是' else: useRSA = '否' if self.comboBox.currentText() == "PHP": r = phpCore.TestConn(url, passWord, useRSA) else: r = jspCore.TestConn(url, passWord) self.textBrowser.setText('连接成功!\n' + r) except Exception as e: self.textBrowser.setText('连接失败!\n' + str(Exception(e)))
def displayShell(self): try: url = self.mainWindow.shellTableWidget.item( self.mainWindow.row_num, 0).text() password = self.mainWindow.shellTableWidget.item( self.mainWindow.row_num, 2).text() useRSA = self.mainWindow.shellTableWidget.item( self.mainWindow.row_num, 6).text() script = self.mainWindow.shellTableWidget.item( self.mainWindow.row_num, 7).text() if script == 'JSP': r = jspCore.TestConn(url, password) else: r = phpCore.TestConn(url, password, useRSA) rdata = r.split('\n') QtWidgets.QMessageBox.about(self.mainWindow, "连接成功!", r) self.mainWindow.tabMaxIndex += 1 # tb是TabIndex中的元素 tb = self.mainWindow.tabMaxIndex self.mainWindow.tabIndex.append(tb) new_tab = QtWidgets.QWidget() self.gridLayout = QtWidgets.QGridLayout(new_tab) self.gridLayout.setObjectName("gridLayout") fileTableWidget = QtWidgets.QTableWidget(new_tab) fileTableWidget.setObjectName("fileTableWidget") fileTableWidget.setColumnCount(4) fileTableWidget.setSelectionBehavior( QtWidgets.QAbstractItemView.SelectRows) fileTableWidget.horizontalHeader().setSectionResizeMode( QtWidgets.QHeaderView.Stretch) item = QtWidgets.QTableWidgetItem() item.setText("名称") fileTableWidget.setHorizontalHeaderItem(0, item) item = QtWidgets.QTableWidgetItem() item.setText("日期") fileTableWidget.setHorizontalHeaderItem(1, item) item = QtWidgets.QTableWidgetItem() item.setText("大小") fileTableWidget.setHorizontalHeaderItem(2, item) item = QtWidgets.QTableWidgetItem() item.setText("属性") fileTableWidget.setHorizontalHeaderItem(3, item) fileTableWidget.horizontalHeader().setSectionResizeMode( 0, QtWidgets.QHeaderView.Interactive) fileTableWidget.setColumnWidth(0, 200) # 更新fileTableWidget if script == 'JSP': files = jspCore.scanDir(url, password, rdata[0] + '/').split('\n') else: files = phpCore.scanDir(url, password, rdata[0] + '/', useRSA).split('\n') files = list(filter(None, files)) self.updataTable(files, fileTableWidget) treeWidget = QtWidgets.QTreeWidget(new_tab) treeWidget.setObjectName("treeWidget") treeWidget.setStyle(QtWidgets.QStyleFactory.create("windows")) # tree信息初始化 # 根节点 self.root = QtWidgets.QTreeWidgetItem(treeWidget) if not rdata[1].endswith(':'): self.root.setText(0, rdata[1]) self.root.setIcon( 0, QIcon( os.path.dirname(os.path.realpath(sys.argv[0])) + '/Icons/default_root_folder_opened.svg')) else: # 处理windows路径 r = rdata[1].split(':')[:-1] for i in r: if i == rdata[0][0]: self.root.setText(0, i + ':/') self.root.setIcon( 0, QIcon( os.path.dirname(os.path.realpath(sys.argv[0])) + '/Icons/default_root_folder_opened.svg')) else: root = QtWidgets.QTreeWidgetItem(treeWidget) root.setText(0, i + ':/') root.setIcon( 0, QIcon( os.path.dirname(os.path.realpath(sys.argv[0])) + '/Icons/default_root_folder_opened.svg')) # 子节点 if rdata[0][1] != ':': folders = rdata[0][1:].split('/') else: # 处理windows folders = rdata[0][3:].split('/') itemStack = [self.root] for i in range(len(folders)): item = QtWidgets.QTreeWidgetItem(itemStack.pop()) item.setText(0, folders[i]) if i == len(folders) - 1: item.setIcon( 0, QIcon( os.path.dirname(os.path.realpath(sys.argv[0])) + '/Icons/default_folder.svg')) else: item.setIcon( 0, QIcon( os.path.dirname(os.path.realpath(sys.argv[0])) + '/Icons/default_folder_opened.svg')) itemStack.append(item) # 更新节点 self.updateTree([ url, password, treeWidget, fileTableWidget, rdata, useRSA, script, 1, item ]) treeWidget.clicked.connect(lambda: self.updateTree([ url, password, treeWidget, fileTableWidget, rdata, useRSA, script, 0 ])) # 处理展开的Icon treeWidget.itemExpanded.connect(self.treeExpaned) treeWidget.itemCollapsed.connect(self.treeCollapsed) treeWidget.header().setVisible(False) treeWidget.header().setHighlightSections(False) treeWidget.expandAll() self.label = QtWidgets.QLabel(new_tab) self.label.setMaximumSize(QtCore.QSize(91, 61)) self.label.setTextFormat(QtCore.Qt.RichText) self.label.setScaledContents(False) self.label.setObjectName("label") self.label_2 = QtWidgets.QLabel(new_tab) self.label_2.setMaximumSize(QtCore.QSize(91, 61)) self.label_2.setTextFormat(QtCore.Qt.RichText) self.label_2.setScaledContents(False) self.label_2.setObjectName("label_2") self.gridLayout.addWidget(self.label, 1, 0) self.gridLayout.addWidget(self.label_2, 1, 1) self.gridLayout.addWidget(treeWidget, 2, 0) self.gridLayout.addWidget(fileTableWidget, 2, 1) # 调整比例 self.gridLayout.setColumnStretch(0, 1) self.gridLayout.setColumnStretch(1, 2) self.label.setText( "<html><head/><body><p align=\"center\"><span style=\" font-size:16pt; font-weight:600;\">目录列表</span></p></body></html>" ) self.label_2.setText( "<html><head/><body><p align=\"center\"><span style=\" font-size:16pt; font-weight:600;\">文件列表</span></p></body></html>" ) self.mainWindow.tabWidget.addTab( new_tab, self.mainWindow.shellTableWidget.item(self.mainWindow.row_num, 1).text()) self.mainWindow.horizontalLayout.addWidget( self.mainWindow.tabWidget) xbutton = QtWidgets.QPushButton("x") xbutton.setFixedSize(16, 16) xbutton.clicked.connect(lambda: self.mainWindow.delTab(tb)) # 用index方法找到标签页的相对位置 self.mainWindow.tabWidget.tabBar().setTabButton( self.mainWindow.tabIndex.index(tb), self.mainWindow.tabWidget.tabBar().RightSide, xbutton) self.mainWindow.tabWidget.setCurrentIndex( self.mainWindow.tabIndex.index(tb)) # 右键菜单 fileTableWidget.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) fileTableWidget.customContextMenuRequested.connect( partial(self.generateFileListMenu, [ url, password, treeWidget, fileTableWidget, rdata, item, useRSA, script ])) # 双击事件 fileTableWidget.doubleClicked.connect( partial(self.fileTableDoubleClicked, [ url, password, treeWidget, fileTableWidget, rdata, item, useRSA, script ])) except Exception as e: QtWidgets.QMessageBox.about(self.mainWindow, "连接失败!", str(Exception(e)))