-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtelnet_starwars.py
52 lines (46 loc) · 996 Bytes
/
telnet_starwars.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
#!/usr/bin/env python
'''
STARWARS!
'''
import telnetlib
import ui
HOST = "towel.blinkenlights.nl"
playing = False
def button_pressed(sender):
global playing
if sender.title == "Play":
sender.title = 'Pause'
playing = True
else:
sender.title = 'Play'
playing = False
tn = telnetlib.Telnet(HOST)
#view
view = ui.View()
view.background_color = (0,0,0)
view.frame = (0,0,800,800)
#textview
tv = ui.TextView()
tv.font = ('Courier',17)
tv.flex = 'LRTB'
tv.text_color = (1,1,1)
tv.name = 'textview1'
tv.frame = (0, 60, 800, 400)
tv.background_color = (0,0,0)
view.add_subview(tv)
#button
btn = ui.Button()
btn.name = 'button1'
btn.title = 'Play'
btn.action = button_pressed
btn.tint_color = (1,1,1)
btn.flex = 'LR'
btn.frame = (359, 6, 80, 32)
view.add_subview(btn)
view.present('fullscreen')
tn.read_until('\r\n')
while True:
if playing:
txt = ''
lines = tn.read_until('[H').replace('[H','')
view['textview1'].text = lines