-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgui.py
51 lines (40 loc) · 999 Bytes
/
gui.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
import gi
import os
import sys
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
def pause(button):
print("PAUSE", file=p.stdin)
print("PAUSE")
def stop(button):
print("STOP", file=p.stdin)
print("STOP")
handlers = {
"onDestroy": Gtk.main_quit,
"pause": pause,
"stop": stop,
}
builder = Gtk.Builder()
builder.add_from_file("main.glade")
builder.connect_signals(handlers)
window = builder.get_object("test")
window.show_all()
stdin = sys.stdin.fileno() # usually 0
stdout = sys.stdout.fileno() # usually 1
parentStdin, childStdout = os.pipe()
childStdin, parentStdout = os.pipe()
pid = os.fork()
if pid:
# parent process
os.close(childStdout)
os.close(childStdin)
os.dup2(parentStdin, stdin)
os.dup2(parentStdout, stdout)
Gtk.main()
else:
# child process
os.close(parentStdin)
os.close(parentStdout)
os.dup2(childStdin, stdin)
os.dup2(childStdout, stdout)
os.execl("python", "main.py", "main.py")