Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
T-Dynamos committed Mar 1, 2024
1 parent e178310 commit 54f0613
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 0 deletions.
2 changes: 2 additions & 0 deletions kivymd/factory_registers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
register("MDSegmentButtonLabel", module="kivymd.uix.segmentedbutton")
register("MDScrollView", module="kivymd.uix.scrollview")
register("MDRecycleView", module="kivymd.uix.recycleview")
register("MDCarousel", module="kivymd.uix.carousel")
register("MDCarouselImageItem", module="kivymd.uix.carousel")
register("MDResponsiveLayout", module="kivymd.uix.responsivelayout")
register("MDSliverAppbar", module="kivymd.uix.sliverappbar")
register("MDSliverAppbarContent", module="kivymd.uix.sliverappbar")
Expand Down
1 change: 1 addition & 0 deletions kivymd/uix/carousel/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .carousel import MDCarousel, MDCarouselImageItem
3 changes: 3 additions & 0 deletions kivymd/uix/carousel/carousel.kv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<MDCarouselImageItem>:
size_hint_x:None
width:dp(85)
50 changes: 50 additions & 0 deletions kivymd/uix/carousel/carousel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import os

from kivy.properties import ColorProperty, ListProperty
from kivy.metrics import dp
from kivy.lang import Builder
from kivy.uix.image import AsyncImage
from kivymd import uix_path
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.behaviors import StencilBehavior
from kivymd.uix.scrollview import MDScrollView

with open(
os.path.join(uix_path, "carousel", "carousel.kv"), encoding="utf-8"
) as kv_file:
Builder.load_string(kv_file.read())

class MDCarouselImageItem(AsyncImage, StencilBehavior):

def __init__(self, *arg, **kwargs):
super().__init__(*arg, **kwargs)
self.fit_mode = "cover"
self.radius = [10] *4

class MDCarousel(
MDScrollView
):

images = ListProperty([])
md_bg_color = ColorProperty([0,0,0,0])

_child_layout = None
_image_widgets = {}

def __init__(self, *arg, **kwargs):
self.do_scroll_x = True
self.do_scroll_y = False
super().__init__(*arg, **kwargs)
self.init_child()

def init_child(self):
self._child_layout = MDBoxLayout()
self._child_layout.adaptive_width = True
self._child_layout.spacing = dp(10)
self._child_layout.padding = [dp(10)] * 4
self._child_layout.md_bg_color = self.md_bg_color
self.add_widget(self._child_layout)

def on_images(self, instance, images):
for image in images:
self._child_layout.add_widget(MDCarouselImageItem(source=image["source"]))
40 changes: 40 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from kivy.metrics import dp
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
from kivymd.app import MDApp

from examples.common_app import CommonApp, KV

MAIN_KV = """
<Item>:
size_hint_y:None
height:dp(50)
MDScreen:
md_bg_color: app.theme_cls.backgroundColor
BoxLayout:
orientation:"vertical"
MDCarousel:
id:carousel
size_hint_y:None
height:dp(200)
Widget:
"""


class Item(BoxLayout):
pass


class Example(MDApp, CommonApp):
def build(self):
self.theme_cls.theme_style = "Dark"
return Builder.load_string(MAIN_KV)

def on_start(self):
super().on_start()
self.root.ids.carousel.images = [
{"source":"/home/tdynamos/Documents/time_table.jpeg"},
] * 10

Example().run()
2 changes: 2 additions & 0 deletions ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
~/material-components-android/lib/java/com/google/android/material/carousel

0 comments on commit 54f0613

Please sign in to comment.