-
-
Notifications
You must be signed in to change notification settings - Fork 674
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .carousel import MDCarousel, MDCarouselImageItem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<MDCarouselImageItem>: | ||
size_hint_x:None | ||
width:dp(85) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
~/material-components-android/lib/java/com/google/android/material/carousel | ||
|