diff --git a/images/icon/学习.svg b/images/icon/学习.svg new file mode 100644 index 0000000..3c777f7 --- /dev/null +++ b/images/icon/学习.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/images/icon/工作.svg b/images/icon/工作.svg new file mode 100644 index 0000000..9ae4891 --- /dev/null +++ b/images/icon/工作.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/images/icon/冲浪.svg b/images/icon/度假.svg similarity index 100% rename from images/icon/冲浪.svg rename to images/icon/度假.svg diff --git a/images/icon/沙滩.svg b/images/icon/沙滩.svg deleted file mode 100644 index 5418fbe..0000000 --- a/images/icon/沙滩.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/images/icon/行李箱.svg b/images/icon/行李箱.svg deleted file mode 100644 index aaa048e..0000000 --- a/images/icon/行李箱.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/images/icon/购物.svg b/images/icon/购物.svg index cbcbb66..9436b03 100644 --- a/images/icon/购物.svg +++ b/images/icon/购物.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/main/main.py b/main/main.py index abe6b88..7ec9499 100644 --- a/main/main.py +++ b/main/main.py @@ -2,7 +2,7 @@ import os import sys from PyQt5.QtGui import * from PyQt5.QtWidgets import * -from PyQt5.QtCore import Qt +from PyQt5.QtCore import Qt, pyqtSignal import configparser from utils.BasicUtils import get_todo_list, remove_todo_list, change_value @@ -18,6 +18,8 @@ from view.MyDayView import MyDay class MainWidget(QWidget): + update_signal = pyqtSignal() + def __init__(self): super(MainWidget, self).__init__() self.user_label = User() @@ -57,11 +59,6 @@ class MainWidget(QWidget): layout.addWidget(self.stackedWidget, 6) - 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, None, os.getcwd() + '/../images/star.svg') - self.system_listWidget.currentRowChanged.connect(self.stackedWidget.setCurrentIndex) self.setLayout(layout) @@ -71,25 +68,26 @@ class MainWidget(QWidget): # 先清除列表,方便后面调用 self.system_listWidget.clear() # 系统默认的两个 item + 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, None, os.getcwd() + '/../images/star.svg') + 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) # todo : 通过信号修改显示的标题名字 - self.system_listWidget.change_list_name.connect(self.change_list) + # self.system_listWidget.change_list_name.connect(self.change_list) # 加载列表 - self.load_list = get_todo_list() + load_list = get_todo_list() # print(load_list) - if self.load_list: - for load in self.load_list: - self.load_item(load[0], load[1]) + if load_list: + for load in load_list: + self.load_item(load[0], load[1], load[3]) # self.system_listWidget.addScrollBarWidget(False) - def change_list(self): - print(self.system_listWidget.currentItem().text()) - # print(name) - # todo 仔细研究右键菜单 def myListWidgetContext(self, position): @@ -107,37 +105,83 @@ class MainWidget(QWidget): # copy_action = QAction("复制分组", self) del_action = QAction("删除分组", self) + change_icon = QMenu('修改图标', pop_menu) + # 背景透明 + change_icon.setAttribute(Qt.WA_TranslucentBackground) + # 无边框、去掉自带阴影 + change_icon.setWindowFlags( + change_icon.windowFlags() | Qt.FramelessWindowHint | Qt.NoDropShadowWindowHint) + + # 二级菜单 + action1 = QAction(QIcon(os.getcwd() + '/../images/icon/星宿.svg'), "星宿", self) + action2 = QAction(QIcon(os.getcwd() + '/../images/icon/度假.svg'), "度假", self) + action3 = QAction(QIcon(os.getcwd() + '/../images/icon/冰淇淋.svg'), "冰淇淋", self) + action4 = QAction(QIcon(os.getcwd() + '/../images/icon/学习.svg'), "学习", self) + action5 = QAction(QIcon(os.getcwd() + '/../images/icon/工作.svg'), "工作", self) + action6 = QAction(QIcon(os.getcwd() + '/../images/icon/购物.svg'), "购物", self) + change_icon.addAction(action1) + change_icon.addAction(action2) + change_icon.addAction(action3) + change_icon.addAction(action4) + change_icon.addAction(action5) + change_icon.addAction(action6) + + action1.triggered.connect(lambda: self.change_icon('星宿')) + action2.triggered.connect(lambda: self.change_icon('度假')) + action3.triggered.connect(lambda: self.change_icon('冰淇淋')) + action4.triggered.connect(lambda: self.change_icon('学习')) + action5.triggered.connect(lambda: self.change_icon('工作')) + action6.triggered.connect(lambda: self.change_icon('购物')) # 查看右键时是否在item上面,如果不在.就不显示删除和修改. - pop_menu.addAction(rename_action) + if self.system_listWidget.itemAt(position): pop_menu.addAction(del_action) pop_menu.addAction(rename_action) + # pop_menu.addAction(change_icon) + pop_menu.addMenu(change_icon) rename_action.triggered.connect(self.rename_item) # copy_action.triggered.connect(self.create_item) del_action.triggered.connect(self.delete_item) pop_menu.exec_(self.system_listWidget.mapToGlobal(position)) + def change_icon(self, icon): + # print(icon) + load_list = get_todo_list() + change_value(load_list[self.system_listWidget.currentRow() - 2][1], 'icon', icon) + self.initUI() + # 加载左侧列表 - def load_item(self, list_name, uid): - item = SelfListWidgetItem(list_name, 0, uid) + + def load_item(self, list_name, uid, icon=None): + # print(icon) + # self.stackedWidget.currentChanged.connect(self.change) + item = SelfListWidgetItem(list_name, 0, uid, os.getcwd() + '/../images/icon/' + icon + '.svg') item.setTextAlignment(Qt.AlignCenter) # 使得item是可以编辑的. item.setFlags(item.flags() | Qt.ItemIsEditable) self.system_listWidget.addItem(item) todo_list = ToDoList(list_name, uid) # 信号测试成功!! - # 更新重要内容 + # 更新 重要 内容 todo_list.update_signal.connect(self.important.refresh_action) + todo_list.update_signal.connect(self.my_day.refresh_action) + # 删除分组时可用 self.important.update_signal.connect(todo_list.refresh_action) + self.important.update_signal.connect(self.my_day.refresh_action) + self.my_day.update_signal.connect(todo_list.refresh_action) + self.my_day.update_signal.connect(self.important.refresh_action) + + self.update_signal.connect(todo_list.refresh_action) # 创建后就可以编辑item,用户自己起名字. # self.system_listWidget.editItem(item) self.stackedWidget.addWidget(todo_list) self.system_listWidget.setItemWidget(item, item.widget) - + def change(self): + print(1) # 点击创建新的分组 def create_item(self, new_list='新建列表', uid=None): # 创建一个没有名字的item @@ -152,67 +196,47 @@ class MainWidget(QWidget): 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 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]) + load_list = get_todo_list() + remove_todo_list(load_list[self.system_listWidget.currentRow() - 2][1]) self.system_listWidget.takeItem(self.system_listWidget.currentRow()) # 重命名分组 # todo : 重命名还没做好 def rename_item(self): - dialog = QDialog() - dialog.setWindowTitle('重命名') - dialog_layout = QGridLayout() - dialog.resize(300, 200) - dialog.setLayout(dialog_layout) + # curRow = self.todo_list.currentRow() + # item = self.todo_list.item(curRow) + + 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('请输入新的名字') - 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) + 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())) - # 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)) + self.dialog.exec_() - def ChangeItem(self, item): - print(item) - - print("test") - - 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() + def change_name(self, item_name): + # print(item_name) + load_list = get_todo_list() + change_value(load_list[self.system_listWidget.currentRow() - 2][1], 'title', item_name) + self.update_signal.emit() + # 重命名发送信号 + self.initUI() + # self.update_signal.emit() + self.dialog.close() class MainWindow(QWidget): @@ -233,7 +257,7 @@ if __name__ == "__main__": main = MainWindow() main.setWindowTitle('PyQtToDoList') # print(os.path.abspath('../')) - style_sheet = QSSLoader.read_qss_file('../resource/current.qss') + style_sheet = QSSLoader.read_qss_file(os.getcwd() + '/../resource/current.qss') main.setStyleSheet(style_sheet) app.setWindowIcon(QIcon(os.path.abspath('../') + '/images/todo.svg')) diff --git a/test/QListWidgetTest.py b/test/QListWidgetTest.py deleted file mode 100644 index 35f138d..0000000 --- a/test/QListWidgetTest.py +++ /dev/null @@ -1,54 +0,0 @@ - - self.leftWidget =QListWidget() - #禁止双击可编辑 - self.leftWidget.setEditTriggers(QAbstractItemView.NoEditTriggers) - #右键菜单 - self.leftWidget.setContextMenuPolicy(Qt.CustomContextMenu) - self.leftWidget.customContextMenuRequested.connect(self.myListWidgetContext) - - def myListWidgetContext(self,position): - #弹出菜单 - popMenu = QMenu() - creAct =QAction("新建分组",self) - delAct =QAction("删除分组",self) - renameAct =QAction(u'重命名', self) - #查看右键时是否在item上面,如果不在.就不显示删除和修改. - popMenu.addAction(creAct) - if self.leftWidget.itemAt(position): - popMenu.addAction(delAct) - popMenu.addAction(renameAct) - - creAct.triggered.connect(self.CreateNewItem) - renameAct.triggered.connect(self.RenameItem) - delAct.triggered.connect(self.DeleteItem) - popMenu.exec_(self.leftWidget.mapToGlobal(position)) - - #创建新的分组 - def CreateNewItem(self): - #创建一个没有名字的item - item =QListWidgetItem("") - item.setTextAlignment(Qt.AlignCenter) - #使得item是可以编辑的. - item.setFlags(item.flags() | Qt.ItemIsEditable) - self.leftWidget.addItem(item) - #创建后就可以编辑item,用户自己起名字. - self.leftWidget.editItem(item) - - - -#删除分组 - def DeleteItem(self): - self.leftWidget.takeItem(self.leftWidget.currentRow()) - - #重命名分组 - def RenameItem(self): - curRow =self.leftWidget.currentRow() - item=self.leftWidget.item(curRow) - item.setFlags(item.flags() | Qt.ItemIsEditable) - self.leftWidget.editItem(item) - self.leftWidget.itemChanged.connect(lambda :self.ChangeItem(item)) - - - def ChangeItem(self,item): - print("test") - diff --git a/utils/BasicUtils.py b/utils/BasicUtils.py index 6d1476a..00974f7 100644 --- a/utils/BasicUtils.py +++ b/utils/BasicUtils.py @@ -74,7 +74,8 @@ def get_todo_list(): # try: if json_file['itemType'] == 'ToDoList': # print(json_file['title'], json_file['uid'], '列表') - return_todo_list.append([json_file['title'], json_file['uid'], json_file['updatedAt']]) + return_todo_list.append( + [json_file['title'], json_file['uid'], json_file['updatedAt'], json_file['icon']]) # print(return_todo_list) return_todo_list.sort(key=get_third) @@ -188,7 +189,6 @@ def remove_todo_list(uid): # print(os.path.join(root, name)) os.remove(os.path.join(root, name)) - # print(read_init_file()) # webdav_hostname = read_init_file() # print(webdav_hostname[2]) @@ -196,4 +196,4 @@ def remove_todo_list(uid): # print(get_todo('3f1e033f-2051-4c04-b7f6-afd2eb1f54f4')) # print(load_myday_important('Important')) # change_myday_important_conf('Important', 'theme', 2) -# print(get_myday_important_conf('Important','Theme')) \ No newline at end of file +# print(get_myday_important_conf('Important','Theme')) diff --git a/utils/CreateToDo.py b/utils/CreateToDo.py index 60bf917..43a02dd 100644 --- a/utils/CreateToDo.py +++ b/utils/CreateToDo.py @@ -28,7 +28,7 @@ def CreateToDo(item_type, name, todo_list_uid=None): if not os.path.exists(todo_list_path): os.mkdir(todo_list_path) default_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') - print(''+uid) + print('' + uid) if item_type == 'ToDoList': # print(item_type) try: @@ -49,6 +49,7 @@ def CreateToDo(item_type, name, todo_list_uid=None): "title": name, "uid": uid, "Theme": '0', + "icon": '星宿', "updatedAt": default_time } # library = { @@ -82,10 +83,39 @@ def CreateToDo(item_type, name, todo_list_uid=None): with open(todo_list_path + '{' + uid + '}.otl', 'w') as f: f.write(json.dumps(out_config, indent=4, ensure_ascii=False)) return uid - except IOError as e: print(e) return False + +def create_myday_important(item_type, name): + uid = str(uuid.uuid4()) + config_path = BasicUtils.return_work_dir() + todo_list_path = config_path + 'ToDoList/' + if not os.path.exists(todo_list_path): + os.mkdir(todo_list_path) + default_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') + print('' + uid) + out_config = { + "createdAt": default_time, + "done": False, + "dueTo": '', + "itemType": item_type, + "notes": "", + "isMyDay": False, + "isImportant": False, + "title": name, + "uid": uid, + "updatedAt": default_time + } + try: + if item_type == 'MyDay': + with open(todo_list_path + '{' + uid + '}.otl', 'w') as f: + f.write(json.dumps(out_config, indent=4, ensure_ascii=False)) + return uid + except IOError as e: + print(e) + return False + # # CreateToDo('ToDo', 'test1', '3f1e033f-2051-4c04-b7f6-afd2eb1f54f4') diff --git a/view/AddToDoLabel.py b/view/AddToDoLabel.py index 8082777..bcdd7b2 100644 --- a/view/AddToDoLabel.py +++ b/view/AddToDoLabel.py @@ -38,11 +38,3 @@ class AddToDoAction(QLabel): self.setLayout(layout) self.show() - # def line_edit_action(self): - # print('click left button') - - # # 回车添加事件 - # def line_edit_add(self, name): - # self.todo_name.emit(name) - # print(name) - # self.line_edit.clear() diff --git a/view/ImportantView.py b/view/ImportantView.py index 2d603d2..bc216a4 100644 --- a/view/ImportantView.py +++ b/view/ImportantView.py @@ -8,6 +8,7 @@ from PyQt5.QtCore import Qt, pyqtSignal from utils.BasicUtils import load_myday_important, remove_todo_list, change_value, get_todo, get_myday_important_conf, \ change_myday_important_conf +from utils.CreateToDo import CreateToDo from view.AddToDoLabel import AddToDoAction from view.ToDoItem import ToDoItem @@ -36,6 +37,9 @@ class Important(QWidget): head_widget = QWidget(self) self.todo_list = QListWidget() + + # 关闭滚动条 + self.todo_list.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.todo_list.setObjectName('todo_list') # 添加ToDo的标签 @@ -43,24 +47,14 @@ class Important(QWidget): 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.setPlaceholderText('添加任务') - # head_widget.setMaximumHeight(100) - # head_widget. - # head_widget.setObjectName('head_widget') head_widget.setAttribute(Qt.WA_StyledBackground) - # self.setStyleSheet('#head_widget{margin:50px}') - - # head_widget.setPalette(palette) head_widget.setLayout(head_layout) head_layout.setAlignment(Qt.AlignCenter) - # head_left_layout = QVBoxLayout() - # layout.addStretch(0) + layout.addWidget(head_widget, 2, Qt.AlignTop) - # layout.addSpacing(1) - # layout.addStretch(1) - # layout.addStretch(0) + layout.addWidget(self.todo_list, 6, Qt.AlignCenter | Qt.AlignTop) head_label = QLabel("重要") head_label.setObjectName('head_label') @@ -163,7 +157,6 @@ class Important(QWidget): self.todo_list.addItem(todo_item) self.todo_list.setItemWidget(todo_item, todo_item.widget) - # todo : 下面的方法实现点击更换主题的功能 def menu_action(self, count): # 点击按钮 count = str(count) @@ -178,7 +171,9 @@ class Important(QWidget): if name: self.add_todo.todo_name.emit(name) # print('添加的新ToDo:' + name) - todo_item = ToDoItem(name) + create_todo = CreateToDo('Todo', name) + change_value(create_todo, 'isImportant', True) + todo_item = ToDoItem(name, create_todo) self.todo_list.addItem(todo_item) self.todo_list.setItemWidget(todo_item, todo_item.widget) self.add_todo.line_edit.clear() @@ -200,28 +195,30 @@ class Important(QWidget): del_action = QAction("删除", self) # 查看右键时是否在item上面,如果不在.就不显示删除和修改. - pop_menu.addAction(rename_action) 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) - + mark_myday.triggered.connect(lambda: self.make_action('MyDay')) rename_action.triggered.connect(self.rename_item) # copy_action.triggered.connect(self.create_item) del_action.triggered.connect(self.delete_item) - mark_important.triggered.connect(self.make_important) + mark_important.triggered.connect(lambda: self.make_action('Important')) pop_menu.exec_(self.todo_list.mapToGlobal(position)) - def make_important(self): + def make_action(self, make_type): # print(self.todo_list.currentRow()) - my_day_list = load_myday_important('Important') - # load_todo = get_todo(my_day_list[self.todo_list.currentRow()][1]) - uid = my_day_list[self.todo_list.currentRow()][1] - self.todo_list.takeItem(self.todo_list.currentRow()) - # print(' uid:', uid) - change_value(uid, 'isImportant', False) - # 暂时不需要发送信号 + load_todo = load_myday_important('Important') + print(load_todo) + uid = load_todo[self.todo_list.currentRow()][1] + if make_type == 'MyDay': + change_value(uid, 'isMyDay', True) + elif make_type == 'Important': + change_value(uid, 'isImportant', False) + self.todo_list.takeItem(self.todo_list.currentRow()) + self.refresh_action() + self.update_signal.emit() # 删除分组 @@ -257,9 +254,6 @@ class Important(QWidget): self.dialog.exec_() - # 重命名发送信号 - # self.update_signal.emit() - def change_name(self, item_name): print(item_name) my_day_list = load_myday_important('Important') diff --git a/view/MyDayView.py b/view/MyDayView.py index f03d470..12beb51 100644 --- a/view/MyDayView.py +++ b/view/MyDayView.py @@ -3,7 +3,7 @@ from PyQt5.QtGui import * from PyQt5.QtWidgets import * from PyQt5.QtCore import Qt, pyqtSignal -from utils.BasicUtils import load_myday_important, remove_todo_list, change_value +from utils.BasicUtils import load_myday_important, remove_todo_list, change_value, change_myday_important_conf from utils.CreateToDo import CreateToDo from view.AddToDoLabel import AddToDoAction from view.MyDayHeadLabel import HeadLabel @@ -41,6 +41,8 @@ class MyDay(QWidget): head_widget.setAttribute(Qt.WA_StyledBackground) self.todo_list = QListWidget() + # 关闭滚动条 + self.todo_list.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.todo_list.setFrameShape(QListWidget.NoFrame) self.todo_list.setObjectName('todo_list') @@ -86,6 +88,15 @@ class MyDay(QWidget): self.menu_image.setMenu(self.button_menu) + refresh_label = QAction(self) + refresh_label.setText('刷新') + refresh_label.setIcon(QIcon('../images/refresh.svg')) + # refresh_label.setDisabled(True) + self.button_menu.addAction(refresh_label) + self.button_menu.addSeparator() + refresh_label.triggered.connect(self.refresh_action) + self.menu_image.addAction(refresh_label) + theme_label = QAction(self) theme_label.setText('主题') theme_label.setDisabled(True) @@ -121,12 +132,10 @@ class MyDay(QWidget): label_action5.setText('背景5') label_action5.triggered.connect(lambda: self.menu_action(5)) self.button_menu.addAction(label_action5) + # 右键菜单 + self.todo_list.setContextMenuPolicy(Qt.CustomContextMenu) + self.todo_list.customContextMenuRequested.connect(self.todo_list_context) - # 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]) self.refresh_action() def refresh_action(self): @@ -138,50 +147,28 @@ class MyDay(QWidget): for my_day in my_day_list: self.load_myday(my_day[0], my_day[1]) - # def initUI(self): - # print('(initUI)') - # # thread_action = ThreadAction() - # # thread_action.change_value_action.connect() - # - # self.my_day_list = load_myday_important('Important') - # - # if self.my_day_list: - # for my_day in self.my_day_list: - # self.load_myday(my_day[0], my_day[1]) - 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) - def menu_action(self, count): count = str(count) # 点击按钮 - + change_myday_important_conf('MyDay', 'theme', count) self.setStyleSheet('#my_day{background-image:url("../images/' + count + '.jpg");' 'background-position: center; border-radius: 10px;' '}') - # self.head_label.show() - - print(' 选中:' + count) - - # - # def add_todo_action(self, name): - # print(name) - # todo : 回车添加事件 + # 回车添加事件 def line_edit_add(self, name): if name: self.add_todo.todo_name.emit(name) # print('添加的新ToDo:' + name) - create_todo = CreateToDo('Todo', name, self.uid) - todo_item = ToDoItem(name, create_todo) - + todo_item = ToDoItem(name) self.todo_list.addItem(todo_item) self.todo_list.setItemWidget(todo_item, todo_item.widget) - self.add_todo.line_edit.clear() def todo_list_context(self, position): @@ -201,34 +188,42 @@ class MyDay(QWidget): del_action = QAction("删除", self) # 查看右键时是否在item上面,如果不在.就不显示删除和修改. - pop_menu.addAction(rename_action) 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) + mark_myday.triggered.connect(lambda: self.make_action('MyDay')) rename_action.triggered.connect(self.rename_item) - # copy_action.triggered.connect(self.create_item) + del_action.triggered.connect(self.delete_item) - mark_important.triggered.connect(self.make_important) + mark_important.triggered.connect(lambda: self.make_action('Important')) + pop_menu.exec_(self.todo_list.mapToGlobal(position)) - def make_important(self): + # 设置右键点击事件 + def make_action(self, make_type): # print(self.todo_list.currentRow()) - my_day_list = load_myday_important('Important') - # load_todo = get_todo(my_day_list[self.todo_list.currentRow()][1]) - uid = my_day_list[self.todo_list.currentRow()][1] - self.todo_list.takeItem(self.todo_list.currentRow()) - # print(' uid:', uid) - change_value(uid, 'isImportant', True) - # 暂时不需要发送信号 + load_todo = load_myday_important(make_type) + uid = load_todo[self.todo_list.currentRow()][1] + if make_type == 'MyDay': + change_value(uid, 'isMyDay', False) + self.todo_list.takeItem(self.todo_list.currentRow()) + elif make_type == 'Important': + change_value(uid, 'isImportant', True) + self.refresh_action() + + # + # load_todo = load_myday_important('MyDay') + # uid = load_todo[self.todo_list.currentRow()][1] + self.update_signal.emit() # 删除分组 def delete_item(self): # print(self.load_list[self.system_listWidget.currentRow() - 2][1]) - my_day_list = load_myday_important('Important') + my_day_list = load_myday_important('MyDay') # load_todo = get_todo(my_day_list[self.todo_list.currentRow()][1]) uid = my_day_list[self.todo_list.currentRow()][1] remove_todo_list(uid) @@ -236,16 +231,32 @@ class MyDay(QWidget): self.todo_list.takeItem(self.todo_list.currentRow()) self.update_signal.emit() - # 重命名分组 + # 重命名分组 + def rename_item(self): - curRow = self.todo_list.currentRow() - item = self.todo_list.item(curRow) - item.setFlags(item.flags() | Qt.ItemIsEditable) - self.todo_list.editItem(item) - self.todo_list.itemChanged.connect(lambda: self.ChangeItem(item)) - def ChangeItem(self, item): - print(item) + 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())) - print("test") + self.dialog.exec_() + def change_name(self, item_name): + print(item_name) + my_day_list = load_myday_important('Important') + change_value(my_day_list[self.todo_list.currentRow()][1], 'title', item_name) + # 重命名发送信号 + self.refresh_action() + self.update_signal.emit() + self.dialog.close() diff --git a/view/SelfListWidgetItem.py b/view/SelfListWidgetItem.py index 2bd96c9..fadb0d7 100644 --- a/view/SelfListWidgetItem.py +++ b/view/SelfListWidgetItem.py @@ -26,8 +26,6 @@ class SelfListWidgetItem(QListWidgetItem): self.widget = QWidget() self.widget.setLayout(layout) - # self.list_item = QLabel('') - # 添加左边的图标和右边的气泡 if self.show_icon: self.icon_label = QLabel('') diff --git a/view/ToDoItem.py b/view/ToDoItem.py index 257c92f..1abbb23 100644 --- a/view/ToDoItem.py +++ b/view/ToDoItem.py @@ -42,15 +42,16 @@ class ToDoItem(QListWidgetItem): layout.addWidget(self.todo_label, 6) layout.addWidget(self.important_button, 2) - self.mark_icon.clicked.connect(self.set_done) + self.mark_icon.clicked.connect(lambda: self.set_done(uid)) # print('', uid) self.important_button.clicked.connect(lambda: self.set_important(uid)) # self.mark_icon.trans_signal.connect(self.set_done) - def set_done(self): - self.mark_icon.setIcon(QIcon(os.getcwd()+'/../images/finished.svg')) - # time.sleep(0.2) + def set_done(self, uid): + self.mark_icon.setIcon(QIcon(os.getcwd() + '/../images/finished.svg')) + time.sleep(0.2) + change_value(uid, 'done', True) pass def set_myday(self, uid): @@ -61,7 +62,7 @@ class ToDoItem(QListWidgetItem): # important = Important() # important.load_important.emit() # self.action.emit() - print('',uid) + print('', uid) change_value(uid, 'isImportant', True) # self.transaction.emit() diff --git a/view/ToDoListView.py b/view/ToDoListView.py index f2b95fd..ce611c1 100644 --- a/view/ToDoListView.py +++ b/view/ToDoListView.py @@ -36,6 +36,8 @@ class ToDoList(QWidget): # head_widget.setMinimumHeight(175) self.todo_list = QListWidget() + # 关闭滚动条 + self.todo_list.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.todo_list.setObjectName('todo_list') # 添加ToDo的标签 @@ -43,24 +45,13 @@ class ToDoList(QWidget): 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.setPlaceholderText('添加任务') - - # head_widget.setMaximumHeight(100) - # head_widget. - # head_widget.setObjectName('head_widget') head_widget.setAttribute(Qt.WA_StyledBackground) - # self.setStyleSheet('#head_widget{margin:50px}') - - # head_widget.setPalette(palette) head_widget.setLayout(head_layout) head_layout.setAlignment(Qt.AlignCenter) - # head_left_layout = QVBoxLayout() - # layout.addStretch(0) + layout.addWidget(head_widget, 2, Qt.AlignTop) - # layout.addSpacing(1) - # layout.addStretch(1) - # layout.addStretch(0) + layout.addWidget(self.todo_list, 6, Qt.AlignCenter | Qt.AlignTop) head_label = QLabel(list_name) head_label.setObjectName('head_label') @@ -102,15 +93,7 @@ class ToDoList(QWidget): theme_label.setDisabled(True) self.button_menu.addAction(theme_label) self.button_menu.addSeparator() - # - # for i in range(11): - # label_action = QAction(self) - # label_action.setIcon(QIcon('../images/' + str(i) + '.jpg')) - # label_action.setText(str(i)) - # label_action.triggered.connect(lambda: self.menu_action(str(i))) - # self.button_menu.addAction(label_action) - # for i in range(11): label_action1 = QAction(self) label_action1.setIcon(QIcon('../images/1.jpg')) label_action1.setText('背景1') @@ -152,9 +135,9 @@ class ToDoList(QWidget): # thread_action = ThreadAction() self.load_theme() - self.loadtodo = get_todo(self.uid) - if self.loadtodo: - for load in self.loadtodo: + load_todo = get_todo(self.uid) + if load_todo: + for load in load_todo: self.load_todo(load[0], load[1]) def load_theme(self): @@ -186,15 +169,16 @@ class ToDoList(QWidget): # self.my_day_list[] self.todo_list.clear() # print(self.my_day_list) - self.loadtodo = get_todo(self.uid) - if self.loadtodo: - for load in self.loadtodo: + load_todo = get_todo(self.uid) + if load_todo: + for load in load_todo: self.load_todo(load[0], load[1]) def line_edit_add(self, name): if name: self.add_todo.todo_name.emit(name) # print('添加的新ToDo:' + name) + create_todo = CreateToDo('Todo', name, self.uid) todo_item = ToDoItem(name, create_todo) @@ -220,25 +204,28 @@ class ToDoList(QWidget): del_action = QAction("删除", self) # 查看右键时是否在item上面,如果不在.就不显示删除和修改. - pop_menu.addAction(rename_action) + # pop_menu.addAction(rename_action) 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) + mark_myday.triggered.connect(lambda: self.make_action('MyDay')) rename_action.triggered.connect(self.rename_item) - # copy_action.triggered.connect(self.create_item) del_action.triggered.connect(self.delete_item) - mark_important.triggered.connect(self.make_important) + mark_important.triggered.connect(lambda: self.make_action('Important')) pop_menu.exec_(self.todo_list.mapToGlobal(position)) - def make_important(self): - print(self.todo_list.currentRow()) + def make_action(self, make_type): + # print(self.todo_list.currentRow()) load_todo = get_todo(self.uid) uid = load_todo[self.todo_list.currentRow()][1] - # print(' uid:', uid) - change_value(uid, 'isImportant', True) + if make_type == 'MyDay': + change_value(uid, 'isMyDay', True) + elif make_type == 'Important': + change_value(uid, 'isImportant', True) + self.update_signal.emit() # 删除分组 @@ -254,21 +241,38 @@ class ToDoList(QWidget): # 重命名分组 # todo : 复制重要代码 def rename_item(self): - curRow = self.todo_list.currentRow() - item = self.todo_list.item(curRow) - item.setFlags(item.flags() | Qt.ItemIsEditable) - self.todo_list.editItem(item) - self.todo_list.itemChanged.connect(lambda: self.ChangeItem(item)) + 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() self.update_signal.emit() - - def ChangeItem(self, item): - print(item) - - print("test") + self.dialog.close() def mark_done(self, uid): print('mark done:', uid) - + self.update_signal.emit() def mark_important(self, uid): + self.update_signal.emit() pass