author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Thu, 07 Mar 2024 21:19:45 +0100 | |
changeset 3907 | 394c130196b0 |
parent 3843 | 832bcf1b5b60 |
permissions | -rw-r--r-- |
3843
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
1 |
<?xml version='1.0' encoding='utf-8'?> |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
2 |
<PyFile xmlns:xhtml="http://www.w3.org/1999/xhtml"> |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
3 |
<variables> |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
4 |
<variable name="Test_Python_Var" type="INT" initial="4"/> |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
5 |
<variable name="Second_Python_Var" type="INT" initial="5"/> |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
6 |
</variables> |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
7 |
<globals> |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
8 |
<xhtml:p><![CDATA[ |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
9 |
import time,sys,ctypes |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
10 |
Python_to_C_Call = PLCBinary.Python_to_C_Call |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
11 |
Python_to_C_Call.restype = ctypes.c_int |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
12 |
Python_to_C_Call.argtypes = [ctypes.c_int, ctypes.POINTER(ctypes.c_int)] |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
13 |
|
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
14 |
|
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
15 |
def MyPrintFunction(msg): |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
16 |
if sys.stdout: |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
17 |
sys.stdout.write(msg) |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
18 |
sys.stdout.flush() |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
19 |
else: |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
20 |
PLCObject.LogMessage(msg) |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
21 |
|
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
22 |
def MyPythonFunc(arg): |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
23 |
i = ctypes.c_int() |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
24 |
if(Python_to_C_Call(arg, i)): |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
25 |
res = i.value |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
26 |
print("toC:", arg, "from C:", res, "FBID:", FBID) |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
27 |
else: |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
28 |
print("Failed Python_to_C_Call failed") |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
29 |
res = None |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
30 |
print("Python read PLC global :",PLCGlobals.Test_Python_Var) |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
31 |
print("Python read PLC global Grumpf :",PLCGlobals.Grumpf) |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
32 |
PLCGlobals.Second_Python_Var = 789 |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
33 |
|
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
34 |
if sys.stdout: |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
35 |
sys.stdout.flush() |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
36 |
return res |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
37 |
|
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
38 |
async_error_test_code = """ |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
39 |
def badaboom(): |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
40 |
tuple()[0] |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
41 |
|
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
42 |
import wx |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
43 |
def badaboomwx(): |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
44 |
wx.CallAfter(badaboom) |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
45 |
|
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
46 |
from threading import Timer |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
47 |
a = Timer(3, badaboom) |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
48 |
a.start() |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
49 |
|
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
50 |
b = Timer(6, badaboomwx) |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
51 |
b.start() |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
52 |
""" |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
53 |
]]></xhtml:p> |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
54 |
</globals> |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
55 |
<init> |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
56 |
<xhtml:p><![CDATA[ |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
57 |
global x, y |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
58 |
x = 2 |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
59 |
y = 5 |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
60 |
print("py_runtime init:", x, ",", y) |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
61 |
]]></xhtml:p> |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
62 |
</init> |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
63 |
<cleanup> |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
64 |
<xhtml:p><![CDATA[ |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
65 |
print("py_runtime cleanup") |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
66 |
]]></xhtml:p> |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
67 |
</cleanup> |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
68 |
<start> |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
69 |
<xhtml:p><![CDATA[ |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
70 |
global x, y |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
71 |
print("py_runtime start", x * x + y * y) |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
72 |
]]></xhtml:p> |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
73 |
</start> |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
74 |
<stop> |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
75 |
<xhtml:p><![CDATA[ |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
76 |
print("py_runtime stop") |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
77 |
]]></xhtml:p> |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
78 |
</stop> |
832bcf1b5b60
Runtime/win32: no sys.stdout with pythonw.exe
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3814
diff
changeset
|
79 |
</PyFile> |