diff --git a/main/main.py b/main/main.py index 478c018..791dbdf 100644 --- a/main/main.py +++ b/main/main.py @@ -128,7 +128,7 @@ class MainWidget(QWidget): 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.load_list = get_todo_list() @@ -184,6 +184,10 @@ class MainWidget(QWidget): 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) + self.important.update_signal.connect(todo_list.refresh_action) # 创建后就可以编辑item,用户自己起名字. # self.system_listWidget.editItem(item) self.stackedWidget.addWidget(todo_list) @@ -202,6 +206,8 @@ class MainWidget(QWidget): 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) diff --git a/test/SwitchWindwos.py b/test/SwitchWindwos.py new file mode 100644 index 0000000..24ddd47 --- /dev/null +++ b/test/SwitchWindwos.py @@ -0,0 +1,98 @@ +import sys +from PyQt5 import QtCore, QtWidgets + + +class MainWindow(QtWidgets.QWidget): + + switch_window = QtCore.pyqtSignal(str) + + def __init__(self): + QtWidgets.QWidget.__init__(self) + self.setWindowTitle('Main Window') + + layout = QtWidgets.QGridLayout() + + self.line_edit = QtWidgets.QLineEdit() + layout.addWidget(self.line_edit) + + self.button = QtWidgets.QPushButton('Switch Window') + self.button.clicked.connect(self.switch) + layout.addWidget(self.button) + + self.setLayout(layout) + + def switch(self): + self.switch_window.emit(self.line_edit.text()) + + +class WindowTwo(QtWidgets.QWidget): + + def __init__(self, text): + QtWidgets.QWidget.__init__(self) + self.setWindowTitle('Window Two') + + layout = QtWidgets.QGridLayout() + + self.label = QtWidgets.QLabel(text) + layout.addWidget(self.label) + + self.button = QtWidgets.QPushButton('Close') + self.button.clicked.connect(self.close) + + layout.addWidget(self.button) + + self.setLayout(layout) + + +class Login(QtWidgets.QWidget): + + switch_window = QtCore.pyqtSignal() + + def __init__(self): + QtWidgets.QWidget.__init__(self) + self.setWindowTitle('Login') + + layout = QtWidgets.QGridLayout() + + self.button = QtWidgets.QPushButton('Login') + self.button.clicked.connect(self.login) + + layout.addWidget(self.button) + + self.setLayout(layout) + + def login(self): + self.switch_window.emit() + + +class Controller: + + def __init__(self): + pass + + def show_login(self): + self.login = Login() + self.login.switch_window.connect(self.show_main) + self.login.show() + + def show_main(self): + self.window = MainWindow() + self.window.switch_window.connect(self.show_window_two) + self.login.close() + self.window.show() + + def show_window_two(self, text): + self.window_two = WindowTwo(text) + self.window.close() + self.window_two.show() + + +def main(): + app = QtWidgets.QApplication(sys.argv) + controller = Controller() + controller.show_login() + sys.exit(app.exec_()) + + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/utils/BasicUtils.py b/utils/BasicUtils.py index d7e3b75..da0c894 100644 --- a/utils/BasicUtils.py +++ b/utils/BasicUtils.py @@ -46,9 +46,10 @@ 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']]) + return_todo_list.append([json_file['title'], json_file['uid'], json_file['updatedAt']]) # print(return_todo_list) + return_todo_list.sort(key=get_third) return return_todo_list @@ -70,7 +71,8 @@ def get_todo(todoListUid): if json_file['itemType'] == 'Todo' and not json_file['done'] and json_file[ 'todoListUid'] == todoListUid: # 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'], json_file['updatedAt']]) + return_todo.sort(key=get_third) return return_todo # load_list = get_todo_list() @@ -94,16 +96,21 @@ def load_myday_important(item_type): if item_type == 'MyDay': if json_file['itemType'] == 'Todo' and not json_file['done'] and json_file['isMyDay']: # 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'], json_file['updatedAt']]) # return return_todo elif item_type == 'Important': if json_file['itemType'] == 'Todo' and not json_file['done'] and json_file['isImportant']: # 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'], json_file['updatedAt']]) # print(return_todo) + return_todo.sort(key=get_third) return return_todo +def get_third(elem): + return elem[2] + + # 用于修改某个键值对,比如更新修改时期,设置为重要,我的一天等 def change_value(uid, key, value): config_path = return_work_dir() @@ -142,7 +149,6 @@ def remove_todo_list(uid): todo_path = config_path + 'ToDoList/' os.remove(todo_path + '{' + uid + '}.otl') - # print(read_init_file()) # webdav_hostname = read_init_file() # print(webdav_hostname[2]) diff --git a/view/ImportantView.py b/view/ImportantView.py index d4705cc..29b4b44 100644 --- a/view/ImportantView.py +++ b/view/ImportantView.py @@ -4,13 +4,15 @@ from PyQt5.QtGui import * from PyQt5.QtWidgets import * from PyQt5.QtCore import Qt, pyqtSignal -from utils.BasicUtils import load_myday_important, remove_todo_list +from utils.BasicUtils import load_myday_important, remove_todo_list, change_value, get_todo from view.AddToDoLabel import AddToDoAction from view.ToDoItem import ToDoItem, Button -from view.ToDoListView import ToDoList class Important(QWidget): + # 更新信号,在删除时触发 + update_signal = pyqtSignal() + signal = pyqtSignal() def __init__(self): @@ -149,13 +151,12 @@ class Important(QWidget): def refresh_action(self): # self.my_day_list[] self.todo_list.clear() - print(self.my_day_list) + # print(self.my_day_list) 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 initUI(self): print('') # thread_action = ThreadAction() @@ -192,15 +193,13 @@ class Important(QWidget): # print('选中:' + count) def line_edit_add(self, name): - self.add_todo.todo_name.emit(name) - # print('添加的新ToDo:' + name) - 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() - + if name: + self.add_todo.todo_name.emit(name) + # print('添加的新ToDo:' + name) + 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): # 设置右键菜单 @@ -233,13 +232,26 @@ class Important(QWidget): pop_menu.exec_(self.todo_list.mapToGlobal(position)) def make_important(self): + # 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) + # 暂时不需要发送信号 self.update_signal.emit() # 删除分组 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()) + 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] + remove_todo_list(uid) + # change_value(uid,'isImportant',False) + self.todo_list.takeItem(self.todo_list.currentRow()) + self.update_signal.emit() # 重命名分组 def rename_item(self): @@ -253,4 +265,3 @@ class Important(QWidget): print(item) print("test") - diff --git a/view/MyDayView.py b/view/MyDayView.py index 97e0bf1..ee81b29 100644 --- a/view/MyDayView.py +++ b/view/MyDayView.py @@ -146,17 +146,6 @@ class MyDay(QWidget): 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(button_menu.actions()[0]) - # actions = button_menu.actions() - # for i in actions: - # print(i) - # j = 1 - # i.triggered.connect(lambda: self.menu_action(str(j))) - # j += 1 - - # pass def load_myday(self, name, uid): todo_item = ToDoItem(name, uid) @@ -183,12 +172,13 @@ class MyDay(QWidget): # print(name) # todo : 回车添加事件 def line_edit_add(self, name): - self.add_todo.todo_name.emit(name) - # print('添加的新ToDo:' + name) - create_todo = CreateToDo('Todo', name, self.uid) - todo_item = ToDoItem(name, create_todo) + 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) - self.todo_list.addItem(todo_item) - self.todo_list.setItemWidget(todo_item, todo_item.widget) + self.todo_list.addItem(todo_item) + self.todo_list.setItemWidget(todo_item, todo_item.widget) - self.add_todo.line_edit.clear() + self.add_todo.line_edit.clear() diff --git a/view/SelfListWidgetItem.py b/view/SelfListWidgetItem.py index 4681868..a5c13a6 100644 --- a/view/SelfListWidgetItem.py +++ b/view/SelfListWidgetItem.py @@ -1,6 +1,6 @@ from PyQt5.QtWidgets import * from PyQt5.QtGui import * -from PyQt5.QtCore import Qt +from PyQt5.QtCore import Qt, pyqtSignal class SelfListWidgetItem(QListWidgetItem): @@ -10,6 +10,7 @@ class SelfListWidgetItem(QListWidgetItem): :param todo_count: 设置剩余代办数量,默认为零 :param show_icon: 设置显示的图标路径,默认为空 """ + update_action = pyqtSignal() def __init__(self, item_name, todo_count=0, uid=None, show_icon=None): super(SelfListWidgetItem, self).__init__() diff --git a/view/ToDoListView.py b/view/ToDoListView.py index 81522cb..3b9eb6f 100644 --- a/view/ToDoListView.py +++ b/view/ToDoListView.py @@ -161,17 +161,10 @@ class ToDoList(QWidget): # thread_action = ThreadAction() self.load_theme() - load_todo = get_todo(self.uid) - if load_todo: - for load in load_todo: + self.loadtodo = get_todo(self.uid) + if self.loadtodo: + for load in self.loadtodo: self.load_todo(load[0], load[1]) - # button_menu - # 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))) - # button_menu.addAction(label_action) def load_theme(self): theme = str(load_value(self.uid, 'Theme')) @@ -196,18 +189,26 @@ class ToDoList(QWidget): self.todo_list.addItem(todo_item) self.todo_list.setItemWidget(todo_item, todo_item.widget) - pass + def refresh_action(self): + # 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: + self.load_todo(load[0], load[1]) def line_edit_add(self, name): - self.add_todo.todo_name.emit(name) - # print('添加的新ToDo:' + name) - create_todo = CreateToDo('Todo', name, self.uid) - todo_item = ToDoItem(name, create_todo) + 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) - self.todo_list.addItem(todo_item) - self.todo_list.setItemWidget(todo_item, todo_item.widget) + self.todo_list.addItem(todo_item) + self.todo_list.setItemWidget(todo_item, todo_item.widget) - self.add_todo.line_edit.clear() + self.add_todo.line_edit.clear() def todo_list_context(self, position): # 设置右键菜单 @@ -240,13 +241,22 @@ class ToDoList(QWidget): pop_menu.exec_(self.todo_list.mapToGlobal(position)) def make_important(self): + 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) self.update_signal.emit() # 删除分组 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()) + 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() # 重命名分组 def rename_item(self):