forked from cvpe/Pythonista-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VersionInStatusBar.py
35 lines (33 loc) · 1.06 KB
/
VersionInStatusBar.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
import ui
import objc_util
import os
import sys
def VersionInStatusBar(version=False):
# called at begin of a script with version=text
# end version=False
root, ext = os.path.splitext(sys.argv[0]) # script path without .py
script_name = os.path.basename(root) # script name without the path
app = objc_util.UIApplication.sharedApplication()
w = objc_util.ObjCClass('UIApplication').sharedApplication().keyWindow()
main_view = w.rootViewController().view()
bar = app.statusBar()
b = bar.bounds()
sv = bar.subviews()
for v in sv:
if v._get_objc_classname().startswith(b'SUILabel_PY3'):
v.removeFromSuperview()
del v
if not version: # remove version label
return
lbl = ui.Label()
lbl.frame = (200,2,23,16)
lbl.text_color = 'blue'
lbl.border_width = 1
lbl.border_color = 'blue'
lbl.font = ('Courier-Bold',12)
lbl.text = script_name+': version='+version
lbl.width = ui.measure_string(lbl.text,font=lbl.font)[0]
lbl = lbl
bar.addSubview_(lbl)
#VersionInStatusBar(version='test')
#VersionInStatusBar(version=False)