-
Notifications
You must be signed in to change notification settings - Fork 0
/
iOS-lookingglass.py
61 lines (50 loc) · 1.98 KB
/
iOS-lookingglass.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
#!/usr/bin/env python3
import ui
import time
import objc_util
# Check out https://github.com/jankais3r/HoloSkype for an example project
url = 'http://192.168.1.75:9090/holo.html'
@objc_util.on_main_thread
def main():
global wk, second_screen, second_window
UIScreen = objc_util.ObjCClass('UIScreen')
if len(UIScreen.screens()) > 1:
second_screen = UIScreen.screens()[1]
second_screen.overscanCompensation = 0
bounds = second_screen.bounds()
UIWindow = objc_util.ObjCClass('UIWindow')
second_window = UIWindow.alloc().initWithFrame_(bounds)
second_window.setScreen(second_screen)
second_window.makeKeyAndVisible()
wk = objc_util.ObjCClass('WKWebView').alloc().initWithFrame_(objc_util.CGRect((0, 0), (second_screen.bounds().size.width, second_screen.bounds().size.height - 1))).autorelease()
second_window.addSubview(wk)
request = objc_util.ObjCClass('NSURLRequest').alloc().init()
nsurl = objc_util.nsurl(url)
x = request.initWithURL_(nsurl)
wk.loadRequest_(x)
else:
print('No secondary screen detected. Connect your Looking Glass.')
v.close()
quit()
def close_button(sender):
global v, wk, second_screen, second_window
wk.loadHTMLString_baseURL_('', None)
del wk, second_window, second_screen
v.close()
quit()
button = ui.Button(title = 'Close', background_color = 'white', tint_color = 'white', corner_radius = 5)
button.action = close_button
v = ui.View()
v.add_subview(button)
v.present(style = 'fullscreen', hide_title_bar = True)
button.frame = (v.width / 2 - 40, v.height / 2 - 16, 80, 32)
button.background_color = 'black'
wk, second_window = None, None
main()
try:
# If you are rendering a complex Three.js scene and the hologram doesn't look right, try increasing the sleep timer.
# This is a hack around a webkit bug. The window needs to be resized once the rendering completes in order to apply correct shader values.
time.sleep(3)
wk.setFrame_(CGRect((0, 0), (second_screen.bounds().size.width, second_screen.bounds().size.height)))
except:
pass