Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDSmartTile source parameter should be of type ObjectProperty instead of StringProperty #1437

Closed
felixus97 opened this issue Dec 22, 2022 · 3 comments

Comments

@felixus97
Copy link

Description of the Bug

  • "ValueError: MDSmartTile.source accept only str"

  • MDSmartTile "source" parameter accepts only objects of type StringProperty, whereas its nested SmartTileImage (based on FitImage) accepts objects of type ObjectProperty. This breaks the behaviour of being able to pass textures as the tile image source.

Fix:

  • The problem can be fixed by making the source parameter in MDSmartTile of type ObjectProperty.

Code and Logs

Notes:

  • An md_logo.png file is required to run the example, you can use any image as long as it's RGBA.
  • I've run the example in kivymd==1.0.2, but I have checked and the code is still the same in the latest version.
from kivy.graphics.texture import Texture

from kivymd.app import MDApp
from kivymd.uix.imagelist import MDSmartTile

from PIL import Image as PilImage


class TestApp(MDApp):

    def build(self):
        filename = 'md_logo.png'

        with PilImage.open(filename) as im:
            texture = Texture.create(size=(im.height, im.width))

            texture.blit_buffer(im.tobytes(), colorfmt='rgba', bufferfmt='ubyte')

            texture.flip_vertical()

            tile = MDSmartTile(source=texture, size_hint_y=None, size_hint_x=None, size=(im.height, im.width))

        return tile


if __name__ == '__main__':
    TestApp().run()

Versions

  • OS: Win10
  • Python: v3.10.4
  • Kivy: v2.1.0
  • KivyMD: 1.0.2
@HeaTTheatR
Copy link
Member

There is no bugs here. Use source as string.

@felixus97
Copy link
Author

felixus97 commented Dec 22, 2022

It is a bug since the intended usage of FitImage is with both string and texture as source.

Restricting the source to string only means, that you cannot use already loaded textures in an MDSmartTile.

@felixus97
Copy link
Author

I want to use MDSmartTile and RecycleView to make a gallery app.
I only want to load thumbnails, instead of the full images.
I use PIL to make the thumbnails, then convert them to kivy textures.
FitImage accepts texture as source.
Since your code uses FitImage as a base for SmartTileImage, passing a texture to MDSmartTile should be permitted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants