修复不必要包,添加刷新按钮修复标签不自动更新bug

This commit is contained in:
liyp 2022-05-01 22:10:56 +08:00
parent fdbc135d13
commit f75be59746
5 changed files with 19 additions and 20 deletions

View file

@ -343,6 +343,6 @@ if __name__ == "__main__":
style_sheet = QSSLoader.read_qss_file(os.getcwd() + '/../resource/current.qss') style_sheet = QSSLoader.read_qss_file(os.getcwd() + '/../resource/current.qss')
main.setStyleSheet(style_sheet) main.setStyleSheet(style_sheet)
app.setWindowIcon(QIcon(os.path.abspath('../') + '/images/todo.svg')) app.setWindowIcon(QIcon(os.path.abspath('../') + '/images/todo_info.svg'))
main.show() main.show()
sys.exit(app.exec_()) sys.exit(app.exec_())

View file

@ -83,22 +83,17 @@ def get_myday_important_conf(get_type, key):
def get_todo_list(): def get_todo_list():
config_path = return_work_dir() config_path = return_work_dir()
todo_path = config_path + 'ToDoList/' todo_path = config_path + 'ToDoList/'
# print(todo_path)
return_todo_list = [] return_todo_list = []
for root, dirs, files in os.walk(todo_path, topdown=False): for root, dirs, files in os.walk(todo_path, topdown=False):
for name in files: for name in files:
# print(os.path.join(root, name)) # print(os.path.join(root, name))
with open(os.path.join(root, name), 'r') as f: with open(os.path.join(root, name), 'r') as f:
# print(f.read()) # print(f.read())
json_file = json.load(f) json_file = json.load(f)
# try:
if json_file['itemType'] == 'ToDoList': if json_file['itemType'] == 'ToDoList':
# print(json_file['title'], json_file['uid'], '列表')
return_todo_list.append( return_todo_list.append(
[json_file['title'], json_file['uid'], json_file['updatedAt'], json_file['icon']]) [json_file['title'], json_file['uid'], json_file['updatedAt'], json_file['icon']])
# print(return_todo_list)
return_todo_list.sort(key=get_third) return_todo_list.sort(key=get_third)
return return_todo_list return return_todo_list

View file

@ -62,9 +62,6 @@ class CreateConfigure:
config['Account']['webdav_password'] = webdav_password config['Account']['webdav_password'] = webdav_password
config['Account']['type'] = login_type config['Account']['type'] = login_type
# config['System'] = {'exitStatus': 'None'}
# print(config['System']['exitStatus'])
with open(config_file, 'w') as f: with open(config_file, 'w') as f:
config.write(f) config.write(f)
print('create complete!', config_file) print('create complete!', config_file)

View file

@ -177,13 +177,6 @@ class MyDay(QWidget):
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()
self.update_signal.emit() self.update_signal.emit()
# self.add_todo.todo_name.emit(name)
# # print('添加的新ToDo' + name)
# todo_item = ToDoItem(name)
# change_value(create_todo, 'isImportant', True)
# 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): def todo_list_context(self, position):
# 设置右键菜单 # 设置右键菜单

View file

@ -21,6 +21,7 @@ class ToDoList(QWidget):
# 测试更新的信号发送 # 测试更新的信号发送
update_signal = pyqtSignal() update_signal = pyqtSignal()
# todo : 实现刷新功能重新加载list_name 把list_name设置为全局变量
def __init__(self, list_name, uid): def __init__(self, list_name, uid):
super(ToDoList, self).__init__() super(ToDoList, self).__init__()
self.setObjectName('todolist') self.setObjectName('todolist')
@ -56,15 +57,15 @@ class ToDoList(QWidget):
layout.addWidget(head_widget, 2, Qt.AlignTop) layout.addWidget(head_widget, 2, Qt.AlignTop)
layout.addWidget(self.todo_list, 6, Qt.AlignCenter | Qt.AlignTop) layout.addWidget(self.todo_list, 6, Qt.AlignCenter | Qt.AlignTop)
head_label = QLabel(list_name) self.head_label = QLabel(list_name)
head_label.setObjectName('head_label') self.head_label.setObjectName('head_label')
font = QFont() font = QFont()
font.setPointSize(32) font.setPointSize(32)
head_label.setFont(font) self.head_label.setFont(font)
layout.addStretch(1) layout.addStretch(1)
head_layout.addWidget(head_label, 8) head_layout.addWidget(self.head_label, 8)
layout.addStretch(1) layout.addStretch(1)
layout.addWidget(self.add_todo, 2, Qt.AlignHCenter) layout.addWidget(self.add_todo, 2, Qt.AlignHCenter)
@ -90,6 +91,14 @@ class ToDoList(QWidget):
self.menu_image.setMenu(self.button_menu) self.menu_image.setMenu(self.button_menu)
refresh_label = QAction(self)
refresh_label.setText('刷新')
refresh_label.setIcon(QIcon('../images/refresh.svg'))
self.button_menu.addAction(refresh_label)
self.button_menu.addSeparator()
refresh_label.triggered.connect(lambda: self.reload_name(uid))
self.button_menu.addAction(refresh_label)
theme_label = QAction(self) theme_label = QAction(self)
theme_label.setText('主题') theme_label.setText('主题')
theme_label.setDisabled(True) theme_label.setDisabled(True)
@ -157,6 +166,11 @@ class ToDoList(QWidget):
self.todo_list.addItem(self.todo_item) self.todo_list.addItem(self.todo_item)
self.todo_list.setItemWidget(self.todo_item, self.todo_item.widget) self.todo_list.setItemWidget(self.todo_item, self.todo_item.widget)
def reload_name(self, uid):
label_name = load_value(uid, 'title')
self.head_label.setText(label_name)
pass
def refresh_action(self): def refresh_action(self):
# self.my_day_list[] # self.my_day_list[]
self.todo_list.clear() self.todo_list.clear()