Python in Mobile development





It's no secret that the scope of Python is quite wide: from web-based technologies, the gaming industry, and ending with NASA projects. Python works almost everywhere: from handheld computers and smartphones to network servers and on almost all well-known platforms such as Windows, Linux / UNIX, macOS, Palm OS, Raspberry PI and so on. Thanks to the Kivy framework , in 2011 Python also mastered mobile platforms in terms of developing applications for iOS and Android , and in 2015, using the KivyMD library , Python learned to use Material Design .



The KivyMD library is a collection of widgets in the style of Material Design , for use in the Kivy cross-platform framework. In my previous article KivyMD - life goes on , which was released a year ago, I already talked about fork of this library, but in issues and in the mail I often received notifications that the features declared in the fork are not available when installing KivyMD from PyPi . And this was really so, because PyPi contained an old version of the library four years ago from the GitLab repository, which is no longer supported by the author and, since we did not want to use a new name for our fork, such as KivyMD-fork, and load the package into PyPi with such name, it was decided to write to the author of KivyMD Andrés Rodríguez (@mixedCase_) and ask him to remove his package. After some lengthy negotiations, Andre gave us an invite to the Python Package , provided that he remained a co-author of the library. So now the official library repository is here , and our latest updates are available in PyPi .



So, what changes in the library happened a year later? Thanks to those people who use KivyMD in their projects, we have eliminated quite a few errors. Now the repository has 81 closed questions. This is if you do not take into account the fact that the lion's share of issues is resolved in Discord online chat user support. There are both Russian-language and English-language sections in it. Not all Material Design specifications are currently implemented, because almost two people work on the library in their free time. What has already been implemented and what I would like to implement can be viewed in this list . It is far from complete, but you can supplement it, as editing access is open to everyone. Here are some new widgets:



Tooltip



Material design tooltip



code example
from kivy.lang import Builder from kivy.factory import Factory from kivymd.app import MDApp Builder.load_string(''' #:import random random #:import hex_colormap kivy.utils.hex_colormap #:import get_color_from_hex kivy.utils.get_color_from_hex #:import md_icons kivymd.icon_definitions.md_icons #:set ICONS list(md_icons.keys()) <IconButtonTooltips@MDIconButton+MDTooltip> <ExampleTooltips@BoxLayout> orientation: 'vertical' MDToolbar: title: "Example Tooltips" md_bg_color: get_color_from_hex(hex_colormap["crimson"]) elevation: 10 left_action_items: [['dots-vertical', lambda x: None]] tooltip_text: "MDToolbar" Screen: BoxLayout: size_hint: None, None size: self.minimum_size padding: "10dp" spacing: "10dp" pos_hint: {'center_x': .5, "center_y": .9} IconButtonTooltips: icon: random.choice(ICONS) tooltip_text: "MDIconButton" IconButtonTooltips: icon: random.choice(ICONS) tooltip_text: "MDIconButton" IconButtonTooltips: icon: random.choice(ICONS) tooltip_text: "MDIconButton" IconButtonTooltips: icon: random.choice(ICONS) tooltip_text: "MDIconButton" IconButtonTooltips: icon: random.choice(ICONS) tooltip_text: "MDIconButton" IconButtonTooltips: icon: random.choice(ICONS) tooltip_text: "MDIconButton" ''') class Test(MDApp): def build(self): return Factory.ExampleTooltips() Test().run()
      
      













* Mac OS example











Bottom app bar



Material Design Bottom App Bar











On the left is an example of how the Bottom App Bar works from the Flutter demo application, on the right is a demonstration of the KivyMD Bottom App Bar library.



code example
 from kivy.factory import Factory from kivymd.app import MDApp from kivy.lang import Builder Builder.load_string( """ <BottomAppBar@Screen> BoxLayout: spacing: dp(10) orientation: 'vertical' MDToolbar: title: "Title" md_bg_color: app.theme_cls.primary_color left_action_items: [['menu', lambda x: x]] Widget: MDBottomAppBar MDToolbar: title: "Title" icon: "git" type: "bottom" left_action_items: [["menu", lambda x: x]] """ ) class BottomAppBarTest(MDApp): def build(self): return Factory.BottomAppBar() BottomAppBarTest().run()
      
      







Backdropr



Material Design Backdropr











On the left is an example of how Backdropr works from the Flutter demo application, on the right is a demonstration of the Backdropr of the KivyMD library.



We also added the Studies section in the library, which will host demo applications such as Shrine , Basil, and others. For now, you can see what the Shrine application looks like:





And here is the same thing, but from the Flutter application:





So KivyMD looks on Android devices. In some places, of course, there are performance problems, but this concerns, most likely, Kivy itself. For example, there are still problems with starting “heavy” libraries. In the following video, I gave an example application using OpenCV as a backend to an Android camera:





In this particular case, nothing can be done, because at the start, not only OpenCV and NumPy are loaded, but also native calls occur in order to connect all this. However, a well-designed mobile application on Kivy and KivyMD starts pretty quickly. All this applies to mobile platforms. There are no such problems on the desktop and KivyMD looks simply gorgeous there:



Mac OS:





Windows:





In principle, it doesn’t matter which OS it will work on, because KivyMD , like Kivy, looks the same everywhere. You yourself must decide what kind of application your application will have and I think this is only a plus.



We have a lot of plans, but not enough hands. For example, while there is no time to refine the file manager for desktop systems, I would like to introduce support for iOS widgets and much more ... However, despite all the shortcomings, the number of downloads and interest in the library is growing every day:









Join the community if you love Python as much as we love it!



Youtube Channel

KivyMD News

Discord chat



All Articles