forked from Cheaterman/kautopilly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
62 lines (51 loc) · 1.68 KB
/
main.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
from kivy.app import App
from kivy.properties import ObjectProperty
from kivy.uix.popup import Popup
from kivy.uix.label import Label
from krpc_wrapper import Connection
class KautoPilly(App):
connection = ObjectProperty()
def build(self):
self.connection = connection = Connection()
connection.bind(
on_connection_success=self.on_connection_success,
on_connection_failure=self.on_connection_failure,
)
def connect(self, address, rpc_port, stream_port):
self.connection.connect(
address=address,
rpc_port=rpc_port,
stream_port=stream_port,
)
def on_connection_success(self, connection):
root = self.root
root.ids.atmospheric.ksp = self.connection.ksp
root.current = 'atmospheric'
def on_connection_failure(self, connection, message):
popup = Popup(
title='KSP connection error',
content=Label(
text=(
'Could not connect to address:\n\n'
'{}:{} (stream port: {})\n\n'.format(
connection.address,
connection.rpc_port,
connection.stream_port
) +
message
),
color=(1, 0, 0, 1),
font_size=20
),
size_hint=(.9, .5)
)
popup.open()
# Reset connection button text
self.root.ids.connection.dispatch('on_pre_enter')
def on_pause(self):
return True
def on_stop(self):
ksp = self.connection.ksp
if ksp:
ksp.close()
KautoPilly().run()