• upwart

    @enceladus
    This GUI Customview is where the getter_setter would certainly be useful!

    posted in Pythonista read more
  • upwart

    @mikael
    Thanks for this great idea.
    I have renamed your decorator to getter_setter, to make the purpose of it more clear.

    Thus we define a decorator function:

    def getter_setter(func):
        return property(func, func)
    

    and then we can redo the example as:

    class Example:

    @getter_setter
    def my_property(self, *value):
        if value:
            self._my_property = value[0]
        else:
            return self._my_property
    

    or EAFP style:

    class Example:
    
        @getter_setter
        def my_property(self, *value):
            try:
                self._my_property = value[0]
            except IndexError:
                return self._my_property
    

    Optionally, we could define two more decorators for getter only and setter only properties:

    def getter(func):
        def raise_attribute_error(*args):
            raise AttributeError("can't set attribute")
        return property(func, raise_attribute_error)
        
    
    def setter(func):
        def raise_attribute_error(*args):
            raise AttributeError("can't get attribute")
        return property(raise_attribute_error, func)
    
    

    Here is an example of a Circle class demonstrating the three decorators.
    radius can be used to get the radius and set the radius (thus updating the _area attribute)
    area can be used to get the area only. Setting will raise an error.
    diameter can only be used to set the radius. You can’t get it.

    Here is an implementation with getter_setter only:

    import math
    
    
    class Circle:
        def __init__(self, radius):
            self.radius = radius
            
        @getter_setter
        def radius(self, *value):
            if value:
                self._radius = value[0]
                self._area = math.pi * self._radius ** 2
            else:
                return self._radius
                
        @getter_setter
        def area(self, *value):
            if value:
                raise AttributeError("can't set attribute")
            else:
                return self._area
                
        @getter_setter
        def diameter(self, *value):
            if value:
                self.radius = value[0] / 2
            else:
                raise AttributeError("can't get attribute")
    
    And if we use getter and setter as well:
    
    import math
    
    
    class Circle:
        def __init__(self, radius):
            self.radius = radius
            
        @getter_setter
        def radius(self, *value):
            if value:
                self._radius = value[0]
                self._area = math.pi * self._radius ** 2
            else:
                return self._radius
                
        @getter
        def area(self):
            return self._area
                
        @setter
        def diameter(self, value):
            self.radius = value / 2

    posted in Pythonista read more
  • upwart

    You can't install opencv on Python, unfortunately,

    posted in Pythonista read more
  • upwart

    That's very bad news. Let's hope Ole is listening and working on it.

    posted in Pythonista read more
  • upwart

    There is pretty neat Python 3.7 implementation, called Pyto.
    It supports numpy, matplotlib and ... pandas!
    I just wished it had the same Scene interface as Pythonista or even better supported tkinter or pygame.

    posted in Pythonista read more
  • upwart

    I have looked at PyTo and it certainly looks promising.
    But I like Pythonista more, I think.

    posted in Pythonista read more
  • upwart

    @cvp
    Well, that's maybe the way to go, although I prefer to stick with my old fashioned scene_drawing code.

    Thanks just the same.

    posted in Pythonista read more
  • upwart

    Now that I can display the built up picture (as a SpriteNode), I run into another problem. In my scene.draw method, I now update the SpriteNode's texture and then I want to draw some rectangles and texts with the scene_drawing primitives rect and text.
    Unfortunately these do not show up at all, as if they are hidden behind the SpriteNode. I tried to set the SpriteNode's z_position to -1, but that doesn't help.
    So my concrete question is: "How can I show the scene_drawing results in front of the SpriteNode?".

    posted in Pythonista read more
  • upwart

    @JonB
    The PIL image is created for each frame by combining several (sometimes hundreds or thousands) small PIL images. For non-retina resolution it is easy to show them in a scene event loop. For retina resolution I have to escape to a SpriteNode which is filled with a texture for each and every frame.

    posted in Pythonista read more
  • upwart

    @mikael
    I just found out that if change the file format from PNG to BMP speeds up the animation significantly: from 4 to > 16 fps.

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!