简单设置读取文件,明天将我的一天和重要功能实现!

This commit is contained in:
liyp 2022-04-20 22:48:23 +08:00
parent 0ae10a875c
commit 36d3d7bff9
19 changed files with 348 additions and 210 deletions

View file

Before

Width:  |  Height:  |  Size: 324 KiB

After

Width:  |  Height:  |  Size: 324 KiB

View file

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 29 KiB

1
images/edit.svg Normal file
View file

@ -0,0 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1650371936214" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3419" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M960.984615 145.723077l-82.707692-82.707692c-31.507692-31.507692-80.738462-31.507692-110.276923 0l-64.984615 64.984615c-7.876923 7.876923-7.876923 19.692308 0 27.569231l167.384615 167.384615c7.876923 7.876923 19.692308 7.876923 27.569231 0l64.984615-64.984615c29.538462-31.507692 29.538462-80.738462-1.969231-112.246154z m-313.107692 64.984615c-7.876923-7.876923-19.692308-7.876923-27.569231 0L106.338462 724.676923 41.353846 947.2c-5.907692 21.661538 13.784615 43.323077 35.446154 37.415385l224.492308-63.015385h-1.969231l513.969231-513.969231c7.876923-7.876923 7.876923-19.692308 0-27.569231l-165.415385-169.353846z" p-id="3420"></path></svg>

After

Width:  |  Height:  |  Size: 1,021 B

View file

@ -4,6 +4,8 @@ from PyQt5.QtGui import *
from PyQt5.QtWidgets import * from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
import configparser import configparser
from utils.BasicUtils import get_todo_list
from utils.CreateToDo import CreateToDo from utils.CreateToDo import CreateToDo
from utils.QSSLoader import QSSLoader from utils.QSSLoader import QSSLoader
from view.ImportantView import Important from view.ImportantView import Important
@ -71,6 +73,11 @@ class MainWidget(QWidget):
self.system_listWidget.addItem(self.important_item) self.system_listWidget.addItem(self.important_item)
self.system_listWidget.setItemWidget(self.important_item, self.important_item.widget) self.system_listWidget.setItemWidget(self.important_item, self.important_item.widget)
load_list = get_todo_list()
# print(load_list)
if load_list:
for load in load_list:
self.load_item(load[0], load[1])
# self.system_listWidget.addScrollBarWidget(False) # self.system_listWidget.addScrollBarWidget(False)
# 测试添加下面的 # 测试添加下面的
@ -101,22 +108,36 @@ class MainWidget(QWidget):
del_action.triggered.connect(self.DeleteItem) del_action.triggered.connect(self.DeleteItem)
pop_menu.exec_(self.custom.mapToGlobal(position)) pop_menu.exec_(self.custom.mapToGlobal(position))
# 创建新的分组 def load_item(self, list_name, uid):
def CreateNewItem(self): item = SelfListWidgetItem(list_name, 0, uid)
# 创建一个没有名字的item
new_list = '新建列表'
create_todo = CreateToDo('ToDoList', new_list)
item = SelfListWidgetItem(new_list)
item.setTextAlignment(Qt.AlignCenter) item.setTextAlignment(Qt.AlignCenter)
# 使得item是可以编辑的. # 使得item是可以编辑的.
item.setFlags(item.flags() | Qt.ItemIsEditable) item.setFlags(item.flags() | Qt.ItemIsEditable)
self.system_listWidget.addItem(item) self.system_listWidget.addItem(item)
todo_list = ToDoList(new_list) todo_list = ToDoList(list_name, uid)
self.stackedWidget.addWidget(todo_list)
# 创建后就可以编辑item,用户自己起名字. # 创建后就可以编辑item,用户自己起名字.
# self.system_listWidget.editItem(item) # self.system_listWidget.editItem(item)
self.stackedWidget.addWidget(todo_list)
self.system_listWidget.setItemWidget(item, item.widget) self.system_listWidget.setItemWidget(item, item.widget)
# 创建新的分组
def CreateNewItem(self, new_list='新建列表', uid=None):
# 创建一个没有名字的item
# new_list = '新建列表'
if not uid:
create_todo_uid = CreateToDo('ToDoList', new_list)
item = SelfListWidgetItem(new_list, 0, create_todo_uid)
item.setTextAlignment(Qt.AlignCenter)
# 使得item是可以编辑的.
item.setFlags(item.flags() | Qt.ItemIsEditable)
self.system_listWidget.addItem(item)
todo_list = ToDoList(new_list, create_todo_uid)
self.stackedWidget.addWidget(todo_list)
# 创建后就可以编辑item,用户自己起名字.
# self.system_listWidget.editItem(item)
self.system_listWidget.setItemWidget(item, item.widget)
# 删除分组 # 删除分组
def DeleteItem(self): def DeleteItem(self):
self.custom.takeItem(self.custom.currentRow()) self.custom.takeItem(self.custom.currentRow())

View file

@ -18,7 +18,7 @@ home_dir = config['info']['home_dir']
print(users_dir) print(users_dir)
print(name) print(name)
print(home_dir) print(home_dir)
with open('test.ini', 'w') as config_file: with open('../utils/test.ini', 'w') as config_file:
config.write(config_file) config.write(config_file)
config.add_section('Accounts') config.add_section('Accounts')
@ -27,5 +27,5 @@ config['Accounts']['name'] = 'admin'
config['Accounts']['type'] = 'NextCloud' config['Accounts']['type'] = 'NextCloud'
config['Accounts']['username'] = 'admin' config['Accounts']['username'] = 'admin'
with open('test.ini', 'w') as config_file: with open('../utils/test.ini', 'w') as config_file:
config.write(config_file) config.write(config_file)

View file

@ -1,12 +1,12 @@
import os import os
work_path = os.path.expandvars('$HOME') + '/.config/PyQtToDoList' work_path = os.path.expandvars('$HOME') + '/.config/PyQtToDoList/ToDoList'
# sync_path = os.walk(work_path) # sync_path = os.walk(work_path)
# print(sync_path) # print(sync_path)
for root, dirs, files in os.walk(work_path, topdown=False): for root, dirs, files in os.walk(work_path, topdown=False):
for name in files: for name in files:
print(os.path.join(root, name).split('/')[-1]) print(os.path.join(root, name).split('/')[-1])
for name in dirs: # for name in dirs:
# print(os.path.join(root, name)) # # print(os.path.join(root, name))
print(os.path.join(root, name).split('/')[-1]) # print(os.path.join(root, name).split('/')[-1])

57
test/TestGetToDoList.py Normal file
View file

@ -0,0 +1,57 @@
import os
import json
import configparser
from utils import BasicUtils
def get_todo_list():
config_path = BasicUtils.return_work_dir()
todo_path = config_path + 'ToDoList/'
# print(todo_path)
# config = configparser.ConfigParser()
return_todo_list = []
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)
# try:
if json_file['itemType'] == 'ToDoList':
# print(json_file['title'], json_file['uid'], '列表')
return_todo_list.append([json_file['title'], json_file['uid']])
# print(return_todo_list)
return return_todo_list
def get_to_do(todoListUid):
config_path = BasicUtils.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
# load_list = get_todo_list()
# print(load_list)
# if load_list:
# for load in load_list:
# print(load[0], load[1])
print(get_to_do('3f1e033f-2051-4c04-b7f6-afd2eb1f54f4'))

148
utils/BasicUtils.py Normal file
View file

@ -0,0 +1,148 @@
import json
import os
import platform
def return_work_dir():
if platform.system() == 'Linux':
work_path = os.path.expandvars('$HOME') + '/.config/'
if not os.path.exists(work_path):
os.mkdir(work_path)
return os.path.expandvars('$HOME') + '/.config/PyQtToDoList/'
elif platform.system() == 'Windows':
work_path = os.getcwd() + '/config/'
if not os.path.exists(work_path):
os.mkdir(work_path)
return work_path
import configparser
def read_init_file():
config = configparser.ConfigParser()
try:
config.read(return_work_dir() + 'PyQtToDoList.ini')
account = config['Account']
if account:
return [account['webdav_hostname'], account['webdav_login'], account['webdav_password'], account['type']]
except KeyError as e:
return False
def get_todo_list():
config_path = return_work_dir()
todo_path = config_path + 'ToDoList/'
# print(todo_path)
return_todo_list = []
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)
# try:
if json_file['itemType'] == 'ToDoList':
# print(json_file['title'], json_file['uid'], '列表')
return_todo_list.append([json_file['title'], json_file['uid']])
# print(return_todo_list)
return return_todo_list
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
# load_list = get_todo_list()
def load_myday_important(item_type):
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 item_type == 'MyDay':
if json_file['itemType'] == 'Todo' and 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']:
# 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
# 用于修改某个键值对,比如更新修改时期,设置为重要,我的一天等
def change_value(uid, key, value):
config_path = return_work_dir()
todo_path = config_path + 'ToDoList/'
# for root, dirs, files in os.walk(todo_path, topdown=False):
# for name in files:
# print(os.path.join(root, name))
json_file = {}
with open(todo_path + '{' + uid + '}.otl', 'r') as f:
# print(f.read())
json_file = json.load(f)
print(json_file)
json_file[key] = value
# 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)

View file

@ -1,7 +1,7 @@
import configparser import configparser
import platform import platform
import os import os
from utils import ReturnWorkDir from utils import BasicUtils
# todo : 用来创建软件的配置信息 # todo : 用来创建软件的配置信息

View file

@ -3,7 +3,7 @@ import uuid
import json import json
from datetime import datetime from datetime import datetime
from utils import ReturnWorkDir from utils import BasicUtils
""" """
todo : 暂时创建单个文件存储该列表下所有待办事项,文件命名为 {uuid}.otl todo : 暂时创建单个文件存储该列表下所有待办事项,文件命名为 {uuid}.otl
@ -13,78 +13,79 @@ from utils import ReturnWorkDir
可以尝试在待办事项添加 isMyDay属性和isImportant属性 可以尝试在待办事项添加 isMyDay属性和isImportant属性
""" """
# class CreateToDo:
"""
:param item_type: 创建的类型为ToDo和ToDoList
:param name: 要创建的ToDoList名字
:param todo_list_uid : 待办事项列表的uid,可选
"""
class CreateToDo:
"""
:param item_type: 创建的类型为ToDo和ToDoList
:param name: 要创建的ToDoList名字
:param todo_list_uid : 待办事项列表的uid,可选
"""
def __init__(self, item_type, name, todo_list_uid=None): def CreateToDo(item_type, name, todo_list_uid=None):
uid = str(uuid.uuid4()) uid = str(uuid.uuid4())
config_path = ReturnWorkDir.return_work_dir() config_path = BasicUtils.return_work_dir()
todo_list_path = config_path + '{' + uid + '}' todo_list_path = config_path + 'ToDoList/'
# if not os.path.exists(todo_list_path): if not os.path.exists(todo_list_path):
# os.mkdir(todo_list_path) os.mkdir(todo_list_path)
default_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') default_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print(default_time) print(uid)
if item_type == 'ToDoList': if item_type == 'ToDoList':
try: # print(item_type)
""" try:
createdAt : 创建时间 """
dueTo 完成时间 createdAt : 创建时间
itemType 类型 dueTo 完成时间
notes 笔记 itemType 类型
title 标题 notes 笔记
updatedAt 最后一次更新时间 title 标题
""" updatedAt 最后一次更新时间
os.mkdir(todo_list_path) """
out_config = { # os.mkdir(todo_list_path)
"createdAt": default_time, out_config = {
"dueTo": '', "createdAt": default_time,
"itemType": item_type, "dueTo": '',
"notes": "", "itemType": item_type,
"title": name, "notes": "",
"uid": uid, "title": name,
"updatedAt": default_time "uid": uid,
} "updatedAt": default_time
library = { }
"title": name, # library = {
"uid": uid # "title": name,
} # "uid": uid
with open(todo_list_path + '/library.json', 'w') as f: # }
f.write(json.dumps(library)) with open(todo_list_path + '{' + uid + '}.otl', 'w') as f:
except IOError as e: f.write(json.dumps(out_config, indent=4, ensure_ascii=False))
print(e) # json.dump(out_config, f)
elif item_type == 'ToDo': return uid
try: except IOError as e:
# done : 完成状态 print(e)
# todoListUid 父列表id return False
out_config = { elif item_type == 'ToDo':
"createdAt": default_time, try:
"done": False, # done : 完成状态
"dueTo": '', # todoListUid 父列表id
"itemType": "Todo", out_config = {
"notes": "", "createdAt": default_time,
"title": name, "done": False,
"todoListUid": todo_list_uid, "dueTo": '',
"uid": uid, "itemType": "Todo",
"updatedAt": default_time "notes": "",
} "isMyDay": False,
with open(todo_list_path + '/' + uid + '.otl', 'w') as f: "isImportant": False,
f.write(json.dumps(out_config)) "title": name,
except IOError as e: "todoListUid": todo_list_uid,
print(e) "uid": uid,
"theme": '0',
"updatedAt": default_time
}
with open(todo_list_path + '{' + uid + '}.otl', 'w') as f:
f.write(json.dumps(out_config, indent=4, ensure_ascii=False))
return uid
# def get_config_path(self): except IOError as e:
# print(e)
# # print(platform.system()) return False
# if platform.system() == 'Linux':
# # print(os.environ['HOME'] + '/.config/PyQtToDoList') #
# # print(os.path.expandvars('~')) # CreateToDo('ToDo', 'test1', '3f1e033f-2051-4c04-b7f6-afd2eb1f54f4')
# # print(os.path.expandvars('$HOME') + '.config/PyQtToDoList')
# return os.path.expandvars('$HOME') + '/.config/PyQtToDoList'
# elif platform.system() == 'Windows':
# print(os.getcwd() + 'config')
# return os.getcwd() + 'config'

View file

@ -1,36 +0,0 @@
import os
import platform
def return_work_dir():
if platform.system() == 'Linux':
work_path = os.path.expandvars('$HOME') + '/.config/'
if not os.path.exists(work_path):
os.mkdir(work_path)
return os.path.expandvars('$HOME') + '/.config/PyQtToDoList/'
elif platform.system() == 'Windows':
work_path = os.getcwd() + '/config/'
if not os.path.exists(work_path):
os.mkdir(work_path)
return work_path
import configparser
def read_init_file():
config = configparser.ConfigParser()
try:
config.read(return_work_dir() + 'PyQtToDoList.ini')
account = config['Account']
if account:
return [account['webdav_hostname'], account['webdav_login'], account['webdav_password'], account['type']]
except KeyError as e:
return False
#
#
# print(read_init_file())
# webdav_hostname = read_init_file()
# print(webdav_hostname[2])

View file

@ -1,68 +0,0 @@
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
class TabDemo(QTabWidget):
def __init__(self,parent=None):
super(TabDemo, self).__init__(parent)
#创建3个选项卡小控件窗口
self.tab1=QWidget()
self.tab2=QWidget()
self.tab3=QWidget()
#将三个选项卡添加到顶层窗口中
self.addTab(self.tab1, "Tab 1")
self.addTab(self.tab2, "Tab 2")
self.addTab(self.tab3, "Tab 3")
#每个选项卡自定义的内容
self.tab1UI()
self.tab2UI()
self.tab3UI()
def tab1UI(self):
#表单布局
layout=QFormLayout()
#添加姓名,地址的单行文本输入框
layout.addRow('姓名',QLineEdit())
layout.addRow('地址',QLineEdit())
#设置选项卡的小标题与布局方式
self.setTabText(0,'联系方式')
self.tab1.setLayout(layout)
def tab2UI(self):
#zhu表单布局次水平布局
layout=QFormLayout()
sex=QHBoxLayout()
#水平布局添加单选按钮
sex.addWidget(QRadioButton(''))
sex.addWidget(QRadioButton(''))
#表单布局添加控件
layout.addRow(QLabel('性别'),sex)
layout.addRow('生日',QLineEdit())
#设置标题与布局
self.setTabText(1,'个人详细信息')
self.tab2.setLayout(layout)
def tab3UI(self):
#水平布局
layout=QHBoxLayout()
#添加控件到布局中
layout.addWidget(QLabel('科目'))
layout.addWidget(QCheckBox('物理'))
layout.addWidget(QCheckBox('高数'))
#设置小标题与布局方式
self.setTabText(2,'教育程度')
self.tab3.setLayout(layout)
if __name__ == '__main__':
app=QApplication(sys.argv)
demo=TabDemo()
demo.show()
sys.exit(app.exec_())

View file

@ -23,16 +23,14 @@ class Important(QWidget):
head_layout = QHBoxLayout() head_layout = QHBoxLayout()
head_widget = QWidget(self) head_widget = QWidget(self)
# head_widget.setStyleSheet('background-color:gray')
# todo :
# head_widget.setMinimumHeight(175)
self.todo_list = QListWidget() self.todo_list = QListWidget()
self.todo_list.setObjectName('todo_list') self.todo_list.setObjectName('todo_list')
# todo : 重写QLabel实现添加功能
# 添加ToDo的标签 # 添加ToDo的标签
self.add_todo = AddToDoAction() self.add_todo = AddToDoAction()
self.add_todo.line_edit.returnPressed.connect(lambda: self.line_edit_add(self.add_todo.line_edit.text()))
self.add_todo.setAlignment(Qt.AlignCenter) self.add_todo.setAlignment(Qt.AlignCenter)
# self.add_todo.setPlaceholderText('添加任务') # self.add_todo.setPlaceholderText('添加任务')
@ -144,8 +142,8 @@ class Important(QWidget):
count = str(count) count = str(count)
# self.menu_label = ChangeTheme() # self.menu_label = ChangeTheme()
self.setStyleSheet('#important{background-image:url("../images/' + count + '.jpg");' self.setStyleSheet('#important{background-image:url("../images/' + count + '.jpg");'
'background-position: center; border-radius: 10px;' 'background-position: center; border-radius: 10px;'
'}') '}')
print('选中:' + count) print('选中:' + count)
def line_edit_add(self, name): def line_edit_add(self, name):

View file

@ -2,7 +2,7 @@ from PyQt5.QtCore import Qt
from PyQt5.QtGui import * from PyQt5.QtGui import *
from PyQt5.QtWidgets import * from PyQt5.QtWidgets import *
import configparser import configparser
from utils.ReturnWorkDir import * from utils.BasicUtils import *
# #

View file

@ -2,7 +2,7 @@ from PyQt5.QtCore import Qt
from PyQt5.QtGui import * from PyQt5.QtGui import *
from PyQt5.QtWidgets import * from PyQt5.QtWidgets import *
import configparser import configparser
from utils.ReturnWorkDir import * from utils.BasicUtils import *
class LoginWindow(QWidget): class LoginWindow(QWidget):

View file

@ -8,11 +8,12 @@ import os
class SelfListWidgetItem(QListWidgetItem): class SelfListWidgetItem(QListWidgetItem):
""" """
:param item_name: 列表名称 :param item_name: 列表名称
:param uid: 当前列表的uuid
:param todo_count: 设置剩余代办数量默认为零 :param todo_count: 设置剩余代办数量默认为零
:param show_icon: 设置显示的图标路径默认为空 :param show_icon: 设置显示的图标路径默认为空
""" """
def __init__(self, item_name, todo_count=0, show_icon=None): def __init__(self, item_name, todo_count=0, uid=None, show_icon=None):
super(SelfListWidgetItem, self).__init__() super(SelfListWidgetItem, self).__init__()
layout = QHBoxLayout() layout = QHBoxLayout()
# print(show_icon) # print(show_icon)

View file

@ -9,9 +9,10 @@ class ToDoItem(QListWidgetItem):
:param todo_name : 新建的待办事项名称 :param todo_name : 新建的待办事项名称
""" """
# todo : 参数添加uid方便设置重要和我的一天
def __init__(self, todo_name): def __init__(self, todo_name):
super(ToDoItem, self).__init__() super(ToDoItem, self).__init__()
print('添加的新ToDo' + todo_name) print('<ToDoItem> 添加的新ToDo' + todo_name)
self.widget = QWidget() self.widget = QWidget()
layout = QHBoxLayout() layout = QHBoxLayout()

View file

@ -1,9 +1,9 @@
import os import os
import sys
from PyQt5.QtGui import * 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 get_todo
from view.AddToDoLabel import AddToDoAction from view.AddToDoLabel import AddToDoAction
from view.ToDoItem import ToDoItem from view.ToDoItem import ToDoItem
@ -18,7 +18,7 @@ class Menu(QMenu):
class ToDoList(QWidget): class ToDoList(QWidget):
def __init__(self, list_name): def __init__(self, list_name, uid):
super(ToDoList, self).__init__() super(ToDoList, self).__init__()
self.setObjectName('todolist') self.setObjectName('todolist')
self.setAttribute(Qt.WA_StyledBackground) self.setAttribute(Qt.WA_StyledBackground)
@ -32,15 +32,16 @@ class ToDoList(QWidget):
head_layout = QHBoxLayout() head_layout = QHBoxLayout()
head_widget = QWidget(self) head_widget = QWidget(self)
# todo :
# head_widget.setMinimumHeight(175) # head_widget.setMinimumHeight(175)
self.todo_list = QListWidget() self.todo_list = QListWidget()
self.todo_list.setObjectName('todo_list') self.todo_list.setObjectName('todo_list')
# todo : 重写QLabel实现添加功能
# 添加ToDo的标签 # 添加ToDo的标签
self.add_todo = AddToDoAction() self.add_todo = AddToDoAction()
self.add_todo.line_edit.returnPressed.connect(lambda: self.line_edit_add(self.add_todo.line_edit.text()))
self.add_todo.setAlignment(Qt.AlignCenter) self.add_todo.setAlignment(Qt.AlignCenter)
# self.add_todo.setPlaceholderText('添加任务') # self.add_todo.setPlaceholderText('添加任务')
@ -139,6 +140,12 @@ 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)
# 读取配置文件添加Todo
load_todo = get_todo(uid)
if load_todo:
for load in load_todo:
self.load_todo(load[0], load[1])
# button_menu # button_menu
# for i in range(11): # for i in range(11):
# label_action = QAction(self) # label_action = QAction(self)
@ -146,17 +153,24 @@ class ToDoList(QWidget):
# label_action.setText(str(i)) # label_action.setText(str(i))
# label_action.triggered.connect(lambda: self.menu_action(str(i))) # label_action.triggered.connect(lambda: self.menu_action(str(i)))
# button_menu.addAction(label_action) # button_menu.addAction(label_action)
# todo : 下面的方法实现点击更换主题的功能
def menu_action(self, count): def menu_action(self, count):
# 点击按钮 # 点击按钮
count = str(count) count = str(count)
# self.menu_label = ChangeTheme() # self.menu_label = ChangeTheme()
self.setStyleSheet('#todolist{background-image:url("../images/' + count + '.jpg");' self.setStyleSheet('#todolist{background-image:url("../images/' + count + '.jpg");'
'background-position: center; border-radius: 10px;' 'background-position: center; border-radius: 10px;'
'}') '}')
# print('选中:' + count) # print('选中:' + count)
def load_todo(self, name, uid):
todo_item = ToDoItem(name)
self.todo_list.addItem(todo_item)
self.todo_list.setItemWidget(todo_item, todo_item.widget)
pass
def line_edit_add(self, name): def line_edit_add(self, name):
self.add_todo.todo_name.emit(name) self.add_todo.todo_name.emit(name)
# print('添加的新ToDo' + name) # print('添加的新ToDo' + name)

View file

@ -5,7 +5,7 @@ from PyQt5.QtCore import Qt
from PyQt5.QtGui import * from PyQt5.QtGui import *
from PyQt5.QtWidgets import * from PyQt5.QtWidgets import *
import configparser import configparser
from utils.ReturnWorkDir import * from utils.BasicUtils import *
from view.LoginWidget import LoginWidget from view.LoginWidget import LoginWidget