这样不行,需要更换思路来传递信号!
This commit is contained in:
parent
9f80a8e7a0
commit
bc54ef6378
12 changed files with 437 additions and 83 deletions
|
@ -7,10 +7,10 @@
|
|||
- [x] 待办事项列表布局实现
|
||||
- [ ] 待办事项列表功能实现
|
||||
- [ ] 待办事项列表右键功能实现
|
||||
- [ ] 右边`QStackLayout`布局
|
||||
- [x] 右边`QStackLayout`布局
|
||||
- [x] “我的一天”和“重要”布局实现
|
||||
- [ ] 添加的通用布局实现
|
||||
- [ ] 更换主题功能
|
||||
- [x] 添加的通用布局实现
|
||||
- [x] 更换主题功能
|
||||
- [ ] 登录`nextcloud`及其他`WebDav`和同步功能
|
||||
- [ ] 添加“设置”功能
|
||||
- [ ] 拖拽排序功能
|
1
images/make_sun.svg
Normal file
1
images/make_sun.svg
Normal file
|
@ -0,0 +1 @@
|
|||
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1650614954168" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4228" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M512 768c-141.376 0-256-114.624-256-256s114.624-256 256-256 256 114.624 256 256-114.624 256-256 256z m0-85.333333a170.666667 170.666667 0 1 0 0-341.333334 170.666667 170.666667 0 0 0 0 341.333334zM469.333333 85.333333a42.666667 42.666667 0 1 1 85.333334 0v85.333334a42.666667 42.666667 0 1 1-85.333334 0V85.333333z m0 768a42.666667 42.666667 0 1 1 85.333334 0v85.333334a42.666667 42.666667 0 1 1-85.333334 0v-85.333334zM85.333333 554.666667a42.666667 42.666667 0 1 1 0-85.333334h85.333334a42.666667 42.666667 0 1 1 0 85.333334H85.333333z m768 0a42.666667 42.666667 0 1 1 0-85.333334h85.333334a42.666667 42.666667 0 1 1 0 85.333334h-85.333334zM161.834667 222.165333a42.666667 42.666667 0 0 1 60.330666-60.330666l64 64a42.666667 42.666667 0 0 1-60.330666 60.330666l-64-64z m576 576a42.666667 42.666667 0 0 1 60.330666-60.330666l64 64a42.666667 42.666667 0 0 1-60.330666 60.330666l-64-64z m-515.669334 64a42.666667 42.666667 0 0 1-60.330666-60.330666l64-64a42.666667 42.666667 0 0 1 60.330666 60.330666l-64 64z m576-576a42.666667 42.666667 0 0 1-60.330666-60.330666l64-64a42.666667 42.666667 0 0 1 60.330666 60.330666l-64 64z" fill="#1296db" p-id="4229"></path></svg>
|
After Width: | Height: | Size: 1.5 KiB |
139
main/main.py
139
main/main.py
|
@ -5,10 +5,11 @@ from PyQt5.QtWidgets import *
|
|||
from PyQt5.QtCore import Qt
|
||||
import configparser
|
||||
|
||||
from utils.BasicUtils import get_todo_list
|
||||
from utils.BasicUtils import get_todo_list, remove_todo_list
|
||||
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
|
||||
|
@ -16,6 +17,60 @@ from view.AddListLabel import AddListAction
|
|||
from view.MyDayView import MyDay
|
||||
|
||||
|
||||
#
|
||||
#
|
||||
# class SelfListWidgetItem(QListWidgetItem):
|
||||
# """
|
||||
# :param item_name: 列表名称
|
||||
# :param uid: 当前列表的uuid
|
||||
# :param todo_count: 设置剩余代办数量,默认为零
|
||||
# :param show_icon: 设置显示的图标路径,默认为空
|
||||
# """
|
||||
#
|
||||
# def __init__(self, item_name, todo_count=0, uid=None, show_icon=None):
|
||||
# super(SelfListWidgetItem, self).__init__()
|
||||
# layout = QHBoxLayout()
|
||||
# # print(show_icon)
|
||||
# self.item_name = item_name
|
||||
#
|
||||
# self.todo_count = todo_count
|
||||
# self.show_icon = show_icon
|
||||
# # 布局
|
||||
# self.widget = QWidget()
|
||||
# self.widget.setLayout(layout)
|
||||
#
|
||||
# # self.list_item = QLabel('')
|
||||
#
|
||||
# # 添加左边的图标和右边的气泡
|
||||
# if self.show_icon:
|
||||
# self.icon_label = QLabel('')
|
||||
# self.icon_label.setPixmap(
|
||||
# QPixmap(self.show_icon).scaled(30, 30, Qt.IgnoreAspectRatio, Qt.SmoothTransformation))
|
||||
# layout.addWidget(self.icon_label, 1)
|
||||
# # 添加
|
||||
# self.item_name_label = QLabel(self.item_name)
|
||||
# # print(self.item_name)
|
||||
# self.item_name_label.setObjectName('item_name_label')
|
||||
#
|
||||
# layout.addWidget(self.item_name_label, 3)
|
||||
#
|
||||
# if self.todo_count:
|
||||
# # 打印出代办数目
|
||||
# print('todo_count:', self.todo_count)
|
||||
# self.todo_count_label = QLabel(str(self.todo_count))
|
||||
# self.todo_count_label.setFixedSize(16, 16)
|
||||
# self.todo_count_label.setScaledContents(True)
|
||||
# self.todo_count_label.setObjectName('todo_count_label')
|
||||
# self.todo_count_label.setAlignment(Qt.AlignCenter)
|
||||
# layout.addWidget(self.todo_count_label, 1)
|
||||
# # 设置自定义的QListWidgetItem的sizeHint,不然无法显示
|
||||
# self.setSizeHint(self.widget.sizeHint())
|
||||
# MainWidget().system_listWidget.change_list_name.connect(self.change_name)
|
||||
#
|
||||
# def change_name(self):
|
||||
# pass
|
||||
#
|
||||
|
||||
class MainWidget(QWidget):
|
||||
def __init__(self):
|
||||
super(MainWidget, self).__init__()
|
||||
|
@ -27,22 +82,22 @@ class MainWidget(QWidget):
|
|||
self.sub_layout.spacing()
|
||||
self.sub_layout.addWidget(self.user_label, 2)
|
||||
# 左侧列表
|
||||
self.system_listWidget = QListWidget(self)
|
||||
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.CreateNewItem)
|
||||
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.custom.setEditTriggers(QAbstractItemView.NoEditTriggers)
|
||||
self.system_listWidget.setEditTriggers(QAbstractItemView.NoEditTriggers)
|
||||
# 右键菜单
|
||||
# self.custom.setContextMenuPolicy(Qt.CustomContextMenu)
|
||||
# self.custom.setObjectName('custom')
|
||||
# self.custom.customContextMenuRequested.connect(self.myListWidgetContext)
|
||||
self.system_listWidget.setContextMenuPolicy(Qt.CustomContextMenu)
|
||||
self.system_listWidget.setObjectName('custom')
|
||||
self.system_listWidget.customContextMenuRequested.connect(self.myListWidgetContext)
|
||||
|
||||
# 右侧层叠窗口
|
||||
|
||||
|
@ -56,10 +111,10 @@ class MainWidget(QWidget):
|
|||
|
||||
layout.addWidget(self.stackedWidget, 6)
|
||||
|
||||
self.one_day = SelfListWidgetItem('我的一天', 0, None,os.getcwd() + '/../images/sun.svg')
|
||||
self.one_day = SelfListWidgetItem('我的一天', 0, None, os.getcwd() + '/../images/sun.svg')
|
||||
self.system_listWidget.setCurrentRow(1)
|
||||
# self.one_day.setSelected(True)
|
||||
self.important_item = SelfListWidgetItem('重要', 0, None,os.getcwd() + '/../images/star.svg')
|
||||
self.important_item = SelfListWidgetItem('重要', 0, None, os.getcwd() + '/../images/star.svg')
|
||||
|
||||
self.system_listWidget.currentRowChanged.connect(self.stackedWidget.setCurrentIndex)
|
||||
|
||||
|
@ -73,10 +128,13 @@ class MainWidget(QWidget):
|
|||
|
||||
self.system_listWidget.addItem(self.important_item)
|
||||
self.system_listWidget.setItemWidget(self.important_item, self.important_item.widget)
|
||||
load_list = get_todo_list()
|
||||
# 通过信号修改显示的标题名字
|
||||
self.system_listWidget.change_list_name.connect(self.change_list)
|
||||
# 加载列表
|
||||
self.load_list = get_todo_list()
|
||||
# print(load_list)
|
||||
if load_list:
|
||||
for load in load_list:
|
||||
if self.load_list:
|
||||
for load in self.load_list:
|
||||
self.load_item(load[0], load[1])
|
||||
# self.system_listWidget.addScrollBarWidget(False)
|
||||
|
||||
|
@ -86,27 +144,38 @@ class MainWidget(QWidget):
|
|||
# self.custom.setItemWidget(self.two_day, self.two_day.widget)
|
||||
# self.custom.
|
||||
|
||||
def change_list(self):
|
||||
print(self.system_listWidget.currentItem().text())
|
||||
# print(name)
|
||||
|
||||
# todo 仔细研究右键菜单
|
||||
|
||||
def myListWidgetContext(self, position):
|
||||
# 设置右键菜单
|
||||
pop_menu = QMenu(self)
|
||||
if self.system_listWidget.currentRow() > 1:
|
||||
|
||||
rename_action = QAction(u'重命名', self)
|
||||
# 设置右键菜单
|
||||
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)
|
||||
|
||||
copy_action = QAction("复制分组", self)
|
||||
del_action = QAction("删除分组", self)
|
||||
rename_action = QAction(u'重命名', self)
|
||||
|
||||
# 查看右键时是否在item上面,如果不在.就不显示删除和修改.
|
||||
pop_menu.addAction(rename_action)
|
||||
if self.custom.itemAt(position):
|
||||
pop_menu.addAction(del_action)
|
||||
copy_action = QAction("复制分组", self)
|
||||
del_action = QAction("删除分组", self)
|
||||
|
||||
# 查看右键时是否在item上面,如果不在.就不显示删除和修改.
|
||||
pop_menu.addAction(rename_action)
|
||||
if self.system_listWidget.itemAt(position):
|
||||
pop_menu.addAction(del_action)
|
||||
pop_menu.addAction(rename_action)
|
||||
|
||||
rename_action.triggered.connect(self.RenameItem)
|
||||
copy_action.triggered.connect(self.CreateNewItem)
|
||||
del_action.triggered.connect(self.DeleteItem)
|
||||
pop_menu.exec_(self.custom.mapToGlobal(position))
|
||||
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 load_item(self, list_name, uid):
|
||||
item = SelfListWidgetItem(list_name, 0, uid)
|
||||
|
@ -122,7 +191,7 @@ class MainWidget(QWidget):
|
|||
self.system_listWidget.setItemWidget(item, item.widget)
|
||||
|
||||
# 创建新的分组
|
||||
def CreateNewItem(self, new_list='新建列表', uid=None):
|
||||
def create_item(self, new_list='新建列表', uid=None):
|
||||
# 创建一个没有名字的item
|
||||
# new_list = '新建列表'
|
||||
if not uid:
|
||||
|
@ -139,18 +208,22 @@ class MainWidget(QWidget):
|
|||
self.system_listWidget.setItemWidget(item, item.widget)
|
||||
|
||||
# 删除分组
|
||||
def DeleteItem(self):
|
||||
self.custom.takeItem(self.custom.currentRow())
|
||||
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())
|
||||
|
||||
# 重命名分组
|
||||
def RenameItem(self):
|
||||
curRow = self.custom.currentRow()
|
||||
item = self.custom.item(curRow)
|
||||
def rename_item(self):
|
||||
curRow = self.system_listWidget.currentRow()
|
||||
item = self.system_listWidget.item(curRow)
|
||||
item.setFlags(item.flags() | Qt.ItemIsEditable)
|
||||
self.custom.editItem(item)
|
||||
self.custom.itemChanged.connect(lambda: self.ChangeItem(item))
|
||||
self.system_listWidget.editItem(item)
|
||||
self.system_listWidget.itemChanged.connect(lambda: self.ChangeItem(item))
|
||||
|
||||
def ChangeItem(self, item):
|
||||
print(item)
|
||||
|
||||
print("test")
|
||||
|
||||
|
||||
|
|
|
@ -95,11 +95,12 @@ def load_myday_important(item_type):
|
|||
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 return_todo
|
||||
# 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']])
|
||||
# print(return_todo)
|
||||
return return_todo
|
||||
|
||||
|
||||
|
@ -117,14 +118,31 @@ def change_value(uid, key, value):
|
|||
with open(todo_path + '{' + uid + '}.otl', 'r') as f:
|
||||
# print(f.read())
|
||||
json_file = json.load(f)
|
||||
print(json_file)
|
||||
# print('<BasicUtils>'+json_file)
|
||||
json_file[key] = value
|
||||
json_file['updatedAt'] = current_time
|
||||
# print(json_file[key])
|
||||
with open(todo_path + '{' + uid + '}.otl', 'w') as f:
|
||||
json.dump(json_file, f, indent=4, ensure_ascii=False)
|
||||
|
||||
#
|
||||
|
||||
def load_value(uid, key):
|
||||
config_path = return_work_dir()
|
||||
todo_path = config_path + 'ToDoList/'
|
||||
|
||||
with open(todo_path + '{' + uid + '}.otl', 'r') as f:
|
||||
# print(f.read())
|
||||
json_file = json.load(f)
|
||||
# print('<BasicUtils>'+json_file)
|
||||
return json_file[key]
|
||||
|
||||
|
||||
def remove_todo_list(uid):
|
||||
config_path = return_work_dir()
|
||||
todo_path = config_path + 'ToDoList/'
|
||||
os.remove(todo_path + '{' + uid + '}.otl')
|
||||
|
||||
|
||||
# print(read_init_file())
|
||||
# webdav_hostname = read_init_file()
|
||||
# print(webdav_hostname[2])
|
||||
|
|
|
@ -5,6 +5,9 @@ from utils import BasicUtils
|
|||
|
||||
|
||||
# todo : 用来创建软件的配置信息
|
||||
from utils.BasicUtils import return_work_dir
|
||||
|
||||
|
||||
class CreateConfigure:
|
||||
"""
|
||||
:param login_type : 登录方式 有 NextCloud、JianGuoYun、WebDav
|
||||
|
@ -14,7 +17,7 @@ class CreateConfigure:
|
|||
"""
|
||||
|
||||
def __init__(self, login_type, webdav_login, webdav_password, webdav_hostname=None):
|
||||
config_file = ReturnWorkDir.return_work_dir() + 'PyQtToDoList.ini'
|
||||
config_file = return_work_dir() + 'PyQtToDoList.ini'
|
||||
config = configparser.ConfigParser()
|
||||
if not os.path.exists(config_file):
|
||||
# print(config_file)
|
||||
|
|
|
@ -28,7 +28,7 @@ def CreateToDo(item_type, name, todo_list_uid=None):
|
|||
if not os.path.exists(todo_list_path):
|
||||
os.mkdir(todo_list_path)
|
||||
default_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
print(uid)
|
||||
print('<CreateToDo>'+uid)
|
||||
if item_type == 'ToDoList':
|
||||
# print(item_type)
|
||||
try:
|
||||
|
@ -48,6 +48,7 @@ def CreateToDo(item_type, name, todo_list_uid=None):
|
|||
"notes": "",
|
||||
"title": name,
|
||||
"uid": uid,
|
||||
"Theme": '0',
|
||||
"updatedAt": default_time
|
||||
}
|
||||
# library = {
|
||||
|
@ -61,7 +62,7 @@ def CreateToDo(item_type, name, todo_list_uid=None):
|
|||
except IOError as e:
|
||||
print(e)
|
||||
return False
|
||||
elif item_type == 'ToDo':
|
||||
elif item_type == 'Todo':
|
||||
try:
|
||||
# done : 完成状态
|
||||
# todoListUid : 父列表id
|
||||
|
@ -69,14 +70,13 @@ def CreateToDo(item_type, name, todo_list_uid=None):
|
|||
"createdAt": default_time,
|
||||
"done": False,
|
||||
"dueTo": '',
|
||||
"itemType": "Todo",
|
||||
"itemType": item_type,
|
||||
"notes": "",
|
||||
"isMyDay": False,
|
||||
"isImportant": False,
|
||||
"title": name,
|
||||
"todoListUid": todo_list_uid,
|
||||
"uid": uid,
|
||||
"theme": '0',
|
||||
"updatedAt": default_time
|
||||
}
|
||||
with open(todo_list_path + '{' + uid + '}.otl', 'w') as f:
|
||||
|
|
|
@ -2,14 +2,17 @@ import os
|
|||
import sys
|
||||
from PyQt5.QtGui import *
|
||||
from PyQt5.QtWidgets import *
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtCore import Qt, pyqtSignal
|
||||
|
||||
from utils.BasicUtils import load_myday_important
|
||||
from utils.BasicUtils import load_myday_important, remove_todo_list
|
||||
from view.AddToDoLabel import AddToDoAction
|
||||
from view.ToDoItem import ToDoItem
|
||||
from view.ToDoItem import ToDoItem, Button
|
||||
from view.ToDoListView import ToDoList
|
||||
|
||||
|
||||
class Important(QWidget):
|
||||
signal = pyqtSignal()
|
||||
|
||||
def __init__(self):
|
||||
super(Important, self).__init__()
|
||||
self.setObjectName('important')
|
||||
|
@ -86,6 +89,13 @@ class Important(QWidget):
|
|||
|
||||
self.menu_image.setMenu(self.button_menu)
|
||||
|
||||
refresh_label = QAction(self)
|
||||
refresh_label.setText('刷新')
|
||||
# refresh_label.setDisabled(True)
|
||||
self.button_menu.addAction(refresh_label)
|
||||
self.button_menu.addSeparator()
|
||||
refresh_label.triggered.connect(self.refresh_action)
|
||||
|
||||
theme_label = QAction(self)
|
||||
theme_label.setText('主题')
|
||||
theme_label.setDisabled(True)
|
||||
|
@ -102,44 +112,59 @@ class Important(QWidget):
|
|||
# for i in range(11):
|
||||
label_action1 = QAction(self)
|
||||
label_action1.setIcon(QIcon('../images/1.jpg'))
|
||||
label_action1.setText('渐变1')
|
||||
label_action1.setText('背景1')
|
||||
label_action1.triggered.connect(lambda: self.menu_action(1))
|
||||
self.button_menu.addAction(label_action1)
|
||||
|
||||
label_action2 = QAction(self)
|
||||
label_action2.setIcon(QIcon('../images/2.jpg'))
|
||||
label_action2.setText('渐变2')
|
||||
label_action2.setText('背景2')
|
||||
label_action2.triggered.connect(lambda: self.menu_action(2))
|
||||
self.button_menu.addAction(label_action2)
|
||||
|
||||
label_action3 = QAction(self)
|
||||
label_action3.setIcon(QIcon('../images/3.jpg'))
|
||||
label_action3.setText('渐变3')
|
||||
label_action3.setText('背景3')
|
||||
label_action3.triggered.connect(lambda: self.menu_action(3))
|
||||
self.button_menu.addAction(label_action3)
|
||||
|
||||
label_action4 = QAction(self)
|
||||
label_action4.setIcon(QIcon('../images/4.jpg'))
|
||||
label_action4.setText('渐变4')
|
||||
label_action4.setText('背景4')
|
||||
label_action4.triggered.connect(lambda: self.menu_action(4))
|
||||
self.button_menu.addAction(label_action4)
|
||||
|
||||
label_action5 = QAction(self)
|
||||
label_action5.setIcon(QIcon('../images/5.jpg'))
|
||||
label_action5.setText('渐变5')
|
||||
label_action5.setText('背景5')
|
||||
label_action5.triggered.connect(lambda: self.menu_action(5))
|
||||
self.button_menu.addAction(label_action5)
|
||||
# 右键菜单
|
||||
self.todo_list.setContextMenuPolicy(Qt.CustomContextMenu)
|
||||
self.todo_list.customContextMenuRequested.connect(self.todo_list_context)
|
||||
# todolist = ToDoList()
|
||||
|
||||
self.initUI()
|
||||
|
||||
def refresh_action(self):
|
||||
# self.my_day_list[]
|
||||
self.todo_list.clear()
|
||||
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()
|
||||
# thread_action.change_value_action.connect()
|
||||
|
||||
my_day_list = load_myday_important('Important')
|
||||
self.my_day_list = load_myday_important('Important')
|
||||
|
||||
if my_day_list:
|
||||
for my_day in my_day_list:
|
||||
if self.my_day_list:
|
||||
for my_day in self.my_day_list:
|
||||
self.load_important(my_day[0], my_day[1])
|
||||
|
||||
def load_important(self, name, uid):
|
||||
|
@ -164,7 +189,7 @@ class Important(QWidget):
|
|||
self.setStyleSheet('#important{background-image:url("../images/' + count + '.jpg");'
|
||||
'background-position: center; border-radius: 10px;'
|
||||
'}')
|
||||
print('选中:' + count)
|
||||
# print('选中:' + count)
|
||||
|
||||
def line_edit_add(self, name):
|
||||
self.add_todo.todo_name.emit(name)
|
||||
|
@ -175,3 +200,57 @@ class Important(QWidget):
|
|||
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)
|
||||
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)
|
||||
|
||||
mark_myday = QAction(QIcon(QPixmap(os.getcwd() + '/../images/make_sun.svg')), u"设置为我的一天", self)
|
||||
mark_important = QAction(QIcon(QPixmap(os.getcwd() + '/../images/star.svg')), u"取消设置为重要", self)
|
||||
|
||||
del_action = QAction("删除", self)
|
||||
|
||||
# 查看右键时是否在item上面,如果不在.就不显示删除和修改.
|
||||
pop_menu.addAction(rename_action)
|
||||
if self.todo_list.itemAt(position):
|
||||
pop_menu.addAction(mark_myday)
|
||||
pop_menu.addAction(mark_important)
|
||||
pop_menu.addAction(del_action)
|
||||
pop_menu.addAction(rename_action)
|
||||
|
||||
rename_action.triggered.connect(self.rename_item)
|
||||
# copy_action.triggered.connect(self.create_item)
|
||||
del_action.triggered.connect(self.delete_item)
|
||||
mark_important.triggered.connect(self.make_important)
|
||||
pop_menu.exec_(self.todo_list.mapToGlobal(position))
|
||||
|
||||
def make_important(self):
|
||||
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())
|
||||
|
||||
# 重命名分组
|
||||
def rename_item(self):
|
||||
curRow = self.todo_list.currentRow()
|
||||
item = self.todo_list.item(curRow)
|
||||
item.setFlags(item.flags() | Qt.ItemIsEditable)
|
||||
self.todo_list.editItem(item)
|
||||
self.todo_list.itemChanged.connect(lambda: self.ChangeItem(item))
|
||||
|
||||
def ChangeItem(self, item):
|
||||
print(item)
|
||||
|
||||
print("test")
|
||||
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import os
|
||||
from PyQt5.QtGui import *
|
||||
from PyQt5.QtWidgets import *
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtCore import Qt, pyqtSignal
|
||||
|
||||
from utils.BasicUtils import load_myday_important
|
||||
from utils.CreateToDo import CreateToDo
|
||||
from view.AddToDoLabel import AddToDoAction
|
||||
from view.MyDayHeadLabel import HeadLabel
|
||||
from view.ToDoItem import ToDoItem
|
||||
|
@ -19,6 +20,8 @@ class Menu(QMenu):
|
|||
|
||||
|
||||
class MyDay(QWidget):
|
||||
transaction = pyqtSignal()
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super(MyDay, self).__init__()
|
||||
self.setObjectName('my_day')
|
||||
|
@ -110,31 +113,31 @@ class MyDay(QWidget):
|
|||
# for i in range(11):
|
||||
label_action1 = QAction(self)
|
||||
label_action1.setIcon(QIcon('../images/1.jpg'))
|
||||
label_action1.setText('渐变1')
|
||||
label_action1.setText('背景1')
|
||||
label_action1.triggered.connect(lambda: self.menu_action(1))
|
||||
self.button_menu.addAction(label_action1)
|
||||
|
||||
label_action2 = QAction(self)
|
||||
label_action2.setIcon(QIcon('../images/2.jpg'))
|
||||
label_action2.setText('渐变2')
|
||||
label_action2.setText('背景2')
|
||||
label_action2.triggered.connect(lambda: self.menu_action(2))
|
||||
self.button_menu.addAction(label_action2)
|
||||
|
||||
label_action3 = QAction(self)
|
||||
label_action3.setIcon(QIcon('../images/3.jpg'))
|
||||
label_action3.setText('渐变3')
|
||||
label_action3.setText('背景3')
|
||||
label_action3.triggered.connect(lambda: self.menu_action(3))
|
||||
self.button_menu.addAction(label_action3)
|
||||
|
||||
label_action4 = QAction(self)
|
||||
label_action4.setIcon(QIcon('../images/4.jpg'))
|
||||
label_action4.setText('渐变4')
|
||||
label_action4.setText('背景4')
|
||||
label_action4.triggered.connect(lambda: self.menu_action(4))
|
||||
self.button_menu.addAction(label_action4)
|
||||
|
||||
label_action5 = QAction(self)
|
||||
label_action5.setIcon(QIcon('../images/5.jpg'))
|
||||
label_action5.setText('渐变5')
|
||||
label_action5.setText('背景5')
|
||||
label_action5.triggered.connect(lambda: self.menu_action(5))
|
||||
self.button_menu.addAction(label_action5)
|
||||
|
||||
|
@ -162,7 +165,6 @@ class MyDay(QWidget):
|
|||
|
||||
pass
|
||||
|
||||
|
||||
# todo : 下面的方法实现点击更换主题的功能
|
||||
|
||||
def menu_action(self, count):
|
||||
|
@ -170,11 +172,11 @@ class MyDay(QWidget):
|
|||
# 点击按钮
|
||||
|
||||
self.setStyleSheet('#my_day{background-image:url("../images/' + count + '.jpg");'
|
||||
'background-position: center; border-radius: 10px;'
|
||||
'background-position: center; border-radius: 10px;'
|
||||
'}')
|
||||
self.head_label.show()
|
||||
|
||||
print('选中:' + count)
|
||||
print('<MyDayView> 选中:' + count)
|
||||
|
||||
#
|
||||
# def add_todo_action(self, name):
|
||||
|
@ -183,7 +185,8 @@ class MyDay(QWidget):
|
|||
def line_edit_add(self, name):
|
||||
self.add_todo.todo_name.emit(name)
|
||||
# print('添加的新ToDo:' + name)
|
||||
todo_item = ToDoItem(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)
|
||||
|
|
86
view/MyListWidget.py
Normal file
86
view/MyListWidget.py
Normal file
|
@ -0,0 +1,86 @@
|
|||
# listwidget.pyw
|
||||
from typing import Optional
|
||||
from PyQt5.QtWidgets import QListWidget, QWidget, QAbstractItemView, QListWidgetItem
|
||||
from PyQt5.QtGui import QDragEnterEvent, QDropEvent, QDragMoveEvent, QKeyEvent
|
||||
from PyQt5.QtCore import Qt, QModelIndex, pyqtSignal
|
||||
|
||||
|
||||
class MyListWidget(QListWidget):
|
||||
"""支持拖拽的QListWidget"""
|
||||
change_list_name = pyqtSignal()
|
||||
|
||||
def __init__(self, parent: Optional[QWidget] = None) -> None:
|
||||
super().__init__(parent)
|
||||
|
||||
# 拖拽设置
|
||||
# self.setAcceptDrops(True)
|
||||
# self.setDragEnabled(True)
|
||||
# self.setDragDropMode(QAbstractItemView.DragDrop) # 设置拖放
|
||||
# self.setSelectionMode(QAbstractItemView.ExtendedSelection) # 设置选择多个
|
||||
# self.setDefaultDropAction(Qt.CopyAction)
|
||||
# 双击可编辑
|
||||
self.edited_item = self.currentItem()
|
||||
self.close_flag = True
|
||||
self.doubleClicked.connect(self.item_double_clicked)
|
||||
self.currentItemChanged.connect(self.close_edit)
|
||||
|
||||
def keyPressEvent(self, e: QKeyEvent) -> None:
|
||||
|
||||
"""回车事件,关闭edit"""
|
||||
super().keyPressEvent(e)
|
||||
if e.key() == Qt.Key_Return:
|
||||
if self.close_flag:
|
||||
self.close_edit()
|
||||
self.close_flag = True
|
||||
self.change_list_name.emit()
|
||||
|
||||
def edit_new_item(self) -> None:
|
||||
"""edit一个新的item"""
|
||||
self.close_flag = False
|
||||
self.close_edit()
|
||||
count = self.count()
|
||||
self.addItem('')
|
||||
item = self.item(count)
|
||||
self.edited_item = item
|
||||
self.openPersistentEditor(item)
|
||||
self.editItem(item)
|
||||
|
||||
def item_double_clicked(self, modelindex: QModelIndex) -> None:
|
||||
"""双击事件"""
|
||||
if self.currentRow() > 1:
|
||||
self.close_edit()
|
||||
item = self.item(modelindex.row())
|
||||
self.edited_item = item
|
||||
self.openPersistentEditor(item)
|
||||
self.editItem(item)
|
||||
# print(self.currentItem().text())
|
||||
|
||||
def close_edit(self, *_) -> None:
|
||||
"""关闭edit"""
|
||||
# print(self.currentItem().text())
|
||||
# print(self.currentRow())
|
||||
|
||||
if self.edited_item and self.isPersistentEditorOpen(self.edited_item):
|
||||
self.closePersistentEditor(self.edited_item)
|
||||
|
||||
def dragEnterEvent(self, e: QDragEnterEvent) -> None:
|
||||
"""(从外部或内部控件)拖拽进入后触发的事件"""
|
||||
# print(e.mimeData().text())
|
||||
if e.mimeData().hasText():
|
||||
if e.mimeData().text().startswith('file:///'):
|
||||
e.accept()
|
||||
else:
|
||||
e.ignore()
|
||||
|
||||
def dragMoveEvent(self, e: QDragMoveEvent) -> None:
|
||||
"""拖拽移动过程中触发的事件"""
|
||||
e.accept()
|
||||
|
||||
def dropEvent(self, e: QDropEvent) -> None:
|
||||
"""拖拽结束以后触发的事件"""
|
||||
paths = e.mimeData().text().split('\n')
|
||||
for path in paths:
|
||||
path = path.strip()
|
||||
if len(path) > 8:
|
||||
self.addItem(path.strip()[8:])
|
||||
e.accept()
|
|
@ -1,8 +1,6 @@
|
|||
from PyQt5.QtWidgets import *
|
||||
from PyQt5.QtGui import *
|
||||
from PyQt5.QtCore import Qt
|
||||
import sys
|
||||
import os
|
||||
|
||||
|
||||
class SelfListWidgetItem(QListWidgetItem):
|
||||
|
@ -51,3 +49,7 @@ class SelfListWidgetItem(QListWidgetItem):
|
|||
layout.addWidget(self.todo_count_label, 1)
|
||||
# 设置自定义的QListWidgetItem的sizeHint,不然无法显示
|
||||
self.setSizeHint(self.widget.sizeHint())
|
||||
# main=MainWidget()
|
||||
|
||||
def change_name(self):
|
||||
pass
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
from PyQt5 import QtGui
|
||||
from PyQt5.QtCore import Qt, pyqtSignal
|
||||
from PyQt5.QtGui import QPixmap, QIcon
|
||||
from PyQt5.QtWidgets import *
|
||||
|
@ -6,6 +7,24 @@ from PyQt5.QtCore import Qt
|
|||
from utils.BasicUtils import change_value
|
||||
|
||||
|
||||
class Button(QPushButton):
|
||||
trans_signal = pyqtSignal()
|
||||
|
||||
def __init__(self):
|
||||
super(Button, self).__init__()
|
||||
|
||||
def mouseReleaseEvent(self, e: QtGui.QMouseEvent) -> None:
|
||||
self.trans_signal.emit()
|
||||
|
||||
|
||||
|
||||
# def mousePressEvent(self, QMouseEvent):
|
||||
# print('haha')
|
||||
|
||||
# def clicked(self, checked: bool = ...):
|
||||
# self.trans_signal.emit()
|
||||
|
||||
|
||||
class ToDoItem(QListWidgetItem):
|
||||
transaction = pyqtSignal()
|
||||
"""
|
||||
|
@ -13,7 +32,7 @@ class ToDoItem(QListWidgetItem):
|
|||
:param uid : 待办事项的uid
|
||||
"""
|
||||
|
||||
# todo : 参数添加uid,方便设置重要和我的一天
|
||||
# todo : 设置点击事件信号传递
|
||||
def __init__(self, todo_name, uid=None):
|
||||
super(ToDoItem, self).__init__()
|
||||
# print('<ToDoItem> 添加的新ToDo:' + todo_name)
|
||||
|
@ -41,16 +60,16 @@ class ToDoItem(QListWidgetItem):
|
|||
layout.addWidget(self.important_button, 2)
|
||||
|
||||
self.mark_icon.clicked.connect(self.set_done)
|
||||
print(uid)
|
||||
print('<ToDoItem>', uid)
|
||||
|
||||
self.important_button.clicked.connect(lambda: self.set_important(uid))
|
||||
# self.mark_icon.trans_signal.connect(self.set_done)
|
||||
|
||||
def set_done(self):
|
||||
print('<ToDoItem>hello')
|
||||
pass
|
||||
|
||||
def set_myday(self, uid):
|
||||
|
||||
|
||||
change_value(uid, 'done', True)
|
||||
pass
|
||||
|
||||
|
@ -58,7 +77,8 @@ class ToDoItem(QListWidgetItem):
|
|||
# important = Important()
|
||||
# important.load_important.emit()
|
||||
# self.action.emit()
|
||||
print('<ToDoItem>',uid)
|
||||
|
||||
change_value(uid, 'isImportant', True)
|
||||
self.transaction.emit()
|
||||
pass
|
||||
# self.transaction.emit()
|
||||
pass
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import os
|
||||
from PyQt5.QtGui import *
|
||||
from PyQt5.QtWidgets import *
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtCore import Qt, pyqtSignal
|
||||
|
||||
from utils.BasicUtils import get_todo
|
||||
from utils.BasicUtils import get_todo, change_value, load_value, remove_todo_list
|
||||
from utils.CreateToDo import CreateToDo
|
||||
from view.AddToDoLabel import AddToDoAction
|
||||
from view.ToDoItem import ToDoItem
|
||||
|
||||
|
@ -23,6 +24,9 @@ class ToDoList(QWidget):
|
|||
:param uid : 列表的uid,用于加载Todo和创建时传递参数
|
||||
"""
|
||||
|
||||
# 测试更新的信号发送
|
||||
update_signal = pyqtSignal()
|
||||
|
||||
def __init__(self, list_name, uid):
|
||||
super(ToDoList, self).__init__()
|
||||
self.setObjectName('todolist')
|
||||
|
@ -118,40 +122,44 @@ class ToDoList(QWidget):
|
|||
# for i in range(11):
|
||||
label_action1 = QAction(self)
|
||||
label_action1.setIcon(QIcon('../images/1.jpg'))
|
||||
label_action1.setText('渐变1')
|
||||
label_action1.setText('背景1')
|
||||
label_action1.triggered.connect(lambda: self.menu_action(1))
|
||||
self.button_menu.addAction(label_action1)
|
||||
|
||||
label_action2 = QAction(self)
|
||||
label_action2.setIcon(QIcon('../images/2.jpg'))
|
||||
label_action2.setText('渐变2')
|
||||
label_action2.setText('背景2')
|
||||
label_action2.triggered.connect(lambda: self.menu_action(2))
|
||||
self.button_menu.addAction(label_action2)
|
||||
|
||||
label_action3 = QAction(self)
|
||||
label_action3.setIcon(QIcon('../images/3.jpg'))
|
||||
label_action3.setText('渐变3')
|
||||
label_action3.setText('背景3')
|
||||
label_action3.triggered.connect(lambda: self.menu_action(3))
|
||||
self.button_menu.addAction(label_action3)
|
||||
|
||||
label_action4 = QAction(self)
|
||||
label_action4.setIcon(QIcon('../images/4.jpg'))
|
||||
label_action4.setText('渐变4')
|
||||
label_action4.setText('背景4')
|
||||
label_action4.triggered.connect(lambda: self.menu_action(4))
|
||||
self.button_menu.addAction(label_action4)
|
||||
|
||||
label_action5 = QAction(self)
|
||||
label_action5.setIcon(QIcon('../images/5.jpg'))
|
||||
label_action5.setText('渐变5')
|
||||
label_action5.setText('背景5')
|
||||
label_action5.triggered.connect(lambda: self.menu_action(5))
|
||||
self.button_menu.addAction(label_action5)
|
||||
self.uid = uid
|
||||
|
||||
self.initUI()
|
||||
# 右键菜单
|
||||
self.todo_list.setContextMenuPolicy(Qt.CustomContextMenu)
|
||||
self.todo_list.customContextMenuRequested.connect(self.todo_list_context)
|
||||
|
||||
def initUI(self):
|
||||
# 读取配置文件添加Todo
|
||||
# thread_action = ThreadAction()
|
||||
self.load_theme()
|
||||
|
||||
load_todo = get_todo(self.uid)
|
||||
if load_todo:
|
||||
|
@ -165,17 +173,25 @@ class ToDoList(QWidget):
|
|||
# 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'))
|
||||
self.setStyleSheet('#todolist{background-image:url("../images/' + theme + '.jpg");'
|
||||
'background-position: center; border-radius: 10px;'
|
||||
'}')
|
||||
|
||||
def menu_action(self, count):
|
||||
# 点击按钮
|
||||
count = str(count)
|
||||
# self.menu_label = ChangeTheme()
|
||||
change_value(self.uid, 'Theme', count)
|
||||
self.setStyleSheet('#todolist{background-image:url("../images/' + count + '.jpg");'
|
||||
'background-position: center; border-radius: 10px;'
|
||||
'}')
|
||||
# print('选中:' + count)
|
||||
|
||||
def load_todo(self, name, uid):
|
||||
todo_item = ToDoItem(name)
|
||||
todo_item = ToDoItem(name, uid)
|
||||
# todo_item.mark_icon.trans_signal.connect(self.todo_list.clear())
|
||||
|
||||
self.todo_list.addItem(todo_item)
|
||||
self.todo_list.setItemWidget(todo_item, todo_item.widget)
|
||||
|
@ -185,9 +201,62 @@ class ToDoList(QWidget):
|
|||
def line_edit_add(self, name):
|
||||
self.add_todo.todo_name.emit(name)
|
||||
# print('添加的新ToDo:' + name)
|
||||
todo_item = ToDoItem(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.add_todo.line_edit.clear()
|
||||
|
||||
def todo_list_context(self, position):
|
||||
# 设置右键菜单
|
||||
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)
|
||||
|
||||
mark_myday = QAction(QIcon(QPixmap(os.getcwd() + '/../images/make_sun.svg')), u"设置为我的一天", self)
|
||||
mark_important = QAction(QIcon(QPixmap(os.getcwd() + '/../images/star.svg')), u"设置为重要", self)
|
||||
|
||||
del_action = QAction("删除", self)
|
||||
|
||||
# 查看右键时是否在item上面,如果不在.就不显示删除和修改.
|
||||
pop_menu.addAction(rename_action)
|
||||
if self.todo_list.itemAt(position):
|
||||
pop_menu.addAction(mark_myday)
|
||||
pop_menu.addAction(mark_important)
|
||||
pop_menu.addAction(del_action)
|
||||
pop_menu.addAction(rename_action)
|
||||
|
||||
rename_action.triggered.connect(self.rename_item)
|
||||
# copy_action.triggered.connect(self.create_item)
|
||||
del_action.triggered.connect(self.delete_item)
|
||||
mark_important.triggered.connect(self.make_important)
|
||||
pop_menu.exec_(self.todo_list.mapToGlobal(position))
|
||||
|
||||
def make_important(self):
|
||||
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())
|
||||
|
||||
# 重命名分组
|
||||
def rename_item(self):
|
||||
curRow = self.todo_list.currentRow()
|
||||
item = self.todo_list.item(curRow)
|
||||
item.setFlags(item.flags() | Qt.ItemIsEditable)
|
||||
self.todo_list.editItem(item)
|
||||
self.todo_list.itemChanged.connect(lambda: self.ChangeItem(item))
|
||||
|
||||
def ChangeItem(self, item):
|
||||
print(item)
|
||||
|
||||
print("test")
|
||||
|
|
Loading…
Reference in a new issue