Greetings!Not so long ago, they wrote about Python in Mobile development and the development of mobile applications in Python using the Kivy and KivyMD libraries . This article will continue to acquaint you with cross-platform Python tools, and specifically today we will consider the new items that have appeared in the KivyMD library recently.KivyMD is an addition to the Kivy framework (a cross-platform tool focused on developing modern applications with multitouch support), which provides the user with a set of widgets "from Google". In quotation marks, because under the hood, KivyMD uses Kivy, which in turn pulls SDL2 and OpenGL ES 2.0 to render the UI, that is, like in Flutter , there is its own engine for rendering widgets, which means everything you see on the screen - this is not native. Exceptions and disputes regarding this, we will resolutely leave aside and proceed.MDDataTable
So, in KivyMD latest version (0.104.1) we finally implemented the DataTable widget:Implementation of use is quite simple:from kivy.metrics import dp
from kivymd.app import MDApp
from kivymd.uix.datatables import MDDataTable
class Example(MDApp):
def build(self):
data_tables = MDDataTable(
size_hint=(0.9, 0.6),
use_pagination=True,
check=True,
column_data=[
("Desert (100g serving)", dp(70)),
("Calories", dp(30)),
("Fat (g)", dp(30)),
("Carbs (g)", dp(30)),
("Protein (g)", dp(30)),
("Sodium (mg)", dp(30)),
("Calcium (%)", dp(30)),
("Iron (%)", dp(30)),
],
row_data=[
("Frozen yogurt", "159", "6.0", "24", "4.0", "87", "14%", "1%"),
],
)
data_tables.open()
Example().run()
In DataTable, not all functions from Material Design spec DataTables are implemented yet , but we are working on improvements.MDDialogs
The use of dialog boxes has been simplified and improved - now they comply with the material design specification. dialog = MDDialog(
title="Reset settings?",
text="This will reset your device to its default factory settings.",
buttons=[
MDFlatButton(
text="CANCEL", text_color=self.theme_cls.primary_color
),
MDFlatButton(
text="ACCEPT", text_color=self.theme_cls.primary_color
),
],
)
dialog.open()
MDCard
In MDCard were added to conduct focus_behavior and ripple_behavior :focus_behavior :MDCard:
focus_behavior: True
ripple_behavior :MDCard:
ripple_behavior: True
MDCardSwipe :<SwipeToDeleteItem>:
size_hint_y: None
height: content.height
MDCardSwipeLayerBox:
MDCardSwipeFrontBox:
OneLineListItem:
id: content
text: root.text
_no_ripple_effect: True
class SwipeToDeleteItem(MDCardSwipe):
text = StringProperty()
MDTextField
Added text field with fill mode :MDTextField:
hint_text: "Fill mode"
mode: "fill"
fill_color: 0, 0, 0, .4
In all classes of text fields there is the ability to set the icon on the right:MDMenu
Improved performance of the MDMenu class.TapTargetView
Added TapTargetView widget:MDFloatingActionButtonSpeedDial
Implemented the MDFloatingActionButtonSpeedDial widget:from kivy.uix.screenmanager import Screen
from kivymd.app import MDApp
from kivymd.uix.button import MDFloatingActionButtonSpeedDial
class Example(MDApp):
data = {
'language-python': 'Python',
'language-php': 'PHP',
'language-cpp': 'C++',
}
def build(self):
screen = Screen()
speed_dial = MDFloatingActionButtonSpeedDial()
speed_dial.data = self.data
speed_dial.rotation_root_button = True
screen.add_widget(speed_dial)
return screen
Example().run()
Hot reload
The Flutter framework is very proud of its Hot reload tool (reloading widget properties on the fly) ... In Kivy, this has long been implemented. We just improved this utility and included it in the KivyMD package:And, yes, the official KivyMD documentation is already available. That's all for now, thanks for watching!