-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
91 lines (74 loc) · 2.36 KB
/
app.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
# encoding: utf-8
import sys
from PyQt5 import QtQuick
from PyQt5.QtCore import QObject, pyqtSlot, QTimer
from PyQt5.QtGui import QIcon
from PyQt5.QtQml import QQmlApplicationEngine
from PyQt5.QtWidgets import QWidget, QApplication, QLabel
from resources import resources
print(QtQuick)
print(resources)
class MyAppMainWindow(QWidget):
def __init__(self):
super(MyAppMainWindow, self).__init__()
self.initUI()
def initUI(self):
##
self.resize(800, 600)
##
self.label = QLabel(self)
self.label.setText("哈哈哈哈")
##
screen = QApplication.primaryScreen()
qpixmap = screen.grabWindow(0)
print(qpixmap)
self.label.setPixmap(qpixmap)
##
self.setWindowTitle("My First PyQt5 App")
self.setWindowIcon(QIcon('icon.ico'))
#
self.show()
class ScreenCaptureWindow(QWidget):
def __init__(self):
super(ScreenCaptureWindow, self).__init__()
self.index = 0
self.resize(800, 600)
self.setWindowTitle("录屏实况")
self.label = QLabel(self)
self.timer = QTimer()
self.timer.timeout.connect(self.capture_screen)
self.capture_screen()
def capture_screen(self):
self.index += 1
screen = QApplication.primaryScreen()
screen_img = screen.grabWindow(0)
self.label.setPixmap(screen_img)
print(screen_img)
print("截图:" + str(self.index))
def capture_screen_start(self):
self.show()
self.timer.start(100)
def capture_screen_stop(self):
self.hide()
self.timer.stop()
class MyClass(QObject):
def __init__(self):
super(MyClass, self).__init__()
self.scw = ScreenCaptureWindow()
@pyqtSlot(str)
def screen_capture_start(self):
self.scw.capture_screen_start()
@pyqtSlot(str)
def screen_capture_stop(self):
self.scw.capture_screen_stop()
if __name__ == "__main__":
app = QApplication(sys.argv)
engine = QQmlApplicationEngine()
# engine.load("resources/qmls/app_main_window.qml")
# engine.load(QUrl("qrc:/resources/qmls/app_main_window.qml"))
engine.load(":/resources/qmls/app_main_window.qml")
con = MyClass()
context = engine.rootContext()
context.setContextProperty("con", con)
# myApp = MyAppMainWindow()
sys.exit(app.exec_())