-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrun.py
63 lines (43 loc) · 1.34 KB
/
run.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
from pathlib import Path
import ctypes
from io import BytesIO
import numpy as np
from PIL import Image, ImageTk
from tkinter import Tk, Label
from utils import dlopen, dlclose, enc_args, FUNCTYPE
root = Tk()
root.title("[DBHI/vboard] VGA screen")
panel = Label(root, bd=0)
panel.pack()
def save_screenshot(img, width, height, id):
print(" Python save_screenshot:", img, width, height, id)
image = Image.fromarray(np.ctypeslib.as_array(img, shape=(height, width)))
image.mode = 'RGBA'
# TODO: passing 'image' to panel.image should be possible without writting to an intermediate buffer
buf = BytesIO()
image.save(buf, format="PNG")
pimg = ImageTk.PhotoImage(Image.open(buf))
panel.configure(image=pimg)
panel.image = pimg
root.update()
def sim_cleanup():
print(" Python sim_cleanup!")
def run_sim():
C_SAVE_SCREENSHOT = FUNCTYPE(
None,
ctypes.POINTER(ctypes.c_int),
ctypes.c_uint,
ctypes.c_uint,
ctypes.c_int
)(save_screenshot)
C_SIM_CLEANUP = FUNCTYPE(
None
)(sim_cleanup)
# TODO pass argv to GHDL
C_ARGS = enc_args([str(Path(__file__))])
CAUXDLL = dlopen("./caux.so")
print("> pymain")
print(CAUXDLL.py_main(len(C_ARGS), C_ARGS, C_SAVE_SCREENSHOT, C_SIM_CLEANUP))
dlclose(CAUXDLL)
root.after(0, run_sim)
root.mainloop()