所有功能实现,还有小bug需要解决!

This commit is contained in:
liyp 2022-04-27 21:39:09 +08:00
parent f6ef0ea479
commit 0c725c0ccf
15 changed files with 370 additions and 317 deletions

View file

@ -2,9 +2,7 @@ import os
import sys import sys
from PyQt5.QtGui import * from PyQt5.QtGui import *
from PyQt5.QtWidgets import * from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt, pyqtSignal from PyQt5.QtCore import Qt, pyqtSignal, QRect
import configparser
from utils.BasicUtils import get_todo_list, remove_todo_list, change_value, read_ini, set_exit_status from utils.BasicUtils import get_todo_list, remove_todo_list, change_value, read_ini, set_exit_status
from utils.CreateConfigure import CreateConfigure from utils.CreateConfigure import CreateConfigure
from utils.CreateToDo import CreateToDo from utils.CreateToDo import CreateToDo
@ -67,12 +65,14 @@ class MainWidget(QWidget):
self.initUI() self.initUI()
def initUI(self): 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.system_listWidget.clear()
# 系统默认的两个 item # 系统默认的两个 item
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.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.addItem(self.one_day) self.system_listWidget.addItem(self.one_day)
@ -85,6 +85,7 @@ class MainWidget(QWidget):
# 加载列表 # 加载列表
load_list = get_todo_list() load_list = get_todo_list()
# print(load_list) # print(load_list)
# todobug 第一个为空会导致无法添加
if load_list: if load_list:
for load in load_list: for load in load_list:
self.load_item(load[0], load[1], load[3]) self.load_item(load[0], load[1], load[3])
@ -170,9 +171,9 @@ class MainWidget(QWidget):
# 删除分组时可用 # 删除分组时可用
self.important.update_signal.connect(todo_list.refresh_action) self.important.update_signal.connect(todo_list.refresh_action)
self.important.update_signal.connect(self.my_day.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(todo_list.refresh_action)
self.my_day.update_signal.connect(self.important.refresh_action) # self.my_day.update_signal.connect(self.important.refresh_action)
self.update_signal.connect(todo_list.refresh_action) self.update_signal.connect(todo_list.refresh_action)
# 创建后就可以编辑item,用户自己起名字. # 创建后就可以编辑item,用户自己起名字.
@ -288,8 +289,12 @@ class MainWindow(QWidget):
def closeEvent(self, event): def closeEvent(self, event):
# 创建一个消息盒子(提示框) # 创建一个消息盒子(提示框)
quitMsgBox = QMessageBox() 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 = QCheckBox('记住选择')
self.save_config.isChecked() self.save_config.setChecked(True)
quitMsgBox.setCheckBox(self.save_config) quitMsgBox.setCheckBox(self.save_config)
# self.save_config.stateChanged.connect(self.save_exit) # self.save_config.stateChanged.connect(self.save_exit)
quitMsgBox.resize(300, 200) quitMsgBox.resize(300, 200)
@ -302,27 +307,7 @@ class MainWindow(QWidget):
buttonN = QPushButton('最小化到托盘') buttonN = QPushButton('最小化到托盘')
# 将两个按钮加到这个消息盒子中去并指定yes和no的功能 # 将两个按钮加到这个消息盒子中去并指定yes和no的功能
style = """ style = QSSLoader.read_qss_file(os.getcwd() + '/../resource/closeDialog.qss')
/*设置堆栈按钮样式*/
QPushButton {
/* padding: 3px 20px;*/
/* text-align:center;*/
background-color:orange;
border-radius:15px;
}
QPushButton:hover {
/* padding: 3px 20px;*/
/* text-align:center;*/
background-color:#dddddd;
border-radius:15px;
}
QPushButton:pressed {
/* padding: 3px 20px;*/
/* text-align:center;*/
background-color:#9f9f9f;
border-radius:15px;
}
"""
buttonY.setStyleSheet(style) buttonY.setStyleSheet(style)
buttonN.setStyleSheet(style) buttonN.setStyleSheet(style)

19
resource/closeDialog.qss Normal file
View file

@ -0,0 +1,19 @@
/*设置堆栈按钮样式*/
QPushButton {
/* padding: 3px 20px;*/
/* text-align:center;*/
background-color:orange;
border-radius:15px;
}
QPushButton:hover {
/* padding: 3px 20px;*/
/* text-align:center;*/
background-color:#dddddd;
border-radius:15px;
}
QPushButton:pressed {
/* padding: 3px 20px;*/
/* text-align:center;*/
background-color:#9f9f9f;
border-radius:15px;
}

21
resource/login.qss Normal file
View file

@ -0,0 +1,21 @@
QLineEdit#lineedit{
border: 1px solid gray;
background:#f3f3f3;
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;
}

View file

@ -55,9 +55,13 @@ def change_myday_important_conf(change_type, key, value):
def get_myday_important_conf(get_type, key): def get_myday_important_conf(get_type, key):
config = configparser.ConfigParser() config = configparser.ConfigParser()
config_path = return_work_dir() config_path = return_work_dir()
try:
todo_file = config_path + 'PyQtToDoList.conf' todo_file = config_path + 'PyQtToDoList.conf'
config.read(todo_file) config.read(todo_file)
return config[get_type][key] return config[get_type][key]
except KeyError as e:
print('File Not Found!')
return False
def get_todo_list(): def get_todo_list():
@ -146,9 +150,6 @@ def change_value(uid, key, value):
config_path = return_work_dir() config_path = return_work_dir()
todo_path = config_path + 'ToDoList/' todo_path = config_path + 'ToDoList/'
# for root, dirs, files in os.walk(todo_path, topdown=False):
# for name in files:
# print(os.path.join(root, name))
json_file = {} json_file = {}
current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
@ -219,6 +220,25 @@ def set_exit_status(status):
return False return False
# 判断是否登录
def check_login_status():
try:
# work_dir = return_work_dir()
init_file_list = read_init_file()
print(init_file_list)
if init_file_list and 'None' not in init_file_list:
return True
else:
return False
#
# for i in init_file_list:
# if i == 'None':
# return False
# else:
# return True
except TypeError as e:
return False
# 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])
@ -229,3 +249,4 @@ def set_exit_status(status):
# print(get_myday_important_conf('Important','Theme')) # print(get_myday_important_conf('Important','Theme'))
# print(read_ini('System', 'exitstatus')) # print(read_ini('System', 'exitstatus'))
# print(set_exit_status('Min')) # print(set_exit_status('Min'))
# print(check_login_status())

View file

@ -59,8 +59,8 @@ 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'} # config['System'] = {'exitStatus': 'None'}
print(config['System']['exitStatus']) # print(config['System']['exitStatus'])
with open(config_file, 'w') as f: with open(config_file, 'w') as f:
config.write(f) config.write(f)

View file

@ -1,87 +1,75 @@
import os import os
import platform from webdav4.fsspec import WebdavFileSystem
from webdav3.exceptions import LocalResourceNotFound
from webdav3.client import Client
import configparser import configparser
from PyQt5.QtCore import Qt, pyqtSignal, QThread from PyQt5.QtCore import Qt, pyqtSignal, QThread
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from utils.BasicUtils import read_init_file, return_work_dir from utils.BasicUtils import read_init_file, return_work_dir
from webdav4.client import HTTPError, Client
# todo : 暂时只有手动同步,没有做自动同步,暂时不需要传递参数
class Sync(QThread): class Sync(QThread):
sync_signal = pyqtSignal() sync_signal = pyqtSignal()
def __init__(self): def __init__(self):
super(Sync, self).__init__() super(Sync, self).__init__()
self.sync_path = return_work_dir() self.sync_path = return_work_dir()
self.config_info = read_init_file()
def run(self): def run(self):
types = ['NextCloud', 'JianGuoYun', 'WebDav'] # types = ['NextCloud', 'JianGuoYun', 'WebDav']
# 根据不同的账号类型调用不同的方式 # 根据不同的账号类型调用不同的方式
config = configparser.ConfigParser() # config = configparser.ConfigParser()
# try: conf_file = self.sync_path + 'PyQtToDoList.conf'
# config.read(read_init_file()) todo_path = self.sync_path + 'ToDoList/'
self.config_info = read_init_file() if os.path.exists(conf_file) or os.path.exists(todo_path):
# webdav_hostname = config['Account']['webdav_hostname']
# webdav_login = config['Account']['webdav_login']
# webdav_password = config['Account']['webdav_password']
options = {
'webdav_hostname': self.config_info[0],
'webdav_login': self.config_info[1],
'webdav_password': self.config_info[2],
'disable_check': True
}
self.upload_file(options)
# except FileNotFoundError as e:
# print('<Sync>', e)
def upload_file(self, options):
try: try:
client = Client(options) client = WebdavFileSystem(base_url=self.config_info[0],
auth=(self.config_info[1], self.config_info[2]))
path = client.check('PyQtToDoList') # ls = client.ls('/PyQtToDoList', detail=False)
print(path) # print(ls)
# list1 = client.list('/') work_path_exist = client.exists('PyQtToDoList')
# print('/ ', list1) # 如果WebDav服务器的同步目录没有就创建同步目录和Todo目录
client.mkdir('PyQtToDoList/') if not work_path_exist:
list1 = client.list('/') client.mkdir('PyQtToDoList')
print('/ ', list1) client.mkdir('PyQtToDoList/ToDoList/')
client.upload_file('PyQtToDoList/' + 'PyQtToDoList.conf', self.sync_path + 'PyQtToDoList.conf') # 如果有同步目录没有Todo目录就创建Todo目录
client.upload_directory('PyQtToDoList/' + 'ToDoList/', self.sync_path + 'ToDoList/') remote_todo_path = client.exists('PyQtToDoList/ToDoList')
if not path: if not remote_todo_path:
client.mkdir('PyQtToDoList/PyQtToDoList.conf') client.mkdir('PyQtToDoList/ToDoList/')
list1 = client.list('/') # 检查本地配置文件
print('/ ', list1) if os.path.exists(conf_file):
conf_file = client.check('PyQtToDoList/PyQtToDoList.conf') client.upload(conf_file, 'PyQtToDoList/PyQtToDoList.conf')
print('conf_file:', conf_file) if os.path.exists(todo_path):
if not conf_file: todo_files = os.listdir(todo_path)
try: for file in todo_files:
client.push('PyQtToDoList/' + 'PyQtToDoList.conf', self.sync_path + 'PyQtToDoList.conf') client.upload(todo_path + file, 'PyQtToDoList/ToDoList/' + file)
client.push('PyQtToDoList/', self.sync_path + 'ToDoList')
self.sync_signal.emit() self.sync_signal.emit()
except LocalResourceNotFound as e: # print(status)
print('An error happen: LocalResourceNotFound ---')
except Exception as e: except Exception as e:
print('<Sync>', e) print('<Sync>', e)
# config_file, upload_files, upload_dirs = else:
# client.upload('OpenTodoList/', config_file) client = WebdavFileSystem(base_url=self.config_info[0],
# for upload_dir in upload_dirs: auth=(self.config_info[1], self.config_info[2]))
# upload_dir_name = upload_dir.split('/')[-1] work_path_exist = client.exists('PyQtToDoList/')
# client.mkdir('OpenTodoList/' + upload_dir_name) if work_path_exist:
# for upload_file in upload_files: if client.exists('PyQtToDoList/PyQtToDoList.conf'):
# upload_dir = upload_file.split('/')[-2] client.download('PyQtToDoList/PyQtToDoList.conf', conf_file)
# upload_file_name = upload_file.split('/')[-1] if client.exists('PyQtToDoList/ToDoList'):
# client.upload('OpenTodoList/' + upload_dir + upload_file_name, upload_file) os.mkdir(todo_path)
# client.pull('OpenTodoList', '') todo_list = client.ls('PyQtToDoList/ToDoList')
# client.push('OpenTodoList', self.get_sync_path()) print('todo_list:', todo_list)
for item in todo_list:
client.download('PyQtToDoList/ToDoList' + item, todo_path + item)
self.sync_signal.emit()
""" @staticmethod
程序的配置文件和数据根据不同系统保存在不同文件夹 def test_link(self, address, name, password):
Linux在 ~/.config/PyQtToDoList下 try:
Windows在 程序目录/config/ client = Client(base_url=address,
""" auth=(name, password), timeout=5000)
# print(client.info('/'))
return 200
except HTTPError as e:
print('HttpError')
return 500

View file

@ -25,6 +25,8 @@ class Important(QWidget):
self.setAttribute(Qt.WA_StyledBackground) self.setAttribute(Qt.WA_StyledBackground)
background = get_myday_important_conf('Important', 'Theme') background = get_myday_important_conf('Important', 'Theme')
if not background:
background = '0'
self.setStyleSheet('#important{background-image:url("../images/' + background + '.jpg");border-radius: 10px;}') self.setStyleSheet('#important{background-image:url("../images/' + background + '.jpg");border-radius: 10px;}')
@ -177,6 +179,7 @@ class Important(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)
self.add_todo.line_edit.clear() self.add_todo.line_edit.clear()
self.update_signal.emit()
def todo_list_context(self, position): def todo_list_context(self, position):
# 设置右键菜单 # 设置右键菜单
@ -255,7 +258,7 @@ class Important(QWidget):
self.dialog.exec_() self.dialog.exec_()
def change_name(self, item_name): def change_name(self, item_name):
print(item_name) # print(item_name)
my_day_list = load_myday_important('Important') my_day_list = load_myday_important('Important')
change_value(my_day_list[self.todo_list.currentRow()][1], 'title', item_name) change_value(my_day_list[self.todo_list.currentRow()][1], 'title', item_name)
# 重命名发送信号 # 重命名发送信号
@ -266,13 +269,13 @@ class Important(QWidget):
def mark_done(self, uid): def mark_done(self, uid):
# print('mark done:', uid) # print('mark done:', uid)
change_value(uid, 'done', True) change_value(uid, 'done', True)
time.sleep(0.5) # time.sleep(0.5)
self.todo_list.takeItem(self.todo_list.currentRow())
self.refresh_action() self.refresh_action()
self.update_signal.emit() self.update_signal.emit()
def mark_important(self, uid): def mark_important(self, uid):
change_value(uid, 'isImportant', True) change_value(uid, 'isImportant', False)
# print('mark important:', uid) # print('mark important:', uid)
self.refresh_action() self.refresh_action()
self.update_signal.emit() self.update_signal.emit()

View file

@ -1,200 +1,111 @@
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5.QtGui import * from PyQt5.QtGui import *
from PyQt5.QtWidgets import * from PyQt5.QtWidgets import *
import configparser import configparser
from utils.BasicUtils import * from utils.BasicUtils import *
from utils.CreateConfigure import CreateConfigure
from utils.QSSLoader import QSSLoader
from utils.Sync import Sync
from view.Tip_UI import TipUi
# class LoginWidget(QWidget):
#
# class LoginWindow(QWidget):
# def __init__(self):
# super().__init__()
# self.setStyleSheet('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;'
# '}')
# layout = QVBoxLayout()
# self.setLayout(layout)
# self.setWindowTitle('登录')
# self.resize(500, 600)
# self.tab_widget = QTabWidget()
# self.tab_widget.setStyleSheet('border:none;background-color:#f3f3f3')
# nextcloud_widget = LoginWidget('NextCloud')
# self.tab_widget.addTab(nextcloud_widget, '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)
# 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.link.clicked.connect(self.close)
class LoginWidget(QTabWidget):
# todo : 添加一个信号,等点击保存后在 main 里面更新未登录的信息 # todo : 添加一个信号,等点击保存后在 main 里面更新未登录的信息
""" login_signal = pyqtSignal()
:param login_type 登录账号类型
"""
def __init__(self): def __init__(self):
super(LoginWidget, self).__init__() super(LoginWidget, self).__init__()
self.resize(500, 300) self.resize(500, 300)
self.setStyleSheet('QLineEdit#lineedit{border: 1px solid gray;background:#f3f3f3;min-width:300px;' style_sheet = QSSLoader.read_qss_file(os.getcwd() + '/../resource/login.qss')
'border-top-left-radius:5px;border-top-right-radius:5px;border-bottom-left-radius:5px;' self.setStyleSheet(style_sheet)
'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;'
'}')
# layout = QVBoxLayout() # layout = QVBoxLayout()
self.setWindowTitle('登录') self.setWindowTitle('登录')
self.combo = QComboBox()
# host_name_layout = QHBoxLayout() self.combo.addItems(['NextCloud', '坚果云', 'WebDav'])
self.layout = QFormLayout()
# self.host_address = QLabel('服务器地址:') self.setLayout(self.layout)
# form_layout = QFormLayout()
self.nextcloud_address_lineedit = QLineEdit()
self.nextcloud_address_lineedit.setObjectName('lineedit')
self.nextcloud_address_lineedit.setPlaceholderText('https://nextcloud.example.com')
# host_name_layout.addWidget(self.host_address, 3)
# host_name_layout.addWidget(self.host_address_lineedit, 6)
# host_name_layout = QHBoxLayout()
# self.host_address = QLabel('服务器地址:')
self.dav_address_lineedit = QLineEdit() self.dav_address_lineedit = QLineEdit()
self.dav_address_lineedit.setObjectName('lineedit') self.dav_address_lineedit.setObjectName('lineedit')
self.dav_address_lineedit.setPlaceholderText('https://webdav.example.com/dav')
self.nextcloud_name_lineedit = QLineEdit()
self.nextcloud_name_lineedit.setPlaceholderText('用户名')
self.nextcloud_name_lineedit.setObjectName('lineedit')
# form_layout.addRow('用户:', self.name_lineedit)
self.dav_name_lineedit = QLineEdit() self.dav_name_lineedit = QLineEdit()
self.dav_name_lineedit.setPlaceholderText('用户名') self.dav_name_lineedit.setPlaceholderText('用户名')
self.dav_name_lineedit.setObjectName('lineedit') self.dav_name_lineedit.setObjectName('lineedit')
self.nextcloud_password_lineedit = QLineEdit()
self.nextcloud_password_lineedit.setEchoMode(QLineEdit.Password)
self.nextcloud_password_lineedit.setPlaceholderText('密码')
self.nextcloud_password_lineedit.setObjectName('lineedit')
# form_layout.addRow('密码:', self.password_lineedit)
self.dav_password_lineedit = QLineEdit() self.dav_password_lineedit = QLineEdit()
self.dav_password_lineedit.setEchoMode(QLineEdit.Password) self.dav_password_lineedit.setEchoMode(QLineEdit.Password)
self.dav_password_lineedit.setPlaceholderText('密码') self.dav_password_lineedit.setPlaceholderText('密码')
self.dav_password_lineedit.setObjectName('lineedit') self.dav_password_lineedit.setObjectName('lineedit')
self.jianguoyun_name_lineedit = QLineEdit()
self.jianguoyun_name_lineedit.setPlaceholderText('用户名')
self.jianguoyun_name_lineedit.setObjectName('lineedit')
self.jianguoyun_password_lineedit = QLineEdit()
self.jianguoyun_password_lineedit.setEchoMode(QLineEdit.Password)
self.jianguoyun_password_lineedit.setPlaceholderText('密码')
self.jianguoyun_password_lineedit.setObjectName('lineedit')
button_layout = QHBoxLayout()
self.test_link = QPushButton('测试连接') self.test_link = QPushButton('测试连接')
self.test_link.setObjectName('login_button') self.test_link.setObjectName('login_button')
self.link = QPushButton('保存配置') self.link = QPushButton('保存配置')
self.link.setObjectName('login_button') self.link.setObjectName('login_button')
button_layout.addWidget(self.test_link)
button_layout.addWidget(self.link)
# form_layout.addRow(self.test_link, self.link)
# layout.addLayout(form_layout) self.layout.addRow(self.combo)
# self.setLayout(layout)
# self.show() self.layout.addRow('服务器地址:', self.dav_address_lineedit)
self.dav_address_lineedit.setPlaceholderText('https://nextcloud.example.com')
self.layout.addRow('用户名:', self.dav_name_lineedit)
self.dav_name_lineedit.setPlaceholderText('用户名')
self.layout.addRow('密码:', self.dav_password_lineedit)
self.layout.addRow(self.test_link, self.link)
self.iniUI()
self.combo.currentIndexChanged.connect(self.iniUI)
self.test_link.clicked.connect(self.link_test) self.test_link.clicked.connect(self.link_test)
self.link.clicked.connect(self.close) self.link.clicked.connect(self.save_link)
self.nextcloud_tab = QWidget()
self.jianguoyun_tab = QWidget()
self.webdav_tab = QWidget()
self.addTab(self.nextcloud_tab, 'NextCloud') def iniUI(self):
self.addTab(self.jianguoyun_tab, '坚果云') # print(self.combo.currentIndex())
self.addTab(self.webdav_tab, 'WebDav')
self.initUI1() if self.combo.currentIndex() == 0:
self.initUI2() self.dav_address_lineedit.setPlaceholderText('https://nextcloud.example.com')
self.initUI3()
# todo : 方向不对,这样设计极其不好,需要更换方式 elif self.combo.currentIndex() == 1:
# self.layout.addRow('用户名:', self.dav_name_lineedit)
self.dav_address_lineedit.setPlaceholderText('https://dav.jianguoyun.com/dav/(默认可为空)')
# self.layout.removeWidget(self.dav_address_lineedit)
def initUI1(self): elif self.combo.currentIndex() == 2:
form_layout = QFormLayout() # self.layout.addRow('服务器地址:', self.dav_address_lineedit)
form_layout.addRow('服务器地址:', self.nextcloud_address_lineedit) self.dav_address_lineedit.setPlaceholderText('https://dav.example.com/dav')
form_layout.addRow('用户:', self.nextcloud_name_lineedit)
form_layout.addRow('密码:', self.nextcloud_password_lineedit)
form_layout.addRow(self.test_link, self.link)
self.nextcloud_tab.setLayout(form_layout)
def initUI2(self):
form_layout = QFormLayout()
form_layout.addRow('服务器地址:', self.dav_address_lineedit)
form_layout.addRow('用户:', self.dav_name_lineedit)
form_layout.addRow('密码:', self.dav_password_lineedit)
form_layout.addRow(self.test_link, self.link)
self.webdav_tab.setLayout(form_layout)
pass
def initUI3(self):
form_layout = QFormLayout()
form_layout.addRow('用户:', self.jianguoyun_name_lineedit)
form_layout.addRow('密码:', self.jianguoyun_password_lineedit)
form_layout.addRow(self.test_link, self.link)
self.jianguoyun_tab.setLayout(form_layout)
pass
def initUI(self, login_type):
form_layout = QFormLayout()
if login_type == 'NextCloud':
print(login_type)
form_layout.addRow('服务器地址:', self.nextcloud_address_lineedit)
form_layout.addRow('用户:', self.name_lineedit)
form_layout.addRow('密码:', self.password_lineedit)
form_layout.addRow(self.test_link, self.link)
self.nextcloud_tab.setLayout(form_layout)
elif login_type == 'WebDav':
print(login_type)
form_layout.addRow('服务器地址:', self.dav_address_lineedit)
form_layout.addRow('用户:', self.name_lineedit)
form_layout.addRow('密码:', self.password_lineedit)
form_layout.addRow(self.test_link, self.link)
self.webdav_tab.setLayout(form_layout)
else:
print(login_type)
form_layout.addRow('用户:', self.name_lineedit)
form_layout.addRow('密码:', self.password_lineedit)
form_layout.addRow(self.test_link, self.link)
self.jianguoyun_tab.setLayout(form_layout)
# if login_type == 'NextCloud':
# self.nextcloud_tab.setLayout(form_layout)
# elif login_type == 'WebDav':
# self.webdav_tab.setLayout(form_layout)
# else:
# self.jianguoyun_tab.setLayout(form_layout)
def link_test(self): def link_test(self):
address = ''
name = ''
password = ''
if self.combo.currentIndex() != 1:
if self.dav_address_lineedit.text() and self.dav_name_lineedit.text() and self.dav_password_lineedit.text():
if self.combo.currentIndex() == 0:
addr = self.dav_address_lineedit.text() + '/' if self.dav_address_lineedit.text()[
-1] != '/' else self.dav_address_lineedit.text()
address = addr + "remote.php/dav/files/admin/"
else:
address = self.dav_address_lineedit.text()
name, password = self.dav_name_lineedit.text(), self.dav_password_lineedit.text()
else:
if self.dav_address_lineedit.text():
address, name, password = self.dav_address_lineedit.text(), self.dav_name_lineedit.text(), self.dav_password_lineedit.text()
else:
address, name, password = 'https://dav.jianguoyun.com/dav/', self.dav_name_lineedit.text(), self.dav_password_lineedit.text()
pass pass
sync = Sync()
status = sync.test_link(address, name, password)
if status == 200:
TipUi.show_tip('连接成功!')
elif status == 500:
TipUi.show_tip('连接失败!')
# print(status)
def save_link(self): def save_link(self):
login = CreateConfigure()
login_type = ['NextCloud', 'JianGuoYun', 'WebDav']
login.login(login_type[self.combo.currentIndex()], self.dav_name_lineedit.text(),
self.dav_password_lineedit.text(), self.dav_address_lineedit.text())
self.login_signal.emit()
self.close() self.close()
pass pass

View file

@ -1,4 +1,6 @@
import os import os
import time
from PyQt5.QtGui import * from PyQt5.QtGui import *
from PyQt5.QtWidgets import * from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt, pyqtSignal from PyQt5.QtCore import Qt, pyqtSignal
@ -149,7 +151,8 @@ class MyDay(QWidget):
def load_myday(self, name, uid): def load_myday(self, name, uid):
todo_item = ToDoItem(name, uid) todo_item = ToDoItem(name, uid)
todo_item.mark_icon.clicked.connect(lambda: self.mark_done(uid))
todo_item.important_button.clicked.connect(lambda: self.mark_important(uid))
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)
@ -161,6 +164,7 @@ class MyDay(QWidget):
self.setStyleSheet('#my_day{background-image:url("../images/' + count + '.jpg");' self.setStyleSheet('#my_day{background-image:url("../images/' + count + '.jpg");'
'background-position: center; border-radius: 10px;' 'background-position: center; border-radius: 10px;'
'}') '}')
# 回车添加事件 # 回车添加事件
def line_edit_add(self, name): def line_edit_add(self, name):
if name: if name:
@ -213,11 +217,6 @@ class MyDay(QWidget):
elif make_type == 'Important': elif make_type == 'Important':
change_value(uid, 'isImportant', True) change_value(uid, 'isImportant', True)
self.refresh_action() self.refresh_action()
#
# load_todo = load_myday_important('MyDay')
# uid = load_todo[self.todo_list.currentRow()][1]
self.update_signal.emit() self.update_signal.emit()
# 删除分组 # 删除分组
@ -260,3 +259,18 @@ class MyDay(QWidget):
self.refresh_action() self.refresh_action()
self.update_signal.emit() self.update_signal.emit()
self.dialog.close() self.dialog.close()
def mark_done(self, uid):
# print('mark done:', uid)
# self.todo_list.mark_icon.setIcon(QIcon(os.getcwd() + '/../images/finished.svg'))
change_value(uid, 'done', True)
# time.sleep(0.5)
self.todo_list.takeItem(self.todo_list.currentRow())
self.refresh_action()
self.update_signal.emit()
def mark_important(self, uid):
change_value(uid, 'isImportant', True)
# print('mark important:', uid)
self.refresh_action()
self.update_signal.emit()

View file

@ -1,4 +1,4 @@
from PyQt5.QtCore import Qt, pyqtSignal from PyQt5.QtCore import Qt, pyqtSignal, QRect
from PyQt5.QtGui import * from PyQt5.QtGui import *
from PyQt5.QtWidgets import * from PyQt5.QtWidgets import *
@ -11,12 +11,16 @@ class SettingWidget(QWidget):
def __init__(self): def __init__(self):
super(SettingWidget, self).__init__() super(SettingWidget, self).__init__()
self.setWindowTitle('设置') self.setWindowTitle('设置')
self.resize(400, 300) # self.resize(400, 300)
layout = QFormLayout() layout = QFormLayout()
self.setLayout(layout) self.setLayout(layout)
self.combo = QComboBox() self.combo = QComboBox()
exit_status = read_ini('System', 'exitstatus') exit_status = read_ini('System', 'exitstatus')
# 设置气泡在屏幕上的位置水平居中垂直屏幕80%位置
desktop = QApplication.desktop()
self.setGeometry(QRect(int(desktop.width() / 2 - 75), int(desktop.height() * 0.5), 400, 300))
self.combo.addItem('最小化到托盘') self.combo.addItem('最小化到托盘')
self.combo.addItem('退出程序') self.combo.addItem('退出程序')
index = 0 index = 0
@ -31,5 +35,6 @@ class SettingWidget(QWidget):
def save_exit_status(self, index): def save_exit_status(self, index):
print(index) print(index)
status = ['Mix', 'Exit'] status = ['Min', 'Exit']
set_exit_status(status[index]) set_exit_status(status[index])
self.update_signal.emit()

66
view/Tip_UI.py Normal file
View file

@ -0,0 +1,66 @@
from view.UI_Tips import Ui_Dialog
from PyQt5.QtWidgets import QApplication, QDialog
from PyQt5.QtCore import Qt, QTimer, QRect
import sys
# 创建静态变量的装饰器,参考 https://www.jianshu.com/p/3ed1037b7c18
def static_vars(**kwargs):
def decorate(func):
for k in kwargs:
setattr(func, k, kwargs[k])
return func
return decorate
class TipUi(QDialog):
def __init__(self, text: str, parent=None):
# 设置ui
super().__init__(parent)
self.ui = Ui_Dialog()
self.ui.setupUi(self)
# 设置定时器,用于动态调节窗口透明度
self.timer = QTimer()
# 设置气泡在屏幕上的位置水平居中垂直屏幕80%位置
desktop = QApplication.desktop()
self.setGeometry(QRect(int(desktop.width() / 2 - 75), int(desktop.height() * 0.8), 152, 50))
# 显示的文本
self.ui.pushButton.setText(text)
# 设置隐藏标题栏、无边框、隐藏任务栏图标、始终置顶
self.setWindowFlags(Qt.CustomizeWindowHint | Qt.FramelessWindowHint | Qt.Tool | Qt.WindowStaysOnTopHint)
# 设置窗口透明背景
self.setAttribute(Qt.WA_TranslucentBackground, True)
# 窗口关闭自动退出,一定要加,否则无法退出
self.setAttribute(Qt.WA_QuitOnClose, True)
# 用来计数的参数
self.windosAlpha = 0
# 设置定时器25ms1600ms记64个数
self.timer.timeout.connect(self.hide_windows)
self.timer.start(25)
# 槽函数
def hide_windows(self):
self.timer.start(25)
# 前750ms设置透明度不变后850ms透明度线性变化
if self.windosAlpha <= 30:
self.setWindowOpacity(1.0)
else:
self.setWindowOpacity(1.882 - 0.0294 * self.windosAlpha)
self.windosAlpha += 1
# 差不多3秒自动退出
if self.windosAlpha >= 63:
self.close()
# 静态方法创建气泡提示
# @staticmethod
@static_vars(tip=None)
def show_tip(text):
TipUi.show_tip.tip = TipUi(text)
TipUi.show_tip.tip.show()
#
# if __name__ == '__main__':
# app = QApplication(sys.argv)
# TipUi.show_tip('连接成功!')
# sys.exit(app.exec_())

View file

@ -42,28 +42,3 @@ class ToDoItem(QListWidgetItem):
layout.addWidget(self.todo_label, 6) layout.addWidget(self.todo_label, 6)
layout.addWidget(self.important_button, 2) layout.addWidget(self.important_button, 2)
# self.mark_icon.clicked.connect(lambda: self.set_done(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, uid):
# # self.mark_icon.setIcon(QIcon(os.getcwd() + '/../images/finished.svg'))
# # time.sleep(0.2)
# change_value(uid, 'done', True)
# pass
# def set_myday(self, uid):
# change_value(uid, 'done', True)
# pass
#
# def set_important(self, uid):
# # important = Important()
# # important.load_important.emit()
# # self.action.emit()
# print('<ToDoItem>', uid)
#
# change_value(uid, 'isImportant', True)
# # self.transaction.emit()
# pass

View file

@ -73,8 +73,7 @@ class ToDoList(QWidget):
# self.menu_image.setScaledContents(True) # self.menu_image.setScaledContents(True)
pic_btn = QPixmap(os.getcwd() + "/../images/menu.png") pic_btn = QPixmap(os.getcwd() + "/../images/menu.png")
self.menu_image.setIcon(QIcon(pic_btn)) self.menu_image.setIcon(QIcon(pic_btn))
# self.menu_image.setFixedSize(QPixmap(os.getcwd() + "/../images/menu.png").size())
# head_layout.addLayout(head_left_layout)
head_layout.addWidget(self.menu_image, 2) head_layout.addWidget(self.menu_image, 2)
head_layout.addStretch(1) head_layout.addStretch(1)
@ -190,6 +189,7 @@ class ToDoList(QWidget):
self.add_todo.line_edit.clear() self.add_todo.line_edit.clear()
self.refresh_action() self.refresh_action()
self.update_signal.emit()
# self.initUI() # self.initUI()
def todo_list_context(self, position): def todo_list_context(self, position):
@ -277,14 +277,15 @@ class ToDoList(QWidget):
def mark_done(self, uid): def mark_done(self, uid):
# print('uid:',uid) # print('uid:',uid)
self.todo_item.mark_icon.setIcon(QIcon(os.getcwd() + '/../images/finished.svg')) self.todo_item.mark_icon.setIcon(QIcon(os.getcwd() + '/../images/finished.svg'))
print('mark done:', uid) # print('mark done:', uid)
change_value(uid, 'done', True)
time.sleep(0.2) time.sleep(0.5)
self.todo_list.takeItem(self.todo_list.currentRow()) self.todo_list.takeItem(self.todo_list.currentRow())
# self.refresh_action() # self.refresh_action()
self.update_signal.emit() self.update_signal.emit()
self.refresh_action() self.refresh_action()
def mark_important(self, uid): def mark_important(self, uid):
change_value(uid, 'isImportant', True)
self.update_signal.emit() self.update_signal.emit()
pass pass

39
view/UI_Tips.py Normal file
View file

@ -0,0 +1,39 @@
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(150, 54)
Dialog.setStyleSheet("background: transparent;")
self.pushButton = QtWidgets.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(0, 0, 151, 51))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton.sizePolicy().hasHeightForWidth())
self.pushButton.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setFamily("MiSans Regular")
font.setPointSize(10)
font.setBold(True)
font.setWeight(75)
self.pushButton.setFont(font)
self.pushButton.setFocusPolicy(QtCore.Qt.NoFocus)
self.pushButton.setContextMenuPolicy(QtCore.Qt.NoContextMenu)
self.pushButton.setAutoFillBackground(False)
# 在这里设置气泡的stylesheet
self.pushButton.setStyleSheet("background-color:rgb(255,200,150);\n"
"border-style:none;\n"
"padding:8px;\n"
"border-radius:25px;")
self.pushButton.setObjectName("pushButton")
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.pushButton.setText(_translate("Dialog", "提示框"))

View file

@ -7,15 +7,13 @@ from utils.CreateConfigure import CreateConfigure
from utils.Sync import Sync from utils.Sync import Sync
from view.LoginWidget import LoginWidget from view.LoginWidget import LoginWidget
from view.SettingWidget import SettingWidget from view.SettingWidget import SettingWidget
from view.Tip_UI import TipUi
class User(QLabel): class User(QLabel):
update_signal = pyqtSignal() update_signal = pyqtSignal()
sync_signal = pyqtSignal() sync_signal = pyqtSignal()
# 自定义信号, 注意信号必须为类属性
# button_clicked_signal = pyqtSignal()
def __init__(self): def __init__(self):
super(User, self).__init__() super(User, self).__init__()
self.widget = QWidget(self) self.widget = QWidget(self)
@ -51,7 +49,7 @@ class User(QLabel):
self.context_menu.clear() self.context_menu.clear()
# 读取文件内容 # 读取文件内容
account = read_init_file() account = read_init_file()
if account[0] != 'None': if account and account[0] != 'None':
self.user_name.setText(account[1]) self.user_name.setText(account[1])
self.user_mail.setText(account[3]) self.user_mail.setText(account[3])
else: else:
@ -68,7 +66,7 @@ class User(QLabel):
self.context_menu.addAction(QIcon(os.getcwd() + '/../images/setting.svg'), '设置', self.setting) self.context_menu.addAction(QIcon(os.getcwd() + '/../images/setting.svg'), '设置', self.setting)
self.context_menu.addAction(QIcon(os.getcwd() + '/../images/sync.svg'), '同步', self.sync) self.context_menu.addAction(QIcon(os.getcwd() + '/../images/sync.svg'), '同步', self.sync)
if account[0] != 'None': if account and account[0] != 'None':
self.context_menu.addAction(QIcon(os.getcwd() + '/../images/exit.svg'), '登出', self.exit_account) self.context_menu.addAction(QIcon(os.getcwd() + '/../images/exit.svg'), '登出', self.exit_account)
else: else:
self.context_menu.addAction(QIcon(os.getcwd() + '/../images/login.svg'), '登录', self.login_account) self.context_menu.addAction(QIcon(os.getcwd() + '/../images/login.svg'), '登录', self.login_account)
@ -83,13 +81,20 @@ class User(QLabel):
self.setting_widget.show() self.setting_widget.show()
def sync(self): def sync(self):
account = read_init_file()
if account and account[0] != 'None':
sync = Sync() sync = Sync()
sync.start()
sync.sync_signal.connect(self.sync_status)
sync.sync_signal.connect(self.sync_status) sync.sync_signal.connect(self.sync_status)
sync.run()
self.sync_signal.emit() self.sync_signal.emit()
else:
self.login_account()
pass pass
def sync_status(self): def sync_status(self):
TipUi.show_tip('同步成功!')
print('Success!') print('Success!')
def exit_account(self): def exit_account(self):
@ -106,6 +111,6 @@ class User(QLabel):
pass pass
def login_account(self): def login_account(self):
self.login_window = LoginWidget() self.login_window = LoginWidget()
self.login_window.login_signal.connect(self.iniUI)
self.login_window.show() self.login_window.show()