重新设计main函数,减少读取文件次数
This commit is contained in:
parent
f75be59746
commit
e3bf7cd01d
8 changed files with 400 additions and 136 deletions
|
@ -3,7 +3,7 @@
|
||||||
使用Pyqt开发的todo list软件!
|
使用Pyqt开发的todo list软件!
|
||||||
|
|
||||||
- [x] 用户信息布局
|
- [x] 用户信息布局
|
||||||
- [ ] 用户信息右键及功能实现
|
- [x] 用户信息右键及功能实现
|
||||||
- [x] 待办事项列表布局实现
|
- [x] 待办事项列表布局实现
|
||||||
- [x] 添加待办事项列表
|
- [x] 添加待办事项列表
|
||||||
- [x] 待办事项列表功能实现
|
- [x] 待办事项列表功能实现
|
||||||
|
@ -12,6 +12,10 @@
|
||||||
- [x] “我的一天”和“重要”布局实现
|
- [x] “我的一天”和“重要”布局实现
|
||||||
- [x] 添加的通用布局实现
|
- [x] 添加的通用布局实现
|
||||||
- [x] 更换主题功能
|
- [x] 更换主题功能
|
||||||
- [ ] 登录`nextcloud`及其他`WebDav`和同步功能
|
- [x] 登录`nextcloud`及其他`WebDav`和同步功能
|
||||||
- [ ] 待办事项的笔记功能
|
- [ ] 待办事项的笔记功能
|
||||||
- [x] 最小化到任务栏功能
|
- [x] 最小化到任务栏功能
|
||||||
|
|
||||||
|
### 已知 bug
|
||||||
|
- 列表右键重命名导致堆栈布局更新失败
|
||||||
|
- 不能及时更新堆栈布局的title
|
41
main/main.py
41
main/main.py
|
@ -60,6 +60,7 @@ class MainWidget(QWidget):
|
||||||
layout.addWidget(self.stackedWidget, 6)
|
layout.addWidget(self.stackedWidget, 6)
|
||||||
|
|
||||||
self.system_listWidget.currentRowChanged.connect(self.stackedWidget.setCurrentIndex)
|
self.system_listWidget.currentRowChanged.connect(self.stackedWidget.setCurrentIndex)
|
||||||
|
self.load_list = get_todo_list()
|
||||||
|
|
||||||
self.setLayout(layout)
|
self.setLayout(layout)
|
||||||
self.user_label.sync_signal.connect(self.initUI)
|
self.user_label.sync_signal.connect(self.initUI)
|
||||||
|
@ -84,11 +85,10 @@ class MainWidget(QWidget):
|
||||||
# todo : 通过信号修改显示的标题名字
|
# todo : 通过信号修改显示的标题名字
|
||||||
# self.system_listWidget.change_list_name.connect(self.change_list)
|
# self.system_listWidget.change_list_name.connect(self.change_list)
|
||||||
# 加载列表
|
# 加载列表
|
||||||
load_list = get_todo_list()
|
|
||||||
# print(load_list)
|
# print(load_list)
|
||||||
# todo:bug 第一个为空会导致无法添加
|
# todo:bug 第一个为空会导致无法添加
|
||||||
if load_list:
|
if self.load_list:
|
||||||
for load in load_list:
|
for load in self.load_list:
|
||||||
self.load_item(load[0], load[1], load[3])
|
self.load_item(load[0], load[1], load[3])
|
||||||
# self.system_listWidget.addScrollBarWidget(False)
|
# self.system_listWidget.addScrollBarWidget(False)
|
||||||
|
|
||||||
|
@ -150,8 +150,11 @@ class MainWidget(QWidget):
|
||||||
|
|
||||||
def change_icon(self, icon):
|
def change_icon(self, icon):
|
||||||
# print(icon)
|
# print(icon)
|
||||||
load_list = get_todo_list()
|
# load_list = get_todo_list()
|
||||||
change_value(load_list[self.system_listWidget.currentRow() - 2][1], 'icon', icon)
|
# print(self.load_list)
|
||||||
|
self.load_list[self.system_listWidget.currentRow() - 2][3] = icon
|
||||||
|
# print(self.load_list[self.system_listWidget.currentRow() - 2][3])
|
||||||
|
change_value(self.load_list[self.system_listWidget.currentRow() - 2][1], 'icon', icon)
|
||||||
self.initUI()
|
self.initUI()
|
||||||
|
|
||||||
# 加载左侧列表
|
# 加载左侧列表
|
||||||
|
@ -187,14 +190,17 @@ class MainWidget(QWidget):
|
||||||
def create_item(self, new_list='新建列表', uid=None):
|
def create_item(self, new_list='新建列表', uid=None):
|
||||||
# 创建一个没有名字的item
|
# 创建一个没有名字的item
|
||||||
# new_list = '新建列表'
|
# new_list = '新建列表'
|
||||||
|
print('<main>(create_item)', self.stackedWidget.currentIndex())
|
||||||
|
|
||||||
if not uid:
|
if not uid:
|
||||||
create_todo_uid = CreateToDo('ToDoList', new_list)
|
create_todo = CreateToDo('ToDoList', new_list)
|
||||||
item = SelfListWidgetItem(new_list, 0, create_todo_uid)
|
self.load_list.append(create_todo)
|
||||||
|
item = SelfListWidgetItem(new_list, 0, create_todo[1])
|
||||||
item.setTextAlignment(Qt.AlignCenter)
|
item.setTextAlignment(Qt.AlignCenter)
|
||||||
# 使得item是可以编辑的.
|
# 使得item是可以编辑的.
|
||||||
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[1])
|
||||||
|
|
||||||
self.stackedWidget.addWidget(todo_list)
|
self.stackedWidget.addWidget(todo_list)
|
||||||
self.system_listWidget.setItemWidget(item, item.widget)
|
self.system_listWidget.setItemWidget(item, item.widget)
|
||||||
|
@ -202,8 +208,15 @@ class MainWidget(QWidget):
|
||||||
# 删除分组
|
# 删除分组
|
||||||
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])
|
||||||
load_list = get_todo_list()
|
index = self.system_listWidget.currentRow() - 2
|
||||||
remove_todo_list(load_list[self.system_listWidget.currentRow() - 2][1])
|
# print(self.load_list)
|
||||||
|
# print('index:',index)
|
||||||
|
# print('delete:', self.load_list[index])
|
||||||
|
remove_todo_list(self.load_list[index][1])
|
||||||
|
del self.load_list[index]
|
||||||
|
# print('result:', self.load_list)
|
||||||
|
# print('<main>(delete_item)', self.stackedWidget.indexOf(self.stackedWidget.currentWidget()))
|
||||||
|
self.stackedWidget.removeWidget(self.stackedWidget.currentWidget())
|
||||||
self.system_listWidget.takeItem(self.system_listWidget.currentRow())
|
self.system_listWidget.takeItem(self.system_listWidget.currentRow())
|
||||||
|
|
||||||
# 重命名分组
|
# 重命名分组
|
||||||
|
@ -231,9 +244,13 @@ class MainWidget(QWidget):
|
||||||
|
|
||||||
def change_name(self, item_name):
|
def change_name(self, item_name):
|
||||||
# print(item_name)
|
# print(item_name)
|
||||||
|
index = self.system_listWidget.currentRow() - 2
|
||||||
if item_name:
|
if item_name:
|
||||||
load_list = get_todo_list()
|
self.load_list[index][0] = item_name
|
||||||
change_value(load_list[self.system_listWidget.currentRow() - 2][1], 'title', item_name)
|
# print(self.load_list)
|
||||||
|
# print(self.load_list[index][1])
|
||||||
|
change_value(self.load_list[index][1], 'title', item_name)
|
||||||
|
|
||||||
self.update_signal.emit()
|
self.update_signal.emit()
|
||||||
# 重命名发送信号
|
# 重命名发送信号
|
||||||
self.initUI()
|
self.initUI()
|
||||||
|
|
354
main/main1.py
Normal file
354
main/main1.py
Normal file
|
@ -0,0 +1,354 @@
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from PyQt5.QtGui import *
|
||||||
|
from PyQt5.QtWidgets import *
|
||||||
|
from PyQt5.QtCore import Qt, pyqtSignal, QRect
|
||||||
|
from utils.BasicUtils import get_todo_list, remove_todo_list, change_value, read_ini, set_exit_status
|
||||||
|
from utils.CreateConfigure import CreateConfigure
|
||||||
|
from utils.CreateToDo import CreateToDo
|
||||||
|
from utils.QSSLoader import QSSLoader
|
||||||
|
from view.ImportantView import Important
|
||||||
|
from view.MyListWidget import MyListWidget
|
||||||
|
from view.ToDoListView import ToDoList
|
||||||
|
from view.UserLabel import User
|
||||||
|
from view.SelfListWidgetItem import SelfListWidgetItem
|
||||||
|
from view.AddListLabel import AddListAction
|
||||||
|
from view.MyDayView import MyDay
|
||||||
|
|
||||||
|
|
||||||
|
class MainWidget(QWidget):
|
||||||
|
update_signal = pyqtSignal()
|
||||||
|
init_signal = pyqtSignal()
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super(MainWidget, self).__init__()
|
||||||
|
self.user_label = User()
|
||||||
|
self.create_config = CreateConfigure()
|
||||||
|
# 主布局,左右两侧
|
||||||
|
layout = QHBoxLayout()
|
||||||
|
# 子布局,左边的部分
|
||||||
|
self.sub_layout = QVBoxLayout()
|
||||||
|
self.sub_layout.spacing()
|
||||||
|
self.sub_layout.addWidget(self.user_label, 2)
|
||||||
|
# 左侧列表
|
||||||
|
self.system_listWidget = MyListWidget(self)
|
||||||
|
self.system_listWidget.setFrameShape(QListWidget.NoFrame)
|
||||||
|
self.sub_layout.addWidget(self.system_listWidget, 15)
|
||||||
|
|
||||||
|
# 添加最下边的QLabel
|
||||||
|
self.add_list_action = AddListAction()
|
||||||
|
self.add_list_action.create_todo_list.connect(self.create_item)
|
||||||
|
|
||||||
|
# self.add_item_label.setPixmap(QPixmap())
|
||||||
|
self.sub_layout.addWidget(self.add_list_action, 1)
|
||||||
|
# 禁止双击可编辑
|
||||||
|
self.system_listWidget.setEditTriggers(QAbstractItemView.NoEditTriggers)
|
||||||
|
# 右键菜单
|
||||||
|
self.system_listWidget.setContextMenuPolicy(Qt.CustomContextMenu)
|
||||||
|
self.system_listWidget.setObjectName('custom')
|
||||||
|
self.system_listWidget.customContextMenuRequested.connect(self.myListWidgetContext)
|
||||||
|
|
||||||
|
# 右侧层叠窗口
|
||||||
|
|
||||||
|
self.my_day = MyDay()
|
||||||
|
self.important = Important()
|
||||||
|
self.stackedWidget = QStackedWidget(self)
|
||||||
|
self.stackedWidget.addWidget(self.my_day)
|
||||||
|
self.stackedWidget.addWidget(self.important)
|
||||||
|
|
||||||
|
layout.addLayout(self.sub_layout, 2)
|
||||||
|
|
||||||
|
layout.addWidget(self.stackedWidget, 6)
|
||||||
|
|
||||||
|
self.system_listWidget.currentRowChanged.connect(self.stackedWidget.setCurrentIndex)
|
||||||
|
|
||||||
|
self.setLayout(layout)
|
||||||
|
self.user_label.sync_signal.connect(self.initUI)
|
||||||
|
# self.init_signal.connect(self.initUI)
|
||||||
|
self.initUI()
|
||||||
|
|
||||||
|
def initUI(self):
|
||||||
|
self.important.update_signal.connect(self.my_day.refresh_action)
|
||||||
|
self.my_day.update_signal.connect(self.important.refresh_action)
|
||||||
|
# 先清除列表,方便后面调用
|
||||||
|
self.system_listWidget.clear()
|
||||||
|
self.stackedWidget.window().close()
|
||||||
|
# 系统默认的两个 item
|
||||||
|
self.one_day = SelfListWidgetItem('我的一天', 0, None, os.getcwd() + '/../images/sun.svg')
|
||||||
|
self.system_listWidget.setCurrentRow(1)
|
||||||
|
|
||||||
|
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)
|
||||||
|
# 加载列表
|
||||||
|
load_list = get_todo_list()
|
||||||
|
# print('<main>',load_list)
|
||||||
|
# todo:bug 第一次为空会导致无法添加
|
||||||
|
if load_list:
|
||||||
|
for load in load_list:
|
||||||
|
self.load_item(load[0], load[1], load[3])
|
||||||
|
# self.system_listWidget.addScrollBarWidget(False)
|
||||||
|
|
||||||
|
def myListWidgetContext(self, position):
|
||||||
|
if self.system_listWidget.currentRow() > 1:
|
||||||
|
|
||||||
|
# 设置右键菜单
|
||||||
|
pop_menu = QMenu(self)
|
||||||
|
pop_menu.setObjectName('lift_menu')
|
||||||
|
pop_menu.setAttribute(Qt.WA_TranslucentBackground)
|
||||||
|
# 无边框、去掉自带阴影
|
||||||
|
pop_menu.setWindowFlags(
|
||||||
|
pop_menu.windowFlags() | Qt.FramelessWindowHint | Qt.NoDropShadowWindowHint)
|
||||||
|
|
||||||
|
rename_action = QAction(u'重命名', self)
|
||||||
|
|
||||||
|
# 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上面,如果不在.就不显示删除和修改.
|
||||||
|
|
||||||
|
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, icon=None):
|
||||||
|
|
||||||
|
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 create_item(self, new_list='新建列表', uid=None):
|
||||||
|
# 创建一个没有名字的item
|
||||||
|
# new_list = '新建列表'
|
||||||
|
if not uid:
|
||||||
|
create_todo_uid = CreateToDo('ToDoList', new_list)
|
||||||
|
item = SelfListWidgetItem(new_list, 0, create_todo_uid)
|
||||||
|
item.setTextAlignment(Qt.AlignCenter)
|
||||||
|
# 使得item是可以编辑的.
|
||||||
|
item.setFlags(item.flags() | Qt.ItemIsEditable)
|
||||||
|
self.system_listWidget.addItem(item)
|
||||||
|
todo_list = ToDoList(new_list, create_todo_uid)
|
||||||
|
|
||||||
|
self.stackedWidget.addWidget(todo_list)
|
||||||
|
self.system_listWidget.setItemWidget(item, item.widget)
|
||||||
|
# todo_list.update_signal.connect(self.initUI)
|
||||||
|
|
||||||
|
# 删除分组
|
||||||
|
def delete_item(self):
|
||||||
|
# print(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())
|
||||||
|
self.update_signal.emit()
|
||||||
|
|
||||||
|
# 重命名分组
|
||||||
|
|
||||||
|
def rename_item(self):
|
||||||
|
# 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('请输入新的名字')
|
||||||
|
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.system_listWidget.takeItem(self.system_listWidget.currentRow())
|
||||||
|
|
||||||
|
self.dialog.exec_()
|
||||||
|
|
||||||
|
def change_name(self, item_name):
|
||||||
|
# print(item_name)
|
||||||
|
if 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.system_listWidget.takeItem(self.system_listWidget.currentRow())
|
||||||
|
# 重命名发送信号
|
||||||
|
self.initUI()
|
||||||
|
# self.update_signal.emit()
|
||||||
|
self.dialog.close()
|
||||||
|
|
||||||
|
|
||||||
|
class MainWindow(QWidget):
|
||||||
|
def __init__(self):
|
||||||
|
super(MainWindow, self).__init__()
|
||||||
|
self.resize(1150, 850)
|
||||||
|
self.setWindowTitle("待办事项")
|
||||||
|
# 主布局,用来显示主页面,设置页面等
|
||||||
|
self.layout = QStackedLayout(self)
|
||||||
|
|
||||||
|
self.main_widget = MainWidget()
|
||||||
|
# self.main_widget.resize(50, 200)
|
||||||
|
self.layout.addWidget(self.main_widget)
|
||||||
|
|
||||||
|
self.tray_icon = QSystemTrayIcon(self)
|
||||||
|
self.tray_icon.setIcon(QIcon(os.getcwd() + '/../images/todo_info.svg'))
|
||||||
|
# # self.style().standardIcon(QStyle.SP_ComputerIcon))
|
||||||
|
#
|
||||||
|
# self.checkbox = QCheckBox('最小化')
|
||||||
|
# layout.addWidget(self.checkbox)
|
||||||
|
|
||||||
|
'''
|
||||||
|
Define and add steps to work with the system tray icon
|
||||||
|
show - show window
|
||||||
|
hide - hide window
|
||||||
|
exit - exit from application
|
||||||
|
'''
|
||||||
|
show_action = QAction("显示", self)
|
||||||
|
quit_action = QAction("退出", self)
|
||||||
|
hide_action = QAction("隐藏", self)
|
||||||
|
show_action.triggered.connect(self.show)
|
||||||
|
hide_action.triggered.connect(self.hide)
|
||||||
|
quit_action.triggered.connect(QApplication.instance().quit)
|
||||||
|
tray_menu = QMenu()
|
||||||
|
tray_menu.addAction(show_action)
|
||||||
|
tray_menu.addAction(hide_action)
|
||||||
|
tray_menu.addAction(quit_action)
|
||||||
|
self.tray_icon.setContextMenu(tray_menu)
|
||||||
|
self.tray_icon.show()
|
||||||
|
|
||||||
|
# self.exit_widget = QWidget(self)
|
||||||
|
#
|
||||||
|
# self.exit_widget.setLayout(layout)
|
||||||
|
|
||||||
|
# 关闭窗口时弹出确认消息
|
||||||
|
|
||||||
|
def closeEvent(self, event):
|
||||||
|
# 创建一个消息盒子(提示框)
|
||||||
|
quitMsgBox = QMessageBox()
|
||||||
|
|
||||||
|
# 设置气泡在屏幕上的位置,水平居中,垂直屏幕80%位置
|
||||||
|
# desktop = QApplication.desktop()
|
||||||
|
# quitMsgBox.setGeometry(QRect(int(desktop.width() / 2 - 75), int(desktop.height() * 0.5), 400, 300))
|
||||||
|
self.save_config = QCheckBox('记住选择')
|
||||||
|
self.save_config.setChecked(True)
|
||||||
|
quitMsgBox.setCheckBox(self.save_config)
|
||||||
|
# self.save_config.stateChanged.connect(self.save_exit)
|
||||||
|
quitMsgBox.resize(300, 200)
|
||||||
|
# 设置提示框的标题
|
||||||
|
quitMsgBox.setWindowTitle('确认窗口')
|
||||||
|
# 设置提示框的内容
|
||||||
|
quitMsgBox.setText('你确定退出吗?')
|
||||||
|
# 创建两个点击的按钮,修改文本显示内容
|
||||||
|
buttonY = QPushButton('退出程序')
|
||||||
|
|
||||||
|
buttonN = QPushButton('最小化到托盘')
|
||||||
|
# 将两个按钮加到这个消息盒子中去,并指定yes和no的功能
|
||||||
|
style = QSSLoader.read_qss_file(os.getcwd() + '/../resource/closeDialog.qss')
|
||||||
|
buttonY.setStyleSheet(style)
|
||||||
|
buttonN.setStyleSheet(style)
|
||||||
|
|
||||||
|
quitMsgBox.addButton(buttonY, QMessageBox.YesRole)
|
||||||
|
|
||||||
|
quitMsgBox.addButton(buttonN, QMessageBox.NoRole)
|
||||||
|
exit_status = read_ini('System', 'exitstatus')
|
||||||
|
if exit_status == 'None':
|
||||||
|
# self.center(quitMsgBox)
|
||||||
|
quitMsgBox.exec_()
|
||||||
|
# 判断返回值,如果点击的是Yes按钮,我们就关闭组件和应用,否则就忽略关闭事件
|
||||||
|
if quitMsgBox.clickedButton() == buttonY:
|
||||||
|
if self.save_config.isChecked():
|
||||||
|
set_exit_status('Exit')
|
||||||
|
event.accept()
|
||||||
|
else:
|
||||||
|
if self.save_config.isChecked():
|
||||||
|
set_exit_status('Min')
|
||||||
|
self.hide()
|
||||||
|
event.ignore()
|
||||||
|
elif exit_status == 'Exit':
|
||||||
|
event.accept()
|
||||||
|
elif exit_status == 'Min':
|
||||||
|
# print('Min')
|
||||||
|
self.hide()
|
||||||
|
event.ignore()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
main = MainWindow()
|
||||||
|
main.setWindowTitle('PyQtToDoList')
|
||||||
|
# print(os.path.abspath('../'))
|
||||||
|
style_sheet = QSSLoader.read_qss_file(os.getcwd() + '/../resource/current.qss')
|
||||||
|
main.setStyleSheet(style_sheet)
|
||||||
|
|
||||||
|
app.setWindowIcon(QIcon(os.path.abspath('../') + '/images/todo_info.svg'))
|
||||||
|
main.show()
|
||||||
|
sys.exit(app.exec_())
|
|
@ -246,7 +246,7 @@ def check_login_status():
|
||||||
# print(webdav_hostname[2])
|
# print(webdav_hostname[2])
|
||||||
# change_value('4f52f02b-4450-405a-9fd1-2005a03006e0', 'isMyDay', False)
|
# change_value('4f52f02b-4450-405a-9fd1-2005a03006e0', 'isMyDay', False)
|
||||||
# print(get_todo('3f1e033f-2051-4c04-b7f6-afd2eb1f54f4'))
|
# print(get_todo('3f1e033f-2051-4c04-b7f6-afd2eb1f54f4'))
|
||||||
# print(load_myday_important('Important'))
|
print(load_myday_important('Important'))
|
||||||
# change_myday_important_conf('Important', 'theme', 2)
|
# change_myday_important_conf('Important', 'theme', 2)
|
||||||
# print(get_myday_important_conf('Important','Theme'))
|
# print(get_myday_important_conf('Important','Theme'))
|
||||||
# print(read_ini('System', 'exitstatus'))
|
# print(read_ini('System', 'exitstatus'))
|
||||||
|
|
|
@ -5,7 +5,6 @@ from datetime import datetime
|
||||||
|
|
||||||
from utils import BasicUtils
|
from utils import BasicUtils
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
:param item_type: 创建的类型,为ToDo和ToDoList
|
:param item_type: 创建的类型,为ToDo和ToDoList
|
||||||
:param name: 要创建的ToDoList名字
|
:param name: 要创建的ToDoList名字
|
||||||
|
@ -45,7 +44,7 @@ def CreateToDo(item_type, name, todo_list_uid=None):
|
||||||
with open(todo_list_path + '{' + uid + '}.otl', 'w') as f:
|
with open(todo_list_path + '{' + uid + '}.otl', 'w') as f:
|
||||||
f.write(json.dumps(out_config, indent=4, ensure_ascii=False))
|
f.write(json.dumps(out_config, indent=4, ensure_ascii=False))
|
||||||
# json.dump(out_config, f)
|
# json.dump(out_config, f)
|
||||||
return uid
|
return [name, uid, default_time, '星宿']
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
print(e)
|
print(e)
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -1,116 +0,0 @@
|
||||||
from PyQt5.QtCore import Qt
|
|
||||||
from PyQt5.QtGui import *
|
|
||||||
from PyQt5.QtWidgets import *
|
|
||||||
import configparser
|
|
||||||
from utils.BasicUtils import *
|
|
||||||
|
|
||||||
|
|
||||||
class LoginWindow(QWidget):
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__()
|
|
||||||
layout = QVBoxLayout()
|
|
||||||
self.setLayout(layout)
|
|
||||||
self.setWindowTitle('登录')
|
|
||||||
self.resize(500, 600)
|
|
||||||
self.tab_widget = QTabWidget()
|
|
||||||
self.tab_widget.setStyleSheet('background-color:#f3f3f3')
|
|
||||||
self.tab_widget.addTab(LoginWidget('NextCloud'), 'NextCloud')
|
|
||||||
self.tab_widget.addTab(LoginWidget('JianGuoYun'), '坚果云')
|
|
||||||
self.tab_widget.addTab(LoginWidget('WebDav'), 'WebDav')
|
|
||||||
|
|
||||||
# print('open new window')
|
|
||||||
# self.stack_widget = QStackedWidget()
|
|
||||||
# self.show()
|
|
||||||
layout.addWidget(self.tab_widget)
|
|
||||||
|
|
||||||
|
|
||||||
class LoginWidget(QWidget):
|
|
||||||
"""
|
|
||||||
:param login_type 登录账号类型
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
super(LoginWidget, self).__init__()
|
|
||||||
self.setStyleSheet('QLineEdit#lineedit{border: 1px solid gray;background:#f3f3f3;min-width:300px;'
|
|
||||||
'border-top-left-radius:5px;border-top-right-radius:5px;border-bottom-left-radius:5px;'
|
|
||||||
'border-bottom-right-radius:5px;}'
|
|
||||||
'QPushButton#login_button {max-width: 120px;color: white;'
|
|
||||||
'border-top-left-radius:10px;border-top-right-radius:10px;'
|
|
||||||
'border-bottom-left-radius:10px;border-bottom-right-radius:10px;background: #74d4ec;}'
|
|
||||||
'QPushButton#login_button:pressed,QPushButton#login_button:pressed:focus {'
|
|
||||||
'background-color: #f50057;border-style:inset;border-style:inset;'
|
|
||||||
'}')
|
|
||||||
|
|
||||||
self.setWindowTitle('登录')
|
|
||||||
self.resize(500, 600)
|
|
||||||
self.tab_widget = QTabWidget()
|
|
||||||
layout = QVBoxLayout()
|
|
||||||
|
|
||||||
sub_widget = QWidget()
|
|
||||||
self.sub_layout = QVBoxLayout()
|
|
||||||
sub_widget.setLayout(self.sub_layout)
|
|
||||||
|
|
||||||
self.host_name_layout = QHBoxLayout()
|
|
||||||
|
|
||||||
self.host_address = QLabel('服务器地址:')
|
|
||||||
self.host_address_lineedit = QLineEdit()
|
|
||||||
self.host_address_lineedit.setObjectName('lineedit')
|
|
||||||
self.host_address_lineedit.setPlaceholderText('https://nextcloud.example.com')
|
|
||||||
self.host_name_layout.addWidget(self.host_address, 3)
|
|
||||||
self.host_name_layout.addWidget(self.host_address_lineedit, 6)
|
|
||||||
|
|
||||||
self.host_name_layout = QHBoxLayout()
|
|
||||||
self.host_address = QLabel('服务器地址:')
|
|
||||||
self.host_address_lineedit = QLineEdit()
|
|
||||||
self.host_address_lineedit.setObjectName('lineedit')
|
|
||||||
self.host_address_lineedit.setPlaceholderText('https://webdav.example.com/dav')
|
|
||||||
self.host_name_layout.addWidget(self.host_address, 3)
|
|
||||||
self.host_name_layout.addWidget(self.host_address_lineedit, 6)
|
|
||||||
|
|
||||||
name_layout = QHBoxLayout()
|
|
||||||
self.name = QLabel('用户:')
|
|
||||||
self.name_lineedit = QLineEdit()
|
|
||||||
self.name_lineedit.setPlaceholderText('用户名')
|
|
||||||
self.name_lineedit.setObjectName('lineedit')
|
|
||||||
name_layout.addWidget(self.name, 3)
|
|
||||||
name_layout.addWidget(self.name_lineedit)
|
|
||||||
self.sub_layout.addLayout(name_layout)
|
|
||||||
|
|
||||||
password_layout = QHBoxLayout()
|
|
||||||
self.password = QLabel('密码:')
|
|
||||||
self.password_lineedit = QLineEdit()
|
|
||||||
self.password_lineedit.setEchoMode(QLineEdit.Password)
|
|
||||||
self.password_lineedit.setPlaceholderText('密码')
|
|
||||||
self.password_lineedit.setObjectName('lineedit')
|
|
||||||
password_layout.addWidget(self.password, 3)
|
|
||||||
password_layout.addWidget(self.password_lineedit, 6)
|
|
||||||
self.sub_layout.addLayout(password_layout)
|
|
||||||
|
|
||||||
button_layout = QHBoxLayout()
|
|
||||||
self.test_link = QPushButton('测试连接')
|
|
||||||
self.test_link.setObjectName('login_button')
|
|
||||||
self.link = QPushButton('保存配置')
|
|
||||||
self.link.setObjectName('login_button')
|
|
||||||
button_layout.addWidget(self.test_link)
|
|
||||||
button_layout.addWidget(self.link)
|
|
||||||
layout.addLayout(button_layout)
|
|
||||||
self.setLayout(layout)
|
|
||||||
self.sub_widget.show()
|
|
||||||
|
|
||||||
self.test_link.clicked.connect(self.link_test)
|
|
||||||
self.link.clicked.connect(self.close)
|
|
||||||
|
|
||||||
def link_test(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def save_link(self):
|
|
||||||
self.close()
|
|
||||||
pass
|
|
||||||
|
|
||||||
def initUI(self, login_type):
|
|
||||||
if login_type == 'NextCloud':
|
|
||||||
print(login_type)
|
|
||||||
self.sub_layout.addLayout(self.host_name_layout)
|
|
||||||
elif login_type == 'WebDav':
|
|
||||||
print(login_type)
|
|
||||||
self.sub_layout.addLayout(self.host_name_layout)
|
|
|
@ -212,7 +212,9 @@ class MyDay(QWidget):
|
||||||
# 设置右键点击事件
|
# 设置右键点击事件
|
||||||
def make_action(self, make_type):
|
def make_action(self, make_type):
|
||||||
# print(self.todo_list.currentRow())
|
# print(self.todo_list.currentRow())
|
||||||
load_todo = load_myday_important(make_type)
|
# print(make_type)
|
||||||
|
load_todo = load_myday_important('MyDay')
|
||||||
|
# print(load_todo)
|
||||||
uid = load_todo[self.todo_list.currentRow()][1]
|
uid = load_todo[self.todo_list.currentRow()][1]
|
||||||
if make_type == 'MyDay':
|
if make_type == 'MyDay':
|
||||||
change_value(uid, 'isMyDay', False)
|
change_value(uid, 'isMyDay', False)
|
||||||
|
|
|
@ -136,6 +136,8 @@ class ToDoList(QWidget):
|
||||||
self.button_menu.addAction(label_action5)
|
self.button_menu.addAction(label_action5)
|
||||||
self.uid = uid
|
self.uid = uid
|
||||||
|
|
||||||
|
# self.update_signal.connect(self.refresh_action)
|
||||||
|
|
||||||
self.refresh_action()
|
self.refresh_action()
|
||||||
# 右键菜单
|
# 右键菜单
|
||||||
self.todo_list.setContextMenuPolicy(Qt.CustomContextMenu)
|
self.todo_list.setContextMenuPolicy(Qt.CustomContextMenu)
|
||||||
|
@ -165,17 +167,19 @@ 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)
|
||||||
|
self.update_signal.emit()
|
||||||
|
|
||||||
def reload_name(self, uid):
|
def reload_name(self, uid):
|
||||||
label_name = load_value(uid, 'title')
|
label_name = load_value(uid, 'title')
|
||||||
self.head_label.setText(label_name)
|
self.head_label.setText(label_name)
|
||||||
pass
|
self.refresh_action()
|
||||||
|
|
||||||
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)
|
||||||
load_todo = get_todo(self.uid)
|
load_todo = get_todo(self.uid)
|
||||||
|
# print('<ToDoListView>', load_todo)
|
||||||
if load_todo:
|
if load_todo:
|
||||||
for load in load_todo:
|
for load in load_todo:
|
||||||
self.load_todo(load[0], load[1])
|
self.load_todo(load[0], load[1])
|
||||||
|
|
Loading…
Reference in a new issue