• rownn

    Hey everyone,

    I have a ui.path in a shapeNode, which is growing somehow every second. Unfortunately, the path is jumping from state to state. I know why it is jumping and I also know for what this behavior is good for, but I‘d like to fix the path in center where it is meant to be. I guess playing around with the anchor_point would fix the problem only in some cases. Of course I could calculate around with the nodes bbox and the path bounds, but I cannot imagine that there is no better solution. I also thought about defining the size of path with a rect() before generating the actual path, but the resulting rectangle would be visible, of course. I hope you know what I’m talking about. Following a snippet which hopefully describes better what my long questions is about.

    from scene import *
    from time import time
    
    
    class MyScene (Scene):
                
        def setup(self):
            self.points = (Point(-100, -100),Point(100, -100),Point(100, 100),Point(-200, 100))
            self.startTime = time()
            self.prev_dt = -1       
            
            ground = Node(parent=self)
            ground.position = (self.size.w/2, self.size.h/2)
            
            self.node = ShapeNode(ui.Path.oval(0,0,10,10), fill_color='clear', stroke_color='red')
            self.node2 = ShapeNode(ui.Path.oval(0,0,20,20), fill_color='clear', stroke_color='yellow')
            
            ground.add_child(self.node)
            ground.add_child(self.node2)
    
        
        def update(self):
            dt = int((time()-self.startTime)%4)
    
            if dt != self.prev_dt:
                self.prev_dt = dt
                
                path = ui.Path.oval(0,0,10,10)
                path.move_to(self.points[0].x, self.points[0].y)
                path.line_to(self.points[1].x, self.points[1].y)
                
                for i in range(dt): path.line_to(self.points[(i+2)%4].x,self.points[(i+2)%4].y)
                
                self.node.path = path
    
    if __name__ == '__main__':
        run(MyScene(), show_fps=False) 
    

    Thx alot forfor every hint :)
    rownn

    posted in Pythonista read more
  • rownn

    For this part of the discussion alone this thread is worthy to exist. :)

    @rownn said: (boolean+1)%2
    The school math way

    @mikael said: boolean = boolean == False
    The developers way

    @cvp said: boolean = not boolean
    The pythonish way

    @stephen said: boolean = !boolean
    The beautiful but !pythonish way

    posted in Pythonista read more
  • rownn

    Hey guys,

    amazing again. I think I will study you snippets over a glass of wine this evening :)

    posted in Pythonista read more
  • rownn

    Hey @mikael,

    thanks alot! It is amazing to see one of my codes in a rewritten most likely better way :) I just flew over it, but there are many very nice looking changes and I‘m excited to get into it deeper soon. Until then I thank you for the time you spent and the insights which I will have.

    PS: Thought it would be clever to avoid the update method. Isnt it performance-consuming?

    posted in Pythonista read more
  • rownn

    Hey @stephen,

    good question. Actually I wanted to shrink the scene, too. But than I realized that it wouldnt effect the appearance I wish. Besides this I wasnt able to get the scene shinking smoothly with the sceneView :( Is there a way to achieve this?

    Thanks for the tip regarding the ui importing, you are right, of course :)
    And thanks for looking though the code

    posted in Pythonista read more
  • rownn

    Hey everyone,

    awkward title of the topic, I know. I struggled with fitting nodes in resizing sceneViews. I have a sceneView, which is resized via animation by pushing a button. The question was how to stick the scene at the top of the view. I have found a solution, but because of the fact I am new to that stuff I‘d like to post the code here with the silent question if there is a better way or if it is a common way.

    from scene import *
    import ui
    
    class MyScene(Scene):
        def __init__(self):
            Scene.__init__(self)
            self.background_color= '#eee'
            self.frm = ShapeNode(parent=self, fill_color='red', stroke_color='clear')
        
        def setup(self):
            self.viewSizeHasChanged()
            
        def viewSizeHasChanged(self):
            self.frm.position = (150,self.view.height/2-(500-self.view.height)/2)
            self.frm.path = ui.Path.rect(0,0,250,450)
    
    class GUI(ui.View):
        def __init__(self):
            self.background_color = '#ddd'
            self.scales = (100, 500)
            self.state = True
            self.separator_H = 10
            
            self.mainView = ui.View(frame=(50,50,300,500), background_color='#fff')
            self.add_subview(self.mainView)
            
            self.sn = SceneView()
            self.sn.frame = self.mainView.bounds
            self.mainView.add_subview(self.sn)
            self.sn.scene = MyScene()
            
            self.btn_Do = ui.Button(name='Do', title='Do', background_color= '#ddd', corner_radius = 12, action = self.btn_tapped)
            self.btn_Do.frame = (175, 275, 50, 50)
            self.add_subview(self.btn_Do)
            
        def btn_tapped(self, sender):
            if sender.name == 'Do':
                self.state = (self.state+1)%2
                self.sn.scene.viewSizeHasChanged()
                self.animate(self.scales[self.state])
                    
        def animate(self, H):
            def animation(): self.mainView.frame = (50,(600-H)/2,300,H)
            ui.animate(animation, duration=1.0)
            
    if __name__ == '__main__':
        GUI().present('fullscreen')
    

    Thx for every hint guys
    rownn

    posted in Pythonista read more
  • rownn

    Great! Thanks:)

    posted in Pythonista read more
  • rownn

    The animation part of the code seems to be not needed.
    So...

    def keyboard_frame_will_change(self, frame):
        self.y = self.scene.size.h-self.textView_H-frame[3]
        #self.animate(frame)
            
    #def animate(self, frame):
        #def animation():
            #self.y = self.scene.size.h-self.textView_H-frame[3]
        #ui.animate(animation, duration=0.25)
         ```

    posted in Pythonista read more
  • rownn

    Hi everyone,

    my first idea was to detect if the TextView is focused or not, but sometimes I work with an external keyboard, so JonBs hint is perfect. It works perfectly fine for me. Hope there won‘t be any unexpected issues. Here the reduced code:

    from scene import *
    import ui
    
    class MyScene (Scene):
        def setup(self):
            v = V(scene=self)
            self.view.add_subview(v)
            
            background = Node(parent=self)
            background.position = (self.size.w/2,self.size.h/2)#(self.size.w/2, self.size.h/2)
            background.add_child(ShapeNode(ui.Path.rect(0,0,self.size.w,self.size.h), fill_color='#dddddd', stroke_color='clear'))
            
            self.add_child(background)
            
    class V(ui.View):
        def __init__(self, *args, **kwargs):
            self.scene = kwargs["scene"]
            self.textView_H = 200
            self.frame=(0, self.scene.size.h-self.textView_H, self.scene.size.w, self.scene.size.h)
            
            self.tv=ui.TextView(frame=(10, 0, self.scene.size.w-20, self.textView_H), font=('Courier', 17.0), background_color='#333333', text_color = '#ffffff')
            self.tv.text = 'Heyhey.'
            self.tv.delegate=self
            self.add_subview(self.tv)
        
        def keyboard_frame_will_change(self, frame):
            self.animate(frame)
            
        def animate(self, frame):
            def animation():
                self.y = self.scene.size.h-self.textView_H-frame[3]
            ui.animate(animation, duration=0.25)
        
            
    if __name__ == '__main__':
        run(MyScene(), PORTRAIT, show_fps=True)
    

    Thank you guys. Amazing fast replying forum!

    posted in Pythonista read more
  • rownn

    Hi everyone,

    I work on a scene with ui.TextView and I‘d like to know how I could detect if the virtual keyboard is open/visible or not. Depending on the visibility of the keyboard I‘d like to do some layout changes. Does somebody have a hint for me?

    Greetings :)
    rownn

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!