-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathro-debug-twisted-withKeyDispatcher.py
83 lines (72 loc) · 2.26 KB
/
ro-debug-twisted-withKeyDispatcher.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
#!/usr/bin/env python3
import tkinter
import tkinter.scrolledtext as scrolledtext
import RO.Comm.Generic
RO.Comm.Generic.setFramework("twisted")
from RO.Comm.HubConnection import HubConnection
import RO.KeyDispatcher
import time
from getpass import getpass
if __name__=="__main__":
root=tkinter.Tk() ## For Tk.
import twisted.internet.tksupport
twisted.internet.tksupport.install(root)
from twisted.internet import reactor
host = "hub35m.apo.nmsu.edu"
port = 9877
progID = "TU01"
password = getpass("Enter password: ")
username = "gmac"
def updateScrolledText(astr):
timeStr = time.ctime()
textArea.configure(state='normal')
textArea.insert(tkinter.INSERT, f"{timeStr}: {astr}\n")
textArea.configure(state='disabled')
textArea.see(tkinter.END)
def onExit():
conn.disconnect()
reactor.stop()
def readCallback(sock, astr):
print(f"read: {astr}")
updateScrolledText(astr)
def stateCallback(sock):
state, reason = sock.fullState
if reason:
print(f"{state}: {reason}")
else:
print(f"{state}:")
root.title("RO Debug") ## Window title
tkinter.Label(root, ## Text area title
text="Messages from hub35m"
).grid(
column=0,
row=0
)
textArea = scrolledtext.ScrolledText(root, ## Text area
width=120,
height=30
)
textArea.grid(column=0, pady=10, padx=10)
tkinter.Button(root, ## Quit button
text="Exit",
command=onExit
).grid(
column=0,
row=2
)
conn = HubConnection(
name="debug-client",
stateCallback=stateCallback,
readCallback=readCallback
)
disp = RO.KeyDispatcher.KeyDispatcher(connection=conn)
print("**** DOING CONNECTION ****")
disp.connection.connect( progID = progID,
password = password,
username = username,
host = host,
port = port,
)
print("**** FINISHED DOING CONNECTION ****")
disp.refreshAllVar(resetAll=True)
reactor.run() ## For twisted.