diff --git a/main/main.py b/main/main.py index d39b061..320ef60 100644 --- a/main/main.py +++ b/main/main.py @@ -56,10 +56,10 @@ class MainWidget(QWidget): layout.addWidget(self.stackedWidget, 6) - self.one_day = SelfListWidgetItem('我的一天', 0, os.getcwd() + '/../images/sun.svg') + self.one_day = SelfListWidgetItem('我的一天', 0, None,os.getcwd() + '/../images/sun.svg') self.system_listWidget.setCurrentRow(1) # self.one_day.setSelected(True) - self.important_item = SelfListWidgetItem('重要', 0, os.getcwd() + '/../images/star.svg') + self.important_item = SelfListWidgetItem('重要', 0, None,os.getcwd() + '/../images/star.svg') self.system_listWidget.currentRowChanged.connect(self.stackedWidget.setCurrentIndex) diff --git a/utils/BasicUtils.py b/utils/BasicUtils.py index 345f9aa..990ca87 100644 --- a/utils/BasicUtils.py +++ b/utils/BasicUtils.py @@ -1,6 +1,7 @@ import json import os import platform +from datetime import datetime def return_work_dir(): @@ -66,12 +67,13 @@ def get_todo(todoListUid): json_file = json.load(f) # print(json_file['itemType']) - if json_file['itemType'] == 'Todo' and json_file['todoListUid'] == todoListUid: + if json_file['itemType'] == 'Todo' and not json_file['done'] and json_file[ + 'todoListUid'] == todoListUid: # print(json_file['title'], json_file['uid'], '待办事项') return_todo.append([json_file['title'], json_file['uid']]) - return return_todo + return return_todo - # load_list = get_todo_list() + # load_list = get_todo_list() def load_myday_important(item_type): @@ -90,35 +92,15 @@ def load_myday_important(item_type): # print(json_file['itemType']) if item_type == 'MyDay': - if json_file['itemType'] == 'Todo' and json_file['done'] and json_file['isMyDay']: + if json_file['itemType'] == 'Todo' and not json_file['done'] and json_file['isMyDay']: # print(json_file['title'], json_file['uid'], '待办事项') return_todo.append([json_file['title'], json_file['uid']]) return return_todo elif item_type == 'Important': - if json_file['itemType'] == 'Todo' and json_file['done'] and json_file['isImportant']: + if json_file['itemType'] == 'Todo' and not json_file['done'] and json_file['isImportant']: # print(json_file['title'], json_file['uid'], '待办事项') return_todo.append([json_file['title'], json_file['uid']]) - return return_todo - - def get_todo(todoListUid): - config_path = return_work_dir() - todo_path = config_path + 'ToDoList/' - # print(todo_path) - # config = configparser.ConfigParser() - return_todo = [] - - for root, dirs, files in os.walk(todo_path, topdown=False): - for name in files: - # print(os.path.join(root, name)) - with open(os.path.join(root, name), 'r') as f: - # print(f.read()) - json_file = json.load(f) - - # print(json_file['itemType']) - if json_file['itemType'] == 'Todo' and json_file['todoListUid'] == todoListUid: - # print(json_file['title'], json_file['uid'], '待办事项') - return_todo.append([json_file['title'], json_file['uid']]) - return return_todo + return return_todo # 用于修改某个键值对,比如更新修改时期,设置为重要,我的一天等 @@ -130,19 +112,22 @@ def change_value(uid, key, value): # for name in files: # print(os.path.join(root, name)) json_file = {} + current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') with open(todo_path + '{' + uid + '}.otl', 'r') as f: # print(f.read()) json_file = json.load(f) print(json_file) json_file[key] = value + json_file['updatedAt'] = current_time # print(json_file[key]) with open(todo_path + '{' + uid + '}.otl', 'w') as f: json.dump(json_file, f, indent=4, ensure_ascii=False) - # # print(read_init_file()) # webdav_hostname = read_init_file() # print(webdav_hostname[2]) -change_value('4f52f02b-4450-405a-9fd1-2005a03006e0', 'isMyDay', False) +# change_value('4f52f02b-4450-405a-9fd1-2005a03006e0', 'isMyDay', False) +# print(get_todo('3f1e033f-2051-4c04-b7f6-afd2eb1f54f4')) +# print(load_myday_important('Important')) diff --git a/view/ImportantView.py b/view/ImportantView.py index e4a8eaf..cc68a99 100644 --- a/view/ImportantView.py +++ b/view/ImportantView.py @@ -4,6 +4,7 @@ from PyQt5.QtGui import * from PyQt5.QtWidgets import * from PyQt5.QtCore import Qt +from utils.BasicUtils import load_myday_important from view.AddToDoLabel import AddToDoAction from view.ToDoItem import ToDoItem @@ -128,6 +129,25 @@ class Important(QWidget): label_action5.setText('渐变5') label_action5.triggered.connect(lambda: self.menu_action(5)) self.button_menu.addAction(label_action5) + self.initUI() + + def initUI(self): + print('') + # thread_action = ThreadAction() + # thread_action.change_value_action.connect() + + my_day_list = load_myday_important('Important') + + if my_day_list: + for my_day in my_day_list: + self.load_important(my_day[0], my_day[1]) + + def load_important(self, name, uid): + todo_item = ToDoItem(name, uid) + + self.todo_list.addItem(todo_item) + self.todo_list.setItemWidget(todo_item, todo_item.widget) + # button_menu # for i in range(11): # label_action = QAction(self) diff --git a/view/MyDayView.py b/view/MyDayView.py index 5cea3cb..f5e997e 100644 --- a/view/MyDayView.py +++ b/view/MyDayView.py @@ -3,6 +3,7 @@ from PyQt5.QtGui import * from PyQt5.QtWidgets import * from PyQt5.QtCore import Qt +from utils.BasicUtils import load_myday_important from view.AddToDoLabel import AddToDoAction from view.MyDayHeadLabel import HeadLabel from view.ToDoItem import ToDoItem @@ -136,6 +137,12 @@ class MyDay(QWidget): label_action5.setText('渐变5') label_action5.triggered.connect(lambda: self.menu_action(5)) self.button_menu.addAction(label_action5) + + my_day_list = load_myday_important('MyDay') + + if my_day_list: + for my_day in my_day_list: + self.load_myday(my_day[0], my_day[1]) # print(self.button_menu.size()) # print(button_menu.actions()[0]) @@ -147,6 +154,14 @@ class MyDay(QWidget): # j += 1 # pass + def load_myday(self, name, uid): + todo_item = ToDoItem(name, uid) + + self.todo_list.addItem(todo_item) + self.todo_list.setItemWidget(todo_item, todo_item.widget) + + pass + # todo : 下面的方法实现点击更换主题的功能 diff --git a/view/ToDoItem.py b/view/ToDoItem.py index 07c1f60..520912f 100644 --- a/view/ToDoItem.py +++ b/view/ToDoItem.py @@ -1,18 +1,22 @@ -from PyQt5.QtCore import Qt +from PyQt5.QtCore import Qt, pyqtSignal from PyQt5.QtGui import QPixmap, QIcon from PyQt5.QtWidgets import * from PyQt5.QtCore import Qt +from utils.BasicUtils import change_value + class ToDoItem(QListWidgetItem): + transaction = pyqtSignal() """ :param todo_name : 新建的待办事项名称 + :param uid : 待办事项的uid """ # todo : 参数添加uid,方便设置重要和我的一天 - def __init__(self, todo_name): + def __init__(self, todo_name, uid=None): super(ToDoItem, self).__init__() - print(' 添加的新ToDo:' + todo_name) + # print(' 添加的新ToDo:' + todo_name) self.widget = QWidget() layout = QHBoxLayout() @@ -35,3 +39,26 @@ class ToDoItem(QListWidgetItem): layout.addWidget(self.mark_icon, 2) layout.addWidget(self.todo_label, 6) layout.addWidget(self.important_button, 2) + + self.mark_icon.clicked.connect(self.set_done) + print(uid) + + self.important_button.clicked.connect(lambda: self.set_important(uid)) + + def set_done(self): + 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() + + change_value(uid, 'isImportant', True) + self.transaction.emit() + pass \ No newline at end of file diff --git a/view/ToDoListView.py b/view/ToDoListView.py index 7e9bf2b..19efcb2 100644 --- a/view/ToDoListView.py +++ b/view/ToDoListView.py @@ -18,6 +18,11 @@ class Menu(QMenu): class ToDoList(QWidget): + """ + :param list_name: 列表名,用于显示标题 + :param uid : 列表的uid,用于加载Todo和创建时传递参数 + """ + def __init__(self, list_name, uid): super(ToDoList, self).__init__() self.setObjectName('todolist') @@ -140,9 +145,15 @@ class ToDoList(QWidget): label_action5.setText('渐变5') label_action5.triggered.connect(lambda: self.menu_action(5)) self.button_menu.addAction(label_action5) + self.uid = uid + self.initUI() + + def initUI(self): # 读取配置文件添加Todo - load_todo = get_todo(uid) + # thread_action = ThreadAction() + + load_todo = get_todo(self.uid) if load_todo: for load in load_todo: self.load_todo(load[0], load[1])