-
Notifications
You must be signed in to change notification settings - Fork 0
/
ccd_daq_control_panel.py
107 lines (83 loc) · 3.79 KB
/
ccd_daq_control_panel.py
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
import sys
import time
import pythoncom
import re
from threading import Thread
from PyQt5.QtGui import QIcon, QPixmap, QCursor, QMouseEvent, QColor, QFont
from PyQt5.QtCore import Qt, pyqtSignal, QPoint, QEvent
from PyQt5.QtWidgets import QWidget, QApplication, QGraphicsDropShadowEffect,QDesktopWidget, QFileDialog, QVBoxLayout, QMessageBox
# Write in file paths of dlls needed.
# Import functions from dlls.
class MyWindow(polarizer_sweep_ui.Ui_Form, QWidget):
def __init__(self):
super().__init__()
# init UI
self.setupUi(self)
self.ui_width = int(QDesktopWidget().availableGeometry().size().width()*0.85)
self.ui_height = int(QDesktopWidget().availableGeometry().size().height()*0.62)
self.resize(self.ui_width, self.ui_height)
center_pointer = QDesktopWidget().availableGeometry().center()
x = center_pointer.x()
y = center_pointer.y()
old_x, old_y, width, height = self.frameGeometry().getRect()
self.move(int(x - width / 2), int(y - height / 2))
# set flag off and widget translucent
self.setWindowFlags(Qt.FramelessWindowHint)
self.setAttribute(Qt.WA_TranslucentBackground)
# set window blur
self.render_shadow()
# init window button signal
self.window_btn_signal()
'''Set window ui'''
def window_btn_signal(self):
# window button sigmal
self.close_btn.clicked.connect(self.close)
self.max_btn.clicked.connect(self.maxornorm)
self.min_btn.clicked.connect(self.showMinimized)
#create window blur
def render_shadow(self):
self.shadow = QGraphicsDropShadowEffect(self)
self.shadow.setOffset(0, 0) # 偏移
self.shadow.setBlurRadius(30) # 阴影半径
self.shadow.setColor(QColor(128, 128, 255)) # 阴影颜色
self.mainwidget.setGraphicsEffect(self.shadow) # 将设置套用到widget窗口中
def maxornorm(self):
if self.isMaximized():
self.showNormal()
self.norm_icon = QIcon()
self.norm_icon.addPixmap(QPixmap(":/my_icons/images/icons/max.svg"), QIcon.Normal, QIcon.Off)
self.max_btn.setIcon(self.norm_icon)
else:
self.showMaximized()
self.max_icon = QIcon()
self.max_icon.addPixmap(QPixmap(":/my_icons/images/icons/norm.svg"), QIcon.Normal, QIcon.Off)
self.max_btn.setIcon(self.max_icon)
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.m_flag = True
self.m_Position = QPoint
self.m_Position = event.globalPos() - self.pos() # 获取鼠标相对窗口的位置
event.accept()
self.setCursor(QCursor(Qt.OpenHandCursor)) # 更改鼠标图标
def mouseMoveEvent(self, QMouseEvent):
m_position = QPoint
m_position = QMouseEvent.globalPos() - self.pos()
width = QDesktopWidget().availableGeometry().size().width()
height = QDesktopWidget().availableGeometry().size().height()
if m_position.x() < width*0.7 and m_position.y() < height*0.06:
self.m_flag = True
if Qt.LeftButton and self.m_flag:
pos_x = int(self.m_Position.x())
pos_y = int(self.m_Position.y())
if pos_x < width*0.7 and pos_y < height*0.06:
self.move(QMouseEvent.globalPos() - self.m_Position) # 更改窗口位置
QMouseEvent.accept()
def mouseReleaseEvent(self, QMouseEvent):
self.m_flag = False
self.setCursor(QCursor(Qt.ArrowCursor))
# def closeEvent(self, event):
if __name__ == '__main__':
app = QApplication(sys.argv)
w = MyWindow()
w.show()
app.exec()