130 lines
4.5 KiB
Python
130 lines
4.5 KiB
Python
import os
|
|
import sys
|
|
|
|
from PyQt5.QtCore import Qt
|
|
from PyQt5.QtGui import *
|
|
from PyQt5.QtWidgets import *
|
|
import configparser
|
|
from utils.BasicUtils import *
|
|
from view.LoginWidget import LoginWidget
|
|
|
|
|
|
# class LoginWindow(QWidget):
|
|
# def __init__(self):
|
|
# super().__init__()
|
|
# layout = QVBoxLayout()
|
|
# self.setLayout(layout)
|
|
# self.setWindowTitle('登录')
|
|
# self.resize(500, 600)
|
|
# self.tab_widget = QTabWidget()
|
|
# self.tab_widget.setStyleSheet('background-color:#f3f3f3')
|
|
# self.tab_widget.addTab(LoginWidget('NextCloud'), 'NextCloud')
|
|
# self.tab_widget.addTab(LoginWidget('JianGuoYun'), '坚果云')
|
|
# self.tab_widget.addTab(LoginWidget('WebDav'), 'WebDav')
|
|
#
|
|
# # print('open new window')
|
|
# # self.stack_widget = QStackedWidget()
|
|
# # self.show()
|
|
# layout.addWidget(self.tab_widget)
|
|
|
|
|
|
class User(QLabel):
|
|
# 自定义信号, 注意信号必须为类属性
|
|
# button_clicked_signal = pyqtSignal()
|
|
|
|
def __init__(self):
|
|
super(User, self).__init__()
|
|
self.widget = QWidget(self)
|
|
self.widget.setMaximumWidth(300)
|
|
self.setObjectName('User')
|
|
# todo:修改布局使适合微软todo的样式,设置点击事件,使用右键菜单的样式添加设置、同步、退出,暂时就这样
|
|
|
|
layout = QHBoxLayout()
|
|
info_layout = QVBoxLayout()
|
|
self.pic_label = QLabel('')
|
|
self.pic_label.setObjectName('pic_label')
|
|
self.pic_label.setPixmap(
|
|
QPixmap(os.path.abspath('../') + '/images/user.svg').scaled(50, 50, Qt.IgnoreAspectRatio,
|
|
Qt.SmoothTransformation))
|
|
layout.addWidget(self.pic_label, 2)
|
|
self.user_name = QLabel("本地账号")
|
|
self.user_name.setObjectName('user_name')
|
|
self.user_mail = QLabel('未同步')
|
|
|
|
# 读取文件内容
|
|
self.account = read_init_file()
|
|
if self.account:
|
|
self.user_name.setText(self.account[1])
|
|
self.user_mail.setText(self.account[3])
|
|
# self.user_mail.setObjectName('user_mail')
|
|
self.user_mail.setStyleSheet('font-size:14px')
|
|
# self.menu_label = QLabel('')type
|
|
# self.menu_label.setObjectName('menu')
|
|
# self.menu_label.setPixmap(
|
|
# QPixmap(os.path.abspath('../') + '/images/up-down.svg').scaled(20, 20, Qt.IgnoreAspectRatio,
|
|
# Qt.SmoothTransformation))
|
|
|
|
info_layout.addWidget(self.user_name)
|
|
info_layout.addWidget(self.user_mail)
|
|
layout.addLayout(info_layout, 4)
|
|
layout.addStretch(1)
|
|
# layout.addWidget(self.menu_label, 1)
|
|
|
|
self.widget.setLayout(layout)
|
|
# 设置右键菜单
|
|
self.context_menu = QMenu(self)
|
|
self.init_menu()
|
|
|
|
# def mouseReleaseEvent(self, QMouseEvent):
|
|
# self.button_clicked_signal.emit()
|
|
#
|
|
|
|
# 可在外部与槽函数连接 用处不大
|
|
# def connect_customized_slot(self, func):
|
|
# self.button_clicked_signal.connect(func)
|
|
|
|
def contextMenuEvent(self, event):
|
|
self.context_menu.exec_(event.globalPos())
|
|
|
|
def init_menu(self):
|
|
# 背景透明
|
|
self.context_menu.setAttribute(Qt.WA_TranslucentBackground)
|
|
# 无边框、去掉自带阴影
|
|
self.context_menu.setWindowFlags(
|
|
self.context_menu.windowFlags() | Qt.FramelessWindowHint | Qt.NoDropShadowWindowHint)
|
|
|
|
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 self.account:
|
|
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)
|
|
|
|
# todo 设置右键点击事件
|
|
|
|
def setting(self):
|
|
pass
|
|
|
|
def sync(self):
|
|
pass
|
|
|
|
def exit_account(self):
|
|
pass
|
|
|
|
def login_account(self):
|
|
|
|
self.login_window = LoginWidget()
|
|
self.login_window.show()
|
|
|
|
# if __name__ == '__main__':
|
|
# app = QApplication(sys.argv)
|
|
# # 创建窗口
|
|
# window = User()
|
|
# # newWin = LoginWindow()
|
|
#
|
|
# # 显示窗口
|
|
# window.show()
|
|
# # window.collec_btn.clicked.connect(newWin.show)
|
|
# # 运行应用,并监听事件
|
|
# sys.exit(app.exec_())
|