Skip to content

Commit

Permalink
Merge branch 'master' into material_motion
Browse files Browse the repository at this point in the history
  • Loading branch information
T-Dynamos authored May 22, 2024
2 parents 8a65f99 + f283a8b commit 8080789
Show file tree
Hide file tree
Showing 10 changed files with 305 additions and 157 deletions.
119 changes: 50 additions & 69 deletions examples/material_scroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,79 +2,50 @@
import sys

from kivy.core.window import Window
from kivy.metrics import dp
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
from kivy import __version__ as kv__version__
from kivymd import __version__
from kivy.lang import Builder
from kivy.metrics import dp

from kivymd.app import MDApp
from kivymd import __version__
from kivymd.uix.list import (
MDListItem,
MDListItemHeadlineText,
MDListItemSupportingText,
MDListItemLeadingIcon,
)

from materialyoucolor import __version__ as mc__version__

from examples.common_app import CommonApp, KV
from examples.common_app import CommonApp

MAIN_KV = """
<Item>:
size_hint_y:None
height:dp(50)
text:""
sub_text:""
icon:""
spacing:dp(5)
MDIcon:
icon:root.icon
size_hint:None, 1
width:self.height
BoxLayout:
orientation:"vertical"
MDLabel:
text:root.text
MDLabel:
adaptive_height:True
text:root.sub_text
font_style:"Body"
role:"medium"
shorten:True
shorten_from:"right"
theme_text_color:"Custom"
text_color:app.theme_cls.onSurfaceVariantColor[:-1] + [0.9]
MDScreen:
md_bg_color: app.theme_cls.backgroundColor
BoxLayout:
orientation:"vertical"
MDScrollView:
do_scroll_x:False
MDScrollView:
do_scroll_x: False
MDBoxLayout:
id: main_scroll
orientation: "vertical"
adaptive_height: True
MDBoxLayout:
spacing:dp(20)
orientation:"vertical"
adaptive_height:True
id:main_scroll
padding:[dp(10), 0]
MDBoxLayout:
adaptive_height:True
MDLabel:
theme_font_size:"Custom"
text:"OS Info"
font_size:"55sp"
adaptive_height:True
padding:[dp(10),dp(20),0,0]
BoxLayout:
orientation:"vertical"
size_hint_x:None
width:dp(70)
padding:[0, dp(20), dp(10),0]
MDIconButton:
on_release: app.open_menu(self)
size_hint: None, None
size:[dp(50)] * 2
icon: "menu"
pos_hint:{"center_x":0.8, "center_y":0.9}
Widget:
"""
adaptive_height: True
MDLabel:
theme_font_size: "Custom"
text: "OS Info"
font_size: "55sp"
adaptive_height: True
padding: "10dp", "20dp", 0, 0
class Item(BoxLayout):
pass
MDIconButton:
icon: "menu"
on_release: app.open_menu(self)
pos_hint: {"center_y": .5}
"""


class Example(MDApp, CommonApp):
Expand All @@ -98,24 +69,34 @@ def on_start(self):
"Kivy Version": ["v" + kv__version__, "alpha-k-circle-outline"],
"KivyMD Version": ["v" + __version__, "material-design"],
"MaterialYouColor Version": ["v" + mc__version__, "invert-colors"],
"Pillow Version":["Unknown", "image"],
"Pillow Version": ["Unknown", "image"],
"Working Directory": [os.getcwd(), "folder"],
"Home Directory": [os.path.expanduser("~"), "folder-account"],
"Environment Variables": [os.environ, "code-json"],
}

try:
from PIL import __version__ as pil__version_
info["Pillow Version"] = ["v" + pil__version_ ,"image"]

info["Pillow Version"] = ["v" + pil__version_, "image"]
except Exception:
pass

for info_item in info:
widget = Item()
widget.text = info_item
widget.sub_text = str(info[info_item][0])
widget.icon = info[info_item][1]
self.root.ids.main_scroll.add_widget(widget)
self.root.ids.main_scroll.add_widget(
MDListItem(
MDListItemLeadingIcon(
icon=info[info_item][1],
),
MDListItemHeadlineText(
text=info_item,
),
MDListItemSupportingText(
text=str(info[info_item][0]),
),
pos_hint={"center_x": .5, "center_y": .5},
)
)

Window.size = [dp(350), dp(600)]

Expand Down
7 changes: 7 additions & 0 deletions kivymd/uix/appbar/appbar.kv
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@


<MDTopAppBarTitle>
padding:
[
self._appbar._left_padding,
0,
self._appbar._right_padding,
0,
]
font_style:
{ \
"small": "Title", \
Expand Down
116 changes: 68 additions & 48 deletions kivymd/uix/appbar/appbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,8 @@ class MDTopAppBarTrailingButtonContainer(BaseTopAppBarButtonContainer):
# FIXME: The on_enter/on_leave event is not triggered for
# MDActionTopAppBarButton buttons in the MDTopAppBarTrailingButtonContainer
# container.
# When the screen size is changed on desktop devices, the position of the
# trailing container is shifted until the screen size change is completed.
class MDTopAppBar(
DeclarativeBehavior,
ThemableBehavior,
Expand Down Expand Up @@ -729,6 +731,12 @@ class MDTopAppBar(
_trailing_button_container = ObjectProperty()
_leading_button_container = ObjectProperty()
_appbar_title = ObjectProperty()
_right_padding = NumericProperty(0)
_left_padding = NumericProperty(0)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Clock.schedule_once(lambda x: self.on_size(self, (0, 0)))

def on_type(self, instance, value) -> None:
def on_type(*args):
Expand All @@ -745,16 +753,17 @@ def on_size(self, instance, size) -> None:
self._appbar_title._title_width = (
self._appbar_title.texture_size[0]
)
Clock.schedule_once(
lambda x: self._appbar_title.on_pos_hint(
self._appbar_title, self._appbar_title.pos_hint
)
self._right_padding = 0
self._left_padding = 0
self._appbar_title.on_pos_hint(
self._appbar_title, self._appbar_title.pos_hint
)

def add_widget(self, widget, *args, **kwargs):
if isinstance(widget, MDTopAppBarTitle):
widget._appbar = self
self._appbar_title = widget
widget.bind(text=lambda *x: self.on_size(*x))
Clock.schedule_once(lambda x: self._add_title(widget))
elif isinstance(widget, MDTopAppBarTrailingButtonContainer):
self._trailing_button_container = widget
Expand All @@ -779,81 +788,92 @@ def _set_padding_title(self, value):
not self._trailing_button_container
and self._leading_button_container
):
left_padding = (self.width // 2) - (
self._leading_button_container.width
+ (self._appbar_title._title_width // 2)
)
self._appbar_title.padding = [left_padding, 0, 0, 0]
self._left_padding = (
(self.width // 2)
- (
self._leading_button_container.width
+ (self._appbar_title._title_width // 2)
)
) - self._left_padding
elif (
self._trailing_button_container
and not self._leading_button_container
):
left_padding = (self.width // 2) - (
self._appbar_title._title_width // 2
)
right_padding = (self.width // 2) - (
self._trailing_button_container.width
+ (self._appbar_title._title_width // 2)
)
self._appbar_title.padding = [left_padding, 0, right_padding, 0]
self._left_padding = (
(self.width // 2) - (self._appbar_title._title_width // 2)
) - self._left_padding
self._right_padding = (
(self.width // 2)
- (
self._trailing_button_container.width
+ (self._appbar_title._title_width // 2)
)
) - self._right_padding
elif (
not self._trailing_button_container
and not self._leading_button_container
):
left_padding = (self.width // 2) - (
self._appbar_title._title_width // 2
)
right_padding = (self.width // 2) - (
self._appbar_title._title_width // 2
)
self._appbar_title.padding = [left_padding, 0, right_padding, 0]
self._left_padding = (
(self.width // 2) - (self._appbar_title._title_width // 2)
) - self._left_padding
self._right_padding = (
(self.width // 2) - (self._appbar_title._title_width // 2)
) - self._right_padding
elif (
self._trailing_button_container
and self._leading_button_container
):
left_padding = (self.width // 2) - (
self._leading_button_container.width
+ (self._appbar_title._title_width // 2)
)
right_padding = (self.width // 2) - (
self._trailing_button_container.width
+ (self._appbar_title._title_width // 2)
)
self._appbar_title.padding = [left_padding, 0, right_padding, 0]
self._left_padding = (
(self.width // 2)
- (
self._leading_button_container.width
+ (self._appbar_title._title_width // 2)
)
) - self._left_padding
self._right_padding = (
(self.width // 2)
- (
self._trailing_button_container.width
+ (self._appbar_title._title_width // 2)
)
) - self._right_padding
elif (
not value
and self._trailing_button_container
and self._leading_button_container
):
if self.type == "small":
right_padding = self.width - (
self._trailing_button_container.width
+ self._leading_button_container.width
+ self._appbar_title._title_width

self._right_padding = (
self.width
- (
self._trailing_button_container.width
+ self._leading_button_container.width
+ self._appbar_title._title_width
)
- self._right_padding
)
self._appbar_title.padding = [0, 0, right_padding, 0]
elif (
not value
and self._trailing_button_container
and not self._leading_button_container
):
if self.type == "small":
right_padding = self.width - (
self._trailing_button_container.width
+ self._appbar_title._title_width
self._right_padding = (
self.width
- (
self._trailing_button_container.width
+ self._appbar_title._title_width
)
- self._right_padding
)
self._appbar_title.padding = [
dp(16),
0,
right_padding - dp(16),
0,
]
self._left_padding = dp(16)
elif (
not value
and not self._trailing_button_container
and not self._leading_button_container
):
self._appbar_title.padding_x = dp(16)
self._left_padding = dp(16)


class MDBottomAppBar(
Expand Down
4 changes: 3 additions & 1 deletion kivymd/uix/fitimage/fitimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,15 @@ def build(self):
from kivy.uix.image import AsyncImage

from kivymd.uix.behaviors import StencilBehavior
from kivymd.uix.behaviors import DeclarativeBehavior


class FitImage(AsyncImage, StencilBehavior):
class FitImage(DeclarativeBehavior, StencilBehavior, AsyncImage):
"""
Fit image class.
For more information, see in the
:class:`~kivymd.uix.behaviors.declarative_behavior.DeclarativeBehavior` and
:class:`~kivy.uix.image.AsyncImage` and
:class:`~kivymd.uix.behaviors.stencil_behavior.StencilBehavior`
classes documentation.
Expand Down
2 changes: 1 addition & 1 deletion kivymd/uix/navigationbar/navigationbar.kv
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
) \
if self.parent else self.theme_cls.transparentColor
RoundedRectangle:
radius: [16,]
radius: [dp(16), ]
size:
( \
(self.parent.parent._selected_region_width, dp(32)) \
Expand Down
4 changes: 3 additions & 1 deletion kivymd/uix/progressindicator/progressindicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ def build(self):

from kivymd import uix_path
from kivymd.theming import ThemableBehavior
from kivymd.uix.behaviors import DeclarativeBehavior

with open(
os.path.join(uix_path, "progressindicator", "progressindicator.kv"),
Expand All @@ -212,11 +213,12 @@ def build(self):
Builder.load_string(kv_file.read())


class MDLinearProgressIndicator(ThemableBehavior, ProgressBar):
class MDLinearProgressIndicator(DeclarativeBehavior, ThemableBehavior, ProgressBar):
"""
Implementation of the linear progress indicator.
For more information, see in the
:class:`~kivymd.uix.behaviors.declarative_behavior.DeclarativeBehavior` and
:class:`~kivymd.theming.ThemableBehavior` and
:class:`~kivy.uix.progressbar.ProgressBar`
classes documentation.
Expand Down
Loading

0 comments on commit 8080789

Please sign in to comment.