Skip to content

Commit

Permalink
2.0.0 - Material Design 3
Browse files Browse the repository at this point in the history
Fix doc string.
  • Loading branch information
HeaTTheatR committed Nov 27, 2023
1 parent 5a85f2f commit 21adae4
Showing 1 changed file with 50 additions and 57 deletions.
107 changes: 50 additions & 57 deletions kivymd/theming.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,26 +174,29 @@ def build(self):
KV = '''
MDScreen:
md_bg_color: self.theme_cls.backgroundColor
MDCard:
orientation: "vertical"
padding: 0, 0, 0 , "36dp"
size_hint: .5, .5
style: "elevated"
pos_hint: {"center_x": .5, "center_y": .5}
elevation: 2
shadow_offset: 0, -2
MDLabel:
text: "Theme style - {}".format(app.theme_cls.theme_style)
halign: "center"
valign: "center"
bold: True
font_style: "H5"
font_style: "Display"
role: "small"
MDRaisedButton:
text: "Set theme"
MDButton:
on_release: app.switch_theme_style()
pos_hint: {"center_x": .5}
MDButtonText:
text: "Set theme"
'''
Expand All @@ -219,8 +222,10 @@ def switch_theme_style(self):
.. code-block:: python
from kivy.clock import Clock
from kivymd.app import MDApp
from kivymd.uix.button import MDRaisedButton
from kivymd.uix.button import MDButton, MDButtonText
from kivymd.uix.card import MDCard
from kivymd.uix.label import MDLabel
from kivymd.uix.screen import MDScreen
Expand All @@ -236,14 +241,18 @@ def build(self):
MDCard(
MDLabel(
id="label",
text="Theme style - {}".format(self.theme_cls.theme_style),
text="Theme style - {}".format(
self.theme_cls.theme_style),
halign="center",
valign="center",
bold=True,
font_style="H5",
font_style="Display",
role="small",
),
MDRaisedButton(
text="Set theme",
MDButton(
MDButtonText(
text="Set theme",
),
on_release=self.switch_theme_style,
pos_hint={"center_x": 0.5},
),
Expand All @@ -252,20 +261,25 @@ def build(self):
padding=(0, 0, 0, "36dp"),
size_hint=(0.5, 0.5),
pos_hint={"center_x": 0.5, "center_y": 0.5},
elevation=2,
shadow_offset=(0, -2),
style="elevated",
)
)
)
def on_start(self):
def on_start(*args):
self.root.md_bg_color = self.theme_cls.backgroundColor
Clock.schedule_once(on_start)
def switch_theme_style(self, *args):
self.theme_cls.primary_palette = (
"Orange" if self.theme_cls.primary_palette == "Red" else "Red"
)
self.theme_cls.theme_style = (
"Dark" if self.theme_cls.theme_style == "Light" else "Light"
)
self.root.ids.card.ids.label.text = (
self.root.get_ids().label.text = (
"Theme style - {}".format(self.theme_cls.theme_style)
)
Expand Down Expand Up @@ -304,58 +318,37 @@ def build(self):
"""
App theme style.
.. tabs::
.. tab:: Imperative python style
.. code-block:: python
from kivymd.app import MDApp
from kivymd.uix.screen import MDScreen
from kivymd.uix.button import MDRectangleFlatButton
class MainApp(MDApp):
def build(self):
self.theme_cls.primary_palette = "Orange"
self.theme_cls.theme_style = "Dark" # "Light"
screen = MDScreen()
screen.add_widget(
MDRectangleFlatButton(
text="Hello, World",
pos_hint={"center_x": 0.5, "center_y": 0.5},
)
)
return screen
MainApp().run()
.. code-block:: python
.. tab:: Declarative python style
from kivy.clock import Clock
.. code-block:: python
from kivymd.app import MDApp
from kivymd.uix.screen import MDScreen
from kivymd.uix.button import MDButton, MDButtonText
from kivymd.app import MDApp
from kivymd.uix.button import MDRectangleFlatButton
from kivymd.uix.screen import MDScreen
class Example(MDApp):
def build(self):
self.theme_cls.primary_palette = "Orange"
self.theme_cls.theme_style = "Light" # "Dark"
return MDScreen(
MDButton(
MDButtonText(
text="Hello, World",
),
style="outlined",
pos_hint={"center_x": 0.5, "center_y": 0.5},
)
)
class Example(MDApp):
def build(self):
self.theme_cls.primary_palette = "Orange"
self.theme_cls.theme_style = "Dark" # "Light"
def on_start(self):
def on_start(*args):
self.root.md_bg_color = self.theme_cls.backgroundColor
return (
MDScreen(
MDRectangleFlatButton(
text="Hello, World",
pos_hint={"center_x": 0.5, "center_y": 0.5},
),
)
)
Clock.schedule_once(on_start)
Example().run()
Example().run()
.. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/theme-style.png
:align: center
Expand Down

0 comments on commit 21adae4

Please sign in to comment.