📜 ⬆️ ⬇️

Kivy is a small fruit with a great future.


Welcome to all!


Today's small structure, however, as always, of course, with a keynote and stationer, as a keynote, frame for a multiplayer-or-one -self-to-one-on-one-to-one connection.


B dannom matepiale pazveyany myths are played o tom, chto ne Kivy goditcya for pazpabotki clozhnyx ppilozheny, are played oppovepgnyty ppedvzyatye opinion kotopye ppedctavlyayut pazpabotchikam and zakazchikam Kivy, kak malo podxodyaschy and kpivoy inctpyment for cepeznoy paboty and covcem negodnym for production.


Cegodnyashnyaya ctatya bolno ydapit Po koctylyam other frameworks, zactavit their poshatnytcya, ocoznat, they are normally chto ne yzhe otnyud edinctvennye and podvinytcya nazad in peytinge kpoccplatfopmennoy pazpabotki, cppavedlivo yctypaya mecto Kivy, both in terms of more rapid development, not less reliable and more profitable tool!


All interested, welcome under the cat ...


Back to the past


The desperate recuperative recuperation would be to remember what happened next year from the second part of the Kivy cycle. CREATION TO PRODUCTION - One step so and did not appear on the pages of Habpa. This is connected with the fact that for the last year almost all of my free time I was busy in other projects, I had a couple of free hours and a wild desire to sleep.


So, ppotsecce paboty nad obeschannym in vysheypomyanytoy ctate ppilozheniem PyConversations , unto me poctypilo ppedlozhenie cdelat nebolshyyu ppogpammy nA Kivy for ppocmotpa and napicaniya poctov in gpyppy BKontakte , kotopaya pocvyaschena tematike Kivy.


Ghd o Kivy framework in that sense, which is younger, wonderfully and very slowly, has never been expected in production, and we’ll be better off at all and have been reformed by Reactor.


This is the name of the author of the Future


The present construction is the demilitarization of the potential of the project by means of the Kivy framework. And how many of my programs and activities on Haber are associated with Kivy, so that would not be a good material for the sponsor of the group and the programmers would be the group of the sponsors of the group and the sponsor of the group.


Invisible


I was not surprised, but all of them were staged by the observer at Habré on the ratings of modern frames for a mobile development system from a remote developer. Or only a little com- munity in the sense that Kivy is dreamed up only to create quick ways to use simple programs, simple programs and we have already been able to do React docs for us and our children.


Thought about the situation in the pianofortea.tk.


Uncle Mok, can I throw mud at him?


Misdiagnosis 1


The procedure for Kivy closes when trying to turn it in three.


Loss 2


The poor part of the job with a list with a list with a larger number of widgets.


Loss 3


LOCATION OF OPTIMAL INTERFACE AND APPLICATION.


Misdiagnition 4


BIG END OF THE FINAL PROCESS FOR INSTALLATION ON DIVISION (from 15 MB).


Well, djvayte on the example of the client VKGroups, sponsored by the use of the framework Kivy, proceeded by this pitch ...


Misdiagnosis 1


The procedure for Kivy closes when trying to turn it in three.



When you see the trips in the trips, it is not closable, and it continues in a consistent and stable manner, unlike most native applications, such as CMBrowser, which is always open up, as well as the mainboard programs, as well as the mainboard, as well as the mainboard, you can use the same patterns, you can always get to the pro- grammes, and you can use the same programs, and you can use the same programs, and you can use the same programs, and you can use the same programs, and you will have the same patterns, and you can use the same patterns, and you will have the same patterns, and you can use the same patterns, and you can use the same patterns, and you will have the same programs, and you can use the same patterns, and you will have the same patterns, and you will have the programs, you can use, as well as the main drawers, and the pro- jects, which are always open, can be out of trouble, you can use all the programs, you can use all the programs, you can use all the programs, you can use all the programs and you will be able to use them. The application and a bunch of programs on Android are reloaded when you exit the tray. But the label was hanged for some reason only on the Kivy. Do not you think that this is not fair?


Loss 2


The poor part of the job with a list with a list with a larger number of widgets.


Before the release of the version of Kivy 1.9.2, I was also impressed with this kind of opinion. Dannaya ppoblema ctala kamnem ppetknovenya VARIATIONS pazpabotke VKGroups, pockolky pendeping cpicka coctoyaschego even from dvadtsati poctov / kommentapiev (Shout kactomny vidzhet pocta / kommentapiya was poctpoen of cemi vidzhetov Kivy: Label, AsyncImage, Button, etc, cymme poctov 20 * 7 widgets Kivy = 140 widgets and controlers)



... took him a lot, a lot of time (about 10 seconds), which was done by abusively not usable and not suited for use in production.


Peshenie dannoy ppoblemy okazaloc very simple - to icpolzyyte vyvoda bolshix cpickov ne ScrollView a RecycleView - vidzhet, Who, nachinaya c vepcii Kivy 1.9.2, vklyuchen in ctandaptnyyu biblioteky Kivy.


The following example of a file manager using RecycleView demonstrates opening a list of 1000 items (1000 empty text files on my system that I created in advance)



Even though you can display on the screen a list of 10,000 pkktokov. It doesn’t affect this, as RecycleView will create a list of items on the screen. A speed of rendering shows the complexity of the widget from the key of the list.


A simple example of creating a list with RecycleView
from kivy.uix.boxlayout import BoxLayout from kivy.lang import Builder from kivy.app import App from kivy.utils import hex_colormap, get_color_from_hex from kivy.metrics import dp KV = """ #   . <Item@BoxLayout>: color: [] name_color: '' Label canvas.before: Color: rgba: root.color Rectangle: pos: self.pos size: self.size text: root.name_color color: 0, 0, 0, 1 #   . BoxLayout: orientation: "vertical" #   ScrollView. RecycleView: id: rv key_size: 'height' key_viewclass: 'viewclass' RecycleBoxLayout: id: box default_size: None, None default_size_hint: 1, None size_hint_y: None height: self.minimum_height orientation: 'vertical' spacing: dp(10) padding: dp(5) """ class RecycleViewApp(App): def build(self): self.root = Builder.load_string(KV) self.rv = self.root.ids.rv self.create() def create(self): colors = [] #  . for name_color in hex_colormap.keys(): colors.append({ "name_color": name_color, "viewclass": "Item", 'color': get_color_from_hex(hex_colormap[name_color]), 'height': dp(40) }) self.rv.data = colors RecycleViewApp().run() 

Well, the following animation demonstrates the work of the native file manager from the PyDroid3 program at about the same level of complexity:



As you see, the speed of work does not differ from the work of the naval orders. More than that, I have met file managers of such a level, written in Java, who work much smaller.


Loss 3


LOCATION OF OPTIMAL INTERFACE AND APPLICATION.


Here it is worth exploring from the Kivy Ski Resort that you can find a list of things to do. However, in standard delivery with the default parameters of the Android 4 theme, all of these widgets look generously and dramatically.


Odnako blagodapya tomy chto date every vidzhet and kontpoll in Kivy pezinovy ​​and imeet kychy cvoyctv and papametpov you mozhete delat c them vce chto zaxotite, ppidat them lyuboy look and povedenie vplot do dicneevckoy animatsii and dokazat chto nA camom dele etot vidzhet was ynacledovan from the principle of this. Tak poyavilac zamechatelnaya biblioteka Kivy Material A Design , kotopaya cpedctvami camogo Kivy pealizyet ogpomny cpicok 'nativnyx' vidzhetov and kontpollov, icpolzyyuschixcya for pazpabotki in Java.


By quoting the word 'native', I mean that these are all the same Kivy widgets that look and behave just like their brothers in Java.


Misdiagnition 4


BIG END OF THE FINAL PROCESS FOR INSTALLATION ON DIVISION (from 15 MB)


Once I read on the forum the question of how much the finished application weighs on Kivy. I was very surprised by one answer, that, say, from 15 Mb, and there, depending on how much you put on. I declare with confidence that all this is utter nonsense! Your Kivy application may well be 5-6 meters in size, it all depends on the resources in your program (images, audio files, additional libraries, etc.). And, perhaps, you did not know about it, but the usual Hello world, written in Kivy, has 4-5 Mb of unnecessary files and libraries that can be safely discarded from your project.


For example, I downloaded and installed the Kivy Pyonic Interpreter 3 app - Python 3.6 interpreter for Android. Its size is 12 megabytes. Having exhausted everything unnecessary from the package (about 500 kilobytes of the standard library, 1 megabyte of unnecessary Kivy fonts, 2.2 megabytes of static libraries that are not used, and not used Kivy packages and modules on trifles). The package size of 12 megabytes was equal to 8.2 meters. But, considering that Pyonic uses the pygmemts and Jedi libraries (which I, naturally, cannot throw out without disrupting the application), the total size of which is 3.5 megabytes, you can easily find that the simplest application on Kivy weighs 4.6 meters, and not 10-15, as many believe.


Since in this article we will not dwell on the filtering technology of unused resources, I will give you a demonstration of installing and running the Pyonic application. Note the size of the installation package.



Continuing the theme of nativeness, I want to note that in the Kivy applications you can use the Java API if the capabilities of the Kivy itself are not enough. For example, you can use the native browser, modal dialogs, toast, geolocation, and much more that is available to Java programmers. Specifically, we will not dwell on this topic today, since the topic of this article is a demonstration of possibilities, and not their analysis. Below is an overview and code for creating a native modal dialog using jnius, a package that allows you to use the Java API in your applications. The following animation demonstrates calling the native and kivy dialogs.



Creating a native conversation using jnius
 from kivy.clock import Clock from kivy.event import EventDispatcher from kivy.logger import Logger from functools import partial from jnius import autoclass, PythonJavaClass, java_method, cast from android import activity from android.runnable import run_on_ui_thread Builder = autoclass('android.app.AlertDialog$Builder') String = autoclass('java.lang.String') context = autoclass('org.renpy.android.PythonActivity').mActivity class _OnClickListener(PythonJavaClass): __javainterfaces__ = ['android.content.DialogInterface$OnClickListener',] __javacontext__ = 'app' def __init__(self, action): self.action = action super(_OnClickListener, self).__init__() @java_method('(Landroid/content/DialogInterface;I)V') def onClick(self, dialog, which): self.action() class AndroidDialog(EventDispatcher): __events__ = ('on_dismiss',) def __init__(self, callback, action_name = 'okay', cancel_name = 'cancel', text = 'Are you sure?', title = 'Alert!', **kwargs): self.callback = callback if callback else lambda *args: None self.title = title self.text = text self.action_name = action_name self.cancel_name = cancel_name def answer(self, yesno): self.callback(yesno) @run_on_ui_thread def open(self): builder = self.builder = Builder( cast('android.app.Activity', context)) builder.setMessage(String(self.text)) builder.setTitle(String(self.title)) self.positive = _OnClickListener(partial(self.answer, True)) self.negative = _OnClickListener(partial(self.answer, False)) builder.setPositiveButton(String(self.action_name), self.positive) builder.setNegativeButton(String(self.cancel_name), self.negative) self.dialog = builder.create() self.dialog.show() def dismiss(self): self.dispatch('on_dismiss') def on_dismiss(self): pass #   . from jnius import autoclass, cast from android.runnable import run_on_ui_thread Toast = autoclass('android.widget.Toast') context = autoclass('org.renpy.android.PythonActivity').mActivity @run_on_ui_thread def toast(text, length_long=False): duration = Toast.LENGTH_LONG if length_long else Toast.LENGTH_SHORT String = autoclass('java.lang.String') c = cast('java.lang.CharSequence', String(text)) t = Toast.makeText(context, c, duration) t.show() 

As you can see, to use the Java API you need to understand it well. You can also write your own classes in Java and thus use them if the need arises. Although the resources of Kivy with the head cover the needs of modern mobile applications.


In conclusion, I provide a full video of the VKGroups application.



I hope you enjoyed today's review. I promise not to disappear for a year anymore, and I will try at least once a month to publish a publication on application development using the Kivy framework. Your questions and suggestions in the comments, what kind of publications you want to see in the future and on which issues, will help and speed up writing articles on the remarkable Kivy framework, which is gaining popularity.


Well, the fact that interest in Kivy is getting higher every day confirms
Moscow Python , which will be held in February in the Moscow office of Yandex. Presentations will be made by developers from Kaspersky Lab, Sberbank and Yandex. They will talk about asyncio, mobile Python development, and JupyterHub application.


And the most interesting thing is that Vladislav Shashkov will give a talk on the Python mobile application with kivy / buildozer - the key to success , which will tell you about the real experience of creating a mobile application on Kivy. Moreover, there are pitfalls there - if you know about them, you can save a lot of time. Its history will be interesting not only to developers, but also to productologists. From his own experience, he will tell you that new product ideas are no longer being sold as presentations or clickable prototypes, but are being sold as a working service. Quickly and effectively it turns out to do exactly on Python.


Participation is free, but you must register in advance. Limited number of seats.


Thank you for your attention and see you soon!


')

Source: https://habr.com/ru/post/348772/


All Articles