def list_dialog(title='', items=None, multiple=False, done_button_title='Done'): ''' copy of list_dialog from dialogs module, with themed mode, and with extra buttonitems to load and save history''' if not items: items = [] c = _ListDialogController(title, items, multiple, done_button_title=done_button_title) c.idxNew=0 #editor.apply_ui_theme(c.view,editor.get_theme_dict()['name']) save=ui.ButtonItem(title='Save') save.action=save_history load=ui.ButtonItem(title='Load') load.action=load_history copy=ui.ButtonItem(title='Copy') copy.action=copy_history searchField=ui.TextField() searchField.placeholder='Search' searchField.frame=(0,0,180,32) searchField.clear_button_mode='always' editor.apply_ui_theme(searchField) searchBarButton=ui.ButtonItem() ObjCInstance(searchBarButton).customView=searchField searchField.delegate=c.view.data_source c.view.right_button_items=[save,load,copy] c.view.left_button_items=[searchBarButton] editor.present_themed(c.view,editor.get_theme_dict()['name'],style='popover') c.view.wait_modal() return c.selected_item
def list_dialog(title='', items=None, multiple=False, done_button_title='Done'): ''' copy of list_dialog from dialogs module, with themed mode, and with extra buttonitems to load and save history''' if not items: items = [] c = _ListDialogController(title, items, multiple, done_button_title=done_button_title) c.idxNew = 0 #editor.apply_ui_theme(c.view,editor.get_theme_dict()['name']) save = ui.ButtonItem(title='Save') save.action = save_history load = ui.ButtonItem(title='Load') load.action = load_history copy = ui.ButtonItem(title='Copy') copy.action = copy_history searchField = ui.TextField() searchField.placeholder = 'Search' searchField.frame = (0, 0, 180, 32) searchField.clear_button_mode = 'always' editor.apply_ui_theme(searchField) searchBarButton = ui.ButtonItem() ObjCInstance(searchBarButton).customView = searchField searchField.delegate = c.view.data_source c.view.right_button_items = [save, load, copy] c.view.left_button_items = [searchBarButton] editor.present_themed(c.view, editor.get_theme_dict()['name'], style='popover') c.view.wait_modal() return c.selected_item
def date_picker(w, h, date=None, first_day_week=calendar.SUNDAY, style='sheet', animated=False, theme=None, modal=True): frame = (0, 0, w, h) cal = IJCalendar(frame=f, name='Select a date', date=date, first_day_week=first_day_week) editor.present_themed(cal, theme_name=theme, style=style, animated=animated, hide_title_bar=True) if modal: cal.wait_modal() return cal.date print('date_picker complete')
self.tone_slider.value = 0.5 self.tone_slider.action = self.set_frequency self.add_subview(self.tone_label) self.add_subview(self.tone_slider) def layout(self): _x, _y, _w, _h = self.frame self.tone_label.x = (_w / 2) - (self.tone_label.width / 2) self.tone_label.y = (_h / 3) self.tone_slider.width = sw = _w * 0.8 self.tone_slider.x = (_w / 2) - (sw / 2) self.tone_slider.y = _h / 2 def set_frequency(self, sender): self.instance.frequency = sender.value * 880 self.tone_label.text = f'{int(self.instance.frequency):03}' def will_close(self): self.py_audio.shutdown() view = View() editor.present_themed( view, theme_name='Theme09_Editorial', style='fullscreen', #hide_title_bar=True, orientations=['portrait'])
def take_screenshot(self): # take a screenshot of the ui.View.bounds with ui.ImageContext(self.width, self.height) as ctx: self.draw_snapshot() return ctx.get_image() if __name__ == '__main__': # initial theme theme = 'Cool Glow' # decode the pyui str pyui_str = pyui_decode(__pyui_str__) tv = ThemeViewer(theme=theme, pyui_str=pyui_str) editor.present_themed(tv, theme_name=theme, style='sheet', animated=False) # take a screen shot of the view, could be used to create thumbnail # images for example... img = tv.take_screenshot() # show the image in the console img.show() # write the snapshot to a png file bytes = img.to_png() with open(theme + '.png', 'wb') as file: file.write(bytes)
s.line_width = 10 ui.set_color('blue') s.stroke() class MyClass(ui.View): #def __init__(self, *args, **kwargs): #super().__init__(*args, **kwargs) def add_view(self, v): self.add_subview(v) # comment out either line below for 1 effect slide_up(self, v, reverse=False, delay = 3) slide_in(self, v, reverse=False, delay=.8) if __name__ == '__main__': _use_theme = True w, h = 540, 540 f = ui.Rect(0, 0, w, h) style='sheet' mc = MyClass(frame=f, bg_color='white') if not _use_theme: mc.present(style = style, animated=False) else: editor.present_themed(mc, theme_name='Oceanic', style=style, animated=False) mc2 = MyClass2(frame = f) mc.add_view(mc2)
if __name__ == '__main__': _use_theme = True w, h = 400, 400 f = (0, 0, w, h) ui_file = 'title_panel' style = 'sheet' animated = False mc = MyClass(ui_file, frame=f, bg_color='white') if not _use_theme: mc.name = 'No Theme' mc.present(style = style, animated=animated) else: theme = choice(_themes) mc.name = theme editor.present_themed(mc, theme_name=theme, style=style, animated=animated) ''' pf = ui.Rect(*mc.bounds.inset(20, 20)) pf.height = 150 v = Panel(ui_file, frame = pf ) v.add(mc) ''' ui_file = 'comp' pf = ui.Rect(*mc.bounds.inset(5, 5)) p = Combo(ui_file, frame = pf) p.add(mc) # --------------------
fill_tableview() #thought_bubble.text = instructions # This lambda function is what allows me to pass arguments to a view's action function. This function is what makes it all work. f = lambda sender: updates(sender, chapters.data_source, testaments) # Quick and dirty query to preload a tableview with an sqlite record. books.data_source.items = [ x[0] for x in sqlite3.connect('bible-sqlite.db').execute( 'select n from key_english') ] books.data_source.action = f #for v in top_pane.subviews: # print(v.action) #--- SPLASH #splash = ui.load_view_str(splash_view) #splash.multitouch_enabled=True #splash.present(hide_title_bar=True) #assembly=dialogs.list_dialog('Choose your Assembly',churches) #dialogs.alert('Welcome {}'.format(assembly)) #choose_file() # Display the bible witha hidden title bar and restrict its orientation to landscape. #bible.present(orientations=['landscape'],hide_title_bar=True) editor.apply_ui_theme(bible) editor.present_themed(bible)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) if __name__ == '__main__': _use_theme = True animated = False w, h = 600, 800 f = (0, 0, w, h) mc = MyClass(frame=f, bg_color='white') if not _use_theme: mc.present('sheet', animated=animated) else: editor.present_themed(mc, theme_name='Cool Glow', style='sheet', animated=False) r = ui.Rect(*mc.bounds).inset(20, 20) r.height = 100 delay = .3 x = choice([-1, 1, 0]) * mc.width y = choice([-1, 1, 0]) * mc.height for i in range(6): p = Panel(str(i),frame = r, bg_color=choice(_colors)) mc.add_subview(p) e(p,.5, delay * (i*(i * .3)), x, y) r.y = r.max_y + 20
return obj return Wrapper class PYUIViewer(ui.View): # this acts as a normal Custom ui.View class # the root view of the class is the pyui file read in def __init__(self, pyui_fn, *args, **kwargs): ui.load_view(pyui_fn, bindings={ 'MyClass': WrapInstance(self), 'self': self }) # call after so our kwargs modify attrs super().__init__(*args, **kwargs) if __name__ == '__main__': w, h = 600, 600 f = (0, 0, w, h) fn = 'icurr.pyui' # .pyui file name here style = 'sheet' theme = _themes['sd'] v = PYUIViewer(fn, frame=f) editor.present_themed(v, theme_name=theme, style=style, animated=True)
'Solarized Dark', 'Cool Glow', 'Gold', 'Tomorrow Night', 'Oceanic', 'Editorial'] def pyui_encode(pyui_filename): with open(pyui_filename, 'rb') as f: pyui = f.read() compressed = base64.b64encode(bz2.compress(pyui)).decode('utf-8') return '\n'.join(textwrap.wrap(compressed, 70)) def pyui_decode(str): s = bz2.decompress(base64.b64decode(str)) return s.decode('utf-8') def WrapInstance(obj): class Wrapper(obj.__class__): def __new__(cls): return obj return Wrapper class MyClass(ui.View): def __init__(self, str, *args, **kwargs): ui.load_view_str(str, bindings={'MyClass': WrapInstance(self), 'self': self}) super().__init__(*args, **kwargs) if __name__ == '__main__': for theme in _themes: mc = MyClass( pyui_decode(__the_view), name = theme) editor.present_themed(mc, theme_name=theme, style = 'sheet') mc.wait_modal()
if __name__ == '__main__': import console import ui import editor import dialogs items = [] for log in get_log(): items.append('{} - {}'.format(log['CFLog Local Time'], log['Message'])) log_text = '\n'.join(items) def share(sender): dialogs.share_text(log_text) theme = editor.get_theme_dict() view = ui.TextView() view.name = 'Pythonista System Log' view.text = log_text view.font = ('Menlo-Regular', 15) view.editable = False share_button = ui.ButtonItem(title='Share', action=share) view.right_button_items = [share_button] editor.present_themed(view)
ui_file = 'myui' style = 'sheet' animated = False theme = 'Oceanic' hide_title_bar = False mc = MYUIClass(ui_file, frame=f, bg_color='white') if not _use_theme: mc.present('sheet', animated=animated, hide_title_bar=hide_title_bar) else: mc.name = theme editor.present_themed(mc, theme_name=theme, style=style, animated=animated, hide_title_bar=hide_title_bar) # -------------------- import ui def mediaPicker_didPickMediaItems_(_self, _cmd, mediaPicker, mediaItemCollection): print '!!!', ObjCInstance(mediaPicker), ObjCInstance(mediaItemCollection) mediaPickerDelegate = create_objc_class( 'mediaPickerDelegate', methods=[mediaPicker_didPickMediaItems_],
# https://forum.omz-software.com/topic/4110/reading-pythonistas-apples-plist-file-format/2 import editor import ui import time class SomeUi(ui.View): def __init__(self): self.frame = (0, 0, 500, 470) self.table_view = ui.TableView(frame=(10, 10, 480, 400)) self.text_view = ui.TextField(frame=(10, 420, 480, 40)) self.add_subview(self.table_view) self.add_subview(self.text_view) editor.apply_ui_theme(self) def wait(dt=1.0): t = time.perf_counter() while time.perf_counter() - t < dt: pass op = SomeUi() op.present('sheet') wait(3) op.close() wait(1) editor.present_themed(op, style='sheet')
s = ui.Path.rect(*r) s.fill() if __name__ == '__main__': _use_theme = True w, h = 600, 600 f = (0, 0, w, h) name = 'Silly Demo' mc = MyClass(frame=f, bg_color='white', name=name) if not _use_theme: mc.present('sheet', animated=False) else: editor.present_themed(mc, theme_name='Oceanic', style='sheet', animated=False) # -------------------- btn = make_button(i, title=self._list[i]) btn.alpha = (1 + i) * (1 / len(self._list) ) # will go from 1/n to 1.0, where n = Len of list self.add_subview(btn) # -------------------- import editor import math import ui # this is a pretty funky function... def get_rotated_icon(named_icon_name, wh=32, degree=0): '''
return logs if __name__ == '__main__': import console import ui import editor import dialogs items = [] for log in get_log(): items.append('{} - {}'.format(log['CFLog Local Time'], log['Message'])) log_text = '\n'.join(items) def share(sender): dialogs.share_text(log_text) theme = editor.get_theme_dict() view = ui.TextView() view.name = 'Pythonista System Log' view.text = log_text view.font = ('Menlo-Regular', 15) view.editable = False share_button = ui.ButtonItem(title='Share', action=share) view.right_button_items = [share_button] editor.present_themed(view)
self.frequency_slider.action = self.set_frequency self.add_subview(self.frequency_label) self.add_subview(self.frequency_slider) def layout(self): _x, _y, _w, _h = self.frame self.frequency_label.x = (_w / 2) - (self.frequency_label.width / 2) self.frequency_label.y = (_h / 3) self.frequency_slider.width = sw = _w * 0.92 self.frequency_slider.x = (_w / 2) - (sw / 2) self.frequency_slider.y = (_h / 2) - (self.frequency_slider.height / 2) def set_frequency(self, sender): self.instance.frequency = sender.value * 880 self.frequency_label.text = f'{int(self.instance.frequency):03}' @ui.in_background def will_close(self): self.instance.buffer = [-1] *self.segment self.py_audio.shutdown() view = View() editor.present_themed( view, theme_name='Theme09_Editorial', style='fullscreen', orientations=['portrait'])
# in a way, ignore the above. just subclass BaseViewClass.. # can be a lot better, just a idea # ios has some well defined views, to composite a interface. class StdClass(BaseViewClass): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.cv.bg_color = 'deeppink' if __name__ == '__main__': # some switches here, for testing _use_theme = False w, h = 600, 800 f = (0, 0, w, h) style = 'sheet' style = 'panel' style = 'full_screen' # hide_title_bar _htb = False mc = StdClass(frame=f, bg_color='white') if not _use_theme: mc.present(style = style, animated=False, hide_title_bar = _htb) else: editor.present_themed(mc, theme_name='Oceanic', style=style, animated=False, hide_title_bar = _htb) # --------------------