From 95bc38cc39014ffa2b81f454624c69f13054a46f Mon Sep 17 00:00:00 2001 From: liyp Date: Tue, 26 Apr 2022 21:10:49 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=8A=9F=E8=83=BD=E5=AE=8C?= =?UTF-8?q?=E6=88=90=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +-- main/main.py | 5 +-- utils/CreateConfigure.py | 91 +++++++++++++++++++++------------------- view/ImportantView.py | 8 ++-- view/SettingWidget.py | 35 ++++++++++++++++ view/ToDoItem.py | 46 ++++++++++---------- view/ToDoListView.py | 44 ++++++++++++------- view/UserLabel.py | 56 ++++--------------------- 8 files changed, 150 insertions(+), 141 deletions(-) create mode 100644 view/SettingWidget.py diff --git a/README.md b/README.md index 4a2fd21..3f50e9d 100644 --- a/README.md +++ b/README.md @@ -7,13 +7,11 @@ - [x] 待办事项列表布局实现 - [x] 添加待办事项列表 - [x] 待办事项列表功能实现 -- [ ] 待办事项列表右键功能实现 +- [x] 待办事项列表右键功能实现 - [x] 右边`QStackLayout`布局 - [x] “我的一天”和“重要”布局实现 - [x] 添加的通用布局实现 - [x] 更换主题功能 - [ ] 登录`nextcloud`及其他`WebDav`和同步功能 -- [ ] 添加“设置”功能 -- [ ] 拖拽排序功能 - [ ] 待办事项的笔记功能 -- [ ] 最小化到任务栏功能 \ No newline at end of file +- [x] 最小化到任务栏功能 \ No newline at end of file diff --git a/main/main.py b/main/main.py index d1222b8..815ba66 100644 --- a/main/main.py +++ b/main/main.py @@ -6,6 +6,7 @@ from PyQt5.QtCore import Qt, pyqtSignal import configparser from utils.BasicUtils import get_todo_list, remove_todo_list, change_value, read_ini, set_exit_status +from utils.CreateConfigure import CreateConfigure from utils.CreateToDo import CreateToDo from utils.QSSLoader import QSSLoader from view.ImportantView import Important @@ -23,6 +24,7 @@ class MainWidget(QWidget): def __init__(self): super(MainWidget, self).__init__() self.user_label = User() + self.create_config = CreateConfigure() # 主布局,左右两侧 layout = QHBoxLayout() # 子布局,左边的部分 @@ -88,8 +90,6 @@ class MainWidget(QWidget): self.load_item(load[0], load[1], load[3]) # self.system_listWidget.addScrollBarWidget(False) - # todo 仔细研究右键菜单 - def myListWidgetContext(self, position): if self.system_listWidget.currentRow() > 1: @@ -351,7 +351,6 @@ class MainWindow(QWidget): event.ignore() - if __name__ == "__main__": app = QApplication(sys.argv) main = MainWindow() diff --git a/utils/CreateConfigure.py b/utils/CreateConfigure.py index ec2fbc5..f52fc96 100644 --- a/utils/CreateConfigure.py +++ b/utils/CreateConfigure.py @@ -1,13 +1,30 @@ import configparser -import platform import os -from utils import BasicUtils # todo : 用来创建软件的配置信息 from utils.BasicUtils import return_work_dir class CreateConfigure: + + def __init__(self): + config_file = return_work_dir() + 'PyQtToDoList.ini' + config = configparser.ConfigParser() + if not os.path.exists(config_file): + options = { + 'webdav_hostname': "None", + 'webdav_login': "None", + 'webdav_password': "None", + 'type': "None" + } + + config['Account'] = options + # todo 解决保存配置文件的问题 + config['System'] = {'exitStatus': 'None'} + + with open(config_file, 'w') as f: + config.write(f) + """ :param login_type : 登录方式 有 NextCloud、JianGuoYun、WebDav :param webdav_login : 登录用户名 @@ -15,52 +32,40 @@ class CreateConfigure: :param webdav_hostname : 服务地址 """ - def __init__(self, login_type, webdav_login, webdav_password, webdav_hostname=None): + def login(self, login_type, webdav_login, webdav_password, webdav_hostname=None): config_file = return_work_dir() + 'PyQtToDoList.ini' config = configparser.ConfigParser() - if not os.path.exists(config_file): - # print(config_file) - options = {} - if login_type == 'NextCloud': - webdav_hostname = webdav_hostname + '/' if webdav_hostname[-1] != '/' else webdav_hostname - options = { - 'webdav_hostname': webdav_hostname + "remote.php/dav/files/admin/", - 'webdav_login': webdav_login, - 'webdav_password': webdav_password, - 'type': login_type - } + config.read(config_file) + # if not os.path.exists(config_file): + print(config['Account']['type']) + if login_type == 'NextCloud': + webdav_hostname = webdav_hostname + '/' if webdav_hostname[-1] != '/' else webdav_hostname - elif login_type == 'JianGuoYun': - options = { - 'webdav_hostname': "https://dav.jianguoyun.com/dav/", - 'webdav_login': webdav_login, - 'webdav_password': webdav_password, - 'type': login_type + config['Account']['webdav_hostname'] = webdav_hostname + "remote.php/dav/files/admin/" + config['Account']['webdav_login'] = webdav_login + config['Account']['webdav_password'] = webdav_password + config['Account']['type'] = login_type - } - elif login_type == 'WebDav': - webdav_hostname = webdav_hostname + '/' if webdav_hostname[-1] != '/' else webdav_hostname - options = { - 'webdav_hostname': webdav_hostname, - 'webdav_login': webdav_login, - 'webdav_password': webdav_password, - 'type': login_type + elif login_type == 'JianGuoYun': + config['Account']['webdav_hostname'] = "https://dav.jianguoyun.com/dav/" + config['Account']['webdav_login'] = webdav_login + config['Account']['webdav_password'] = webdav_password + config['Account']['type'] = login_type - } - config['Account'] = options - config['System'] = {'exitStatus': 'None'} + elif login_type == 'WebDav': - with open(config_file, 'w') as f: - config.write(f) - print('create complete!', config_file) + webdav_hostname = webdav_hostname + '/' if webdav_hostname[-1] != '/' else webdav_hostname + config['Account']['webdav_hostname'] = webdav_hostname + config['Account']['webdav_login'] = webdav_login + config['Account']['webdav_password'] = webdav_password + config['Account']['type'] = login_type + + # todo 解决保存配置文件的问题 + config['System'] = {'exitStatus': 'None'} + print(config['System']['exitStatus']) + + with open(config_file, 'w') as f: + config.write(f) + print('create complete!', config_file) - # def return_config_file(self): - # if platform.system() == 'Linux': - # work_path = os.path.expandvars('$HOME') + '/.config/PyQtToDoList' - # if not os.path.exists(work_path): - # os.mkdir(work_path) - # return os.path.expandvars('$HOME') + '/.config/PyQtToDoList/PyQtToDoList.ini' - # elif platform.system() == 'Windows': - # return os.getcwd() + '/PyQtToDoList.ini' -# CreateConfigure('NextCloud', 'admin', '19990903@lyp', 'https://cloud.liyp.cc') diff --git a/view/ImportantView.py b/view/ImportantView.py index bc216a4..22a697e 100644 --- a/view/ImportantView.py +++ b/view/ImportantView.py @@ -264,13 +264,15 @@ class Important(QWidget): self.dialog.close() def mark_done(self, uid): - print('mark done:', uid) + # print('mark done:', uid) change_value(uid, 'done', True) time.sleep(0.5) self.refresh_action() self.update_signal.emit() def mark_important(self, uid): - print('mark important:', uid) + change_value(uid, 'isImportant', True) + # print('mark important:', uid) + self.refresh_action() + self.update_signal.emit() - pass diff --git a/view/SettingWidget.py b/view/SettingWidget.py new file mode 100644 index 0000000..1697bc5 --- /dev/null +++ b/view/SettingWidget.py @@ -0,0 +1,35 @@ +from PyQt5.QtCore import Qt, pyqtSignal +from PyQt5.QtGui import * +from PyQt5.QtWidgets import * + +from utils.BasicUtils import read_ini, set_exit_status + + +class SettingWidget(QWidget): + update_signal = pyqtSignal() + + def __init__(self): + super(SettingWidget, self).__init__() + self.setWindowTitle('设置') + self.resize(400, 300) + layout = QFormLayout() + self.setLayout(layout) + self.combo = QComboBox() + exit_status = read_ini('System', 'exitstatus') + + self.combo.addItem('最小化到托盘') + self.combo.addItem('退出程序') + index = 0 + if exit_status == 'Exit': + index = 1 + self.combo.setCurrentIndex(index) + self.combo.currentIndexChanged.connect(lambda: self.save_exit_status(self.combo.currentIndex())) + + layout.addRow('关闭窗口时', self.combo) + + # layout.addWidget(self.setting_widget) + + def save_exit_status(self, index): + print(index) + status = ['Mix', 'Exit'] + set_exit_status(status[index]) diff --git a/view/ToDoItem.py b/view/ToDoItem.py index 1abbb23..15fe1a1 100644 --- a/view/ToDoItem.py +++ b/view/ToDoItem.py @@ -42,28 +42,28 @@ class ToDoItem(QListWidgetItem): layout.addWidget(self.todo_label, 6) layout.addWidget(self.important_button, 2) - self.mark_icon.clicked.connect(lambda: self.set_done(uid)) - # print('', uid) - - self.important_button.clicked.connect(lambda: self.set_important(uid)) + # self.mark_icon.clicked.connect(lambda: self.set_done(uid)) + # # print('', uid) + # + # self.important_button.clicked.connect(lambda: self.set_important(uid)) # self.mark_icon.trans_signal.connect(self.set_done) + # + # def set_done(self, uid): + # # self.mark_icon.setIcon(QIcon(os.getcwd() + '/../images/finished.svg')) + # # time.sleep(0.2) + # change_value(uid, 'done', True) + # pass - def set_done(self, uid): - self.mark_icon.setIcon(QIcon(os.getcwd() + '/../images/finished.svg')) - time.sleep(0.2) - change_value(uid, 'done', True) - pass - - def set_myday(self, uid): - change_value(uid, 'done', True) - pass - - def set_important(self, uid): - # important = Important() - # important.load_important.emit() - # self.action.emit() - print('', uid) - - change_value(uid, 'isImportant', True) - # self.transaction.emit() - pass + # def set_myday(self, uid): + # change_value(uid, 'done', True) + # pass + # + # def set_important(self, uid): + # # important = Important() + # # important.load_important.emit() + # # self.action.emit() + # print('', uid) + # + # change_value(uid, 'isImportant', True) + # # self.transaction.emit() + # pass diff --git a/view/ToDoListView.py b/view/ToDoListView.py index ce611c1..0e972a5 100644 --- a/view/ToDoListView.py +++ b/view/ToDoListView.py @@ -1,4 +1,6 @@ import os +import time + from PyQt5.QtGui import * from PyQt5.QtWidgets import * from PyQt5.QtCore import Qt, pyqtSignal, QPropertyAnimation, QRect, QEasingCurve @@ -125,20 +127,22 @@ class ToDoList(QWidget): self.button_menu.addAction(label_action5) self.uid = uid - self.initUI() + self.refresh_action() # 右键菜单 self.todo_list.setContextMenuPolicy(Qt.CustomContextMenu) self.todo_list.customContextMenuRequested.connect(self.todo_list_context) - - def initUI(self): - # 读取配置文件添加Todo - # thread_action = ThreadAction() self.load_theme() - load_todo = get_todo(self.uid) - if load_todo: - for load in load_todo: - self.load_todo(load[0], load[1]) + # + # def initUI(self): + # # 读取配置文件添加Todo + # # thread_action = ThreadAction() + # self.todo_list.clear() + # + # load_todo = get_todo(self.uid) + # if load_todo: + # for load in load_todo: + # self.load_todo(load[0], load[1]) def load_theme(self): theme = str(load_value(self.uid, 'Theme')) @@ -157,13 +161,12 @@ class ToDoList(QWidget): # print('选中:' + count) def load_todo(self, name, uid): - todo_item = ToDoItem(name, uid) - todo_item.mark_icon.clicked.connect(lambda: self.mark_done(uid)) - todo_item.important_button.clicked.connect(lambda: self.mark_important(uid)) - # todo_item.mark_icon.trans_signal.connect(self.todo_list.clear()) + self.todo_item = ToDoItem(name, uid) + self.todo_item.mark_icon.clicked.connect(lambda: self.mark_done(uid)) + self.todo_item.important_button.clicked.connect(lambda: self.mark_important(uid)) - self.todo_list.addItem(todo_item) - self.todo_list.setItemWidget(todo_item, todo_item.widget) + self.todo_list.addItem(self.todo_item) + self.todo_list.setItemWidget(self.todo_item, self.todo_item.widget) def refresh_action(self): # self.my_day_list[] @@ -186,6 +189,8 @@ class ToDoList(QWidget): self.todo_list.setItemWidget(todo_item, todo_item.widget) self.add_todo.line_edit.clear() + self.refresh_action() + # self.initUI() def todo_list_context(self, position): # 设置右键菜单 @@ -239,7 +244,7 @@ class ToDoList(QWidget): self.update_signal.emit() # 重命名分组 - # todo : 复制重要代码 + def rename_item(self): self.dialog = QDialog() self.dialog.setWindowTitle('重命名') @@ -270,8 +275,15 @@ class ToDoList(QWidget): self.dialog.close() def mark_done(self, uid): + # print('uid:',uid) + self.todo_item.mark_icon.setIcon(QIcon(os.getcwd() + '/../images/finished.svg')) print('mark done:', uid) + + time.sleep(0.2) + self.todo_list.takeItem(self.todo_list.currentRow()) + # self.refresh_action() self.update_signal.emit() + self.refresh_action() def mark_important(self, uid): self.update_signal.emit() diff --git a/view/UserLabel.py b/view/UserLabel.py index 1f974be..af22716 100644 --- a/view/UserLabel.py +++ b/view/UserLabel.py @@ -1,34 +1,15 @@ -import os -import sys - -from PyQt5.QtCore import Qt +from PyQt5.QtCore import Qt, pyqtSignal from PyQt5.QtGui import * from PyQt5.QtWidgets import * import configparser from utils.BasicUtils import * from view.LoginWidget import LoginWidget - - -# class LoginWindow(QWidget): -# def __init__(self): -# super().__init__() -# layout = QVBoxLayout() -# self.setLayout(layout) -# self.setWindowTitle('登录') -# self.resize(500, 600) -# self.tab_widget = QTabWidget() -# self.tab_widget.setStyleSheet('background-color:#f3f3f3') -# self.tab_widget.addTab(LoginWidget('NextCloud'), 'NextCloud') -# self.tab_widget.addTab(LoginWidget('JianGuoYun'), '坚果云') -# self.tab_widget.addTab(LoginWidget('WebDav'), 'WebDav') -# -# # print('open new window') -# # self.stack_widget = QStackedWidget() -# # self.show() -# layout.addWidget(self.tab_widget) +from view.SettingWidget import SettingWidget class User(QLabel): + update_signal = pyqtSignal() + # 自定义信号, 注意信号必须为类属性 # button_clicked_signal = pyqtSignal() @@ -58,31 +39,17 @@ class User(QLabel): self.user_mail.setText(self.account[3]) # self.user_mail.setObjectName('user_mail') self.user_mail.setStyleSheet('font-size:14px') - # self.menu_label = QLabel('')type - # self.menu_label.setObjectName('menu') - # self.menu_label.setPixmap( - # QPixmap(os.path.abspath('../') + '/images/up-down.svg').scaled(20, 20, Qt.IgnoreAspectRatio, - # Qt.SmoothTransformation)) info_layout.addWidget(self.user_name) info_layout.addWidget(self.user_mail) layout.addLayout(info_layout, 4) layout.addStretch(1) - # layout.addWidget(self.menu_label, 1) self.widget.setLayout(layout) # 设置右键菜单 self.context_menu = QMenu(self) self.init_menu() - # def mouseReleaseEvent(self, QMouseEvent): - # self.button_clicked_signal.emit() - # - - # 可在外部与槽函数连接 用处不大 - # def connect_customized_slot(self, func): - # self.button_clicked_signal.connect(func) - def contextMenuEvent(self, event): self.context_menu.exec_(event.globalPos()) @@ -104,6 +71,9 @@ class User(QLabel): # todo 设置右键点击事件 def setting(self): + self.setting_widget = SettingWidget() + self.setting_widget.show() + pass def sync(self): @@ -116,15 +86,3 @@ class User(QLabel): self.login_window = LoginWidget() self.login_window.show() - -# if __name__ == '__main__': -# app = QApplication(sys.argv) -# # 创建窗口 -# window = User() -# # newWin = LoginWindow() -# -# # 显示窗口 -# window.show() -# # window.collec_btn.clicked.connect(newWin.show) -# # 运行应用,并监听事件 -# sys.exit(app.exec_())