Kivy Image Child Class Produces Two Images
<p>I think this is probably a simple miss understanding about something deeper in kivy, but I have an RoundedImage class that is producing two images, where one is the original without rounded corners and one with the rounded corners off screen a bit. Whats going on?</p>

<p>Screenshot:
<a href="http://imgur.com/gallery/IRYfr" rel="nofollow">http://imgur.com/gallery/IRYfr</a></p>

<p>I think it may be something to do with subclassing Image?</p>

<pre><code>class RoundedImage(Image,StyleUnit):

    _styleist = RadialGradientStyleist    
    _radius = [20]
    _source = ''
    _style = None
    def __init__(self,**kwargs):

        super(RoundedImage,self).__init__(**kwargs)
        #self._source = source
        #self.initalizeStyle()

        with self.canvas:
            StencilPush()
            self.m_rect = RoundedRectangle( size = self.norm_image_size , \
                                            pos=self.center, \
                                            radius=self._radius)
            StencilUse()
            self.rect = Rectangle(  size = self.norm_image_size , \
                                    pos = self.center, \
                                    texture = self.texture)
            StencilUnUse()
            StencilPop()
            #Color(1,1,1)
            #self.line = Line(   rounded_rectangle=self.pos+self.size+self._radius,
            #        width=10)


        self.bind(pos = self.update_rect,
                  size = self.update_rect)

    def update_rect(self,*args):
        self.m_rect.pos = self.center
        self.m_rect.size = self.norm_image_size
        self.rect.pos = self.center
        self.rect.size = self.norm_image_size
</code></pre>

<p>The application code is simple:</p>

<pre><code>class ProfilesApp(App):

    def build(self):
       profile = RoundedImage( source = source,#self.imageLocation,\
                                    allow_stretch=True)
       return profile

profileApp = ProfilesApp()
profileApp.run()
</code></pre>

<p>No imports, no other required classes and although I've seen that rounded rectangle somewhere, I don't have a clue what does that custom class do, so no runnable code. Let's work with that anyway.</p>

<p>Yes, it's because of that subclassing - the picture is already placed in the canvas and you use the texture of it which is there in <code>Rectangle(texture=&lt;here&gt;)</code>. Instead of that remove subclassing of the image <em>and</em> use <code>source</code> keyword argument for the <code>Rectangle</code> like this:</p>

<p><code>Rectangle(source=&lt;path to image&gt;)</code></p>

<p>Then again although you use <code>source</code> in your class that inherits from <code>Image</code>, you need to change that and fetch the <code>source</code> from kwargs:</p>

<p><code>self.source = kwargs.get('source')</code></p>

<p>then instead of <code>Rectangle(texture=self.texture)</code> do <code>Rectangle(source=self.source)</code></p>

python image canvas graphics kivy