Skip to content

Commit 8230590

Browse files
committed
...
1 parent ff21509 commit 8230590

9 files changed

+714
-0
lines changed

apps/strip-pylib.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# https://forum.omz-software.com/topic/3691/preparation-for-xcode-delete-files-in-pythonistaapptemplate/12
2+
3+
import inspect
4+
import importlib
5+
6+
pyt_mods = [
7+
"os",
8+
"datetime",
9+
"json",
10+
"requests",
11+
"operator",
12+
"time",
13+
]
14+
15+
pythonista_mods = [
16+
"ui",
17+
"console",
18+
"dialogs",
19+
"objc_util"
20+
]
21+
22+
all_mods = pyt_mods + pythonista_mods
23+
24+
keep_list = []
25+
for imods in all_mods:
26+
try:
27+
module_obj = importlib.import_module(imods)
28+
filepath = inspect.getfile(module_obj).split("PythonistaKit.framework")[1]
29+
keep_list.append(filepath)
30+
31+
except TypeError as e:
32+
print(e)
33+
34+
for filep in keep_list:
35+
print(filep)
36+

apps/strip_pylib.py

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# https://forum.omz-software.com/topic/3691/preparation-for-xcode-delete-files-in-pythonistaapptemplate/13
2+
3+
# Clear all
4+
# To get pythonista to work again, restart the app
5+
import sys
6+
sys.modules[__name__].__dict__.clear()
7+
8+
# Now import
9+
import sys
10+
import inspect
11+
import importlib
12+
13+
splitstr = "PythonistaKit.framework"
14+
15+
pyt_mods = [
16+
"os",
17+
"datetime",
18+
"json",
19+
"requests",
20+
"operator",
21+
"time",
22+
]
23+
24+
pythonista_mods = [
25+
"ui",
26+
"console",
27+
"dialogs",
28+
"objc_util"
29+
]
30+
31+
all_mods = pyt_mods + pythonista_mods
32+
33+
keep_list = []
34+
for imods in all_mods:
35+
try:
36+
m = importlib.import_module(imods)
37+
dirpath, filepath = inspect.getfile(m).split(splitstr)
38+
keep_list.append(filepath)
39+
40+
except TypeError as e:
41+
#print(e)
42+
pass
43+
44+
# Get the imported modules
45+
dict = sys.modules
46+
for key in dict:
47+
val = dict[key]
48+
if val == None:
49+
continue
50+
else:
51+
try:
52+
filepath = inspect.getfile(val)
53+
if splitstr in filepath:
54+
filepath_append = filepath.split(splitstr)[1]
55+
keep_list.append(filepath_append)
56+
else:
57+
pass
58+
59+
except TypeError as e:
60+
#print(e)
61+
pass
62+
63+
# Make uniq and sort
64+
keep_list = sorted(set(keep_list))
65+
66+
# Now find all files
67+
import os
68+
69+
fp = dirpath+splitstr
70+
extensions = [".py", ".pyo"]
71+
all_files = []
72+
for path, dirs, files in os.walk(fp):
73+
for f in files:
74+
filename, file_extension = os.path.splitext(f)
75+
if "/pylib/" in path or "/pylib_ext/" in path:
76+
if file_extension in extensions:
77+
stringfp = os.path.join(path, f)
78+
dirpath, filepath = stringfp.split(splitstr)
79+
all_files.append(filepath)
80+
81+
# Make uniq and sort
82+
all_files = sorted(set(all_files))
83+
84+
# Make a delete list
85+
dellist = [x for x in all_files if x not in keep_list]
86+
87+
# Write delete file
88+
fname = 'pylib_clean.sh'
89+
f = open(fname,'w')
90+
f.write("#!/usr/bin/env bash\n")
91+
92+
for idel in dellist:
93+
f.write("rm ."+idel+"\n")
94+
f.close()
95+
96+
f = open(fname, "r")
97+
for line in f:
98+
print(line),
99+
f.close()
100+

camera/live_camera_view.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# coding: utf-8
2+
3+
# https://github.com/jsbain/objc_hacks/blob/master/live_camera_view.py
4+
5+
# https://forum.omz-software.com/topic/2062/video-preview-inside-ui-view-beta
6+
7+
from objc_util import *
8+
import ui
9+
10+
class LiveCameraView(ui.View):
11+
def __init__(self,device=0, *args, **kwargs):
12+
ui.View.__init__(self,*args,**kwargs)
13+
self._session=ObjCClass('AVCaptureSession').alloc().init()
14+
self._session.setSessionPreset_('AVCaptureSessionPresetHigh');
15+
inputDevices=ObjCClass('AVCaptureDevice').devices()
16+
self._inputDevice=inputDevices[device]
17+
18+
deviceInput=ObjCClass('AVCaptureDeviceInput').deviceInputWithDevice_error_(self._inputDevice, None);
19+
if self._session.canAddInput_(deviceInput):
20+
self._session.addInput_(deviceInput)
21+
self._previewLayer=ObjCClass('AVCaptureVideoPreviewLayer').alloc().initWithSession_(self._session)
22+
self._previewLayer.setVideoGravity_(
23+
'AVLayerVideoGravityResizeAspectFill')
24+
rootLayer=ObjCInstance(self).layer()
25+
rootLayer.setMasksToBounds_(True)
26+
self._previewLayer.setFrame_(
27+
CGRect(CGPoint(-70, 0), CGSize(self.height,self.height)))
28+
rootLayer.insertSublayer_atIndex_(self._previewLayer,0)
29+
self._session.startRunning()
30+
def will_close(self):
31+
self._session.stopRunning()
32+
def layout(self):
33+
if not self._session.isRunning():
34+
self._session.startRunning()
35+
36+
rootview=LiveCameraView(frame=(0,0,576,576))
37+
rootview.present('sheet')
38+

math/random-math-view.py

+216
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
#!/usr/bin/env python2
2+
3+
# -*- coding: utf-8 -*-
4+
5+
# https://forum.omz-software.com/topic/3698/how-to-save-user-input-from-text-field-and-use-throughout-script-with-ui/3
6+
7+
""" Random Math View """
8+
9+
10+
import ui
11+
import random
12+
13+
14+
def eval_answer(sender):
15+
sender.superview["text_view"].text = sender.text
16+
17+
return sender.text
18+
19+
def the_views(s_t):
20+
21+
""" the view """
22+
23+
try:
24+
25+
#d = U+00F7
26+
27+
count = 0
28+
29+
me_font_20 = "Baskerville-BoldItalic", 20
30+
31+
me_font_30 = "Baskerville-BoldItalic", 30
32+
33+
me_font_80 = "Baskerville-BoldItalic", 80
34+
35+
my_views = ui.View()
36+
37+
my_views.name = "Rand Math"
38+
39+
my_views.border_width = 3
40+
41+
my_views.border_color = "maroon"
42+
my_views.background_color = "tan"
43+
44+
# Label A random math app
45+
46+
a_label = ui.Label()
47+
48+
a_label.border_width = 3
49+
50+
a_label.border_color = "tan"
51+
52+
a_label.background_color = "maroon"
53+
54+
a_label.frame = (0,0,325,50)
55+
56+
a_label.text = "Random Math App."
57+
58+
a_label.alignment = 50
59+
60+
a_label.font = me_font_30
61+
62+
# Label S how many equations to do
63+
64+
s_label = ui.TextField()
65+
66+
s_label.border_width = 3
67+
68+
s_label.border_color = "maroon"
69+
70+
s_label.background_color = "white"
71+
72+
s_label.frame = (0, 45, 325, 50)
73+
74+
s_label.text = "How many equations: "
75+
76+
s_label.alignment = 50
77+
78+
s_label.font = me_font_20
79+
80+
# Label B top set of numbers
81+
82+
b_label_rand = random.randint(0, 5)
83+
84+
str_b = str(b_label_rand)
85+
86+
b_label = ui.Label()
87+
88+
#b_label.border_width = 3
89+
90+
#b_label.border_color = "tan"
91+
92+
b_label.frame = (80, 150, 180, 90)
93+
94+
b_label.alignment = 50
95+
96+
b_label.font = me_font_80
97+
98+
b_label.text = str_b
99+
100+
# Label C bottom set of numbers
101+
102+
c_label_rand = random.randint(0, 5)
103+
104+
str_c = str(c_label_rand)
105+
106+
while b_label_rand < c_label_rand:
107+
108+
b_label_rand = b_label_rand + c_label_rand
109+
110+
c_label = ui.Label()
111+
112+
#c_label.border_width = 3
113+
114+
#c_label.border_color = "tan"
115+
116+
c_label.frame = (80, 235, 180, 90)
117+
118+
c_label.alignment = 50
119+
120+
c_label.font = me_font_80
121+
122+
c_label.text = str_c
123+
124+
# Label O math operator
125+
126+
o_label_rand = random.choice(["+", "-", "x", "/"])
127+
128+
str_o = str(o_label_rand)
129+
130+
o_label = ui.Label()
131+
132+
#o_label.border_width = 3
133+
134+
#o_label.border_color = "tan"
135+
136+
o_label.frame = (0, 235, 80, 90)
137+
138+
o_label.alignment = 50
139+
140+
o_label.font = me_font_80
141+
142+
o_label.text = str_o
143+
144+
# Label L underline
145+
146+
l_label = ui.Label()
147+
148+
#l_label.border_width = 3
149+
150+
#l_label.border_color = "tan"
151+
152+
l_label.frame = (0, 260, 319, 90)
153+
154+
l_label.alignment = 50
155+
156+
l_label.font = me_font_80
157+
158+
l_label.text = "______"
159+
160+
# TextField answer input
161+
162+
ans_text_field = ui.TextField()
163+
164+
ans_text_field.frame = (75, 340, 185, 90)
165+
ans_text_field.border_width = 3
166+
ans_text_field.border_color = "maroon"
167+
168+
ans_text_field.font = me_font_80
169+
ans_text_field.placeholder = "###"
170+
171+
172+
# just to check
173+
174+
ans_text_field.action = eval_answer
175+
176+
text_view = ui.TextView()
177+
178+
text_view.name = "text_view"
179+
180+
text_view.editable = False
181+
182+
text_view.frame = (0, 100, 90, 90)
183+
my_views.add_subview(text_view)
184+
185+
if eval_answer == 0:
186+
187+
my_views.background_color = "red"
188+
189+
# added subviews
190+
my_views.add_subview(a_label)
191+
my_views.add_subview(s_label)
192+
my_views.add_subview(b_label)
193+
my_views.add_subview(c_label)
194+
my_views.add_subview(o_label)
195+
my_views.add_subview(l_label)
196+
my_views.add_subview(ans_text_field)
197+
198+
# present sheet
199+
my_views.present("sheet")
200+
201+
except:
202+
203+
print "failed to load"
204+
205+
206+
def main():
207+
208+
""" run the view """
209+
210+
se_te = eval_answer
211+
212+
the_views(se_te)
213+
214+
if __name__ == "__main__":
215+
main()
216+

0 commit comments

Comments
 (0)