Look at the stopwatch1.py and stopwatch1.pyui example in the following GitHub repository. May be this is what you are looking for.
https://github.com/encela95dus/ios_pythonista_examples
Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Best posts made by enceladus
-
RE: Pythonista Countdown on button with .pyui
-
RE: Examples for dialogs.form_dialog() ?
You could have footer also in the sections
import dialogs import datetime form_list_of_sections = [] sectionA_dicts = [] sectionA_dicts.append(dict(type = 'text', title = 'First Name', key = 'first', placeholder = 'John')) sectionA_dicts.append(dict(type = 'text', title = 'Last Name', key = 'last', placeholder = 'Doe')) sectionA_dicts.append(dict(type = 'number', title = 'age', key = 'age', placeholder='30')) form_list_of_sections.append(('Section A', sectionA_dicts, 'Section A ends')) sectionB_dicts = [] sectionB_dicts.append(dict(type = 'date', title = 'Date Of Birth', key = 'DOB', value = datetime.date.today())) sectionB_dicts.append(dict(type = 'url', title = 'Home Page', key = 'homepage', placeholder = 'http://example.com')) form_list_of_sections.append(('Section B', sectionB_dicts, 'Section B ends')) sectionC_dicts = [] sectionC_dicts.append(dict(type = 'email', title = 'email', key = 'email', placeholder = 'name@mailserver.com')) sectionC_dicts.append(dict(type = 'switch', title = 'is_married', key = 'is_married', value = True)) sectionC_dicts.append(dict(type = 'check', title = 'is_registered', key = 'is_registered', value = False)) form_list_of_sections.append(('Section C', sectionC_dicts, 'Section C ends')) diag = dialogs.form_dialog(title = 'Form Dialog', sections=form_list_of_sections) print(diag)
-
RE: Analog Clock Example to ui Example - help
Here is the code displaying four analog clocks (no scene functions, pure ui)
import ui from math import pi, sin, cos from datetime import datetime LabelNode = ui.Label SpriteNode = ui.ImageView class ShapeNode(ui.View): def __init__(self, path=None, fill_color='white', stroke_color='clear', shadow=None, *args, **kwargs): self.path = path self.fill_color = fill_color self.stroke_color = stroke_color super().__init__(*args, **kwargs) def draw(self): ui.set_color(self.fill_color) self.path.fill() ui.set_color(self.stroke_color) self.path.stroke() class AnalogClock(ui.View): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) center_x, center_y = self.center self.w1 = min(self.height, self.width) center_x, center_y = (self.w1/2, self.w1/2) r = (self.w1/2) * 0.9 #print(r) circle = ui.Path.oval(0, 0, r*2, r*2) circle.line_width = 6 shadow = ('black', 0, 0, 15) frame = (center_x -r, center_y - r, 2*r, 2*r) self.face = ShapeNode(circle, 'white', 'silver', shadow=shadow, frame=frame ) self.add_subview(self.face) for i in range(12): a = 2 * pi * (i+1)/12.0 -pi/2 label = LabelNode(text='{:2d}'.format(i+1), font=('HelveticaNeue-UltraLight', 0.2*r), text_color='black', frame=(cos(a)*(r*0.85)+center_x-.1*r, sin(a)*(r*0.85)+center_y-r*.85, 2*r*.85, 2*r*.85)) self.add_subview(label) self.hands = [] self.update_interval = .1 hand_attrs = [(r*0.6, 8, 'black'), (r*0.9, 8, 'black'), (r*0.9, 4, 'red')] for l, w, color in hand_attrs: shape = ShapeNode(ui.Path.rounded_rect(l-w/2, 0, w, l, w/2), color, frame=(center_x-l, center_y-l, 2*l, 2*l)) #shape.anchor_point = (0.5, 0) self.hands.append(shape) self.add_subview(shape) self.add_subview(ShapeNode(ui.Path.oval(0, 0, 15, 15), 'black', frame=(center_x-7.5, center_y-7.5, 15, 15))) def update(self): t = datetime.now() tick = 2 * pi / 60.0 seconds = t.second + t.microsecond/1000000.0 minutes = t.minute + seconds/60.0 hours = (t.hour % 12) + minutes/60.0 self.hands[0].transform = ui.Transform.rotation(5 * tick * hours) self.hands[1].transform = ui.Transform.rotation(tick * minutes) self.hands[2].transform = ui.Transform.rotation(tick * seconds) v = ui.View(frame=(0,0,600,600)) v1 = AnalogClock(frame=(0,0,200,200)) v2 = AnalogClock(frame=(0,300,200,200)) v3 = AnalogClock(frame=(300,0,200,200)) v4 = AnalogClock(frame=(300,300,200,200)) v.add_subview(v1) v.add_subview(v2) v.add_subview(v3) v.add_subview(v4) v.present('sheet')
With timezone code
https://gist.github.com/19e99d748397855003afdebf32dafc3a -
RE: Polling from a ui.View (built in timers in ui.Views)
You can also use async module timer
import ui import asyncio from time import localtime class DigitalClock(ui.View): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def draw(self): t = localtime() ui.draw_string("{:02}:{:02}:{:02}".format( t.tm_hour, t.tm_min, t.tm_sec), font=('Helvetica', 20), rect=(100, 100,0,0), alignment=ui.ALIGN_CENTER) def update(self, event_loop): self.set_needs_display() event_loop.call_later(.5, self.update, event_loop) v = DigitalClock(frame=(0,0,300, 300), frame_interval=10) v.present('sheet') event_loop = asyncio.get_event_loop() event_loop.call_soon(v.update, event_loop) event_loop.run_forever()
Stop watch example (use the stopwatch.pyui from gist link in previous post)
import ui import asyncio class StopWatch(ui.View): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.value = 0 self.state = 'stop' def draw(self): t0 = (self.value//(600*60), self.value//600, self.value//10) t1 = (t0[0], t0[1]%60, t0[2]%60) ui.draw_string("{:02}:{:02}:{:02}".format(*t1), font=('Helvetica', 20), rect=(150, 0, 0, 0), color='black', alignment=ui.ALIGN_CENTER) def update(self, event_loop): if self.state == 'run': self.value += 1 self.set_needs_display() event_loop.call_later(.1, self.update, event_loop) def button_action(sender): v1 = sender.superview['view1'] if sender.title == 'Reset': v1.value = 0 v1.state = 'stop' elif sender.title == 'Start': v1.value = 0 v1.state = 'run' elif sender.title == 'Stop': v1.state = 'stop' v = ui.load_view() v.present('sheet') event_loop = asyncio.get_event_loop() event_loop.call_soon(v['view1'].update, event_loop) event_loop.run_forever()
-
RE: Scene help
https://github.com/encela95dus/ios_pythonista_examples contains some scene examples including the game pong
(look at the scene section of the readme ).From readme:
scene examples
animation examples in examples directory
games examples in examples directory
basic_nodes.py
change_attributes.py
change_positions.py
update_example.py
scene_action1,2,3
textanimation.py
textanimation_wayy.py
scene_viewexample.py - scene embedded in a view
digital_watch.py, stop_watch.py - more examples on update
action_based_timer.py
animations from forum
planet motion https://forum.omz-software.com/topic/3754/show-all-scene-child-nodes
pendulum motion https://forum.omz-software.com/topic/3312/labelsprite-rotate_by-problem
https://forum.omz-software.com/topic/4284/how-do-i-make-a-full-screen-button-and-handle-button-down-and-button-up-events/6
games from forum
pong https://forum.omz-software.com/topic/3367/drawing-with-pythonistas-modules
cards https://forum.omz-software.com/topic/4856/can-someone-turn-this-script-into-a-node-tutorial-please
word game https://forum.omz-software.com/topic/4790/boggle-app-need-help-changing-labels-3x-in-a-function/9
shader
shader_example1.py - basic example to run shaders
template_shadertoy.py - template to run shadertoy examples
https://www.shadertoy.com/ contains a large collection of shader examples
from forum
an introductory online book on shaders to learn shaders
https://thebookofshaders.com/
https://forum.omz-software.com/topic/3274/fast-color-change-animation-of-a-shape -
RE: Text input in a <Scene> based Game
You could also use dialogs.
def touch_began(self, touch): if touch.location[1] > (ui.get_screen_size()[1]-50): global MESSAGE MESSAGE = dialogs.text_dialog('enter text', text='') self.letter_index = 0 return if self.instructions: self.instructions.run_action(Action.fade_to(0, 1)) self.instructions = None self.prev_touch = touch.location
-
RE: Interactive test
Here is an example implementation and I hope it helps
https://gist.github.com/4e520ac2104b902b7a2394d4e7855fa3 -
RE: It has been 9 months since the latest version
@reticulated have you seen this post?
https://forum.omz-software.com/topic/2747/python-3-x-progress-update/148from @omz: That's very kind of you, but I really wouldn't feel comfortable taking donations. Pythonista is doing quite well, actually – over the last 3 years, I've managed to convince an average of 50 people every day to buy the app, and as a solo developer without a lot of expenses, I think that's pretty good. :) There are a lot of projects that need donations much more than I do.
from @Olaf : wow, 3 * 365 * 50 > 50,000 Pythonistas, that's quite a global tribe! -
RE: Find consecutive elements in a list
def hasdupelems(l): return len(l) != len(set(l)) print(hasdupelems(['ab', 'cd', 'ab', 'ef'])) print(hasdupelems(['ab', 'cd', 'ef']))
-
RE: Saving painted image as matrix
You can use designer. See
https://gist.github.com/8f81907e4844d579ef8eda2ed5d65d5e -
RE: Filling tableView gradually
You can also use update
import ui def table_tapped(sender): rowtext = sender.items[sender.selected_row] print(rowtext) class TableUpdate(ui.View): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.reset_value = 2 self.stop_value = 20 self.value = self.reset_value self.state = 'stop' self.update_interval = 1 self.add_subview(ui.TableView(name='tableview1', frame=(0,0,400,400))) self.reset_table_view() self.add_subview(ui.Button(title='Reset', frame=(50,450,100,100), action=button_action)) self.add_subview(ui.Button(title='Start', frame=(160,450,100,100), action=button_action)) self.add_subview(ui.Button(title='Stop', frame=(270,450,100,100), action=button_action)) def reset_table_view(self): self.value = self.reset_value self.update_table_view() def update_table_view(self): self['tableview1'].data_source = ui.ListDataSource(range(self.value)) self['tableview1'].data_source.action = table_tapped self['tableview1'].delegate = self['tableview1'].data_source self['tableview1'].reload_data() def update(self): if self.state == 'run': if self.value < self.stop_value: self['tableview1'].data_source.items.append(self.value) self['tableview1'].reload_data() self.value += 1 self.set_needs_display() def button_action(sender): v1 = sender.superview if sender.title == 'Reset': v1.state = 'stop' v1.reset_table_view() elif sender.title == 'Start': v1.state = 'run' elif sender.title == 'Stop': v1.state = 'stop' v = TableUpdate(frame=(0,0,400,500), name='view1') v.present('sheet')
-
RE: How can i pass data between different scenes and/or ui views
Look at the brickbreaker example in examples/games folder (BrickBraker.py in Examples/Games). It uses 'pause and present_modal_scene for displaying menu and I hope it will be useful in understanding . (BTW, you can also use global variables to pass data.)
-
RE: Cross-platform GUI library using WebKit
I am not sure whether it is relevant or useful. Anyway here is a small example that I tried.
https://gist.github.com/encela95dus/3b672b4119b598064d2c943158fabaad -
RE: Cross-platform GUI library using WebKit
I have not tried but may be worth looking at:
https://github.com/dddomodossola/remi -
RE: How can i use latex in pyui TextView
You can use webview and mathjax to display latex. Here is an example to display matrix.
https://gist.github.com/5eee7b48ea86f6ef8edc24c276df9d1a -
RE: Scripter - Pythonista UI animation framework built on ui.View.update()
current_func = lambda s,t,d:s+curve_sinodial(t)*d should work (I am outside and I will post the proper working code later.)
-
RE: Viewing Definitions
Look at the Animation class in the scene_drawing.py. Action implementation is similar to that. (Scene_drawing.py is the old implementation . It is there mainly for compatibility with old scene code)
-
RE: Viewing Definitions
You can not add extra parameters to custom_action but you can put the desired information in the node. In the example, initial_position is the information passed to custom_action.