已经实现传递信号!!!
This commit is contained in:
parent
bc54ef6378
commit
179a8c59a4
7 changed files with 183 additions and 61 deletions
|
@ -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)
|
||||
|
|
98
test/SwitchWindwos.py
Normal file
98
test/SwitchWindwos.py
Normal 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()
|
|
@ -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])
|
||||
|
|
|
@ -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('<ImportantView>')
|
||||
# thread_action = ThreadAction()
|
||||
|
@ -192,16 +193,14 @@ class Important(QWidget):
|
|||
# print('选中:' + count)
|
||||
|
||||
def line_edit_add(self, name):
|
||||
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):
|
||||
# 设置右键菜单
|
||||
pop_menu = QMenu(self)
|
||||
|
@ -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('<ToDoListView> 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")
|
||||
|
||||
|
|
|
@ -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,6 +172,7 @@ class MyDay(QWidget):
|
|||
# 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)
|
||||
|
|
|
@ -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__()
|
||||
|
|
|
@ -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,9 +189,17 @@ 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):
|
||||
if name:
|
||||
self.add_todo.todo_name.emit(name)
|
||||
# print('添加的新ToDo:' + name)
|
||||
create_todo = CreateToDo('Todo', name, self.uid)
|
||||
|
@ -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('<ToDoListView> 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):
|
||||
|
|
Loading…
Reference in a new issue