Skip to content

Commit 8080789

Browse files
authored
Merge branch 'master' into material_motion
2 parents 8a65f99 + f283a8b commit 8080789

File tree

10 files changed

+305
-157
lines changed

10 files changed

+305
-157
lines changed

Diff for: examples/material_scroll.py

+50-69
Original file line numberDiff line numberDiff line change
@@ -2,79 +2,50 @@
22
import sys
33

44
from kivy.core.window import Window
5-
from kivy.metrics import dp
6-
from kivy.uix.boxlayout import BoxLayout
7-
from kivy.lang import Builder
85
from kivy import __version__ as kv__version__
9-
from kivymd import __version__
6+
from kivy.lang import Builder
7+
from kivy.metrics import dp
8+
109
from kivymd.app import MDApp
10+
from kivymd import __version__
11+
from kivymd.uix.list import (
12+
MDListItem,
13+
MDListItemHeadlineText,
14+
MDListItemSupportingText,
15+
MDListItemLeadingIcon,
16+
)
17+
1118
from materialyoucolor import __version__ as mc__version__
1219

13-
from examples.common_app import CommonApp, KV
20+
from examples.common_app import CommonApp
1421

1522
MAIN_KV = """
16-
<Item>:
17-
size_hint_y:None
18-
height:dp(50)
19-
text:""
20-
sub_text:""
21-
icon:""
22-
spacing:dp(5)
23-
MDIcon:
24-
icon:root.icon
25-
size_hint:None, 1
26-
width:self.height
27-
BoxLayout:
28-
orientation:"vertical"
29-
MDLabel:
30-
text:root.text
31-
MDLabel:
32-
adaptive_height:True
33-
text:root.sub_text
34-
font_style:"Body"
35-
role:"medium"
36-
shorten:True
37-
shorten_from:"right"
38-
theme_text_color:"Custom"
39-
text_color:app.theme_cls.onSurfaceVariantColor[:-1] + [0.9]
40-
4123
MDScreen:
4224
md_bg_color: app.theme_cls.backgroundColor
43-
BoxLayout:
44-
orientation:"vertical"
45-
MDScrollView:
46-
do_scroll_x:False
25+
26+
MDScrollView:
27+
do_scroll_x: False
28+
29+
MDBoxLayout:
30+
id: main_scroll
31+
orientation: "vertical"
32+
adaptive_height: True
33+
4734
MDBoxLayout:
48-
spacing:dp(20)
49-
orientation:"vertical"
50-
adaptive_height:True
51-
id:main_scroll
52-
padding:[dp(10), 0]
53-
MDBoxLayout:
54-
adaptive_height:True
55-
MDLabel:
56-
theme_font_size:"Custom"
57-
text:"OS Info"
58-
font_size:"55sp"
59-
adaptive_height:True
60-
padding:[dp(10),dp(20),0,0]
61-
BoxLayout:
62-
orientation:"vertical"
63-
size_hint_x:None
64-
width:dp(70)
65-
padding:[0, dp(20), dp(10),0]
66-
MDIconButton:
67-
on_release: app.open_menu(self)
68-
size_hint: None, None
69-
size:[dp(50)] * 2
70-
icon: "menu"
71-
pos_hint:{"center_x":0.8, "center_y":0.9}
72-
Widget:
73-
"""
35+
adaptive_height: True
7436
37+
MDLabel:
38+
theme_font_size: "Custom"
39+
text: "OS Info"
40+
font_size: "55sp"
41+
adaptive_height: True
42+
padding: "10dp", "20dp", 0, 0
7543
76-
class Item(BoxLayout):
77-
pass
44+
MDIconButton:
45+
icon: "menu"
46+
on_release: app.open_menu(self)
47+
pos_hint: {"center_y": .5}
48+
"""
7849

7950

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

10778
try:
10879
from PIL import __version__ as pil__version_
109-
info["Pillow Version"] = ["v" + pil__version_ ,"image"]
80+
81+
info["Pillow Version"] = ["v" + pil__version_, "image"]
11082
except Exception:
11183
pass
11284

11385
for info_item in info:
114-
widget = Item()
115-
widget.text = info_item
116-
widget.sub_text = str(info[info_item][0])
117-
widget.icon = info[info_item][1]
118-
self.root.ids.main_scroll.add_widget(widget)
86+
self.root.ids.main_scroll.add_widget(
87+
MDListItem(
88+
MDListItemLeadingIcon(
89+
icon=info[info_item][1],
90+
),
91+
MDListItemHeadlineText(
92+
text=info_item,
93+
),
94+
MDListItemSupportingText(
95+
text=str(info[info_item][0]),
96+
),
97+
pos_hint={"center_x": .5, "center_y": .5},
98+
)
99+
)
119100

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

Diff for: kivymd/uix/appbar/appbar.kv

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020

2121

2222
<MDTopAppBarTitle>
23+
padding:
24+
[
25+
self._appbar._left_padding,
26+
0,
27+
self._appbar._right_padding,
28+
0,
29+
]
2330
font_style:
2431
{ \
2532
"small": "Title", \

Diff for: kivymd/uix/appbar/appbar.py

+68-48
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,8 @@ class MDTopAppBarTrailingButtonContainer(BaseTopAppBarButtonContainer):
675675
# FIXME: The on_enter/on_leave event is not triggered for
676676
# MDActionTopAppBarButton buttons in the MDTopAppBarTrailingButtonContainer
677677
# container.
678+
# When the screen size is changed on desktop devices, the position of the
679+
# trailing container is shifted until the screen size change is completed.
678680
class MDTopAppBar(
679681
DeclarativeBehavior,
680682
ThemableBehavior,
@@ -729,6 +731,12 @@ class MDTopAppBar(
729731
_trailing_button_container = ObjectProperty()
730732
_leading_button_container = ObjectProperty()
731733
_appbar_title = ObjectProperty()
734+
_right_padding = NumericProperty(0)
735+
_left_padding = NumericProperty(0)
736+
737+
def __init__(self, *args, **kwargs):
738+
super().__init__(*args, **kwargs)
739+
Clock.schedule_once(lambda x: self.on_size(self, (0, 0)))
732740

733741
def on_type(self, instance, value) -> None:
734742
def on_type(*args):
@@ -745,16 +753,17 @@ def on_size(self, instance, size) -> None:
745753
self._appbar_title._title_width = (
746754
self._appbar_title.texture_size[0]
747755
)
748-
Clock.schedule_once(
749-
lambda x: self._appbar_title.on_pos_hint(
750-
self._appbar_title, self._appbar_title.pos_hint
751-
)
756+
self._right_padding = 0
757+
self._left_padding = 0
758+
self._appbar_title.on_pos_hint(
759+
self._appbar_title, self._appbar_title.pos_hint
752760
)
753761

754762
def add_widget(self, widget, *args, **kwargs):
755763
if isinstance(widget, MDTopAppBarTitle):
756764
widget._appbar = self
757765
self._appbar_title = widget
766+
widget.bind(text=lambda *x: self.on_size(*x))
758767
Clock.schedule_once(lambda x: self._add_title(widget))
759768
elif isinstance(widget, MDTopAppBarTrailingButtonContainer):
760769
self._trailing_button_container = widget
@@ -779,81 +788,92 @@ def _set_padding_title(self, value):
779788
not self._trailing_button_container
780789
and self._leading_button_container
781790
):
782-
left_padding = (self.width // 2) - (
783-
self._leading_button_container.width
784-
+ (self._appbar_title._title_width // 2)
785-
)
786-
self._appbar_title.padding = [left_padding, 0, 0, 0]
791+
self._left_padding = (
792+
(self.width // 2)
793+
- (
794+
self._leading_button_container.width
795+
+ (self._appbar_title._title_width // 2)
796+
)
797+
) - self._left_padding
787798
elif (
788799
self._trailing_button_container
789800
and not self._leading_button_container
790801
):
791-
left_padding = (self.width // 2) - (
792-
self._appbar_title._title_width // 2
793-
)
794-
right_padding = (self.width // 2) - (
795-
self._trailing_button_container.width
796-
+ (self._appbar_title._title_width // 2)
797-
)
798-
self._appbar_title.padding = [left_padding, 0, right_padding, 0]
802+
self._left_padding = (
803+
(self.width // 2) - (self._appbar_title._title_width // 2)
804+
) - self._left_padding
805+
self._right_padding = (
806+
(self.width // 2)
807+
- (
808+
self._trailing_button_container.width
809+
+ (self._appbar_title._title_width // 2)
810+
)
811+
) - self._right_padding
799812
elif (
800813
not self._trailing_button_container
801814
and not self._leading_button_container
802815
):
803-
left_padding = (self.width // 2) - (
804-
self._appbar_title._title_width // 2
805-
)
806-
right_padding = (self.width // 2) - (
807-
self._appbar_title._title_width // 2
808-
)
809-
self._appbar_title.padding = [left_padding, 0, right_padding, 0]
816+
self._left_padding = (
817+
(self.width // 2) - (self._appbar_title._title_width // 2)
818+
) - self._left_padding
819+
self._right_padding = (
820+
(self.width // 2) - (self._appbar_title._title_width // 2)
821+
) - self._right_padding
810822
elif (
811823
self._trailing_button_container
812824
and self._leading_button_container
813825
):
814-
left_padding = (self.width // 2) - (
815-
self._leading_button_container.width
816-
+ (self._appbar_title._title_width // 2)
817-
)
818-
right_padding = (self.width // 2) - (
819-
self._trailing_button_container.width
820-
+ (self._appbar_title._title_width // 2)
821-
)
822-
self._appbar_title.padding = [left_padding, 0, right_padding, 0]
826+
self._left_padding = (
827+
(self.width // 2)
828+
- (
829+
self._leading_button_container.width
830+
+ (self._appbar_title._title_width // 2)
831+
)
832+
) - self._left_padding
833+
self._right_padding = (
834+
(self.width // 2)
835+
- (
836+
self._trailing_button_container.width
837+
+ (self._appbar_title._title_width // 2)
838+
)
839+
) - self._right_padding
823840
elif (
824841
not value
825842
and self._trailing_button_container
826843
and self._leading_button_container
827844
):
828845
if self.type == "small":
829-
right_padding = self.width - (
830-
self._trailing_button_container.width
831-
+ self._leading_button_container.width
832-
+ self._appbar_title._title_width
846+
847+
self._right_padding = (
848+
self.width
849+
- (
850+
self._trailing_button_container.width
851+
+ self._leading_button_container.width
852+
+ self._appbar_title._title_width
853+
)
854+
- self._right_padding
833855
)
834-
self._appbar_title.padding = [0, 0, right_padding, 0]
835856
elif (
836857
not value
837858
and self._trailing_button_container
838859
and not self._leading_button_container
839860
):
840861
if self.type == "small":
841-
right_padding = self.width - (
842-
self._trailing_button_container.width
843-
+ self._appbar_title._title_width
862+
self._right_padding = (
863+
self.width
864+
- (
865+
self._trailing_button_container.width
866+
+ self._appbar_title._title_width
867+
)
868+
- self._right_padding
844869
)
845-
self._appbar_title.padding = [
846-
dp(16),
847-
0,
848-
right_padding - dp(16),
849-
0,
850-
]
870+
self._left_padding = dp(16)
851871
elif (
852872
not value
853873
and not self._trailing_button_container
854874
and not self._leading_button_container
855875
):
856-
self._appbar_title.padding_x = dp(16)
876+
self._left_padding = dp(16)
857877

858878

859879
class MDBottomAppBar(

Diff for: kivymd/uix/fitimage/fitimage.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,15 @@ def build(self):
8585
from kivy.uix.image import AsyncImage
8686

8787
from kivymd.uix.behaviors import StencilBehavior
88+
from kivymd.uix.behaviors import DeclarativeBehavior
8889

8990

90-
class FitImage(AsyncImage, StencilBehavior):
91+
class FitImage(DeclarativeBehavior, StencilBehavior, AsyncImage):
9192
"""
9293
Fit image class.
9394
9495
For more information, see in the
96+
:class:`~kivymd.uix.behaviors.declarative_behavior.DeclarativeBehavior` and
9597
:class:`~kivy.uix.image.AsyncImage` and
9698
:class:`~kivymd.uix.behaviors.stencil_behavior.StencilBehavior`
9799
classes documentation.

Diff for: kivymd/uix/navigationbar/navigationbar.kv

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
) \
6060
if self.parent else self.theme_cls.transparentColor
6161
RoundedRectangle:
62-
radius: [16,]
62+
radius: [dp(16), ]
6363
size:
6464
( \
6565
(self.parent.parent._selected_region_width, dp(32)) \

Diff for: kivymd/uix/progressindicator/progressindicator.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ def build(self):
204204

205205
from kivymd import uix_path
206206
from kivymd.theming import ThemableBehavior
207+
from kivymd.uix.behaviors import DeclarativeBehavior
207208

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

214215

215-
class MDLinearProgressIndicator(ThemableBehavior, ProgressBar):
216+
class MDLinearProgressIndicator(DeclarativeBehavior, ThemableBehavior, ProgressBar):
216217
"""
217218
Implementation of the linear progress indicator.
218219
219220
For more information, see in the
221+
:class:`~kivymd.uix.behaviors.declarative_behavior.DeclarativeBehavior` and
220222
:class:`~kivymd.theming.ThemableBehavior` and
221223
:class:`~kivy.uix.progressbar.ProgressBar`
222224
classes documentation.

0 commit comments

Comments
 (0)