diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..85b4290 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +main/__pycache__/ diff --git a/tool/ConfigWidget.py b/main/ConfigWidget.py similarity index 99% rename from tool/ConfigWidget.py rename to main/ConfigWidget.py index 407e0e8..a8f140f 100644 --- a/tool/ConfigWidget.py +++ b/main/ConfigWidget.py @@ -1,5 +1,5 @@ from PyQt5.QtWidgets import * -from tool.FileConfig import * +from FileConfig import * class ConfigView(QWidget): diff --git a/tool/FileConfig.py b/main/FileConfig.py similarity index 70% rename from tool/FileConfig.py rename to main/FileConfig.py index 5bcd366..5db254d 100644 --- a/tool/FileConfig.py +++ b/main/FileConfig.py @@ -46,20 +46,22 @@ def checkConfig(config_file): return [access_key_id, access_key_secret, bucket_name, endpoint, upload_path, upload_domain] except Exception as e: print(e) + saveConfig(None) return None -def saveConfig(access_key_id, access_key_secret, bucket_name, endpoint, upload_path, upload_domain): +def saveConfig(access_key_id=None, access_key_secret=None, bucket_name=None, endpoint=None, upload_path=None, upload_domain=None): config_file = set_config_path() with open(config_file, 'w+') as file: - json_config = { - "OSS_ACCESS_KEY_ID": access_key_id, - "OSS_ACCESS_KEY_SECRET": access_key_secret, - "OSS_BUCKET": bucket_name, - "OSS_ENDPOINT": endpoint, - "UPLOAD_PATH": upload_path if upload_path[-1] == '/' else upload_path + '/', - "UPLOAD_DOMAIN": upload_domain if upload_domain[-1] == '/' else upload_domain + '/' - } - file.write(json.dumps(json_config)) \ No newline at end of file + if access_key_id is not None: + json_config = { + "OSS_ACCESS_KEY_ID": access_key_id, + "OSS_ACCESS_KEY_SECRET": access_key_secret, + "OSS_BUCKET": bucket_name, + "OSS_ENDPOINT": endpoint, + "UPLOAD_PATH": upload_path if upload_path[-1] == '/' else upload_path + '/', + "UPLOAD_DOMAIN": upload_domain if upload_domain[-1] == '/' else upload_domain + '/' + } + file.write(json.dumps(json_config)) \ No newline at end of file diff --git a/tool/QSSLoader.py b/main/QSSLoader.py similarity index 100% rename from tool/QSSLoader.py rename to main/QSSLoader.py diff --git a/tool/UploadTip.py b/main/UploadTip.py similarity index 94% rename from tool/UploadTip.py rename to main/UploadTip.py index 6e4e4b9..95c34a8 100644 --- a/tool/UploadTip.py +++ b/main/UploadTip.py @@ -7,7 +7,7 @@ from PyQt5.QtCore import QSize, Qt, QThread, pyqtSignal, pyqtSlot from PyQt5.QtWidgets import * from PyQt5 import QtCore from PyQt5.QtGui import QPixmap -from tool import FileConfig +import FileConfig import notify2 @@ -20,7 +20,7 @@ class UploadAction(QThread): with open(FileConfig.set_config_path(), 'r') as file: config = json.load(file) except Exception as e: - print(e) + print(e,'UploadTip') self.status.emit(False) self.filepath = filepath @@ -154,9 +154,10 @@ class UploadTip(QWidget): mimeData = clipboard.mimeData() if mimeData.hasImage(): + import uuid # 根据时间设置图片文件名 - file_name = time.strftime('%Y-%m-%d-%H%M%S', time.localtime()) + '.png' + file_name = str(uuid.uuid4())[:5] +'-'+time.strftime('%Y-%m-%d-%H%M%S', time.localtime())+ '.png' # 将图片保存到指定位置 self.restore_path = '/tmp/' + file_name clipboard.pixmap().save(self.restore_path, 'PNG') @@ -164,8 +165,12 @@ class UploadTip(QWidget): # print(restore_path) self.setImage(self.restore_path) elif mimeData.hasText(): - self.restore_path = clipboard.text() - self.setImage(self.restore_path) + try: + self.restore_path = clipboard.text() + self.setImage(self.restore_path) + except Exception as e: + print('目录不是图片!') + print("pasted from clipboard") # 设置点击事件的信号传递 diff --git a/main/__main__.py b/main/__main__.py index cebbf53..af81bca 100644 --- a/main/__main__.py +++ b/main/__main__.py @@ -4,9 +4,9 @@ from PyQt5.QtWidgets import * from PyQt5.QtGui import * from PyQt5.QtCore import Qt, QSize -from tool.UploadTip import UploadTip -from tool.ConfigWidget import ConfigView -from tool import QSSLoader +from UploadTip import UploadTip +from ConfigWidget import ConfigView +import QSSLoader class MainWindow(QWidget): def __init__(self): @@ -53,8 +53,8 @@ class MainWindow(QWidget): self.listWidget.addItem(self.upload_item) self.listWidget.addItem(self.set_item) - upload_widget = UploadTip() config_widget = ConfigView() + upload_widget = UploadTip() self.stackedWidget.addWidget(upload_widget) self.stackedWidget.addWidget(config_widget) diff --git a/tool/__init__.py b/tool/__init__.py deleted file mode 100644 index e69de29..0000000