Skip to content

Commit

Permalink
Fixed custom titlebar's behavior
Browse files Browse the repository at this point in the history
BUG Fix
  • Loading branch information
parazeeknova committed Jul 28, 2024
1 parent 782a38d commit 52936ff
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 34 deletions.
53 changes: 20 additions & 33 deletions zenith/core/zenith_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@

from lupa import LuaRuntime # type: ignore
from PyQt6.Qsci import QsciScintilla
from PyQt6.QtCore import (
QEasingCurve,
QPropertyAnimation,
QSize,
Qt,
QThreadPool,
pyqtSignal,
)
from PyQt6.QtCore import QEvent, QSize, Qt, QThreadPool, pyqtSignal
from PyQt6.QtGui import QColor, QIcon, QPalette
from PyQt6.QtWidgets import (
QApplication,
Expand Down Expand Up @@ -71,33 +64,27 @@ def __init__(self):
self.setupUI()
self.setupConnections()
self.setupTerminal()
self.normalGeometry = None

self.maximizeAnimation = QPropertyAnimation(self, b"geometry")
self.maximizeAnimation.setDuration(300)
self.maximizeAnimation.setEasingCurve(QEasingCurve.Type.InOutQuad)

def animatedMaximize(self):
if not self.isMaximized():
self.maximizeAnimation.setStartValue(self.geometry())
self.maximizeAnimation.setEndValue(self.screen().availableGeometry())
self.maximizeAnimation.start()
else:
self.showNormal()

def animatedMinimize(self):
self.maximizeAnimation.setStartValue(self.geometry())
end_rect = self.geometry()
end_rect.setHeight(0)
self.maximizeAnimation.setEndValue(end_rect)
self.maximizeAnimation.finished.connect(self.hide)
self.maximizeAnimation.start()

# Override these methods
def showMaximized(self):
self.animatedMaximize()

def showMinimized(self):
self.animatedMinimize()
if not self.isMaximized():
self.normalGeometry = self.geometry()
super().showMaximized()

def showNormal(self):
super().showNormal()
if self.normalGeometry:
self.setGeometry(self.normalGeometry)

def changeEvent(self, event):
if event.type() == QEvent.Type.WindowStateChange:
if self.windowState() & Qt.WindowState.WindowMinimized:
event.ignore()
elif self.windowState() & Qt.WindowState.WindowMaximized:
super().showMaximized()
else:
self.showNormal()
super().changeEvent(event)

def setupUI(self):
self.setWindowTitle("Zenith")
Expand Down
5 changes: 4 additions & 1 deletion zenith/framework/titleBar.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(self, zenithInstance=None, parent=None):
self.minimizeButton = QPushButton(self)
self.minimizeButton.setIcon(QIcon(minimiseIcon))
self.minimizeButton.setIconSize(QSize(12, 12))
self.minimizeButton.clicked.connect(parent.showMinimized)
self.minimizeButton.clicked.connect(self.minimizeWindow)
self.layout.addWidget(self.minimizeButton)
self.minimizeButton.setStyleSheet(button_style)

Expand Down Expand Up @@ -114,3 +114,6 @@ def closeApplication(self):

def menuBar(self, zenithInstance):
return menu_bar(self, zenithInstance)

def minimizeWindow(self):
self.parent().showMinimized()

0 comments on commit 52936ff

Please sign in to comment.