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?

  • Try some thing like [this](https://kivymd.readthedocs.io/en/latest/components/mdswiper/index.html) – Ne1zvestnyj Jun 20 '21 at 13:48
  • Thanks so much @Neizvestnyj i need this but other than I need make a gallery. for example- Many gridlayout in gallery. –  Jun 21 '21 at 01:49
  • I am trying use (https://kivymd.readthedocs.io/en/latest/components/image-list/) but is not showing any picture in my gallery. –  Jun 21 '21 at 08:20
  • Post your code. – Ne1zvestnyj Jun 21 '21 at 09:51
  • @Neizvestnyj where do i post in here? Answer? –  Jun 21 '21 at 10:25
  • In question, and describe what do you need – Ne1zvestnyj Jun 21 '21 at 10:58
  • @Neizvestnyj See in my question –  Jun 21 '21 at 11:16
  • Can you post runnable example – Ne1zvestnyj Jun 21 '21 at 11:18
  • No! That's empty! No problem! I do post –  Jun 21 '21 at 11:23
  • It's just easier to understand what you specifically want if the programmer answering your question looks at your attempts to solve this problem. You want to write a full-fledged application for you in your question. – Ne1zvestnyj Jun 21 '21 at 11:26
  • @Neizvestnyj see in my question. I have post all question in here. –  Jun 21 '21 at 11:37
  • @Neizvestnyj tell me how to solve in my question? –  Jun 22 '21 at 12:13
  • Attach an example that I can run (with all the imports as expected) and find out what the error is – Ne1zvestnyj Jun 22 '21 at 16:25
  • The main problem is my title in **source** and can see error in asyncimage. –  Jun 23 '21 at 02:33
  • Everything is clearly written in your error, the image you specified does not exist – Ne1zvestnyj Jun 23 '21 at 13:30
  • Yeah! What is problem in this code only for image. I need one folder in gallery so How do all? –  Jun 23 '21 at 15:00
  • Everything is correct in your printer, for my project I did about the same, specify the path explicitly. Add images to the layout in a loop – Ne1zvestnyj Jun 23 '21 at 17:09
  • @Neizvestnyj i have tried to this (https://stackoverflow.com/questions/64643313/generalize-the-kivymd-image-list-example) so it's working then i'm trying to use path `MyTile: source: r"C:\Users"` it's working too but no showing any picture in that so i want to add source in **MyTitle** so how do it? –  Jun 24 '21 at 03:39
  • Tell me everyone! How does all this codes? –  Jul 02 '21 at 05:25

1 Answers1

0

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()
Ne1zvestnyj
  • 1,391
  • 1
  • 7
  • 25
  • Thanks so much! It's working but isn't looking any picture in this gallery. –  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. – Ne1zvestnyj Jul 05 '21 at 13:14
  • I want to use 'from kivy.properties import StringProperty' in this gallery so how do ? –  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() ` – Ne1zvestnyj 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? –  Jul 07 '21 at 09:27
  • just put it in the `ImageManager` it's the same normal `BoxLayout` – Ne1zvestnyj 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 – Ne1zvestnyj Jul 08 '21 at 11:06
  • I will try it. and thanks for help in my project. :) –  Jul 08 '21 at 11:12