已经实现传递信号!!!

This commit is contained in:
liyp 2022-04-23 17:36:22 +08:00
parent bc54ef6378
commit 179a8c59a4
7 changed files with 183 additions and 61 deletions

View file

@ -128,7 +128,7 @@ 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)
# 通过信号修改显示的标题名字 # 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() self.load_list = get_todo_list()
@ -184,6 +184,10 @@ class MainWidget(QWidget):
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(list_name, uid) 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,用户自己起名字. # 创建后就可以编辑item,用户自己起名字.
# self.system_listWidget.editItem(item) # self.system_listWidget.editItem(item)
self.stackedWidget.addWidget(todo_list) self.stackedWidget.addWidget(todo_list)
@ -202,6 +206,8 @@ class MainWidget(QWidget):
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, create_todo_uid) todo_list = ToDoList(new_list, create_todo_uid)
self.stackedWidget.addWidget(todo_list) self.stackedWidget.addWidget(todo_list)
# 创建后就可以编辑item,用户自己起名字. # 创建后就可以编辑item,用户自己起名字.
# self.system_listWidget.editItem(item) # self.system_listWidget.editItem(item)

98
test/SwitchWindwos.py Normal file
View file

@ -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()

View file

@ -46,9 +46,10 @@ def get_todo_list():
# try: # try:
if json_file['itemType'] == 'ToDoList': if json_file['itemType'] == 'ToDoList':
# print(json_file['title'], json_file['uid'], '列表') # 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) # print(return_todo_list)
return_todo_list.sort(key=get_third)
return return_todo_list 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[ if json_file['itemType'] == 'Todo' and not json_file['done'] and json_file[
'todoListUid'] == todoListUid: 'todoListUid'] == todoListUid:
# print(json_file['title'], json_file['uid'], '待办事项') # 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 return return_todo
# load_list = get_todo_list() # load_list = get_todo_list()
@ -94,16 +96,21 @@ def load_myday_important(item_type):
if item_type == 'MyDay': if item_type == 'MyDay':
if json_file['itemType'] == 'Todo' and not json_file['done'] and json_file['isMyDay']: if json_file['itemType'] == 'Todo' and not json_file['done'] and json_file['isMyDay']:
# print(json_file['title'], json_file['uid'], '待办事项') # 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 # return return_todo
elif item_type == 'Important': elif item_type == 'Important':
if json_file['itemType'] == 'Todo' and not json_file['done'] and json_file['isImportant']: if json_file['itemType'] == 'Todo' and not json_file['done'] and json_file['isImportant']:
# print(json_file['title'], json_file['uid'], '待办事项') # 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) # print(return_todo)
return_todo.sort(key=get_third)
return return_todo return return_todo
def get_third(elem):
return elem[2]
# 用于修改某个键值对,比如更新修改时期,设置为重要,我的一天等 # 用于修改某个键值对,比如更新修改时期,设置为重要,我的一天等
def change_value(uid, key, value): def change_value(uid, key, value):
config_path = return_work_dir() config_path = return_work_dir()
@ -142,7 +149,6 @@ def remove_todo_list(uid):
todo_path = config_path + 'ToDoList/' todo_path = config_path + 'ToDoList/'
os.remove(todo_path + '{' + uid + '}.otl') os.remove(todo_path + '{' + uid + '}.otl')
# print(read_init_file()) # print(read_init_file())
# webdav_hostname = read_init_file() # webdav_hostname = read_init_file()
# print(webdav_hostname[2]) # print(webdav_hostname[2])

View file

@ -4,13 +4,15 @@ from PyQt5.QtGui import *
from PyQt5.QtWidgets import * from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt, pyqtSignal 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.AddToDoLabel import AddToDoAction
from view.ToDoItem import ToDoItem, Button from view.ToDoItem import ToDoItem, Button
from view.ToDoListView import ToDoList
class Important(QWidget): class Important(QWidget):
# 更新信号,在删除时触发
update_signal = pyqtSignal()
signal = pyqtSignal() signal = pyqtSignal()
def __init__(self): def __init__(self):
@ -149,13 +151,12 @@ class Important(QWidget):
def refresh_action(self): def refresh_action(self):
# self.my_day_list[] # self.my_day_list[]
self.todo_list.clear() self.todo_list.clear()
print(self.my_day_list) # print(self.my_day_list)
my_day_list = load_myday_important('Important') my_day_list = load_myday_important('Important')
if my_day_list: if my_day_list:
for my_day in my_day_list: for my_day in my_day_list:
self.load_important(my_day[0], my_day[1]) self.load_important(my_day[0], my_day[1])
def initUI(self): def initUI(self):
print('<ImportantView>') print('<ImportantView>')
# thread_action = ThreadAction() # thread_action = ThreadAction()
@ -192,15 +193,13 @@ class Important(QWidget):
# print('选中:' + count) # print('选中:' + count)
def line_edit_add(self, name): def line_edit_add(self, name):
self.add_todo.todo_name.emit(name) if name:
# print('添加的新ToDo' + name) self.add_todo.todo_name.emit(name)
todo_item = ToDoItem(name) # print('添加的新ToDo' + name)
todo_item = ToDoItem(name)
self.todo_list.addItem(todo_item) self.todo_list.addItem(todo_item)
self.todo_list.setItemWidget(todo_item, todo_item.widget) 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): def todo_list_context(self, position):
# 设置右键菜单 # 设置右键菜单
@ -233,13 +232,26 @@ class Important(QWidget):
pop_menu.exec_(self.todo_list.mapToGlobal(position)) pop_menu.exec_(self.todo_list.mapToGlobal(position))
def make_important(self): 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('<ToDoListView> uid:', uid)
change_value(uid, 'isImportant', False)
# 暂时不需要发送信号
self.update_signal.emit() self.update_signal.emit()
# 删除分组 # 删除分组
def delete_item(self): def delete_item(self):
# print(self.load_list[self.system_listWidget.currentRow() - 2][1]) # print(self.load_list[self.system_listWidget.currentRow() - 2][1])
remove_todo_list(self.load_list[self.system_listWidget.currentRow() - 2][1]) my_day_list = load_myday_important('Important')
self.system_listWidget.takeItem(self.system_listWidget.currentRow()) # 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): def rename_item(self):
@ -253,4 +265,3 @@ class Important(QWidget):
print(item) print(item)
print("test") print("test")

View file

@ -146,17 +146,6 @@ class MyDay(QWidget):
if my_day_list: if my_day_list:
for my_day in my_day_list: for my_day in my_day_list:
self.load_myday(my_day[0], my_day[1]) 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): def load_myday(self, name, uid):
todo_item = ToDoItem(name, uid) todo_item = ToDoItem(name, uid)
@ -183,12 +172,13 @@ class MyDay(QWidget):
# print(name) # print(name)
# todo : 回车添加事件 # todo : 回车添加事件
def line_edit_add(self, name): def line_edit_add(self, name):
self.add_todo.todo_name.emit(name) if name:
# print('添加的新ToDo' + name) self.add_todo.todo_name.emit(name)
create_todo = CreateToDo('Todo', name, self.uid) # print('添加的新ToDo' + name)
todo_item = ToDoItem(name, create_todo) create_todo = CreateToDo('Todo', name, self.uid)
todo_item = ToDoItem(name, create_todo)
self.todo_list.addItem(todo_item) self.todo_list.addItem(todo_item)
self.todo_list.setItemWidget(todo_item, todo_item.widget) self.todo_list.setItemWidget(todo_item, todo_item.widget)
self.add_todo.line_edit.clear() self.add_todo.line_edit.clear()

View file

@ -1,6 +1,6 @@
from PyQt5.QtWidgets import * from PyQt5.QtWidgets import *
from PyQt5.QtGui import * from PyQt5.QtGui import *
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt, pyqtSignal
class SelfListWidgetItem(QListWidgetItem): class SelfListWidgetItem(QListWidgetItem):
@ -10,6 +10,7 @@ class SelfListWidgetItem(QListWidgetItem):
:param todo_count: 设置剩余代办数量默认为零 :param todo_count: 设置剩余代办数量默认为零
:param show_icon: 设置显示的图标路径默认为空 :param show_icon: 设置显示的图标路径默认为空
""" """
update_action = pyqtSignal()
def __init__(self, item_name, todo_count=0, uid=None, show_icon=None): def __init__(self, item_name, todo_count=0, uid=None, show_icon=None):
super(SelfListWidgetItem, self).__init__() super(SelfListWidgetItem, self).__init__()

View file

@ -161,17 +161,10 @@ class ToDoList(QWidget):
# thread_action = ThreadAction() # thread_action = ThreadAction()
self.load_theme() self.load_theme()
load_todo = get_todo(self.uid) self.loadtodo = get_todo(self.uid)
if load_todo: if self.loadtodo:
for load in load_todo: for load in self.loadtodo:
self.load_todo(load[0], load[1]) 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): def load_theme(self):
theme = str(load_value(self.uid, 'Theme')) theme = str(load_value(self.uid, 'Theme'))
@ -196,18 +189,26 @@ class ToDoList(QWidget):
self.todo_list.addItem(todo_item) self.todo_list.addItem(todo_item)
self.todo_list.setItemWidget(todo_item, todo_item.widget) 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): def line_edit_add(self, name):
self.add_todo.todo_name.emit(name) if name:
# print('添加的新ToDo' + name) self.add_todo.todo_name.emit(name)
create_todo = CreateToDo('Todo', name, self.uid) # print('添加的新ToDo' + name)
todo_item = ToDoItem(name, create_todo) create_todo = CreateToDo('Todo', name, self.uid)
todo_item = ToDoItem(name, create_todo)
self.todo_list.addItem(todo_item) self.todo_list.addItem(todo_item)
self.todo_list.setItemWidget(todo_item, todo_item.widget) 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): def todo_list_context(self, position):
# 设置右键菜单 # 设置右键菜单
@ -240,13 +241,22 @@ class ToDoList(QWidget):
pop_menu.exec_(self.todo_list.mapToGlobal(position)) pop_menu.exec_(self.todo_list.mapToGlobal(position))
def make_important(self): def make_important(self):
print(self.todo_list.currentRow())
load_todo = get_todo(self.uid)
uid = load_todo[self.todo_list.currentRow()][1]
# print('<ToDoListView> uid:', uid)
change_value(uid, 'isImportant', True)
self.update_signal.emit() self.update_signal.emit()
# 删除分组 # 删除分组
def delete_item(self): def delete_item(self):
# print(self.load_list[self.system_listWidget.currentRow() - 2][1]) # print(self.load_list[self.system_listWidget.currentRow() - 2][1])
remove_todo_list(self.load_list[self.system_listWidget.currentRow() - 2][1]) loadtodo = get_todo(self.uid)
self.system_listWidget.takeItem(self.system_listWidget.currentRow()) # 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): def rename_item(self):