diff --git a/main/main.py b/main/main.py index 815ba66..32c2041 100644 --- a/main/main.py +++ b/main/main.py @@ -2,9 +2,7 @@ import os import sys from PyQt5.QtGui import * from PyQt5.QtWidgets import * -from PyQt5.QtCore import Qt, pyqtSignal -import configparser - +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 @@ -67,12 +65,14 @@ class MainWidget(QWidget): 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() # 系统默认的两个 item 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.system_listWidget.addItem(self.one_day) @@ -85,6 +85,7 @@ class MainWidget(QWidget): # 加载列表 load_list = get_todo_list() # print(load_list) + # todo:bug 第一个为空会导致无法添加 if load_list: for load in load_list: 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(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(self.important.refresh_action) + # self.my_day.update_signal.connect(self.important.refresh_action) self.update_signal.connect(todo_list.refresh_action) # 创建后就可以编辑item,用户自己起名字. @@ -288,8 +289,12 @@ class MainWindow(QWidget): 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.isChecked() + self.save_config.setChecked(True) quitMsgBox.setCheckBox(self.save_config) # self.save_config.stateChanged.connect(self.save_exit) quitMsgBox.resize(300, 200) @@ -302,27 +307,7 @@ class MainWindow(QWidget): buttonN = QPushButton('最小化到托盘') # 将两个按钮加到这个消息盒子中去,并指定yes和no的功能 - style = """ - /*设置堆栈按钮样式*/ - 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; - } - """ + style = QSSLoader.read_qss_file(os.getcwd() + '/../resource/closeDialog.qss') buttonY.setStyleSheet(style) buttonN.setStyleSheet(style) diff --git a/resource/closeDialog.qss b/resource/closeDialog.qss new file mode 100644 index 0000000..9ad8c61 --- /dev/null +++ b/resource/closeDialog.qss @@ -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; +} \ No newline at end of file diff --git a/resource/login.qss b/resource/login.qss new file mode 100644 index 0000000..89076d9 --- /dev/null +++ b/resource/login.qss @@ -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; +} \ No newline at end of file diff --git a/utils/BasicUtils.py b/utils/BasicUtils.py index db06733..660da9d 100644 --- a/utils/BasicUtils.py +++ b/utils/BasicUtils.py @@ -55,9 +55,13 @@ def change_myday_important_conf(change_type, key, value): def get_myday_important_conf(get_type, key): config = configparser.ConfigParser() config_path = return_work_dir() - todo_file = config_path + 'PyQtToDoList.conf' - config.read(todo_file) - return config[get_type][key] + try: + todo_file = config_path + 'PyQtToDoList.conf' + config.read(todo_file) + return config[get_type][key] + except KeyError as e: + print('File Not Found!') + return False def get_todo_list(): @@ -146,9 +150,6 @@ def change_value(uid, key, value): config_path = return_work_dir() 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 = {} current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') @@ -219,6 +220,25 @@ def set_exit_status(status): 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()) # webdav_hostname = read_init_file() # print(webdav_hostname[2]) @@ -229,3 +249,4 @@ def set_exit_status(status): # print(get_myday_important_conf('Important','Theme')) # print(read_ini('System', 'exitstatus')) # print(set_exit_status('Min')) +# print(check_login_status()) diff --git a/utils/CreateConfigure.py b/utils/CreateConfigure.py index 3f4fb16..586bde1 100644 --- a/utils/CreateConfigure.py +++ b/utils/CreateConfigure.py @@ -59,8 +59,8 @@ class CreateConfigure: config['Account']['webdav_password'] = webdav_password config['Account']['type'] = login_type - config['System'] = {'exitStatus': 'None'} - print(config['System']['exitStatus']) + # config['System'] = {'exitStatus': 'None'} + # print(config['System']['exitStatus']) with open(config_file, 'w') as f: config.write(f) diff --git a/utils/Sync.py b/utils/Sync.py index a268ca6..a698835 100644 --- a/utils/Sync.py +++ b/utils/Sync.py @@ -1,87 +1,75 @@ import os -import platform - -from webdav3.exceptions import LocalResourceNotFound -from webdav3.client import Client +from webdav4.fsspec import WebdavFileSystem import configparser 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 webdav4.client import HTTPError, Client -# todo : 暂时只有手动同步,没有做自动同步,暂时不需要传递参数 class Sync(QThread): sync_signal = pyqtSignal() def __init__(self): super(Sync, self).__init__() self.sync_path = return_work_dir() + self.config_info = read_init_file() def run(self): - types = ['NextCloud', 'JianGuoYun', 'WebDav'] + # types = ['NextCloud', 'JianGuoYun', 'WebDav'] # 根据不同的账号类型调用不同的方式 - config = configparser.ConfigParser() - # try: - # config.read(read_init_file()) - self.config_info = read_init_file() - # 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('', e) + # config = configparser.ConfigParser() + conf_file = self.sync_path + 'PyQtToDoList.conf' + todo_path = self.sync_path + 'ToDoList/' + if os.path.exists(conf_file) or os.path.exists(todo_path): + try: + client = WebdavFileSystem(base_url=self.config_info[0], + auth=(self.config_info[1], self.config_info[2])) + # ls = client.ls('/PyQtToDoList', detail=False) + # print(ls) + work_path_exist = client.exists('PyQtToDoList') + # 如果WebDav服务器的同步目录没有,就创建同步目录和Todo目录 + if not work_path_exist: + client.mkdir('PyQtToDoList') + client.mkdir('PyQtToDoList/ToDoList/') + # 如果有同步目录,没有Todo目录,就创建Todo目录 + remote_todo_path = client.exists('PyQtToDoList/ToDoList') + if not remote_todo_path: + client.mkdir('PyQtToDoList/ToDoList/') + # 检查本地配置文件 + if os.path.exists(conf_file): + client.upload(conf_file, 'PyQtToDoList/PyQtToDoList.conf') + if os.path.exists(todo_path): + todo_files = os.listdir(todo_path) + for file in todo_files: + client.upload(todo_path + file, 'PyQtToDoList/ToDoList/' + file) + self.sync_signal.emit() + # print(status) - def upload_file(self, options): + except Exception as e: + print('', e) + + else: + client = WebdavFileSystem(base_url=self.config_info[0], + auth=(self.config_info[1], self.config_info[2])) + work_path_exist = client.exists('PyQtToDoList/') + if work_path_exist: + if client.exists('PyQtToDoList/PyQtToDoList.conf'): + client.download('PyQtToDoList/PyQtToDoList.conf', conf_file) + if client.exists('PyQtToDoList/ToDoList'): + os.mkdir(todo_path) + todo_list = client.ls('PyQtToDoList/ToDoList') + 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): try: - client = Client(options) - - path = client.check('PyQtToDoList') - print(path) - # list1 = client.list('/') - # print('/ ', list1) - client.mkdir('PyQtToDoList/') - list1 = client.list('/') - print('/ ', list1) - client.upload_file('PyQtToDoList/' + 'PyQtToDoList.conf', self.sync_path + 'PyQtToDoList.conf') - client.upload_directory('PyQtToDoList/' + 'ToDoList/', self.sync_path + 'ToDoList/') - if not path: - client.mkdir('PyQtToDoList/PyQtToDoList.conf') - list1 = client.list('/') - print('/ ', list1) - conf_file = client.check('PyQtToDoList/PyQtToDoList.conf') - print('conf_file:', conf_file) - if not conf_file: - try: - client.push('PyQtToDoList/' + 'PyQtToDoList.conf', self.sync_path + 'PyQtToDoList.conf') - client.push('PyQtToDoList/', self.sync_path + 'ToDoList') - self.sync_signal.emit() - except LocalResourceNotFound as e: - print('An error happen: LocalResourceNotFound ---') - - except Exception as e: - print('', e) - - # config_file, upload_files, upload_dirs = - # client.upload('OpenTodoList/', config_file) - # for upload_dir in upload_dirs: - # upload_dir_name = upload_dir.split('/')[-1] - # client.mkdir('OpenTodoList/' + upload_dir_name) - # for upload_file in upload_files: - # upload_dir = upload_file.split('/')[-2] - # upload_file_name = upload_file.split('/')[-1] - # client.upload('OpenTodoList/' + upload_dir + upload_file_name, upload_file) - # client.pull('OpenTodoList', '') - # client.push('OpenTodoList', self.get_sync_path()) - - """ - 程序的配置文件和数据根据不同系统,保存在不同文件夹 - Linux在 ~/.config/PyQtToDoList下 - 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 diff --git a/view/ImportantView.py b/view/ImportantView.py index 22a697e..6c7a6c2 100644 --- a/view/ImportantView.py +++ b/view/ImportantView.py @@ -25,6 +25,8 @@ class Important(QWidget): self.setAttribute(Qt.WA_StyledBackground) background = get_myday_important_conf('Important', 'Theme') + if not background: + background = '0' 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.setItemWidget(todo_item, todo_item.widget) self.add_todo.line_edit.clear() + self.update_signal.emit() def todo_list_context(self, position): # 设置右键菜单 @@ -255,7 +258,7 @@ class Important(QWidget): self.dialog.exec_() def change_name(self, item_name): - print(item_name) + # print(item_name) my_day_list = load_myday_important('Important') 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): # print('mark done:', uid) 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.update_signal.emit() def mark_important(self, uid): - change_value(uid, 'isImportant', True) + change_value(uid, 'isImportant', False) # print('mark important:', uid) self.refresh_action() self.update_signal.emit() - diff --git a/view/LoginWidget.py b/view/LoginWidget.py index fa2f560..271c667 100644 --- a/view/LoginWidget.py +++ b/view/LoginWidget.py @@ -1,200 +1,111 @@ -from PyQt5.QtCore import Qt +from PyQt5.QtCore import Qt, pyqtSignal from PyQt5.QtGui import * from PyQt5.QtWidgets import * import configparser 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 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): +class LoginWidget(QWidget): # todo : 添加一个信号,等点击保存后在 main 里面更新未登录的信息 - """ - :param login_type 登录账号类型 - """ + login_signal = pyqtSignal() def __init__(self): super(LoginWidget, self).__init__() self.resize(500, 300) - 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;' - '}') + style_sheet = QSSLoader.read_qss_file(os.getcwd() + '/../resource/login.qss') + self.setStyleSheet(style_sheet) # layout = QVBoxLayout() self.setWindowTitle('登录') - - # host_name_layout = QHBoxLayout() - - # self.host_address = QLabel('服务器地址:') - # 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.combo = QComboBox() + self.combo.addItems(['NextCloud', '坚果云', 'WebDav']) + self.layout = QFormLayout() + self.setLayout(self.layout) self.dav_address_lineedit = QLineEdit() 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.setPlaceholderText('用户名') 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.setEchoMode(QLineEdit.Password) self.dav_password_lineedit.setPlaceholderText('密码') 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.setObjectName('login_button') self.link = QPushButton('保存配置') 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.setLayout(layout) - # self.show() + self.layout.addRow(self.combo) + + 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.link.clicked.connect(self.close) - self.nextcloud_tab = QWidget() - self.jianguoyun_tab = QWidget() - self.webdav_tab = QWidget() + self.link.clicked.connect(self.save_link) - self.addTab(self.nextcloud_tab, 'NextCloud') - self.addTab(self.jianguoyun_tab, '坚果云') - self.addTab(self.webdav_tab, 'WebDav') + def iniUI(self): + # print(self.combo.currentIndex()) - self.initUI1() - self.initUI2() - self.initUI3() + if self.combo.currentIndex() == 0: + self.dav_address_lineedit.setPlaceholderText('https://nextcloud.example.com') - # 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): - form_layout = QFormLayout() - form_layout.addRow('服务器地址:', self.nextcloud_address_lineedit) - 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) + elif self.combo.currentIndex() == 2: + # self.layout.addRow('服务器地址:', self.dav_address_lineedit) + self.dav_address_lineedit.setPlaceholderText('https://dav.example.com/dav') def link_test(self): - pass + 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 + 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): + 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() pass diff --git a/view/MyDayView.py b/view/MyDayView.py index 12beb51..dbcd195 100644 --- a/view/MyDayView.py +++ b/view/MyDayView.py @@ -1,4 +1,6 @@ import os +import time + from PyQt5.QtGui import * from PyQt5.QtWidgets import * from PyQt5.QtCore import Qt, pyqtSignal @@ -149,7 +151,8 @@ class MyDay(QWidget): def load_myday(self, 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.setItemWidget(todo_item, todo_item.widget) @@ -161,6 +164,7 @@ class MyDay(QWidget): self.setStyleSheet('#my_day{background-image:url("../images/' + count + '.jpg");' 'background-position: center; border-radius: 10px;' '}') + # 回车添加事件 def line_edit_add(self, name): if name: @@ -213,11 +217,6 @@ class MyDay(QWidget): elif make_type == 'Important': change_value(uid, 'isImportant', True) self.refresh_action() - - # - # load_todo = load_myday_important('MyDay') - # uid = load_todo[self.todo_list.currentRow()][1] - self.update_signal.emit() # 删除分组 @@ -260,3 +259,18 @@ class MyDay(QWidget): self.refresh_action() self.update_signal.emit() 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() diff --git a/view/SettingWidget.py b/view/SettingWidget.py index 1697bc5..9561d28 100644 --- a/view/SettingWidget.py +++ b/view/SettingWidget.py @@ -1,4 +1,4 @@ -from PyQt5.QtCore import Qt, pyqtSignal +from PyQt5.QtCore import Qt, pyqtSignal, QRect from PyQt5.QtGui import * from PyQt5.QtWidgets import * @@ -11,12 +11,16 @@ class SettingWidget(QWidget): def __init__(self): super(SettingWidget, self).__init__() self.setWindowTitle('设置') - self.resize(400, 300) + # self.resize(400, 300) layout = QFormLayout() self.setLayout(layout) self.combo = QComboBox() 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('退出程序') index = 0 @@ -31,5 +35,6 @@ class SettingWidget(QWidget): def save_exit_status(self, index): print(index) - status = ['Mix', 'Exit'] + status = ['Min', 'Exit'] set_exit_status(status[index]) + self.update_signal.emit() diff --git a/view/Tip_UI.py b/view/Tip_UI.py new file mode 100644 index 0000000..7666258 --- /dev/null +++ b/view/Tip_UI.py @@ -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 + # 设置定时器25ms,1600ms记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_()) diff --git a/view/ToDoItem.py b/view/ToDoItem.py index 15fe1a1..ed02006 100644 --- a/view/ToDoItem.py +++ b/view/ToDoItem.py @@ -42,28 +42,3 @@ class ToDoItem(QListWidgetItem): layout.addWidget(self.todo_label, 6) layout.addWidget(self.important_button, 2) - # self.mark_icon.clicked.connect(lambda: self.set_done(uid)) - # # print('', 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('', uid) - # - # change_value(uid, 'isImportant', True) - # # self.transaction.emit() - # pass diff --git a/view/ToDoListView.py b/view/ToDoListView.py index 0e972a5..d554c99 100644 --- a/view/ToDoListView.py +++ b/view/ToDoListView.py @@ -73,8 +73,7 @@ class ToDoList(QWidget): # self.menu_image.setScaledContents(True) pic_btn = QPixmap(os.getcwd() + "/../images/menu.png") 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.addStretch(1) @@ -190,6 +189,7 @@ class ToDoList(QWidget): self.add_todo.line_edit.clear() self.refresh_action() + self.update_signal.emit() # self.initUI() def todo_list_context(self, position): @@ -277,14 +277,15 @@ class ToDoList(QWidget): def mark_done(self, uid): # print('uid:',uid) self.todo_item.mark_icon.setIcon(QIcon(os.getcwd() + '/../images/finished.svg')) - print('mark done:', uid) - - time.sleep(0.2) + # print('mark done:', uid) + change_value(uid, 'done', True) + time.sleep(0.5) self.todo_list.takeItem(self.todo_list.currentRow()) # self.refresh_action() self.update_signal.emit() self.refresh_action() def mark_important(self, uid): + change_value(uid, 'isImportant', True) self.update_signal.emit() pass diff --git a/view/UI_Tips.py b/view/UI_Tips.py new file mode 100644 index 0000000..b77f0f5 --- /dev/null +++ b/view/UI_Tips.py @@ -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", "提示框")) + + diff --git a/view/UserLabel.py b/view/UserLabel.py index 4ef39f1..778802d 100644 --- a/view/UserLabel.py +++ b/view/UserLabel.py @@ -7,15 +7,13 @@ from utils.CreateConfigure import CreateConfigure from utils.Sync import Sync from view.LoginWidget import LoginWidget from view.SettingWidget import SettingWidget +from view.Tip_UI import TipUi class User(QLabel): update_signal = pyqtSignal() sync_signal = pyqtSignal() - # 自定义信号, 注意信号必须为类属性 - # button_clicked_signal = pyqtSignal() - def __init__(self): super(User, self).__init__() self.widget = QWidget(self) @@ -51,7 +49,7 @@ class User(QLabel): self.context_menu.clear() # 读取文件内容 account = read_init_file() - if account[0] != 'None': + if account and account[0] != 'None': self.user_name.setText(account[1]) self.user_mail.setText(account[3]) 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/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) else: self.context_menu.addAction(QIcon(os.getcwd() + '/../images/login.svg'), '登录', self.login_account) @@ -83,13 +81,20 @@ class User(QLabel): self.setting_widget.show() def sync(self): - sync = Sync() - sync.sync_signal.connect(self.sync_status) - sync.run() - self.sync_signal.emit() + account = read_init_file() + if account and account[0] != 'None': + sync = Sync() + sync.start() + sync.sync_signal.connect(self.sync_status) + + sync.sync_signal.connect(self.sync_status) + self.sync_signal.emit() + else: + self.login_account() pass def sync_status(self): + TipUi.show_tip('同步成功!') print('Success!') def exit_account(self): @@ -106,6 +111,6 @@ class User(QLabel): pass def login_account(self): - self.login_window = LoginWidget() + self.login_window.login_signal.connect(self.iniUI) self.login_window.show()