-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
62 lines (49 loc) · 1.59 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
# -*- coding: utf-8 -*-
def run_entrypoint(entrypoint):
import runpy
import sys
import os
entrypoint_path = os.path.dirname(entrypoint)
sys.path.append(os.path.realpath(entrypoint_path))
runpy.run_path(
entrypoint,
run_name="__main__")
def run_launcher(tb=None):
from launcher.app import Launcher
Launcher().run()
def dispatch():
import os
# desktop launch
print("dispathc!")
entrypoint = os.environ.get("KIVYLAUNCHER_ENTRYPOINT")
if entrypoint is not None:
return run_entrypoint(entrypoint)
# try android
try:
from jnius import autoclass
activity = autoclass("org.kivy.android.PythonActivity").mActivity
intent = activity.getIntent()
entrypoint = intent.getStringExtra("entrypoint")
orientation = intent.getStringExtra("orientation")
if orientation == "portrait":
# SCREEN_ORIENTATION_PORTRAIT
activity.setRequestedOrientation(0x1)
elif orientation == "landscape":
# SCREEN_ORIENTATION_LANDSCAPE
activity.setRequestedOrientation(0x0)
elif orientation == "sensor":
# SCREEN_ORIENTATION_SENSOR
activity.setRequestedOrientation(0x4)
if entrypoint is not None:
try:
return run_entrypoint(entrypoint)
except Exception:
import traceback
traceback.print_exc()
return
except Exception:
import traceback
traceback.print_exc()
run_launcher()
if __name__ == "__main__":
dispatch()