2022-04-18 21:18:08 +08:00
|
|
|
|
import os
|
2022-04-26 21:10:49 +08:00
|
|
|
|
import time
|
|
|
|
|
|
2022-04-18 21:18:08 +08:00
|
|
|
|
from PyQt5.QtGui import *
|
|
|
|
|
from PyQt5.QtWidgets import *
|
2022-04-24 22:29:42 +08:00
|
|
|
|
from PyQt5.QtCore import Qt, pyqtSignal, QPropertyAnimation, QRect, QEasingCurve
|
2022-04-18 21:18:08 +08:00
|
|
|
|
|
2022-04-22 22:09:38 +08:00
|
|
|
|
from utils.BasicUtils import get_todo, change_value, load_value, remove_todo_list
|
|
|
|
|
from utils.CreateToDo import CreateToDo
|
2022-04-18 21:18:08 +08:00
|
|
|
|
from view.AddToDoLabel import AddToDoAction
|
2022-04-19 20:18:10 +08:00
|
|
|
|
from view.ToDoItem import ToDoItem
|
|
|
|
|
|
|
|
|
|
|
2022-04-18 21:18:08 +08:00
|
|
|
|
class ToDoList(QWidget):
|
2022-04-21 22:42:43 +08:00
|
|
|
|
"""
|
|
|
|
|
:param list_name: 列表名,用于显示标题
|
|
|
|
|
:param uid : 列表的uid,用于加载Todo和创建时传递参数
|
|
|
|
|
"""
|
|
|
|
|
|
2022-04-22 22:09:38 +08:00
|
|
|
|
# 测试更新的信号发送
|
|
|
|
|
update_signal = pyqtSignal()
|
|
|
|
|
|
2022-04-20 22:48:23 +08:00
|
|
|
|
def __init__(self, list_name, uid):
|
2022-04-18 21:18:08 +08:00
|
|
|
|
super(ToDoList, self).__init__()
|
2022-04-19 20:18:10 +08:00
|
|
|
|
self.setObjectName('todolist')
|
2022-04-18 21:18:08 +08:00
|
|
|
|
self.setAttribute(Qt.WA_StyledBackground)
|
|
|
|
|
# todo : 使用网格布局设置背景图
|
2022-04-19 20:18:10 +08:00
|
|
|
|
self.setStyleSheet('#todolist{background-image:url("../images/10.jpg");border-radius: 10px;}')
|
2022-04-18 21:18:08 +08:00
|
|
|
|
|
|
|
|
|
# 布局样式:最外面一个大的垂直布局,里面的最上面标题是一个水平布局,水平布局显示的是一个垂直布局和一个右边的选项,用来更换背景
|
|
|
|
|
# 布局样式:继承QWidget,里面一个垂直布局,最上面一个QWidget用来设置头部布局
|
|
|
|
|
# 头部QWidget里面一个水平布局,水平布局里面一个QWidget(方便设置整体位置),然后是一个
|
|
|
|
|
layout = QVBoxLayout()
|
|
|
|
|
head_layout = QHBoxLayout()
|
|
|
|
|
|
|
|
|
|
head_widget = QWidget(self)
|
2022-04-20 22:48:23 +08:00
|
|
|
|
|
2022-04-18 21:18:08 +08:00
|
|
|
|
# head_widget.setMinimumHeight(175)
|
|
|
|
|
|
|
|
|
|
self.todo_list = QListWidget()
|
2022-04-25 22:32:44 +08:00
|
|
|
|
# 关闭滚动条
|
|
|
|
|
self.todo_list.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
2022-04-18 21:18:08 +08:00
|
|
|
|
self.todo_list.setObjectName('todo_list')
|
|
|
|
|
|
|
|
|
|
# 添加ToDo的标签
|
|
|
|
|
self.add_todo = AddToDoAction()
|
2022-04-20 22:48:23 +08:00
|
|
|
|
self.add_todo.line_edit.returnPressed.connect(lambda: self.line_edit_add(self.add_todo.line_edit.text()))
|
|
|
|
|
|
2022-04-18 21:18:08 +08:00
|
|
|
|
self.add_todo.setAlignment(Qt.AlignCenter)
|
|
|
|
|
head_widget.setAttribute(Qt.WA_StyledBackground)
|
|
|
|
|
|
|
|
|
|
head_widget.setLayout(head_layout)
|
|
|
|
|
head_layout.setAlignment(Qt.AlignCenter)
|
2022-04-25 22:32:44 +08:00
|
|
|
|
|
2022-04-18 21:18:08 +08:00
|
|
|
|
layout.addWidget(head_widget, 2, Qt.AlignTop)
|
2022-04-25 22:32:44 +08:00
|
|
|
|
|
2022-04-18 21:18:08 +08:00
|
|
|
|
layout.addWidget(self.todo_list, 6, Qt.AlignCenter | Qt.AlignTop)
|
|
|
|
|
head_label = QLabel(list_name)
|
|
|
|
|
head_label.setObjectName('head_label')
|
|
|
|
|
font = QFont()
|
|
|
|
|
font.setPointSize(32)
|
|
|
|
|
head_label.setFont(font)
|
|
|
|
|
|
|
|
|
|
layout.addStretch(1)
|
|
|
|
|
|
|
|
|
|
head_layout.addWidget(head_label, 8)
|
|
|
|
|
layout.addStretch(1)
|
|
|
|
|
layout.addWidget(self.add_todo, 2, Qt.AlignHCenter)
|
|
|
|
|
|
|
|
|
|
self.menu_image = QPushButton()
|
|
|
|
|
self.menu_image.setObjectName('menu_image')
|
|
|
|
|
self.menu_image.setFixedSize(30, 30)
|
|
|
|
|
# self.menu_image.setScaledContents(True)
|
|
|
|
|
pic_btn = QPixmap(os.getcwd() + "/../images/menu.png")
|
|
|
|
|
self.menu_image.setIcon(QIcon(pic_btn))
|
2022-04-27 21:39:09 +08:00
|
|
|
|
|
2022-04-18 21:18:08 +08:00
|
|
|
|
head_layout.addWidget(self.menu_image, 2)
|
|
|
|
|
head_layout.addStretch(1)
|
|
|
|
|
|
|
|
|
|
self.setLayout(layout)
|
|
|
|
|
# self.menu_image.clicked.connect(self.menu_action)
|
|
|
|
|
|
2022-04-19 20:18:10 +08:00
|
|
|
|
self.button_menu = QMenu(self)
|
2022-04-18 21:18:08 +08:00
|
|
|
|
# 背景透明
|
2022-04-19 20:18:10 +08:00
|
|
|
|
self.button_menu.setAttribute(Qt.WA_TranslucentBackground)
|
2022-04-18 21:18:08 +08:00
|
|
|
|
# 无边框、去掉自带阴影
|
2022-04-19 20:18:10 +08:00
|
|
|
|
self.button_menu.setWindowFlags(
|
|
|
|
|
self.button_menu.windowFlags() | Qt.FramelessWindowHint | Qt.NoDropShadowWindowHint)
|
2022-04-18 21:18:08 +08:00
|
|
|
|
|
2022-04-19 20:18:10 +08:00
|
|
|
|
self.menu_image.setMenu(self.button_menu)
|
2022-04-18 21:18:08 +08:00
|
|
|
|
|
|
|
|
|
theme_label = QAction(self)
|
|
|
|
|
theme_label.setText('主题')
|
|
|
|
|
theme_label.setDisabled(True)
|
2022-04-19 20:18:10 +08:00
|
|
|
|
self.button_menu.addAction(theme_label)
|
|
|
|
|
self.button_menu.addSeparator()
|
2022-04-25 22:32:44 +08:00
|
|
|
|
|
2022-04-19 20:18:10 +08:00
|
|
|
|
label_action1 = QAction(self)
|
|
|
|
|
label_action1.setIcon(QIcon('../images/1.jpg'))
|
2022-04-22 22:09:38 +08:00
|
|
|
|
label_action1.setText('背景1')
|
2022-04-19 20:18:10 +08:00
|
|
|
|
label_action1.triggered.connect(lambda: self.menu_action(1))
|
|
|
|
|
self.button_menu.addAction(label_action1)
|
|
|
|
|
|
|
|
|
|
label_action2 = QAction(self)
|
|
|
|
|
label_action2.setIcon(QIcon('../images/2.jpg'))
|
2022-04-22 22:09:38 +08:00
|
|
|
|
label_action2.setText('背景2')
|
2022-04-19 20:18:10 +08:00
|
|
|
|
label_action2.triggered.connect(lambda: self.menu_action(2))
|
|
|
|
|
self.button_menu.addAction(label_action2)
|
|
|
|
|
|
|
|
|
|
label_action3 = QAction(self)
|
|
|
|
|
label_action3.setIcon(QIcon('../images/3.jpg'))
|
2022-04-22 22:09:38 +08:00
|
|
|
|
label_action3.setText('背景3')
|
2022-04-19 20:18:10 +08:00
|
|
|
|
label_action3.triggered.connect(lambda: self.menu_action(3))
|
|
|
|
|
self.button_menu.addAction(label_action3)
|
|
|
|
|
|
|
|
|
|
label_action4 = QAction(self)
|
|
|
|
|
label_action4.setIcon(QIcon('../images/4.jpg'))
|
2022-04-22 22:09:38 +08:00
|
|
|
|
label_action4.setText('背景4')
|
2022-04-19 20:18:10 +08:00
|
|
|
|
label_action4.triggered.connect(lambda: self.menu_action(4))
|
|
|
|
|
self.button_menu.addAction(label_action4)
|
|
|
|
|
|
|
|
|
|
label_action5 = QAction(self)
|
|
|
|
|
label_action5.setIcon(QIcon('../images/5.jpg'))
|
2022-04-22 22:09:38 +08:00
|
|
|
|
label_action5.setText('背景5')
|
2022-04-19 20:18:10 +08:00
|
|
|
|
label_action5.triggered.connect(lambda: self.menu_action(5))
|
|
|
|
|
self.button_menu.addAction(label_action5)
|
2022-04-21 22:42:43 +08:00
|
|
|
|
self.uid = uid
|
|
|
|
|
|
2022-04-26 21:10:49 +08:00
|
|
|
|
self.refresh_action()
|
2022-04-22 22:09:38 +08:00
|
|
|
|
# 右键菜单
|
|
|
|
|
self.todo_list.setContextMenuPolicy(Qt.CustomContextMenu)
|
|
|
|
|
self.todo_list.customContextMenuRequested.connect(self.todo_list_context)
|
|
|
|
|
self.load_theme()
|
2022-04-21 22:42:43 +08:00
|
|
|
|
|
2022-04-26 21:10:49 +08:00
|
|
|
|
#
|
|
|
|
|
# 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])
|
2022-04-18 21:18:08 +08:00
|
|
|
|
|
2022-04-22 22:09:38 +08:00
|
|
|
|
def load_theme(self):
|
|
|
|
|
theme = str(load_value(self.uid, 'Theme'))
|
|
|
|
|
self.setStyleSheet('#todolist{background-image:url("../images/' + theme + '.jpg");'
|
|
|
|
|
'background-position: center; border-radius: 10px;'
|
|
|
|
|
'}')
|
|
|
|
|
|
2022-04-18 21:18:08 +08:00
|
|
|
|
def menu_action(self, count):
|
|
|
|
|
# 点击按钮
|
2022-04-19 20:18:10 +08:00
|
|
|
|
count = str(count)
|
2022-04-18 21:18:08 +08:00
|
|
|
|
# self.menu_label = ChangeTheme()
|
2022-04-22 22:09:38 +08:00
|
|
|
|
change_value(self.uid, 'Theme', count)
|
2022-04-19 20:18:10 +08:00
|
|
|
|
self.setStyleSheet('#todolist{background-image:url("../images/' + count + '.jpg");'
|
2022-04-20 22:48:23 +08:00
|
|
|
|
'background-position: center; border-radius: 10px;'
|
|
|
|
|
'}')
|
2022-04-19 20:18:10 +08:00
|
|
|
|
# print('选中:' + count)
|
|
|
|
|
|
2022-04-20 22:48:23 +08:00
|
|
|
|
def load_todo(self, name, uid):
|
2022-04-26 21:10:49 +08:00
|
|
|
|
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))
|
2022-04-20 22:48:23 +08:00
|
|
|
|
|
2022-04-26 21:10:49 +08:00
|
|
|
|
self.todo_list.addItem(self.todo_item)
|
|
|
|
|
self.todo_list.setItemWidget(self.todo_item, self.todo_item.widget)
|
2022-04-20 22:48:23 +08:00
|
|
|
|
|
2022-04-23 17:36:22 +08:00
|
|
|
|
def refresh_action(self):
|
|
|
|
|
# self.my_day_list[]
|
|
|
|
|
self.todo_list.clear()
|
|
|
|
|
# print(self.my_day_list)
|
2022-04-25 22:32:44 +08:00
|
|
|
|
load_todo = get_todo(self.uid)
|
|
|
|
|
if load_todo:
|
|
|
|
|
for load in load_todo:
|
2022-04-23 17:36:22 +08:00
|
|
|
|
self.load_todo(load[0], load[1])
|
2022-04-20 22:48:23 +08:00
|
|
|
|
|
2022-04-19 20:18:10 +08:00
|
|
|
|
def line_edit_add(self, name):
|
2022-04-23 17:36:22 +08:00
|
|
|
|
if name:
|
|
|
|
|
self.add_todo.todo_name.emit(name)
|
|
|
|
|
# print('添加的新ToDo:' + name)
|
2022-04-25 22:32:44 +08:00
|
|
|
|
|
2022-04-23 17:36:22 +08:00
|
|
|
|
create_todo = CreateToDo('Todo', name, self.uid)
|
|
|
|
|
todo_item = ToDoItem(name, create_todo)
|
2022-04-19 20:18:10 +08:00
|
|
|
|
|
2022-04-23 17:36:22 +08:00
|
|
|
|
self.todo_list.addItem(todo_item)
|
|
|
|
|
self.todo_list.setItemWidget(todo_item, todo_item.widget)
|
2022-04-19 20:18:10 +08:00
|
|
|
|
|
2022-04-23 17:36:22 +08:00
|
|
|
|
self.add_todo.line_edit.clear()
|
2022-04-26 21:10:49 +08:00
|
|
|
|
self.refresh_action()
|
2022-04-27 21:39:09 +08:00
|
|
|
|
self.update_signal.emit()
|
2022-04-26 21:10:49 +08:00
|
|
|
|
# self.initUI()
|
2022-04-22 22:09:38 +08:00
|
|
|
|
|
|
|
|
|
def todo_list_context(self, position):
|
|
|
|
|
# 设置右键菜单
|
|
|
|
|
pop_menu = QMenu(self)
|
|
|
|
|
pop_menu.setObjectName('lift_menu')
|
|
|
|
|
pop_menu.setAttribute(Qt.WA_TranslucentBackground)
|
|
|
|
|
# 无边框、去掉自带阴影
|
|
|
|
|
pop_menu.setWindowFlags(
|
|
|
|
|
pop_menu.windowFlags() | Qt.FramelessWindowHint | Qt.NoDropShadowWindowHint)
|
|
|
|
|
|
|
|
|
|
rename_action = QAction(u'重命名', self)
|
|
|
|
|
|
|
|
|
|
mark_myday = QAction(QIcon(QPixmap(os.getcwd() + '/../images/make_sun.svg')), u"设置为我的一天", self)
|
|
|
|
|
mark_important = QAction(QIcon(QPixmap(os.getcwd() + '/../images/star.svg')), u"设置为重要", self)
|
|
|
|
|
|
|
|
|
|
del_action = QAction("删除", self)
|
|
|
|
|
|
|
|
|
|
# 查看右键时是否在item上面,如果不在.就不显示删除和修改.
|
2022-04-25 22:32:44 +08:00
|
|
|
|
# pop_menu.addAction(rename_action)
|
2022-04-22 22:09:38 +08:00
|
|
|
|
if self.todo_list.itemAt(position):
|
|
|
|
|
pop_menu.addAction(mark_myday)
|
|
|
|
|
pop_menu.addAction(mark_important)
|
|
|
|
|
pop_menu.addAction(del_action)
|
|
|
|
|
pop_menu.addAction(rename_action)
|
|
|
|
|
|
2022-04-25 22:32:44 +08:00
|
|
|
|
mark_myday.triggered.connect(lambda: self.make_action('MyDay'))
|
2022-04-22 22:09:38 +08:00
|
|
|
|
rename_action.triggered.connect(self.rename_item)
|
|
|
|
|
del_action.triggered.connect(self.delete_item)
|
2022-04-25 22:32:44 +08:00
|
|
|
|
mark_important.triggered.connect(lambda: self.make_action('Important'))
|
2022-04-22 22:09:38 +08:00
|
|
|
|
pop_menu.exec_(self.todo_list.mapToGlobal(position))
|
|
|
|
|
|
2022-04-25 22:32:44 +08:00
|
|
|
|
def make_action(self, make_type):
|
|
|
|
|
# print(self.todo_list.currentRow())
|
2022-04-23 17:36:22 +08:00
|
|
|
|
load_todo = get_todo(self.uid)
|
|
|
|
|
uid = load_todo[self.todo_list.currentRow()][1]
|
2022-04-25 22:32:44 +08:00
|
|
|
|
if make_type == 'MyDay':
|
|
|
|
|
change_value(uid, 'isMyDay', True)
|
|
|
|
|
elif make_type == 'Important':
|
|
|
|
|
change_value(uid, 'isImportant', True)
|
|
|
|
|
|
2022-04-22 22:09:38 +08:00
|
|
|
|
self.update_signal.emit()
|
|
|
|
|
|
|
|
|
|
# 删除分组
|
|
|
|
|
def delete_item(self):
|
|
|
|
|
# print(self.load_list[self.system_listWidget.currentRow() - 2][1])
|
2022-04-23 17:36:22 +08:00
|
|
|
|
loadtodo = get_todo(self.uid)
|
|
|
|
|
# load_todo = get_todo(my_day_list[self.todo_list.currentRow()][1])
|
|
|
|
|
uid = loadtodo[self.todo_list.currentRow()][1]
|
|
|
|
|
remove_todo_list(uid)
|
|
|
|
|
self.todo_list.takeItem(self.todo_list.currentRow())
|
|
|
|
|
self.update_signal.emit()
|
2022-04-22 22:09:38 +08:00
|
|
|
|
|
|
|
|
|
# 重命名分组
|
2022-04-26 21:10:49 +08:00
|
|
|
|
|
2022-04-22 22:09:38 +08:00
|
|
|
|
def rename_item(self):
|
2022-04-25 22:32:44 +08:00
|
|
|
|
self.dialog = QDialog()
|
|
|
|
|
self.dialog.setWindowTitle('重命名')
|
|
|
|
|
self.dialog_layout = QVBoxLayout()
|
|
|
|
|
self.dialog.resize(300, 200)
|
|
|
|
|
self.dialog.setLayout(self.dialog_layout)
|
|
|
|
|
line_edit = QLineEdit()
|
|
|
|
|
# line_edit.setObjectName('rename_line')
|
|
|
|
|
line_edit.setStyleSheet('border: 1px solid;background:transparent;min-width:400px;')
|
|
|
|
|
line_edit.setPlaceholderText('请输入新的名字')
|
|
|
|
|
self.dialog_layout.addWidget(line_edit)
|
|
|
|
|
confirm_button = QPushButton('确认修改')
|
|
|
|
|
self.dialog_layout.addWidget(confirm_button)
|
|
|
|
|
confirm_button.setStyleSheet('background-color:#bcbcbc;border-radius:5px;')
|
|
|
|
|
confirm_button.clicked.connect(lambda: self.change_name(line_edit.text()))
|
|
|
|
|
|
|
|
|
|
self.dialog.exec_()
|
|
|
|
|
|
|
|
|
|
def change_name(self, item_name):
|
|
|
|
|
# print(item_name)
|
|
|
|
|
load_todo = get_todo(self.uid)
|
|
|
|
|
# load_todo = get_todo(my_day_list[self.todo_list.currentRow()][1])
|
|
|
|
|
uid = load_todo[self.todo_list.currentRow()][1]
|
|
|
|
|
change_value(uid, 'title', item_name)
|
|
|
|
|
# 重命名发送信号
|
|
|
|
|
self.refresh_action()
|
2022-04-24 22:29:42 +08:00
|
|
|
|
self.update_signal.emit()
|
2022-04-25 22:32:44 +08:00
|
|
|
|
self.dialog.close()
|
2022-04-24 22:29:42 +08:00
|
|
|
|
|
|
|
|
|
def mark_done(self, uid):
|
2022-04-26 21:10:49 +08:00
|
|
|
|
# print('uid:',uid)
|
|
|
|
|
self.todo_item.mark_icon.setIcon(QIcon(os.getcwd() + '/../images/finished.svg'))
|
2022-04-27 21:39:09 +08:00
|
|
|
|
# print('mark done:', uid)
|
|
|
|
|
change_value(uid, 'done', True)
|
|
|
|
|
time.sleep(0.5)
|
2022-04-26 21:10:49 +08:00
|
|
|
|
self.todo_list.takeItem(self.todo_list.currentRow())
|
|
|
|
|
# self.refresh_action()
|
2022-04-25 22:32:44 +08:00
|
|
|
|
self.update_signal.emit()
|
2022-04-26 21:10:49 +08:00
|
|
|
|
self.refresh_action()
|
2022-04-24 22:29:42 +08:00
|
|
|
|
|
|
|
|
|
def mark_important(self, uid):
|
2022-04-27 21:39:09 +08:00
|
|
|
|
change_value(uid, 'isImportant', True)
|
2022-04-25 22:32:44 +08:00
|
|
|
|
self.update_signal.emit()
|
2022-04-24 22:29:42 +08:00
|
|
|
|
pass
|