Skip to content

Commit

Permalink
修复了不能自定义窗口大小的问题 (#560)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zzaphkiel committed Dec 17, 2024
1 parent 036c4c0 commit 21bf329
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
16 changes: 14 additions & 2 deletions app/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import os
import sys

from PyQt5.QtCore import QLocale
from PyQt5.QtCore import QLocale, QSize


from .qfluentwidgets import (qconfig, QConfig, ConfigItem, FolderValidator, BoolValidator,
OptionsConfigItem, OptionsValidator, ConfigSerializer,
Expand All @@ -16,14 +17,22 @@ class Language(Enum):


class LanguageSerializer(ConfigSerializer):

def serialize(self, language: Language):
return language.value.name() if language != Language.AUTO else "Auto"

def deserialize(self, value: str):
return Language(QLocale(value)) if value != 'Auto' else Language.AUTO


class QSizeSerializer(ConfigSerializer):
def serialize(self, size: QSize) -> str:
return f"{size.width()}, {size.height()}"

def deserialize(self, value: str) -> QSize:
width, height = map(int, value.split(', '))
return QSize(width, height)


def isWin11():
return sys.platform == 'win32' and sys.getwindowsversion().build >= 22000

Expand Down Expand Up @@ -166,6 +175,9 @@ class Config(QConfig):
enableSilent = ConfigItem(
"General", "EnableSilent", False, BoolValidator())

windowSize = ConfigItem("Personalization", "WindowSize", QSize(
1134, 826), None, QSizeSerializer())


YEAR = 2023
AUTHOR = "Zzaphkiel"
Expand Down
16 changes: 11 additions & 5 deletions app/view/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import asyncio
from aiohttp.client_exceptions import ClientConnectorError
from qasync import asyncClose, asyncSlot
from PyQt5.QtCore import Qt, pyqtSignal, QSize, QEvent, QTimer
from PyQt5.QtCore import Qt, pyqtSignal, QSize, QEvent, QTimer, QPoint
from PyQt5.QtGui import QIcon, QImage
from PyQt5.QtWidgets import QApplication, QSystemTrayIcon

Expand Down Expand Up @@ -66,6 +66,8 @@ def __init__(self):

logger.critical(f"Seraphine started, version: {BETA or VERSION}", TAG)

self.windowSize = cfg.get(cfg.windowSize)

self.__initConfig()
self.__initWindow()
self.__checkWindowSize()
Expand Down Expand Up @@ -258,7 +260,6 @@ def __conncetSignalToSlot(self):
self.mainWindowHide.connect(self.__onWindowHide)

def __initWindow(self):
self.resize(1134, 826)
self.setMinimumSize(1134, 826)
self.setWindowIcon(QIcon("app/resource/images/logo.png"))
self.setWindowTitle("Seraphine")
Expand Down Expand Up @@ -736,6 +737,8 @@ async def closeEvent(self, a0) -> None:
self.__terminateListeners()
self.opggWindow.close()

cfg.set(cfg.windowSize, self.windowSize)

return super().closeEvent(a0)
else:
a0.ignore()
Expand Down Expand Up @@ -1048,8 +1051,11 @@ def __onCurrentStackedChanged(self, index):
widget.delegate.vScrollBar.resetValue(0)

def eventFilter(self, obj, e: QEvent):
# Fix #553
if e.type() == QEvent.Type.MouseButtonRelease:
self.adjustSize()
# Fix #553, #560
if e.type() == QEvent.Type.Resize:
self.windowSize = self.size()

if e.type() == QEvent.Type.Move:
self.resize(self.windowSize)

return super().eventFilter(obj, e)
2 changes: 1 addition & 1 deletion app/view/opgg_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ def setHomeInterfaceEnabled(self, enabeld):

def eventFilter(self, obj, e: QEvent):
# Fix #553
if e.type() == QEvent.Type.MouseButtonRelease:
if e.type() == QEvent.Type.Move:
self.adjustSize()

return super().eventFilter(obj, e)
Expand Down

0 comments on commit 21bf329

Please sign in to comment.