-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow.py
More file actions
162 lines (129 loc) · 5.51 KB
/
Copy pathwindow.py
File metadata and controls
162 lines (129 loc) · 5.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
from PyQt5.QtWidgets import QWidget
from PyQt5 import QtWidgets
from PyQt5.QtCore import (
Qt,
QPropertyAnimation,
QVariantAnimation,
QPoint,
QEasingCurve,
QSize,
pyqtSignal
)
from PyQt5.QtGui import QPainter, QColor, QLinearGradient
from util import get_screen_size, get_local_file
class Window(QWidget):
onMove = pyqtSignal(QPoint)
def __init__(self, p=None, width: int = 640, height: int = 480):
super(Window, self).__init__(p)
self.setWindowTitle("Window")
self.resize(width, height)
self.setWindowFlags(Qt.FramelessWindowHint)
self.setAttribute(Qt.WA_TranslucentBackground)
self.opacity = 255
def mousePressEvent(self, event) -> None:
self.window().windowHandle().startSystemMove()
QtWidgets.QWidget.mousePressEvent(self, event)
def raiseBaseWidget(self):
self.titlebar.raise_()
def moveEvent(self, a0) -> None:
self.onMove.emit(self.pos())
QWidget.moveEvent(self, a0)
def setOpacity(self, opacity: int):
self.opacity = opacity
def paintEvent(self, event) -> None:
window_border_radius = 64
s = self.size()
qp = QPainter(self)
grad = QLinearGradient(0, 0, 250, 500)
grad.setColorAt(0.0, QColor(75, 75, 75))
grad.setColorAt(1.0, QColor(40, 40, 40))
qp.setBrush(grad)
qp.setPen(QColor("transparent"))
qp.setRenderHint(QPainter.Antialiasing)
qp.setRenderHint(QPainter.HighQualityAntialiasing)
qp.drawRoundedRect(0, 0, s.width(), s.height(),
window_border_radius, window_border_radius)
qp.end()
QWidget.paintEvent(self, event)
class Grip(QtWidgets.QSizeGrip):
isResizing = pyqtSignal(bool)
def __init__(self, p):
super(Grip, self).__init__(p)
def mousePressEvent(self, a0) -> None:
self.isResizing.emit(True)
QtWidgets.QSizeGrip.mousePressEvent(self, a0)
def mouseReleaseEvent(self, mouseEvent) -> None:
self.isResizing.emit(False)
QtWidgets.QSizeGrip.mouseReleaseEvent(self, mouseEvent)
class WindowContainer(QWidget):
def __init__(self, window):
super(WindowContainer, self).__init__()
self.resize(250, 642)
self.windowObject = window(self)
self.windowObject.move(20, 20)
self.dropShadow = QtWidgets.QGraphicsDropShadowEffect(self)
self.dropShadow.setBlurRadius(32)
self.dropShadow.setColor(QColor(0, 0, 0, 128))
self.dropShadow.setOffset(0, 0)
self.windowObject.setGraphicsEffect(self.dropShadow)
self.setWindowFlags(Qt.FramelessWindowHint)
self.setAttribute(Qt.WA_TranslucentBackground)
# self.setFocusPolicy(Qt.StrongFocus)
self.sizeGrip = Grip(self)
self.showAnimation = QPropertyAnimation(self, b"pos")
self.showAnimation.setDuration(500)
self.hideAnimation = QPropertyAnimation(self, b"pos")
self.hideAnimation.setDuration(500)
self.oldPos = self.get_center()
with(open(get_local_file("style.qss"))) as styleFile:
self.setStyleSheet(styleFile.read())
# def focusOutEvent(self, a0) -> None:
# anim = QVariantAnimation(self)
# anim.setDuration(150)
# anim.setStartValue(32)
# anim.setEndValue(8)
# anim.valueChanged.connect(self.dropShadow.setBlurRadius)
# anim.start()
# QWidget.focusOutEvent(self, a0)
# def focusInEvent(self, a0) -> None:
# if not self.dropShadow.blurRadius() == 32:
# anim = QVariantAnimation(self)
# anim.setDuration(150)
# anim.setStartValue(8)
# anim.setEndValue(32)
# anim.valueChanged.connect(self.dropShadow.setBlurRadius)
# anim.start()
# QWidget.focusInEvent(self, a0)
def get_center(self):
geometry = self.frameGeometry()
geometry.moveCenter(get_screen_size().center())
return geometry.topLeft()
def sizeEvent(self):
if self.isMaximized():
self.showNormal()
else:
self.showMaximized()
def windowCloseEvent(self) -> None:
self.oldPos = self.pos()
self.hideAnimation.setStartValue(self.oldPos)
self.hideAnimation.setEndValue(QPoint(self.x(), get_screen_size().height()))
self.hideAnimation.setEasingCurve(QEasingCurve.InCubic)
self.hideAnimation.start()
self.hideAnimation.finished.connect(self.close)
def showEvent(self, event) -> None:
self.showAnimation.setStartValue(QPoint(self.x(), get_screen_size().height()))
self.showAnimation.setEndValue(self.oldPos)
self.showAnimation.setEasingCurve(QEasingCurve.OutCubic)
self.showAnimation.start()
QWidget.showEvent(self, event)
def minimizeEvent(self):
self.oldPos = self.pos()
self.hideAnimation.setStartValue(self.oldPos)
self.hideAnimation.setEndValue(QPoint(self.x(), get_screen_size().height()))
self.hideAnimation.setEasingCurve(QEasingCurve.InCubic)
self.hideAnimation.start()
self.hideAnimation.finished.connect(self.showMinimized)
def resizeEvent(self, a0) -> None:
self.windowObject.resize(self.width() - 40, self.height() - 40)
self.sizeGrip.move(self.windowObject.width() + 10, self.windowObject.height() + 10)
QWidget.resizeEvent(self, a0)