omz:forum

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

    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 0
    • Topics 3
    • Posts 132
    • Best 23
    • Controversial 0
    • Groups 0

    abcabc

    @abcabc

    31
    Reputation
    2779
    Profile views
    132
    Posts
    0
    Followers
    0
    Following
    Joined Last Online
    Website github.com/balachandrana

    abcabc Unfollow Follow

    Best posts made by abcabc

    • RE: UniPAGe as a bridge between Kivy and Pythonista

      Nice. Here is a slightly different approach.

      1. Rather than using new set of API, pythonista API is used as standard. For example, "example1.py" (modified example of yours) runs directly in pythonista (currently it requires one line change from kivy code)
      2. In Kivy, you need an extra file "ui.py". All the code is in this file. It is just a wrapper on kivy objects.
      3. This code is not complete and a lot needs to be done.

      example1.py

      import ui
      
      def closepage(sender):
          v.close()
      
      def function_1(sender):
          v['label1'].text = 'Oh! You clicked my button.'
      
      #uncomment or comment lines below based on platform
      #v = ui.MainView(frame=(0, 0, 600, 450)) # kivy
      v = ui.View(frame=(0, 0, 600, 450)) # pythonista
      
      v.add_subview(ui.Label(frame=(80, 10, 240, 20), 
                              name='label1',
                              text='Hey I am just a simple label.'))
      v.add_subview(ui.Button(frame=(40, 40, 100, 40), 
                              title='Click me', 
                              action=function_1))
      v.add_subview(ui.Button(frame=(460, 40, 100, 40),
                              title='Close me', 
                              action=closepage))
      v.add_subview(ui.TextField(frame=(40, 120, 300, 40),
                               name='textfield1',
                               text='I am a text field'))
      v.add_subview(ui.ImageView(frame=(460, 310, 100, 100),
                                  image=ui.Image('insidelogo.png')))
                                  
      v.present('sheet')
      
      

      ui.py

      from kivy.uix.floatlayout import FloatLayout
      from kivy.core.window import Window
      from kivy.base import runTouchApp
      from kivy.utils import platform as core_platform
      import sys
      
      from kivy.uix.label import Label as KivyLabel
      from kivy.uix.button import Button as KivyButton 
      from kivy.uix.textinput import TextInput
      from kivy.uix.image import Image as KivyImage
         
      from kivy.graphics import Color
      from kivy.graphics import Rectangle
      
      class View(object):
          screen_size = (800, 600)
          xratio = screen_size[0] / 800.0
          yratio = screen_size[1] / 600.0
          def __init__(self, frame=(0,0,100,100),
                      name=''):
              self.frame = frame
              self.name = name
              self.superview = None
              self.uniobject = None
              self.rootdict = {}
      
      class MainView(View):
          def __init__(self, frame=(0,0,100,100), name=''):
              super().__init__(frame=frame, name=name)
              self.root = FloatLayout()
              Window.size = View.screen_size
              self.root.canvas.add(
                 Color(1.0, 1.0, 1.0))
              self.root.canvas.add(
                Rectangle(pos = (self.frame[0] * View.xratio,
                      self.frame[1]*View.yratio), 
                      size = (frame[2] * View.xratio, 
                             frame[3] * View.yratio)))
      
          def add_subview(self, v):
              v.superview = self
              if v.name:
                  self.rootdict[v.name] = v.kivyobject
              self.root.add_widget(v.kivyobject)
      
          def __getitem__(self, key):
             return self.rootdict[key]
      
          def close(self):
              if core_platform == 'android':
                  sys.exit()
              else:
                  Window.close()
      
          def present(self, style):
              #todo: screen size, style
              runTouchApp(self.root)
                  
      class Button(View):
          def __init__(self, frame=(0,0,100,100),
                          title='',
                          name='',
                          font=('Helvetica', 20),
                          action=None):
              super().__init__(frame=frame, name=name)
              self.kivyobject = (KivyButton(text=title,
                  size_hint_y = None,
                  size_hint_x = None,
                  width = self.frame[2]* View.xratio,
                  height = self.frame[3]* View.yratio,
                  pos = (self.frame[0] * View.xratio, 
                         self.frame[1] * View.yratio),
                  on_press = action))
                               
      class Label(View):
          def __init__(self, frame=(0,0,100,100),
                          text='',
                          alignment='',
                          name='',
                          font=('Helvetica', 20),
                          text_color='blue'):
              super().__init__(frame=frame, name=name)
              label = KivyLabel(text=text,
                  id=name,
                  size_hint=(1.0, 1.9),
                  halign="left", 
                  valign="bottom",
                  pos = (self.frame[0] * View.xratio,
                         self.frame[1] * View.yratio))
              #label.bind(size=label.setter('text_size'))
              self.kivyobject = (label)
      
      class TextField(View):
          def __init__(self,
                frame=(0,0,100,100),
                text='',
                name='',
                font=('Helvetica', 20),
                alignment='',
                text_color='blue'):
                #action=None):
              super().__init__(frame=frame, name=name)
              self.kivyobject = (TextInput(text=text,
                  size_hint_y = None,
                  size_hint_x = None,
                  height = self.frame[3]* View.yratio,
                  width = self.frame[2]* View.xratio,
                  multiline = True,
                  pos = (self.frame[0] * View.xratio, 
                      self.frame[1] * View.yratio)))
                  #on_press = action))
      
        
      class ImageView(View):
          def __init__(self,
                 frame=(0,0,100,100),
                 name='',
                 image=None):
              super().__init__(frame=frame, name=name)
              if image:
                  image_source = image.source
              else:
                  image_source = None
              self.kivyobject = (
                KivyImage(source=image_source,
                  allow_stretch = True,
                  size = (self.frame[2]* View.xratio,
                          self.frame[3]* View.yratio),
                  pos = (self.frame[0] * View.xratio, 
                          self.frame[1] * View.yratio)))
      
      class Image(object):
          def __init__(self, source):
              self.source = source
      

      Copy of the code in gist.
      https://gist.github.com/balachandrana/4e9accfc894785682f230c54dc5da816#file-ui-py

      posted in Pythonista
      abcabc
      abcabc
    • RE: How do I transfer code, such as PC to IPad?

      It is mainly due to Apple's restrictions such a utility is not built-in. I use the following simple steps to do the transfer.

      1. Save to gist

        From the file navigation panel (script library - left side of editor panel), you can select multiple files (including .pyui files) and tap the share sheet icon at the bottom to save it to gist. You can save it as anonymous if you do not have gist account. The url will be available in clipboard and you can either store the url in a file using 'paste' or you can use the following script (stored as editor action) to mail the url to your friends.

      import dialogs, clipboard
      dialogs.share_text(clipboard.get())  
      
      1. Get from gist

        Open the gist url in safari and run the share script savefile (utility from JonB). It will get all the files in gist and store them in the predefined directory.

        You can get the share script by running the folowing script.

      import requests as r
      with open('savefile.py', 'w', encoding='utf-8') as f:
          f.write(r.get('https://gist.githubusercontent.com/jsbain/fcb3f42932dde9b0ff6c122893d1b230/raw/ab19fcd73598b829413da4c487bf5896b7cddeb0/savefile.py').text)
      
      posted in Pythonista
      abcabc
      abcabc
    • RE: Pythonista edit mode very very slow with a big script?

      I am not sure if this helps. Anyway here are some suggestions.

      1. Try edit.py in stash
      2. convert to .txt extension, edit and then convert back to .py.
      3. If you have large blocks of data, move them to separate file and use ast.literal_eval or json.
      4. If you do not have globals inside the functions, it may be very easy to move them to other files (from file1 import * should work)
      5. If you have global variables, try to encapsulate them in classes/
      posted in Pythonista
      abcabc
      abcabc
    • RE: How to install networkx (or any other package)

      I did the following steps to install networkx.

      1. In stash, I did "pip install networkx"
      2. networkx got installed but it gave error in installing "decorator"
      3. I tried installing "decorator" module separately ('pip install decorator"), it failed again.
      4. I copied decorator.py from the following url to site-packages
        https://github.com/micheles/decorator/tree/master/src

      5, I tried the following basic example and it worked.
      http://networkx.github.io/documentation/development/examples/basic/properties.html

      posted in Pythonista
      abcabc
      abcabc
    • RE: ui.TableViewCell.detail_text_label not working

      Searching "ui.TableViewCell.detail_text_label site:forum.omz-software.com" on google gives the desired result. Google search with site: operator gives better results than searching directly on the forum .

      posted in Pythonista
      abcabc
      abcabc
    • Recording scene programs as an animated gif image

      Here is the code to record scene programs as an animated gif image.
      https://github.com/balachandrana/animating_gif_in_pythonista_scene/blob/master/record_pythonista__scene_as_gif.py

      The program calls "draw_snapshot" method of SceneView to take snapshots of the node at each update call and coverts them to a gif file using images2gif module. Creating gif file is performed in a background thread and hence it does not affect the performance. The "draw_snapshot" method is very costly and it slows down the frame rate considerably. It may not be ok for recording games but for creating animated scenes particularly with shader could be useful. May be there is a faster way to capture data using objc_util. (Note that codea has a facility to record games.)

      There has been discussion before on this.

      1. https://forum.omz-software.com/topic/2185/image-from-scene
      2. https://forum.omz-software.com/topic/1523/controlling-screenshots

      The code works only with 2.7. images2gif module gives problem with 3.5.
      I hope this is useful.

      posted in Pythonista
      abcabc
      abcabc
    • RE: Using a ShapeNode instead of SpriteNode

      "init " method is not called properly. Here is some sample code that illustrates use of ShapeNode. Note that this works with python 3 and for working with python 2.7 you need to call super differently (super(Ball, self))

      import scene, ui
      
      class Coin(scene.SpriteNode):
          def __init__(self, **kwargs):        
              super().__init__('emj:Snowflake', **kwargs)
      
      class Ball(scene.ShapeNode):
          def __init__(self, **kwargs):        
              circle = ui.Path.oval (0, 0, 20, 20)                
              super().__init__(circle, fill_color='red', stroke_color='clear', shadow=None, **kwargs)   
                  
      class Polygon(scene.ShapeNode):
          def __init__(self, **kwargs): 
              path = ui.Path()
              path.line_width = 5
              path.move_to(0, 0)
              path.line_to(200, 0)
              path.line_to(100, 100)
              path.close() 
              super().__init__(path, **kwargs)  
                         
      class MyScene(scene.Scene):
          def setup(self):
              self.ball = Ball(position=(200, 100), parent=self)
              self.coin = Coin(position=(200, 200), parent=self)
              self.triangle1 = Polygon(fill_color='skyblue', stroke_color='green',
                                  position=(200, 400), parent=self)
              self.triangle2 = Polygon(fill_color='red', stroke_color='green',
                                  position=(200, 300), parent=self)
                              
      scene.run(MyScene())
      
      
      posted in Pythonista
      abcabc
      abcabc
    • RE: MySQL in pythonista

      Try the following in stash

      git clone https://github.com/tommasoturchi/mysql-connector-pythonista.git

      posted in Pythonista
      abcabc
      abcabc
    • RE: Can I still build editor tools with sidebars or popovers?

      Or You can use panel in "sidebar" mode. See the discussions here.
      https://forum.omz-software.com/topic/2692/ui-views-can-still-be-presented-in-sidebar-mode-in-pythonista-2-0-sort-of
      https://forum.omz-software.com/topic/3538/a-request-for-jonb

      posted in Pythonista
      abcabc
      abcabc
    • RE: How to stop Scene

      use self.view.close()

      import scene, ui
      
      class MyScene(scene.Scene):
          def setup(self):
              self.test_label = scene.LabelNode('Hello World', 
                  position=self.size/2.0, parent=self)
              self.close_label = scene.LabelNode('Close scene',
                  position=(self.size[0]/2, self.size[1]/2-100),
                  parent=self)
                  
          def touch_began(self, touch):
              if touch.location in self.close_label.frame:
                  self.view.close()
                 
      scene.run(MyScene())
      
      
      posted in Pythonista
      abcabc
      abcabc

    Latest posts made by abcabc

    • RE: UniPAGe as a bridge between Kivy and Pythonista

      I will put it in a github repo with MIT license after two/three weeks ( Need to do some cleanup, add some more features, add few more
      examples)

      posted in Pythonista
      abcabc
      abcabc
    • RE: UniPAGe as a bridge between Kivy and Pythonista

      Did you try my code on mac or PC? (I have tested on PC ,(windows 10, kivy 1.9.1, python 3.6) it works fine.)

      posted in Pythonista
      abcabc
      abcabc
    • RE: How to use ui.TableView

      Look at this
      https://github.com/dgelessus/filenav/blob/master/litenav.py

      posted in Pythonista
      abcabc
      abcabc
    • RE: UniPAGe as a bridge between Kivy and Pythonista

      I am sorry if I hurt your feelings. I thought that this code will help somebody like me who is familiar with pythonista but not with kivy. I just spent two to three hours to code this. I do not have any projects related to this and I am not associated with any company. I am a retired old man and my only intention is to help others. Once again I am sorry if I hurt your feelings.

      posted in Pythonista
      abcabc
      abcabc
    • RE: UniPAGe as a bridge between Kivy and Pythonista

      Nice. Here is a slightly different approach.

      1. Rather than using new set of API, pythonista API is used as standard. For example, "example1.py" (modified example of yours) runs directly in pythonista (currently it requires one line change from kivy code)
      2. In Kivy, you need an extra file "ui.py". All the code is in this file. It is just a wrapper on kivy objects.
      3. This code is not complete and a lot needs to be done.

      example1.py

      import ui
      
      def closepage(sender):
          v.close()
      
      def function_1(sender):
          v['label1'].text = 'Oh! You clicked my button.'
      
      #uncomment or comment lines below based on platform
      #v = ui.MainView(frame=(0, 0, 600, 450)) # kivy
      v = ui.View(frame=(0, 0, 600, 450)) # pythonista
      
      v.add_subview(ui.Label(frame=(80, 10, 240, 20), 
                              name='label1',
                              text='Hey I am just a simple label.'))
      v.add_subview(ui.Button(frame=(40, 40, 100, 40), 
                              title='Click me', 
                              action=function_1))
      v.add_subview(ui.Button(frame=(460, 40, 100, 40),
                              title='Close me', 
                              action=closepage))
      v.add_subview(ui.TextField(frame=(40, 120, 300, 40),
                               name='textfield1',
                               text='I am a text field'))
      v.add_subview(ui.ImageView(frame=(460, 310, 100, 100),
                                  image=ui.Image('insidelogo.png')))
                                  
      v.present('sheet')
      
      

      ui.py

      from kivy.uix.floatlayout import FloatLayout
      from kivy.core.window import Window
      from kivy.base import runTouchApp
      from kivy.utils import platform as core_platform
      import sys
      
      from kivy.uix.label import Label as KivyLabel
      from kivy.uix.button import Button as KivyButton 
      from kivy.uix.textinput import TextInput
      from kivy.uix.image import Image as KivyImage
         
      from kivy.graphics import Color
      from kivy.graphics import Rectangle
      
      class View(object):
          screen_size = (800, 600)
          xratio = screen_size[0] / 800.0
          yratio = screen_size[1] / 600.0
          def __init__(self, frame=(0,0,100,100),
                      name=''):
              self.frame = frame
              self.name = name
              self.superview = None
              self.uniobject = None
              self.rootdict = {}
      
      class MainView(View):
          def __init__(self, frame=(0,0,100,100), name=''):
              super().__init__(frame=frame, name=name)
              self.root = FloatLayout()
              Window.size = View.screen_size
              self.root.canvas.add(
                 Color(1.0, 1.0, 1.0))
              self.root.canvas.add(
                Rectangle(pos = (self.frame[0] * View.xratio,
                      self.frame[1]*View.yratio), 
                      size = (frame[2] * View.xratio, 
                             frame[3] * View.yratio)))
      
          def add_subview(self, v):
              v.superview = self
              if v.name:
                  self.rootdict[v.name] = v.kivyobject
              self.root.add_widget(v.kivyobject)
      
          def __getitem__(self, key):
             return self.rootdict[key]
      
          def close(self):
              if core_platform == 'android':
                  sys.exit()
              else:
                  Window.close()
      
          def present(self, style):
              #todo: screen size, style
              runTouchApp(self.root)
                  
      class Button(View):
          def __init__(self, frame=(0,0,100,100),
                          title='',
                          name='',
                          font=('Helvetica', 20),
                          action=None):
              super().__init__(frame=frame, name=name)
              self.kivyobject = (KivyButton(text=title,
                  size_hint_y = None,
                  size_hint_x = None,
                  width = self.frame[2]* View.xratio,
                  height = self.frame[3]* View.yratio,
                  pos = (self.frame[0] * View.xratio, 
                         self.frame[1] * View.yratio),
                  on_press = action))
                               
      class Label(View):
          def __init__(self, frame=(0,0,100,100),
                          text='',
                          alignment='',
                          name='',
                          font=('Helvetica', 20),
                          text_color='blue'):
              super().__init__(frame=frame, name=name)
              label = KivyLabel(text=text,
                  id=name,
                  size_hint=(1.0, 1.9),
                  halign="left", 
                  valign="bottom",
                  pos = (self.frame[0] * View.xratio,
                         self.frame[1] * View.yratio))
              #label.bind(size=label.setter('text_size'))
              self.kivyobject = (label)
      
      class TextField(View):
          def __init__(self,
                frame=(0,0,100,100),
                text='',
                name='',
                font=('Helvetica', 20),
                alignment='',
                text_color='blue'):
                #action=None):
              super().__init__(frame=frame, name=name)
              self.kivyobject = (TextInput(text=text,
                  size_hint_y = None,
                  size_hint_x = None,
                  height = self.frame[3]* View.yratio,
                  width = self.frame[2]* View.xratio,
                  multiline = True,
                  pos = (self.frame[0] * View.xratio, 
                      self.frame[1] * View.yratio)))
                  #on_press = action))
      
        
      class ImageView(View):
          def __init__(self,
                 frame=(0,0,100,100),
                 name='',
                 image=None):
              super().__init__(frame=frame, name=name)
              if image:
                  image_source = image.source
              else:
                  image_source = None
              self.kivyobject = (
                KivyImage(source=image_source,
                  allow_stretch = True,
                  size = (self.frame[2]* View.xratio,
                          self.frame[3]* View.yratio),
                  pos = (self.frame[0] * View.xratio, 
                          self.frame[1] * View.yratio)))
      
      class Image(object):
          def __init__(self, source):
              self.source = source
      

      Copy of the code in gist.
      https://gist.github.com/balachandrana/4e9accfc894785682f230c54dc5da816#file-ui-py

      posted in Pythonista
      abcabc
      abcabc
    • RE: How can I install Scapy?

      Pythonista does not support modules like subprocess. Hence I think that you may not be able to run this on pythonista.

      I am able to install it but it gives error while running (not able to start the interactive session).

      posted in Pythonista
      abcabc
      abcabc
    • RE: How can I install Scapy?

      Look at this link. I have not tried it.
      https://github.com/secdev/scapy/issues/401

      posted in Pythonista
      abcabc
      abcabc
    • RE: Pythonista and Textastic
      1. dropbox sync (look at few posts before) seems to work fine
        https://forum.omz-software.com/topic/3951/sync-to-dropbox

      2. May be "Pythonista find and replace" does not support regular expressions

      3. A simple appex script could be used to save files on pythonista

      4. loading from working copy is another option

      5. Look at this for some more editor options
        https://forum.omz-software.com/topic/3543/share-in-work-side-bar-replacement

      posted in Pythonista
      abcabc
      abcabc
    • RE: How to improve speed of drawing? Very slow scene view.

      I am able to reproduce the problem on my ipad ( Pythonista version 3.1.1 (311002) running Python 3.5.1 on iOS 10.1.1 on a 32-bit iPad3,4 with ascreen size of (1024 x 768) * 2) ). It looks like that my ipad is not able to handle large paths and i have done the following modifications to run it on my ipad. I have precomputed the shape nodes and have added a reduction factor. I am able to run with reduction factor 4 and above.
      (I have also created a pretty printed version of pathLists file which can be edited on pythonista IDE
      https://gist.github.com/balachandrana/de8c3a84ad59be90064108b148a8bd21 )

      Other possibility is implementing this in shaders and "2D vector graphics library" in shadertoy could help in this implementation.
      https://www.shadertoy.com/view/lslXW8

      import scene
      from variableTools import glyphsListConstruct
      
      glyphs_list1 = glyphsListConstruct()
      reduction_factor = 4.0
      x_factor = (10.24 / 2)*reduction_factor
      
      
      class MyScene(scene.Scene):
          def setup(self):
              self.glyphs_list = [scene.ShapeNode(i) for i in glyphs_list1[::int(reduction_factor)]]
              self.myPath = self.glyphs_list[0]
              self.myPath.anchor_point = 0, 0
              self.myPath.position = (1024 - self.myPath.bbox.width * 1.75,
                                       768 - self.myPath.bbox.height * 1.3)
              self.add_child(self.myPath)
              self.background_color = 'lightgrey'
              self.touch_moved = self.touch_began
      
          def touch_began(self, touch):
              r = int(touch.location.x / x_factor)%len(self.glyphs_list)
              #print(touch.location.x, r)
              self.myPath.remove_from_parent()
              self.myPath = self.glyphs_list[r]
              self.myPath.anchor_point = 0, 0
              self.myPath.position = (1024 - self.myPath.bbox.width * 1.75,
                                       768 - self.myPath.bbox.height * 1.3)
              self.add_child(self.myPath)
      
      
      scene.run(MyScene(), show_fps=True)
      
      
      posted in Pythonista
      abcabc
      abcabc
    • RE: Combine gifs
      1. A simple way to combine gifs would be to get the image lists of each gif, concatenate these image lists to form a single images list and then generate a new gif from this single list.

      2. It seems to be a documentation error. The second one should be remove_assets. You could file an issue regarding this.
        https://github.com/omz/Pythonista-Issues

      posted in Pythonista
      abcabc
      abcabc