Lv100版本源码上传
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
from PublicReference.view.Page import Page
|
||||
|
||||
from PyQt5.QtCore import *
|
||||
from PyQt5.QtWidgets import *
|
||||
from PyQt5.QtGui import *
|
||||
from ..utils.constant import 标题背景, 标题字体
|
||||
|
||||
# title bar
|
||||
TITLE_BAR_HEIGHT = 25
|
||||
TITLE_BUTTON_SIZE = 25
|
||||
TITLE_LABEL_SIZE = 25
|
||||
TITLE_BUTTON_WIDTH = 25
|
||||
TITLE_BUTTON_HEIGHT = 25
|
||||
TITLE_ICON_MAG = 10
|
||||
|
||||
RES_PATH = './ResourceFiles/img/UI/'
|
||||
|
||||
TITLE_MIN_ICON = RES_PATH + "min.png"
|
||||
TITLE_CLS_ICON = RES_PATH + "exit.png"
|
||||
|
||||
WINDOW_DEFAULT_WIDTH = 800
|
||||
WINDOW_DEFAULT_HEIGHT = 480
|
||||
|
||||
|
||||
class Dialog(QMainWindow):
|
||||
def __init__(self, client: Page):
|
||||
super().__init__()
|
||||
|
||||
self.hideOnClose = False
|
||||
|
||||
icon = client.windowIcon()
|
||||
|
||||
titleBar = self.createTitleBar()
|
||||
|
||||
titleBar.setTitle(client.windowTitle())
|
||||
titleBar.setWidth(client.width())
|
||||
|
||||
titleBar.setIcon(icon.pixmap(icon.actualSize(QSize(32, 32))))
|
||||
|
||||
lay = QVBoxLayout()
|
||||
lay.addWidget(titleBar)
|
||||
lay.addWidget(client)
|
||||
lay.setStretch(1, 100)
|
||||
lay.setSpacing(0)
|
||||
lay.setContentsMargins(0, 0, 0, 0)
|
||||
|
||||
center = QWidget(self)
|
||||
center.setLayout(lay)
|
||||
|
||||
self.setCentralWidget(center)
|
||||
self.setWindowTitle(client.windowTitle())
|
||||
self.setWindowIcon(icon)
|
||||
self.setWindowFlags(Qt.FramelessWindowHint)
|
||||
|
||||
def createTitleBar(self):
|
||||
titleBar = QWidget()
|
||||
titleBar.setStyleSheet('''QWidget{background:transparent}''')
|
||||
label = QLabel(titleBar)
|
||||
label.setStyleSheet(标题背景)
|
||||
iconLabel = QLabel(titleBar)
|
||||
titleLabel = QLabel(titleBar)
|
||||
iconLabel.setText('纸飞机计算器')
|
||||
# self.titleLabel.setStyleSheet('''QLabel{color:#9f8d5c}''')
|
||||
|
||||
minButton = QPushButton(titleBar)
|
||||
# restoreButton = QPushButton(self)
|
||||
closeButton = QPushButton(titleBar)
|
||||
|
||||
minButton.setFixedSize(TITLE_BUTTON_SIZE, TITLE_BUTTON_SIZE)
|
||||
# self.restoreButton.setFixedSize(TITLE_BUTTON_SIZE, TITLE_BUTTON_SIZE);
|
||||
closeButton.setFixedSize(TITLE_BUTTON_SIZE, TITLE_BUTTON_SIZE)
|
||||
|
||||
iconLabel.setFixedSize(TITLE_LABEL_SIZE, TITLE_LABEL_SIZE)
|
||||
iconLabel.setStyleSheet(标题字体)
|
||||
|
||||
titleLabel.setFixedHeight(TITLE_LABEL_SIZE)
|
||||
titleLabel.setStyleSheet(标题字体)
|
||||
|
||||
iconLabel.setAlignment(Qt.AlignCenter)
|
||||
titleLabel.setAlignment(Qt.AlignCenter)
|
||||
|
||||
minButton.setIcon(QIcon(TITLE_MIN_ICON))
|
||||
closeButton.setIcon(QIcon(TITLE_CLS_ICON))
|
||||
|
||||
minButton.clicked.connect(self.showMinimized)
|
||||
# self.restoreButton.clicked.connect(self.ShowRestoreWindow)
|
||||
closeButton.clicked.connect(self.close)
|
||||
|
||||
lay = QHBoxLayout(titleBar)
|
||||
|
||||
lay.setSpacing(0)
|
||||
lay.setContentsMargins(0, 0, 0, 0)
|
||||
|
||||
lay.addWidget(iconLabel)
|
||||
lay.addWidget(titleLabel)
|
||||
lay.addWidget(minButton)
|
||||
# self.lay.addWidget(self.restoreButton)
|
||||
lay.addWidget(closeButton)
|
||||
|
||||
titleBar.setLayout(lay)
|
||||
|
||||
def setTitle(text):
|
||||
titleLabel.setText(text)
|
||||
|
||||
def setTitleStyle(style):
|
||||
titleLabel.setStyleSheet(style)
|
||||
|
||||
def setIcon(icon):
|
||||
iconLabel.setPixmap(
|
||||
icon.scaled(iconLabel.size() -
|
||||
QSize(TITLE_ICON_MAG, TITLE_ICON_MAG)))
|
||||
|
||||
def setWidth(width):
|
||||
label.resize(width, TITLE_BAR_HEIGHT)
|
||||
|
||||
titleBar.setTitle = setTitle
|
||||
titleBar.setTitleStyle = setTitleStyle
|
||||
titleBar.setIcon = setIcon
|
||||
titleBar.setWidth = setWidth
|
||||
|
||||
return titleBar
|
||||
|
||||
def setHideOnClose(self, hideOnClose):
|
||||
self.hideOnClose = hideOnClose
|
||||
|
||||
def showEvent(self, event):
|
||||
parent = self.parent()
|
||||
if parent is not None:
|
||||
rect = parent.geometry()
|
||||
x = rect.x() + rect.width() / 2 - self.width() / 2
|
||||
y = rect.y() + rect.height() / 2 - self.height() / 2
|
||||
self.move(int(x), int(y))
|
||||
return super().showEvent(event)
|
||||
|
||||
def closeEvent(self, event):
|
||||
if (self.hideOnClose):
|
||||
self.hide()
|
||||
return
|
||||
return super().closeEvent(event)
|
||||
@@ -0,0 +1,36 @@
|
||||
from .Page import Page
|
||||
from .Dialog import *
|
||||
from PyQt5.QtCore import *
|
||||
|
||||
|
||||
class DialogRegister:
|
||||
def __init__(self):
|
||||
self.dialogs = {}
|
||||
|
||||
def showDialog(self, name: str, client: Page, parent=None):
|
||||
if self.dialogs.__contains__(name) == False:
|
||||
if callable(client): # 如果传入函数 可以懒加载
|
||||
client = client()
|
||||
dialog = Dialog(client)
|
||||
client.setWindow(dialog)
|
||||
dialog.setHideOnClose(True)
|
||||
dialog.setWindowModality(Qt.WindowModality.WindowModal)
|
||||
if (parent is not None):
|
||||
dialog.setParent(parent)
|
||||
self.dialogs[name] = dialog
|
||||
self.dialogs[name].show()
|
||||
|
||||
def dispose(self):
|
||||
for name in self.dialogs.keys():
|
||||
dialog: Dialog = self.dialogs[name]
|
||||
dialog.setHideOnClose(False)
|
||||
dialog.close()
|
||||
self.dialogs.clear()
|
||||
|
||||
def close(self, name: str):
|
||||
if self.dialogs.__contains__(name):
|
||||
dialog = self.dialogs[name]
|
||||
dialog.close()
|
||||
|
||||
|
||||
DefaultDialogRegister = DialogRegister()
|
||||
@@ -0,0 +1,50 @@
|
||||
import sys
|
||||
from .TitleBar import *
|
||||
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
def __init__(self, client):
|
||||
super().__init__()
|
||||
self.InitializeWindow(client)
|
||||
|
||||
def InitializeWindow(self, client):
|
||||
self.setWindowTitle(client.windowTitle())
|
||||
self.icon = client.windowIcon()
|
||||
self.setWindowIcon(self.icon)
|
||||
self.setWindowFlags(Qt.FramelessWindowHint)
|
||||
self.InitializeViews(client)
|
||||
|
||||
def InitializeViews(self, client):
|
||||
self.client = client
|
||||
self.titleBar = TitleBar(self)
|
||||
self.center = QWidget(self)
|
||||
self.setCentralWidget(self.center)
|
||||
|
||||
self.lay = QVBoxLayout()
|
||||
self.center.setLayout(self.lay)
|
||||
|
||||
self.lay.addWidget(self.titleBar)
|
||||
self.lay.addWidget(self.client)
|
||||
self.lay.setStretch(1, 100)
|
||||
self.lay.setSpacing(0)
|
||||
self.lay.setContentsMargins(0, 0, 0, 0)
|
||||
|
||||
self.titleBar.SetTitle(client.windowTitle())
|
||||
self.titleBar.SetWidth(client.width())
|
||||
|
||||
self.titleBar.SetIcon(
|
||||
self.icon.pixmap(self.icon.actualSize(QSize(32, 32))))
|
||||
|
||||
def closeEvent(self, event):
|
||||
self.client.close()
|
||||
super().close()
|
||||
|
||||
# def LoadStyleFromQss(self, f):
|
||||
# file = open(f)
|
||||
# lines = file.readlines()
|
||||
# file.close()
|
||||
# res = ''
|
||||
# for line in lines:
|
||||
# res += line
|
||||
|
||||
# return res
|
||||
@@ -0,0 +1,24 @@
|
||||
from PyQt5.QtGui import *
|
||||
from PublicReference.common import *
|
||||
|
||||
|
||||
class ConfirmButton(QPushButton):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.setEnabled(False)
|
||||
# self.setText("test")
|
||||
self.time = QTimer(self)
|
||||
self.count = 10
|
||||
self.time.setInterval(1000)
|
||||
self.time.timeout.connect(self.Refresh)
|
||||
self.time.start()
|
||||
|
||||
def Refresh(self):
|
||||
# print(self.count)
|
||||
if self.count > 0:
|
||||
self.setText("(" + str(self.count) + "s) 确认")
|
||||
self.count -= 1
|
||||
else:
|
||||
self.time.stop()
|
||||
self.setEnabled(True)
|
||||
self.setText("确认")
|
||||
@@ -0,0 +1,21 @@
|
||||
from PyQt5.QtCore import *
|
||||
from PyQt5.QtWidgets import *
|
||||
from PyQt5.QtGui import *
|
||||
|
||||
|
||||
class Page(QWidget):
|
||||
def setName(self, name):
|
||||
self.__name = name
|
||||
|
||||
def name(self):
|
||||
return self.__name
|
||||
|
||||
def setWindow(self, window: QWindow):
|
||||
self.__window = window
|
||||
|
||||
def window(self):
|
||||
return self.__window
|
||||
|
||||
def closeWindow(self):
|
||||
if self.__window is not None:
|
||||
self.__window.close()
|
||||
@@ -0,0 +1,132 @@
|
||||
import sys
|
||||
from PyQt5.QtCore import *
|
||||
from PyQt5.QtWidgets import *
|
||||
from PyQt5.QtGui import *
|
||||
from PublicReference.utils.constant import 标题背景, 标题字体
|
||||
|
||||
RES_PATH = './ResourceFiles/img/UI/'
|
||||
|
||||
# title bar
|
||||
TITLE_BAR_HEIGHT = 25
|
||||
TITLE_BUTTON_SIZE = 25
|
||||
TITLE_LABEL_SIZE = 25
|
||||
TITLE_BUTTON_WIDTH = 25
|
||||
TITLE_BUTTON_HEIGHT = 25
|
||||
TITLE_ICON_MAG = 10
|
||||
|
||||
TITLE_MIN_ICON = RES_PATH + "min.png"
|
||||
TITLE_CLS_ICON = RES_PATH + "exit.png"
|
||||
|
||||
WINDOW_DEFAULT_WIDTH = 800
|
||||
WINDOW_DEFAULT_HEIGHT = 480
|
||||
|
||||
|
||||
class TitleBar(QWidget):
|
||||
def __init__(self, parent):
|
||||
super(TitleBar, self).__init__()
|
||||
self.win = parent
|
||||
self.InitializeWindow()
|
||||
|
||||
def InitializeWindow(self):
|
||||
self.isPressed = False
|
||||
self.setFixedHeight(TITLE_BAR_HEIGHT)
|
||||
self.InitializeViews()
|
||||
pass
|
||||
|
||||
def InitializeViews(self):
|
||||
|
||||
self.setStyleSheet('''QWidget{background:transparent}''')
|
||||
self.label = QLabel(self)
|
||||
self.label.setStyleSheet(标题背景)
|
||||
self.iconLabel = QLabel(self)
|
||||
self.titleLabel = QLabel(self)
|
||||
self.iconLabel.setText('纸飞机计算器')
|
||||
# self.titleLabel.setStyleSheet('''QLabel{color:#9f8d5c}''')
|
||||
|
||||
self.minButton = QPushButton(self)
|
||||
self.restoreButton = QPushButton(self)
|
||||
self.closeButton = QPushButton(self)
|
||||
|
||||
self.minButton.setFixedSize(TITLE_BUTTON_SIZE, TITLE_BUTTON_SIZE)
|
||||
# self.restoreButton.setFixedSize(TITLE_BUTTON_SIZE, TITLE_BUTTON_SIZE);
|
||||
self.closeButton.setFixedSize(TITLE_BUTTON_SIZE, TITLE_BUTTON_SIZE)
|
||||
|
||||
self.iconLabel.setFixedSize(TITLE_LABEL_SIZE, TITLE_LABEL_SIZE)
|
||||
self.titleLabel.setFixedHeight(TITLE_LABEL_SIZE)
|
||||
|
||||
self.iconLabel.setAlignment(Qt.AlignCenter)
|
||||
self.titleLabel.setAlignment(Qt.AlignCenter)
|
||||
|
||||
self.minButton.setIcon(QIcon(TITLE_MIN_ICON))
|
||||
self.closeButton.setIcon(QIcon(TITLE_CLS_ICON))
|
||||
|
||||
self.minButton.clicked.connect(self.ShowMininizedWindow)
|
||||
# self.restoreButton.clicked.connect(self.ShowRestoreWindow)
|
||||
self.closeButton.clicked.connect(self.CloseWindow)
|
||||
|
||||
self.lay = QHBoxLayout(self)
|
||||
self.setLayout(self.lay)
|
||||
|
||||
self.lay.setSpacing(0)
|
||||
self.lay.setContentsMargins(0, 0, 0, 0)
|
||||
|
||||
self.lay.addWidget(self.iconLabel)
|
||||
self.iconLabel.setStyleSheet(标题字体)
|
||||
self.lay.addWidget(self.titleLabel)
|
||||
self.titleLabel.setStyleSheet(标题字体)
|
||||
self.lay.addWidget(self.minButton)
|
||||
# self.lay.addWidget(self.restoreButton)
|
||||
self.lay.addWidget(self.closeButton)
|
||||
|
||||
def ShowMininizedWindow(self):
|
||||
self.win.showMinimized()
|
||||
|
||||
def SetWidth(self, width):
|
||||
self.label.resize(width, TITLE_BAR_HEIGHT)
|
||||
|
||||
def ShowMaximizedWindow(self):
|
||||
self.win.showMaximized()
|
||||
|
||||
def ShowRestoreWindow(self):
|
||||
if self.win.isMaximized():
|
||||
self.win.showNormal()
|
||||
else:
|
||||
self.win.showMaximized()
|
||||
|
||||
def CloseWindow(self):
|
||||
self.win.close()
|
||||
|
||||
def SetTitle(self, str):
|
||||
self.titleLabel.setText(str)
|
||||
|
||||
def SetTitleStyle(self, str):
|
||||
self.titleLabel.setStyleSheet(str)
|
||||
|
||||
def SetIcon(self, pix):
|
||||
self.iconLabel.setPixmap(
|
||||
pix.scaled(self.iconLabel.size() -
|
||||
QSize(TITLE_ICON_MAG, TITLE_ICON_MAG)))
|
||||
|
||||
# def mouseDoubleClickEvent(self, event):
|
||||
# self.ShowRestoreWindow()
|
||||
# return QWidget().mouseDoubleClickEvent(event)
|
||||
|
||||
def mousePressEvent(self, event):
|
||||
self.isPressed = True
|
||||
self.startPos = event.globalPos()
|
||||
return QWidget().mousePressEvent(event)
|
||||
|
||||
def mouseReleaseEvent(self, event):
|
||||
self.isPressed = False
|
||||
return QWidget().mouseReleaseEvent(event)
|
||||
|
||||
def mouseMoveEvent(self, event):
|
||||
if self.isPressed:
|
||||
if self.win.isMaximized:
|
||||
self.win.showNormal()
|
||||
|
||||
movePos = event.globalPos() - self.startPos
|
||||
self.startPos = event.globalPos()
|
||||
self.win.move(self.win.pos() + movePos)
|
||||
|
||||
return QWidget().mouseMoveEvent(event)
|
||||
Reference in New Issue
Block a user