forked from PyQt5/PyQt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WindowMaster.py
90 lines (75 loc) · 2.57 KB
/
WindowMaster.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on 2019年8月7日
@author: Irony
@site: https://pyqt5.com https://github.com/892768447
@email: [email protected]
@file: QtRemoteObjects.SyncUi.WindowMaster
@description: 主窗口
"""
from PyQt5.QtCore import QUrl, QTimer, pyqtSignal, pyqtSlot
from PyQt5.QtRemoteObjects import QRemoteObjectHost
from PyQt5.QtWidgets import QWidget, QLineEdit, QVBoxLayout, QCheckBox,\
QProgressBar
__Author__ = 'Irony'
__Copyright__ = 'Copyright (c) 2019 Irony'
__Version__ = 1.0
class WindowMaster(QWidget):
# 输入框内容变化信号
editValueChanged = pyqtSignal(str)
# 勾选框变化信号
checkToggled = pyqtSignal(bool)
# 进度条变化信号
progressValueChanged = pyqtSignal(int)
def __init__(self, *args, **kwargs):
super(WindowMaster, self).__init__(*args, **kwargs)
self.setupUi()
# 开启节点
host = QRemoteObjectHost(QUrl('local:WindowMaster'), parent=self)
host.enableRemoting(self, 'WindowMaster')
print('开启节点完成')
# 定时器更新进度条
self._value = 0
self.utimer = QTimer(self, timeout=self.updateProgress)
self.utimer.start(200)
def setupUi(self):
self.setWindowTitle('WindowMaster')
self.resize(300, 400)
layout = QVBoxLayout(self)
# 输入框(双向同步)
self.lineEdit = QLineEdit(self)
self.lineEdit.textChanged.connect(self.editValueChanged.emit)
# 勾选框(双向同步)
self.checkBox = QCheckBox('来勾我啊', self)
self.checkBox.toggled.connect(self.checkToggled.emit)
# 进度条(Master更新Slave)
self.progressBar = QProgressBar(self)
self.progressBar.valueChanged.connect(self.progressValueChanged.emit)
layout.addWidget(self.lineEdit)
layout.addWidget(self.checkBox)
layout.addWidget(self.progressBar)
def updateProgress(self):
self._value += 1
if self._value > 100:
self._value = 0
self.progressBar.setValue(self._value)
@pyqtSlot(str)
def updateEdit(self, text):
"""更新输入框内容的槽函数
:param text:
"""
self.lineEdit.setText(text)
@pyqtSlot(bool)
def updateCheck(self, checked):
"""更新勾选框的槽函数
:param checked:
"""
self.checkBox.setChecked(checked)
if __name__ == '__main__':
import sys
from PyQt5.QtWidgets import QApplication
app = QApplication(sys.argv)
w = WindowMaster()
w.show()
sys.exit(app.exec_())