exampleqmlitem.py
1.4 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
import os
import pathlib
from .. import _import_it
from .. import major
QtCore = _import_it('PyQt', 'QtCore')
QtQuick = _import_it('PyQt', 'QtQuick')
test_path_env_var = 'PYQT{major}TOOLS_TEST_PATH'.format(major=major)
test_file_contents = b'jagular'
write_for_test = test_path_env_var in os.environ
class ExampleQmlItem(QtQuick.QQuickPaintedItem):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@QtCore.pyqtProperty('QString')
def test_value(self):
global write_for_test
if write_for_test:
write_for_test = False
path = pathlib.Path(os.environ[test_path_env_var])
path.parent.mkdir(parents=True, exist_ok=True)
with path.open('ab') as f:
f.write(test_file_contents)
return 'pass the test'
@QtCore.pyqtProperty('QString')
def other_value(self):
pass
@other_value.setter
def other_value(self, value):
pass
def paint(self, painter):
global write_for_test
if write_for_test:
write_for_test = False
path = pathlib.Path(os.environ[test_path_env_var])
path.parent.mkdir(parents=True, exist_ok=True)
with path.open('ab') as f:
f.write(test_file_contents)
painter.drawText(
self.width() / 2,
self.height() / 2,
'pyqt{major}-tools'.format(major=major),
)