omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular
    1. Home
    2. enceladus

    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.


    • Profile
    • Following 0
    • Followers 1
    • Topics 1
    • Posts 110
    • Best 25
    • Controversial 0
    • Groups 0

    enceladus

    @enceladus

    29
    Reputation
    2308
    Profile views
    110
    Posts
    1
    Followers
    0
    Following
    Joined Last Online

    enceladus Unfollow Follow

    Best posts made by enceladus

    • RE: Pythonista Countdown on button with .pyui

      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

      posted in Pythonista
      enceladus
      enceladus
    • 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)
      
      posted in Pythonista
      enceladus
      enceladus
    • 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

      posted in Pythonista
      enceladus
      enceladus
    • 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()       
      
      
      
      posted in Pythonista
      enceladus
      enceladus
    • 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

      posted in Pythonista
      enceladus
      enceladus
    • 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
      
      posted in Pythonista
      enceladus
      enceladus
    • RE: Interactive test

      Here is an example implementation and I hope it helps
      https://gist.github.com/4e520ac2104b902b7a2394d4e7855fa3

      posted in Pythonista
      enceladus
      enceladus
    • 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/148

      from @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!

      posted in Pythonista
      enceladus
      enceladus
    • 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']))
      
      posted in Pythonista
      enceladus
      enceladus
    • RE: Adding characters to strings
      word = 'python'
      print('*'.join(word))
      
      posted in Pythonista
      enceladus
      enceladus

    Latest posts made by enceladus

    • RE: Button that will cycle through SQLite records

      You can look at some examples of dialogs and tableview here.
      https://github.com/encela95dus/ios_pythonista_examples

      posted in Pythonista
      enceladus
      enceladus
    • RE: Please tell me about ‘tableview’ and ‘Navigation View’

      You can look at some examples of navigation view and tableview here.
      https://github.com/encela95dus/ios_pythonista_examples

      posted in Pythonista
      enceladus
      enceladus
    • RE: Random x and y coordinates

      Look at the following scene action examples in
      https://github.com/encela95dus/ios_pythonista_examples

      From readme
      scene_action1,2,3.py
      textanimation.py
      textanimation_wayy.py

      posted in Pythonista
      enceladus
      enceladus
    • RE: Pythonista Countdown on button with .pyui

      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

      posted in Pythonista
      enceladus
      enceladus
    • RE: I need help

      See lorem_generator.py in https://github.com/encela95dus/ios_pythonista_examples. It is based omz's example code in editorial Also look at basic_ui_elements.py.

      posted in Pythonista
      enceladus
      enceladus
    • 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

      posted in Pythonista
      enceladus
      enceladus
    • RE: Need Help With Scene 2d and Buttons

      https://github.com/encela95dus/ios_pythonista_examples contains some scene examples (look at the scene section of the readme ).

      posted in Pythonista
      enceladus
      enceladus
    • RE: Simple demo of tableview logic for the novices

      Do you need something like this? It uses dialog but table example would be similar to that.

      import dialogs
      
      def multiple_selection_list_dialog(lst):
          form_list_of_dicts = []
          for item in lst:
              form_list_of_dicts.append(dict(type = 'check', title = item,
                  key = item, value = False))  
          result = dialogs.form_dialog(title = 'Multiple Selection List', fields=form_list_of_dicts) 
          return [i for i in result if result[i]] if result else None
      
      if __name__ == '__main__':
          lst = ['a'+str(i) for i in range(5)]
          print(multiple_selection_list_dialog(lst))
      
      posted in Pythonista
      enceladus
      enceladus
    • RE: Simple demo of tableview logic for the novices

      The following url has few examples and hope it helps.
      https://github.com/encela95dus/ios_pythonista_examples

      table_example1,2,3,4 - tableview examples
      from forum
      file navigation https://github.com/dgelessus/filenav/blob/master/litenav.py
      fill rows based on the characters that are entered on textfield
      https://forum.omz-software.com/topic/4328/modules-of-pythonista-displayed-with-help

      posted in Pythonista
      enceladus
      enceladus
    • RE: Properties that are more fun

      Using property to update variable in CustomView. (Position in GUI and equivalent value)
      https://gist.github.com/33f06c4f1c439849be7736f897b0c6b0

      posted in Pythonista
      enceladus
      enceladus