From 2d7abbac2117e8c479e84a8767e2c08cb03846e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=92=AE=E6=8C=AF=E6=B1=9F?= <792918183@qq.com> Date: Wed, 26 Aug 2020 14:59:48 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=B7=A6=E4=BE=A7?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=A0=8F=E4=B8=8A=E4=B8=8B=E6=96=87=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E5=8A=9F=E8=83=BD=20=E6=9B=B4=E6=96=B0=E5=B7=A6?= =?UTF-8?q?=E4=BE=A7=E6=96=87=E4=BB=B6=E6=A0=8F=E4=B8=8A=E4=B8=8B=E6=96=87?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E5=8A=9F=E8=83=BD=EF=BC=9A=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E5=8A=9F=E8=83=BDsas=E6=96=87=E4=BB=B6=E6=AD=A3=E5=B8=B8?= =?UTF-8?q?=E8=BF=90=E8=A1=8C=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyminer/pmapp.py | 128 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 122 insertions(+), 6 deletions(-) diff --git a/pyminer/pmapp.py b/pyminer/pmapp.py index 0d1bc783..927348e2 100644 --- a/pyminer/pmapp.py +++ b/pyminer/pmapp.py @@ -8,13 +8,16 @@ import webbrowser import qdarkstyle import os, sys import pandas as pd +import win32api +import pywintypes +import shutil # 导入PyQt5模块 from PyQt5.QtCore import QSize, pyqtSignal, QTimer, QRectF, Qt from PyQt5.QtWidgets import QApplication, QStyleFactory, QDesktopWidget, QMessageBox, QSplashScreen, QTreeWidgetItem, \ QListWidgetItem, QWidget, QHBoxLayout, QGridLayout, QLabel, QSpacerItem, QSizePolicy, \ QGraphicsDropShadowEffect, QListWidget, QGraphicsScene, QAbstractItemView, QTableWidgetItem, QGraphicsObject, \ - QGraphicsItem, QFileDialog, QSystemTrayIcon + QGraphicsItem, QFileDialog, QSystemTrayIcon, QInputDialog, QLineEdit from PyQt5.QtWidgets import QMainWindow, QAction, qApp, QMenu from PyQt5.QtGui import QIcon, QPixmap, QImage, QColor, QPainter, QPainterPath, QPen, QTextCursor, QBrush, QCursor @@ -119,6 +122,9 @@ QMessageBox QPushButton[text="Retry"] { QMessageBox QPushButton[text="Ignore"] { qproperty-text: "忽略"; } +QMessageBox::warning QPushButton[text="&No"] { + qproperty-text: "否"; +} """ @@ -418,16 +424,126 @@ class MyMainForm(QMainWindow, Ui_MainWindow): # ================================自定义功能函数========================= def openActionHandler(self): - print("打开功能的函数是openActionHandler") + ''' + 文件打开 + Returns: + ''' + self.fileIndex = self.treeView_files.selectedIndexes()[0] + #判断打开是否为文件夹 + self.checkDir = self.treeView_files.model.fileInfo(self.fileIndex).isDir() + if self.checkDir: + # 判断文件夹是否折叠 + if self.treeView_files.isExpanded(self.fileIndex): + self.treeView_files.collapse(self.fileIndex) + else: + self.treeView_files.expand(self.fileIndex) + else: + self.filePath = self.treeView_files.model.filePath(self.fileIndex) + try: + win32api.ShellExecute(0, 'open', self.filePath, '', '', 1) + except pywintypes.error: + QMessageBox.information(self, '信息', '无法打开此文件,需在外部指定文件打开方式,解决方法暂未找到') + def importActionHandler(self): - print("打开功能的函数是importActionHandler") + ''' + 文件导入 + Returns: + ''' + self.fileIndex = self.treeView_files.selectedIndexes()[0] + # 判断打开是否为文件夹 + self.checkDir = self.treeView_files.model.fileInfo(self.fileIndex).isDir() + if self.checkDir: + # 判断文件夹是否折叠 + if self.treeView_files.isExpanded(self.fileIndex): + self.treeView_files.collapse(self.fileIndex) + else: + self.treeView_files.expand(self.fileIndex) + else: + self.importFilePath = self.treeView_files.model.filePath(self.fileIndex) + if self.importFilePath.split('/')[-1].endswith(('xlsx')): + pass + elif self.importFilePath.split('/')[-1].endswith(('sav', 'zsav')): + pass + elif self.importFilePath.split('/')[-1].endswith(('sas7bdat')): + self.import_sas_form = io.ImportSasForm() + self.import_sas_form.file_path_init(self.importFilePath) + self.import_sas_form.signal_data_change.connect(self.slot_dataset_reload) # 接收信号 + self.import_sas_form.exec_() + elif self.importFilePath.split('/')[-1].endswith(('txt', 'csv', 'tsv')): + self.import_form = io.ImportForm() + self.import_form.file_path_init() + self.import_form.signal_data_change.connect(self.slot_dataset_reload) # 接收信号 + self.import_form.exec_() + else: + QMessageBox.warning(self, '信息', '格式不满足', QMessageBox.Yes) + def renameActionHandler(self): - print("打开功能的函数是renameActionHandler") + ''' + 文件重命名 + Returns: + ''' + self.fileIndex = self.treeView_files.selectedIndexes()[0] + # 判断打开是否为文件夹 + self.checkDir = self.treeView_files.model.fileInfo(self.fileIndex).isDir() + if self.checkDir: + self.oldFloderPath = self.treeView_files.model.filePath(self.fileIndex) + self.oldFloderPathList = self.oldFloderPath.split('/') + self.newFloderName, confirmPressed = QInputDialog.getText(self, '文件夹重命名', '新的文件夹名称:', QLineEdit.Normal, + self.oldFloderPathList[-1], + flags=Qt.WindowCloseButtonHint) + if confirmPressed and self.newFloderName != '': + self.oldFloderPathList[-1] = self.newFloderName + self.newFloderPath = '/'.join(self.oldFloderPathList) + try: + os.rename(self.oldFloderPath, self.newFloderPath) + except FileExistsError: + QMessageBox.warning(self, '警告', '当前路径已有同名文件夹,无法修改!') + else: + pass + else: + self.oldFilePath = self.treeView_files.model.filePath(self.fileIndex) + self.oldFilePathList = self.oldFilePath.split('/') + self.newFileName, confirmPressed = QInputDialog.getText(self, '文件重命名', '新的文件名:', QLineEdit.Normal, + self.oldFilePathList[-1], + flags=Qt.WindowCloseButtonHint) + if confirmPressed and self.newFileName != '': + self.oldFilePathList[-1] = self.newFileName + self.newFilePath = '/'.join(self.oldFilePathList) + try: + os.rename(self.oldFilePath, self.newFilePath) + except FileExistsError: + QMessageBox.warning(self, '警告', '当前路径已有同名文件,无法修改!') + else: + pass + def deleteActionHandler(self): - print("打开功能的函数是deleteActionHandler") + ''' + 文件or文件夹删除 + Returns: + ''' + self.fileIndex = self.treeView_files.selectedIndexes()[0] + # 判断打开是否为文件夹 + self.checkDir = self.treeView_files.model.fileInfo(self.fileIndex).isDir() + if self.checkDir: + self.floderPath = self.treeView_files.model.filePath(self.fileIndex) + reply = QMessageBox.warning(self, '删除文件夹', '是否删除文件夹:' + self.floderPath.split('/')[-1], + QMessageBox.Yes|QMessageBox.No, QMessageBox.No) + if reply == QMessageBox.Yes: + shutil.rmtree(self.floderPath) + else: + pass + else: + self.filePath = self.treeView_files.model.filePath(self.fileIndex) + reply = QMessageBox.warning(self, '删除文件', '是否删除文件:' + self.filePath.split('/')[-1], + QMessageBox.Yes | QMessageBox.No, QMessageBox.No) + if reply == QMessageBox.Yes: + os.remove(self.filePath) + else: + pass + def setting_check(self): setting_path = get_root_dir() + r'\settings.json' @@ -1297,4 +1413,4 @@ class MyMainForm(QMainWindow, Ui_MainWindow): print('jupyter_notebook_display:', e) def jupyter_log(self, msg): - self.slot_flush_console("info", "jupyter", msg) + self.slot_flush_console("info", "jupyter", msg) \ No newline at end of file -- Gitee From ef81ee741e1fc5f76b6d707d201f7f0e19247f1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=92=AE=E6=8C=AF=E6=B1=9F?= <792918183@qq.com> Date: Wed, 26 Aug 2020 15:02:18 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=96=B0=E5=A2=9Epywin32=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=20=E6=96=B0=E5=A2=9Epywin32=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 95a26b47..73c82dec 100644 --- a/requirements.txt +++ b/requirements.txt @@ -24,4 +24,5 @@ scipy==1.5.2 six==1.15.0 threadpoolctl==2.1.0 xlrd==1.2.0 -qtconsole==4.7.6 \ No newline at end of file +qtconsole==4.7.6 +pywin32==228 \ No newline at end of file -- Gitee