0

I want to this gallery in kivy how to make gallery view How to add this kivy then is showing many display and carousel in gallery? How to make an image and display it on the next page Anyone can help this?

class Gallery(Screen):
        pass 

.kv

<MyTile@SmartTile>:
        size_hint_y: None
        height: "240dp"
    
<Gallery>
    ScrollView:
        MDGridLayout:
            cols: 3
            row_default_height: (self.width - self.cols*self.spacing[0]) / self.cols
            row_force_default: True
            adaptive_height: True
            padding: dp(4), dp(4)
            spacing: dp(4)
            MyTile:
                source:'*.jpg'

https://i.stack.imgur.com/loupw.png

Here's got problem..

[ WARN:1] global C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-vi271kac\opencv\modules\videoio\src\cap_msmf.cpp (376) `anonymous-namespace'::SourceReaderCB::OnReadSample videoio(MSMF): OnReadSample() is called with error status: -1072873821
[ WARN:1] global C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-vi271kac\opencv\modules\videoio\src\cap_msmf.cpp (388) `anonymous-namespace'::SourceReaderCB::OnReadSample videoio(MSMF): async ReadSample() call is failed with error status: -1072873821
[INFO   ] [Loader      ] using a thread pool of 2 workers
[ERROR  ] [AsyncImage  ] Not found <*.jpg>
[INFO   ] [Base        ] Start application main loop
[ WARN:0] global C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-vi271kac\opencv\modules\videoio\src\cap_msmf.cpp (438) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback

Here's gallery but is not showing any picture in here.. Anyone can tell this code what is problem in codes?

Pee
  • 29
  • 1
  • 7

1 Answers1

1

I sketched an example of a gallery, I think this is what you want.

from kivymd.app import MDApp

from kivy.metrics import dp
from kivy.lang.builder import Builder
from kivy.uix.boxlayout import BoxLayout

import os

KV = """
<ImageButton@ButtonBehavior+FitImage>

<ImageManager>
    path: ""
    orientation: "vertical"
    size_hint_y: None
    height: root.height
    padding: dp(10)

    ImageButton:
        source: root.path
        
BoxLayout:
    RecycleView:
        id: rv
        key_viewclass: "viewclass"
        RecycleGridLayout:
            padding: dp(2)
            cols: 3
            default_size: None, dp(48)
            default_size_hint: 1, None
            size_hint_y: None
            height: self.minimum_height
"""


class ImageManager(BoxLayout):
    pass


class GalleryApp(MDApp):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.manager_list = []
        self.dir = os.getcwd()
        self.available_image_format = ['.png', '.jpg', '.jpeg', '.bmp']  # etc

    def build(self):
        return Builder.load_string(KV)

    def on_start(self):
        self.load_images()

    def load_images(self):
        if not self.manager_list:
            for image in os.listdir(self.dir):
                target_filename, target_file_extension = os.path.splitext(image)
                if target_file_extension in self.available_image_format:
                    path_to_image = os.path.join(self.dir, image)
                    self.manager_list.append(
                        {
                            "viewclass": "ImageManager",
                            "path": path_to_image,
                            "height": dp(200),
                        }
                    )
            self.root.ids.rv.data = self.manager_list


GalleryApp().run()
Neizvestnyj
  • 1,727
  • 4
  • 22
  • Thanks so much! It's working but isn't looking any picture in this gallery. – Pee Jul 05 '21 at 11:04
  • This is logical, the images should be in the same place as the script (in my example this is the case), you can set the path you need using the `self.dir` argument. – Neizvestnyj Jul 05 '21 at 13:14
  • I want to use 'from kivy.properties import StringProperty' in this gallery so how do ? – Pee Jul 05 '21 at 13:50
  • If I understand you correctly, just import at the top, and then create the arguments you need in the class itself: `class Test: value = StringProperty() ` – Neizvestnyj Jul 05 '21 at 18:06
  • Thanks A lot! I want this. But A little problem in this gallery because i need also selected button in this gallery [https://kivymd.readthedocs.io/en/latest/components/selection/]] so how do? – Pee Jul 07 '21 at 09:27
  • just put it in the `ImageManager` it's the same normal `BoxLayout` – Neizvestnyj Jul 07 '21 at 13:47
  • Read the documentation carefully and look at the examples, you want to put a picture in the list class, this is impossible. I also advise you to study python itself – Neizvestnyj Jul 08 '21 at 11:06
  • I will try it. and thanks for help in my project. :) – Pee Jul 08 '21 at 11:12