| 22 | |
| 23 | |
| 24 | class WindowNotify(QWidget, Ui_NotifyForm): |
| 25 | SignalClosed = pyqtSignal() # 弹窗关闭信号 |
| 26 | |
| 27 | def __init__(self, title="", content="", timeout=5000, *args, **kwargs): |
| 28 | super(WindowNotify, self).__init__(*args, **kwargs) |
| 29 | self.setupUi(self) |
| 30 | self.setTitle(title).setContent(content) |
| 31 | self._timeout = timeout |
| 32 | self._init() |
| 33 | |
| 34 | def setTitle(self, title): |
| 35 | if title: |
| 36 | self.labelTitle.setText(title) |
| 37 | return self |
| 38 | |
| 39 | def title(self): |
| 40 | return self.labelTitle.text() |
| 41 | |
| 42 | def setContent(self, content): |
| 43 | if content: |
| 44 | self.labelContent.setText(content) |
| 45 | return self |
| 46 | |
| 47 | def content(self): |
| 48 | return self.labelContent.text() |
| 49 | |
| 50 | def setTimeout(self, timeout): |
| 51 | if isinstance(timeout, int): |
| 52 | self._timeout = timeout |
| 53 | return self |
| 54 | |
| 55 | def timeout(self): |
| 56 | return self._timeout |
| 57 | |
| 58 | def onView(self): |
| 59 | print("onView") |
| 60 | webbrowser.open_new_tab("http://alyl.vip") |
| 61 | |
| 62 | def onClose(self): |
| 63 | # 点击关闭按钮时 |
| 64 | print("onClose") |
| 65 | self.isShow = False |
| 66 | QTimer.singleShot(100, self.closeAnimation) # 启动弹回动画 |
| 67 | |
| 68 | def _init(self): |
| 69 | # 隐藏任务栏|去掉边框|顶层显示 |
| 70 | self.setWindowFlags(Qt.Tool | Qt.X11BypassWindowManagerHint | |
| 71 | Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint) |
| 72 | # 关闭按钮事件 |
| 73 | self.buttonClose.clicked.connect(self.onClose) |
| 74 | # 点击查看按钮 |
| 75 | self.buttonView.clicked.connect(self.onView) |
| 76 | # 是否在显示标志 |
| 77 | self.isShow = True |
| 78 | # 超时 |
| 79 | self._timeouted = False |
| 80 | # 桌面 |
| 81 | self._desktop = QApplication.instance().desktop() |