修bug,发现更多bug!

This commit is contained in:
liyp 2022-04-21 22:42:43 +08:00
parent 36d3d7bff9
commit 9f80a8e7a0
6 changed files with 92 additions and 34 deletions

View file

@ -56,10 +56,10 @@ class MainWidget(QWidget):
layout.addWidget(self.stackedWidget, 6) 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.system_listWidget.setCurrentRow(1)
# self.one_day.setSelected(True) # 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) self.system_listWidget.currentRowChanged.connect(self.stackedWidget.setCurrentIndex)

View file

@ -1,6 +1,7 @@
import json import json
import os import os
import platform import platform
from datetime import datetime
def return_work_dir(): def return_work_dir():
@ -66,12 +67,13 @@ def get_todo(todoListUid):
json_file = json.load(f) json_file = json.load(f)
# print(json_file['itemType']) # 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'], '待办事项') # print(json_file['title'], json_file['uid'], '待办事项')
return_todo.append([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): def load_myday_important(item_type):
@ -90,35 +92,15 @@ def load_myday_important(item_type):
# print(json_file['itemType']) # print(json_file['itemType'])
if item_type == 'MyDay': 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'], '待办事项') # print(json_file['title'], json_file['uid'], '待办事项')
return_todo.append([json_file['title'], json_file['uid']]) return_todo.append([json_file['title'], json_file['uid']])
return return_todo return return_todo
elif item_type == 'Important': 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'], '待办事项') # print(json_file['title'], json_file['uid'], '待办事项')
return_todo.append([json_file['title'], json_file['uid']]) return_todo.append([json_file['title'], json_file['uid']])
return return_todo 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
# 用于修改某个键值对,比如更新修改时期,设置为重要,我的一天等 # 用于修改某个键值对,比如更新修改时期,设置为重要,我的一天等
@ -130,19 +112,22 @@ def change_value(uid, key, value):
# for name in files: # for name in files:
# print(os.path.join(root, name)) # print(os.path.join(root, name))
json_file = {} json_file = {}
current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
with open(todo_path + '{' + uid + '}.otl', 'r') as f: with open(todo_path + '{' + uid + '}.otl', 'r') as f:
# print(f.read()) # print(f.read())
json_file = json.load(f) json_file = json.load(f)
print(json_file) print(json_file)
json_file[key] = value json_file[key] = value
json_file['updatedAt'] = current_time
# print(json_file[key]) # print(json_file[key])
with open(todo_path + '{' + uid + '}.otl', 'w') as f: with open(todo_path + '{' + uid + '}.otl', 'w') as f:
json.dump(json_file, f, indent=4, ensure_ascii=False) json.dump(json_file, f, indent=4, ensure_ascii=False)
# #
# print(read_init_file()) # print(read_init_file())
# webdav_hostname = read_init_file() # webdav_hostname = read_init_file()
# print(webdav_hostname[2]) # 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'))

View file

@ -4,6 +4,7 @@ from PyQt5.QtGui import *
from PyQt5.QtWidgets import * from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
from utils.BasicUtils import load_myday_important
from view.AddToDoLabel import AddToDoAction from view.AddToDoLabel import AddToDoAction
from view.ToDoItem import ToDoItem from view.ToDoItem import ToDoItem
@ -128,6 +129,25 @@ class Important(QWidget):
label_action5.setText('渐变5') label_action5.setText('渐变5')
label_action5.triggered.connect(lambda: self.menu_action(5)) label_action5.triggered.connect(lambda: self.menu_action(5))
self.button_menu.addAction(label_action5) self.button_menu.addAction(label_action5)
self.initUI()
def initUI(self):
print('<ImportantView>')
# 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 # button_menu
# for i in range(11): # for i in range(11):
# label_action = QAction(self) # label_action = QAction(self)

View file

@ -3,6 +3,7 @@ from PyQt5.QtGui import *
from PyQt5.QtWidgets import * from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
from utils.BasicUtils import load_myday_important
from view.AddToDoLabel import AddToDoAction from view.AddToDoLabel import AddToDoAction
from view.MyDayHeadLabel import HeadLabel from view.MyDayHeadLabel import HeadLabel
from view.ToDoItem import ToDoItem from view.ToDoItem import ToDoItem
@ -136,6 +137,12 @@ class MyDay(QWidget):
label_action5.setText('渐变5') label_action5.setText('渐变5')
label_action5.triggered.connect(lambda: self.menu_action(5)) label_action5.triggered.connect(lambda: self.menu_action(5))
self.button_menu.addAction(label_action5) 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(self.button_menu.size())
# print(button_menu.actions()[0]) # print(button_menu.actions()[0])
@ -147,6 +154,14 @@ class MyDay(QWidget):
# j += 1 # j += 1
# pass # 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 : 下面的方法实现点击更换主题的功能 # todo : 下面的方法实现点击更换主题的功能

View file

@ -1,18 +1,22 @@
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5.QtGui import QPixmap, QIcon from PyQt5.QtGui import QPixmap, QIcon
from PyQt5.QtWidgets import * from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
from utils.BasicUtils import change_value
class ToDoItem(QListWidgetItem): class ToDoItem(QListWidgetItem):
transaction = pyqtSignal()
""" """
:param todo_name : 新建的待办事项名称 :param todo_name : 新建的待办事项名称
:param uid : 待办事项的uid
""" """
# todo : 参数添加uid方便设置重要和我的一天 # todo : 参数添加uid方便设置重要和我的一天
def __init__(self, todo_name): def __init__(self, todo_name, uid=None):
super(ToDoItem, self).__init__() super(ToDoItem, self).__init__()
print('<ToDoItem> 添加的新ToDo' + todo_name) # print('<ToDoItem> 添加的新ToDo' + todo_name)
self.widget = QWidget() self.widget = QWidget()
layout = QHBoxLayout() layout = QHBoxLayout()
@ -35,3 +39,26 @@ class ToDoItem(QListWidgetItem):
layout.addWidget(self.mark_icon, 2) layout.addWidget(self.mark_icon, 2)
layout.addWidget(self.todo_label, 6) layout.addWidget(self.todo_label, 6)
layout.addWidget(self.important_button, 2) 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

View file

@ -18,6 +18,11 @@ class Menu(QMenu):
class ToDoList(QWidget): class ToDoList(QWidget):
"""
:param list_name: 列表名用于显示标题
:param uid : 列表的uid用于加载Todo和创建时传递参数
"""
def __init__(self, list_name, uid): def __init__(self, list_name, uid):
super(ToDoList, self).__init__() super(ToDoList, self).__init__()
self.setObjectName('todolist') self.setObjectName('todolist')
@ -140,9 +145,15 @@ class ToDoList(QWidget):
label_action5.setText('渐变5') label_action5.setText('渐变5')
label_action5.triggered.connect(lambda: self.menu_action(5)) label_action5.triggered.connect(lambda: self.menu_action(5))
self.button_menu.addAction(label_action5) self.button_menu.addAction(label_action5)
self.uid = uid
self.initUI()
def initUI(self):
# 读取配置文件添加Todo # 读取配置文件添加Todo
load_todo = get_todo(uid) # thread_action = ThreadAction()
load_todo = get_todo(self.uid)
if load_todo: if load_todo:
for load in load_todo: for load in load_todo:
self.load_todo(load[0], load[1]) self.load_todo(load[0], load[1])