2022-04-01 22:25:19 +08:00
|
|
|
|
import os
|
|
|
|
|
import sys
|
|
|
|
|
from PyQt5.QtGui import *
|
2022-03-29 20:28:43 +08:00
|
|
|
|
from PyQt5.QtWidgets import *
|
2022-04-01 22:25:19 +08:00
|
|
|
|
from PyQt5.QtCore import Qt
|
2022-04-19 20:18:10 +08:00
|
|
|
|
import configparser
|
2022-04-20 22:48:23 +08:00
|
|
|
|
|
2022-04-24 22:29:42 +08:00
|
|
|
|
from utils.BasicUtils import get_todo_list, remove_todo_list, change_value
|
2022-04-18 21:18:08 +08:00
|
|
|
|
from utils.CreateToDo import CreateToDo
|
2022-04-01 22:25:19 +08:00
|
|
|
|
from utils.QSSLoader import QSSLoader
|
2022-04-12 21:34:18 +08:00
|
|
|
|
from view.ImportantView import Important
|
2022-04-22 22:09:38 +08:00
|
|
|
|
from view.MyListWidget import MyListWidget
|
2022-04-18 21:18:08 +08:00
|
|
|
|
from view.ToDoListView import ToDoList
|
2022-04-01 22:25:19 +08:00
|
|
|
|
from view.UserLabel import User
|
|
|
|
|
from view.SelfListWidgetItem import SelfListWidgetItem
|
2022-04-07 19:34:28 +08:00
|
|
|
|
from view.AddListLabel import AddListAction
|
2022-04-07 21:11:37 +08:00
|
|
|
|
from view.MyDayView import MyDay
|
2022-03-31 21:55:51 +08:00
|
|
|
|
|
|
|
|
|
|
2022-04-01 22:25:19 +08:00
|
|
|
|
class MainWidget(QWidget):
|
2022-03-31 21:55:51 +08:00
|
|
|
|
def __init__(self):
|
2022-04-01 22:25:19 +08:00
|
|
|
|
super(MainWidget, self).__init__()
|
|
|
|
|
self.user_label = User()
|
|
|
|
|
# 主布局,左右两侧
|
2022-03-31 21:55:51 +08:00
|
|
|
|
layout = QHBoxLayout()
|
2022-04-01 22:25:19 +08:00
|
|
|
|
# 子布局,左边的部分
|
|
|
|
|
self.sub_layout = QVBoxLayout()
|
|
|
|
|
self.sub_layout.spacing()
|
2022-04-07 19:34:28 +08:00
|
|
|
|
self.sub_layout.addWidget(self.user_label, 2)
|
2022-04-01 22:25:19 +08:00
|
|
|
|
# 左侧列表
|
2022-04-22 22:09:38 +08:00
|
|
|
|
self.system_listWidget = MyListWidget(self)
|
2022-04-12 21:34:18 +08:00
|
|
|
|
self.system_listWidget.setFrameShape(QListWidget.NoFrame)
|
2022-04-07 19:34:28 +08:00
|
|
|
|
self.sub_layout.addWidget(self.system_listWidget, 15)
|
2022-04-01 22:25:19 +08:00
|
|
|
|
|
2022-04-07 21:11:37 +08:00
|
|
|
|
# 添加最下边的QLabel
|
2022-04-07 19:34:28 +08:00
|
|
|
|
self.add_list_action = AddListAction()
|
2022-04-22 22:09:38 +08:00
|
|
|
|
self.add_list_action.create_todo_list.connect(self.create_item)
|
2022-04-04 22:34:07 +08:00
|
|
|
|
|
|
|
|
|
# self.add_item_label.setPixmap(QPixmap())
|
2022-04-07 19:34:28 +08:00
|
|
|
|
self.sub_layout.addWidget(self.add_list_action, 1)
|
2022-04-04 22:34:07 +08:00
|
|
|
|
# 禁止双击可编辑
|
2022-04-22 22:09:38 +08:00
|
|
|
|
self.system_listWidget.setEditTriggers(QAbstractItemView.NoEditTriggers)
|
2022-04-04 22:34:07 +08:00
|
|
|
|
# 右键菜单
|
2022-04-22 22:09:38 +08:00
|
|
|
|
self.system_listWidget.setContextMenuPolicy(Qt.CustomContextMenu)
|
|
|
|
|
self.system_listWidget.setObjectName('custom')
|
|
|
|
|
self.system_listWidget.customContextMenuRequested.connect(self.myListWidgetContext)
|
2022-04-04 22:34:07 +08:00
|
|
|
|
|
2022-04-01 22:25:19 +08:00
|
|
|
|
# 右侧层叠窗口
|
2022-04-07 21:11:37 +08:00
|
|
|
|
|
2022-04-12 21:34:18 +08:00
|
|
|
|
self.my_day = MyDay()
|
|
|
|
|
self.important = Important()
|
2022-04-01 22:25:19 +08:00
|
|
|
|
self.stackedWidget = QStackedWidget(self)
|
2022-04-12 21:34:18 +08:00
|
|
|
|
self.stackedWidget.addWidget(self.my_day)
|
|
|
|
|
self.stackedWidget.addWidget(self.important)
|
2022-04-01 22:25:19 +08:00
|
|
|
|
|
2022-04-07 21:11:37 +08:00
|
|
|
|
layout.addLayout(self.sub_layout, 2)
|
2022-04-01 22:25:19 +08:00
|
|
|
|
|
2022-04-07 21:11:37 +08:00
|
|
|
|
layout.addWidget(self.stackedWidget, 6)
|
2022-04-01 22:25:19 +08:00
|
|
|
|
|
2022-04-22 22:09:38 +08:00
|
|
|
|
self.one_day = SelfListWidgetItem('我的一天', 0, None, os.getcwd() + '/../images/sun.svg')
|
2022-04-04 22:34:07 +08:00
|
|
|
|
self.system_listWidget.setCurrentRow(1)
|
2022-04-01 22:25:19 +08:00
|
|
|
|
# self.one_day.setSelected(True)
|
2022-04-22 22:09:38 +08:00
|
|
|
|
self.important_item = SelfListWidgetItem('重要', 0, None, os.getcwd() + '/../images/star.svg')
|
2022-04-12 21:34:18 +08:00
|
|
|
|
|
|
|
|
|
self.system_listWidget.currentRowChanged.connect(self.stackedWidget.setCurrentIndex)
|
2022-04-01 22:25:19 +08:00
|
|
|
|
|
|
|
|
|
self.setLayout(layout)
|
|
|
|
|
self.initUI()
|
|
|
|
|
|
|
|
|
|
def initUI(self):
|
2022-04-24 22:29:42 +08:00
|
|
|
|
# 先清除列表,方便后面调用
|
|
|
|
|
self.system_listWidget.clear()
|
2022-04-04 22:34:07 +08:00
|
|
|
|
# 系统默认的两个 item
|
2022-04-01 22:25:19 +08:00
|
|
|
|
self.system_listWidget.addItem(self.one_day)
|
|
|
|
|
self.system_listWidget.setItemWidget(self.one_day, self.one_day.widget)
|
|
|
|
|
|
2022-04-12 21:34:18 +08:00
|
|
|
|
self.system_listWidget.addItem(self.important_item)
|
|
|
|
|
self.system_listWidget.setItemWidget(self.important_item, self.important_item.widget)
|
2022-04-23 17:36:22 +08:00
|
|
|
|
# todo : 通过信号修改显示的标题名字
|
2022-04-22 22:09:38 +08:00
|
|
|
|
self.system_listWidget.change_list_name.connect(self.change_list)
|
|
|
|
|
# 加载列表
|
|
|
|
|
self.load_list = get_todo_list()
|
2022-04-20 22:48:23 +08:00
|
|
|
|
# print(load_list)
|
2022-04-22 22:09:38 +08:00
|
|
|
|
if self.load_list:
|
|
|
|
|
for load in self.load_list:
|
2022-04-20 22:48:23 +08:00
|
|
|
|
self.load_item(load[0], load[1])
|
2022-04-13 21:42:41 +08:00
|
|
|
|
# self.system_listWidget.addScrollBarWidget(False)
|
2022-04-01 22:25:19 +08:00
|
|
|
|
|
2022-04-22 22:09:38 +08:00
|
|
|
|
def change_list(self):
|
|
|
|
|
print(self.system_listWidget.currentItem().text())
|
|
|
|
|
# print(name)
|
|
|
|
|
|
2022-04-07 19:34:28 +08:00
|
|
|
|
# todo 仔细研究右键菜单
|
2022-04-04 22:34:07 +08:00
|
|
|
|
|
|
|
|
|
def myListWidgetContext(self, position):
|
2022-04-22 22:09:38 +08:00
|
|
|
|
if self.system_listWidget.currentRow() > 1:
|
2022-04-04 22:34:07 +08:00
|
|
|
|
|
2022-04-22 22:09:38 +08:00
|
|
|
|
# 设置右键菜单
|
|
|
|
|
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)
|
2022-04-04 22:34:07 +08:00
|
|
|
|
|
2022-04-22 22:09:38 +08:00
|
|
|
|
rename_action = QAction(u'重命名', self)
|
2022-04-04 22:34:07 +08:00
|
|
|
|
|
2022-04-24 22:29:42 +08:00
|
|
|
|
# copy_action = QAction("复制分组", self)
|
2022-04-22 22:09:38 +08:00
|
|
|
|
del_action = QAction("删除分组", self)
|
|
|
|
|
|
|
|
|
|
# 查看右键时是否在item上面,如果不在.就不显示删除和修改.
|
2022-04-04 22:34:07 +08:00
|
|
|
|
pop_menu.addAction(rename_action)
|
2022-04-22 22:09:38 +08:00
|
|
|
|
if self.system_listWidget.itemAt(position):
|
|
|
|
|
pop_menu.addAction(del_action)
|
|
|
|
|
pop_menu.addAction(rename_action)
|
2022-04-04 22:34:07 +08:00
|
|
|
|
|
2022-04-22 22:09:38 +08:00
|
|
|
|
rename_action.triggered.connect(self.rename_item)
|
2022-04-24 22:29:42 +08:00
|
|
|
|
# copy_action.triggered.connect(self.create_item)
|
2022-04-22 22:09:38 +08:00
|
|
|
|
del_action.triggered.connect(self.delete_item)
|
|
|
|
|
pop_menu.exec_(self.system_listWidget.mapToGlobal(position))
|
2022-04-04 22:34:07 +08:00
|
|
|
|
|
2022-04-24 22:29:42 +08:00
|
|
|
|
# 加载左侧列表
|
2022-04-20 22:48:23 +08:00
|
|
|
|
def load_item(self, list_name, uid):
|
|
|
|
|
item = SelfListWidgetItem(list_name, 0, uid)
|
2022-04-04 22:34:07 +08:00
|
|
|
|
item.setTextAlignment(Qt.AlignCenter)
|
|
|
|
|
# 使得item是可以编辑的.
|
|
|
|
|
item.setFlags(item.flags() | Qt.ItemIsEditable)
|
2022-04-16 21:45:29 +08:00
|
|
|
|
self.system_listWidget.addItem(item)
|
2022-04-20 22:48:23 +08:00
|
|
|
|
todo_list = ToDoList(list_name, uid)
|
2022-04-23 17:36:22 +08:00
|
|
|
|
# 信号测试成功!!
|
2022-04-24 22:29:42 +08:00
|
|
|
|
# 更新重要内容
|
2022-04-23 17:36:22 +08:00
|
|
|
|
todo_list.update_signal.connect(self.important.refresh_action)
|
2022-04-24 22:29:42 +08:00
|
|
|
|
# 删除分组时可用
|
2022-04-23 17:36:22 +08:00
|
|
|
|
self.important.update_signal.connect(todo_list.refresh_action)
|
2022-04-04 22:34:07 +08:00
|
|
|
|
# 创建后就可以编辑item,用户自己起名字.
|
2022-04-16 21:45:29 +08:00
|
|
|
|
# self.system_listWidget.editItem(item)
|
2022-04-20 22:48:23 +08:00
|
|
|
|
self.stackedWidget.addWidget(todo_list)
|
|
|
|
|
|
2022-04-16 21:45:29 +08:00
|
|
|
|
self.system_listWidget.setItemWidget(item, item.widget)
|
2022-04-04 22:34:07 +08:00
|
|
|
|
|
2022-04-24 22:29:42 +08:00
|
|
|
|
# 点击创建新的分组
|
2022-04-22 22:09:38 +08:00
|
|
|
|
def create_item(self, new_list='新建列表', uid=None):
|
2022-04-20 22:48:23 +08:00
|
|
|
|
# 创建一个没有名字的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)
|
2022-04-23 17:36:22 +08:00
|
|
|
|
|
2022-04-20 22:48:23 +08:00
|
|
|
|
self.stackedWidget.addWidget(todo_list)
|
|
|
|
|
# 创建后就可以编辑item,用户自己起名字.
|
|
|
|
|
# self.system_listWidget.editItem(item)
|
|
|
|
|
self.system_listWidget.setItemWidget(item, item.widget)
|
|
|
|
|
|
2022-04-04 22:34:07 +08:00
|
|
|
|
# 删除分组
|
2022-04-22 22:09:38 +08:00
|
|
|
|
def delete_item(self):
|
|
|
|
|
# print(self.load_list[self.system_listWidget.currentRow() - 2][1])
|
|
|
|
|
remove_todo_list(self.load_list[self.system_listWidget.currentRow() - 2][1])
|
|
|
|
|
self.system_listWidget.takeItem(self.system_listWidget.currentRow())
|
2022-04-04 22:34:07 +08:00
|
|
|
|
|
|
|
|
|
# 重命名分组
|
2022-04-24 22:29:42 +08:00
|
|
|
|
# todo : 重命名还没做好
|
2022-04-22 22:09:38 +08:00
|
|
|
|
def rename_item(self):
|
2022-04-24 22:29:42 +08:00
|
|
|
|
dialog = QDialog()
|
|
|
|
|
dialog.setWindowTitle('重命名')
|
|
|
|
|
dialog_layout = QGridLayout()
|
|
|
|
|
dialog.resize(300, 200)
|
|
|
|
|
dialog.setLayout(dialog_layout)
|
|
|
|
|
line_edit = QLineEdit()
|
|
|
|
|
line_edit.setPlaceholderText('请输入新的名字')
|
|
|
|
|
dialog_layout.addWidget(line_edit, 0, 1, 1, 2)
|
|
|
|
|
self.confirm_button = QPushButton('确认修改')
|
|
|
|
|
dialog_layout.addWidget(self.confirm_button, 1, 1)
|
|
|
|
|
# self.load_list = get_todo_list()
|
|
|
|
|
line_edit.textChanged.connect(self.confirm_action)
|
|
|
|
|
|
|
|
|
|
# if line_edit.text() != '':
|
|
|
|
|
# change_value(self.load_list[self.system_listWidget.currentRow() - 2][1], 'title', line_edit.text())
|
|
|
|
|
# self.confirm_button.clicked.connect(self.initUI)
|
|
|
|
|
dialog.exec_()
|
|
|
|
|
#
|
|
|
|
|
# curRow = self.system_listWidget.currentRow()
|
|
|
|
|
# item = self.system_listWidget.item(curRow)
|
|
|
|
|
# item.setFlags(item.flags() | Qt.ItemIsEditable)
|
|
|
|
|
# self.system_listWidget.editItem(item)
|
|
|
|
|
# self.system_listWidget.itemChanged.connect(lambda: self.ChangeItem(item))
|
2022-04-04 22:34:07 +08:00
|
|
|
|
|
|
|
|
|
def ChangeItem(self, item):
|
2022-04-22 22:09:38 +08:00
|
|
|
|
print(item)
|
|
|
|
|
|
2022-04-04 22:34:07 +08:00
|
|
|
|
print("test")
|
|
|
|
|
|
2022-04-24 22:29:42 +08:00
|
|
|
|
def confirm_action(self, text):
|
|
|
|
|
# print(text)
|
|
|
|
|
self.load_list = get_todo_list()
|
|
|
|
|
change_value(self.load_list[self.system_listWidget.currentRow() - 2][1], 'title', text)
|
|
|
|
|
self.confirm_button.clicked.connect(self.load_ui)
|
|
|
|
|
# self.system_listWidget.itemChanged.connect(lambda: self.ChangeItem(text))
|
|
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def load_ui(self):
|
|
|
|
|
# 先清除列表,方便后面调用
|
|
|
|
|
self.system_listWidget.clear()
|
|
|
|
|
# 系统默认的两个 item
|
|
|
|
|
self.system_listWidget.addItem(self.one_day)
|
|
|
|
|
self.system_listWidget.setItemWidget(self.one_day, self.one_day.widget)
|
|
|
|
|
|
|
|
|
|
self.system_listWidget.addItem(self.important_item)
|
|
|
|
|
self.system_listWidget.setItemWidget(self.important_item, self.important_item.widget)
|
|
|
|
|
self.close()
|
|
|
|
|
|
2022-04-01 22:25:19 +08:00
|
|
|
|
|
|
|
|
|
class MainWindow(QWidget):
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super(MainWindow, self).__init__()
|
2022-04-04 22:34:07 +08:00
|
|
|
|
self.resize(1150, 850)
|
2022-04-01 22:25:19 +08:00
|
|
|
|
self.setWindowTitle("待办事项")
|
|
|
|
|
# 主布局,用来显示主页面,设置页面等
|
|
|
|
|
self.layout = QStackedLayout(self)
|
|
|
|
|
|
|
|
|
|
self.main_widget = MainWidget()
|
|
|
|
|
# self.main_widget.resize(50, 200)
|
|
|
|
|
self.layout.addWidget(self.main_widget)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
app = QApplication(sys.argv)
|
|
|
|
|
main = MainWindow()
|
2022-04-19 20:18:10 +08:00
|
|
|
|
main.setWindowTitle('PyQtToDoList')
|
2022-04-01 22:25:19 +08:00
|
|
|
|
# print(os.path.abspath('../'))
|
|
|
|
|
style_sheet = QSSLoader.read_qss_file('../resource/current.qss')
|
|
|
|
|
main.setStyleSheet(style_sheet)
|
|
|
|
|
|
|
|
|
|
app.setWindowIcon(QIcon(os.path.abspath('../') + '/images/todo.svg'))
|
|
|
|
|
main.show()
|
|
|
|
|
sys.exit(app.exec_())
|