-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
75 lines (58 loc) · 1.97 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
63
64
65
66
67
68
69
70
71
72
73
74
75
"""Kivy app entry point"""
import logging
from kivy.lang import Builder
# from kivy.logger import Logger
from kivy.utils import platform
class LogHandler(logging.Handler):
"""The custom handler to populate RecycleView data"""
def __init__(self, view, level=logging.NOTSET):
super().__init__(level=level)
self.data = view.data
def emit(self, record):
self.data.append({
'text': record.levelname
+ record.message.replace('[', ': ').replace(']', ':')
})
def start_service(data=None):
if platform == 'android' and data is None:
import android
from jnius import autoclass
activity = autoclass('org.kivy.android.PythonActivity').mActivity
Context = autoclass('android.content.Context')
wifi_info = activity.getSystemService(
Context.WIFI_SERVICE).getConnectionInfo()
ipaddr = wifi_info.getIpAddress()
# debug
android.start_service(title='Minode')
# service = autoclass(
# '{}.ServiceMinode'.format(activity.getPackageName()))
# argument = ''
# service.start(activity, argument)
return '%d.%d.%d.%d' % (
(ipaddr & 0xff), (ipaddr >> 8 & 0xff),
(ipaddr >> 16 & 0xff), (ipaddr >> 24 & 0xff))
else:
from minode.app import app
app.main()
if __name__ == '__main__':
from kivy.base import runTouchApp
addr = start_service()
root = Builder.load_string("""
<LogItem@Label>
size_hint_x: 1
text_size: self.width-dp(28), self.height
RecycleView:
id: debug
viewclass: 'LogItem'
RecycleBoxLayout:
orientation: 'vertical'
default_size_hint: 1, None
default_size: 0, dp(28)
size_hint_y: None
height: self.minimum_height
""")
root.data.append({'text': 'Listening %s:8444' % addr})
# log = logging.getLogger()
# handler = LogHandler(root, logging.DEBUG)
# log.addHandler(handler)
runTouchApp(root)