EzDev.org

kivy

Open source Python framework for creating NUI applications, running on Windows, Linux, OS X, Android and iOS Kivy: Cross-platform Python Framework for NUI Development open source python framework for rapid development of applications that make use of innovative user interfaces, such as multi-touch apps.


Difference between Kivy and Java for android apps

For a python developer that has some experience creating android apps with java. I want to create a small app that access my university portal and retrieve some data to easy access it on android.

1) Which one its easier and faster to develop android apps?

2) Does Kivy has limitations to access certain parts of android (like not fully integrated with its api)?

3) And finally, an android app developed using kivy would run as fast as one developed using java?


Source: (StackOverflow)

Rounding button corners in kivy

What is the preferred way to create rounded corners for buttons in kivy?

Are there other equally viable ways to perform this task? Thank you.


Source: (StackOverflow)

Drawing SVG on Kivy canvas

I am new to Kivy. i need to create a classic analog clock.

My Question is: how to draw svg graphics into kivy canvas?


Source: (StackOverflow)

How do you check for keyboard events with kivy?

So, awhile ago, I started teaching myself kivy. I started with the main kivy website and went through its pong making tutorial and upon finishing that I decided to try and give it key input. I just can't seem to find any kind of guide to key input with kivy! Anyone know some kind of tutorial or can provide some easy to understand code? I did look at the Keyboard Listener in the examples folder of kivy, but I'm not quite sure how to use that if I'm supposed to.

Thanks for any assistance.


Source: (StackOverflow)

How good is Kivy for android? [closed]

Very little is written about kivy, can you please tell me how good is kivy cross platform framework for Android?


Source: (StackOverflow)

What Kivy Tutorials Are Available [closed]

What Kivy tutorials and learning aids exist? Where is the list for Kivy?

This is besides the pong tutorial on their website?


Source: (StackOverflow)

Can't install Kivy: Cython/GCC error

so I tried to install Kivy following the instructions from the official site:

$ sudo apt-get install python-setuptools python-pygame python-opengl \
  python-gst0.10 python-enchant gstreamer0.10-plugins-good python-dev \
  build-essential libgl1-mesa-dev libgles2-mesa-dev python-pip

$ sudo pip install --upgrade cython

$ sudo easy_install kivy

This is what I get:

Searching for kivy
Reading http://pypi.python.org/simple/kivy/
Best match: Kivy 1.4.1
Downloading http://pypi.python.org/packages/source/K/Kivy/Kivy-1.4.1.tar.gz#md5=94bba894269e4bdecc7881f256367e01
Processing Kivy-1.4.1.tar.gz
Running Kivy-1.4.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-MMi2Fv/Kivy-1.4.1/egg-dist-tmp-EcKbfC
[INFO   ] Kivy v1.4.1
Found GLES 2.0 headers at /usr/include/GLES2/gl2.h
Build configuration is:
 * use_opengl_es2  =  True
 * use_glew  =  False
 * use_opengl_debug  =  False
 * use_mesagl  =  False
Generate config.h
Generate config.pxi
/tmp/easy_install-MMi2Fv/Kivy-1.4.1/kivy/graphics/transformation.c: In function ‘__pyx_f_4kivy_8graphics_14transformation_6Matrix_identity’:
/tmp/easy_install-MMi2Fv/Kivy-1.4.1/kivy/graphics/transformation.c:2774:13: error: incompatible types when assigning to type ‘__pyx_t_4kivy_8graphics_14transformation_matrix_t’ from type ‘double *’
/tmp/easy_install-MMi2Fv/Kivy-1.4.1/kivy/graphics/transformation.c: In function ‘__pyx_f_4kivy_8graphics_14transformation_6Matrix_inverse’:
/tmp/easy_install-MMi2Fv/Kivy-1.4.1/kivy/graphics/transformation.c:2978:13: error: incompatible types when assigning to type ‘__pyx_t_4kivy_8graphics_14transformation_matrix_t’ from type ‘double *’
/tmp/easy_install-MMi2Fv/Kivy-1.4.1/kivy/graphics/transformation.c:2980:13: error: incompatible types when assigning to type    ‘__pyx_t_4kivy_8graphics_14transformation_matrix_t’ from type ‘double *’
/tmp/easy_install-MMi2Fv/Kivy-1.4.1/kivy/graphics/transformation.c: In function ‘__pyx_f_4kivy_8graphics_14transformation_6Matrix_multiply’:
/tmp/easy_install-MMi2Fv/Kivy-1.4.1/kivy/graphics/transformation.c:3364:13: error: incompatible types when assigning to type ‘__pyx_t_4kivy_8graphics_14transformation_matrix_t’ from type ‘double *’
/tmp/easy_install-MMi2Fv/Kivy-1.4.1/kivy/graphics/transformation.c:3366:13: error: incompatible types when assigning to type ‘__pyx_t_4kivy_8graphics_14transformation_matrix_t’ from type ‘double *’
/tmp/easy_install-MMi2Fv/Kivy-1.4.1/kivy/graphics/transformation.c:3368:13: error: incompatible types when assigning to type ‘__pyx_t_4kivy_8graphics_14transformation_matrix_t’ from type ‘double *’
/tmp/easy_install-MMi2Fv/Kivy-1.4.1/kivy/graphics/transformation.c: In function ‘__pyx_pf_4kivy_8graphics_14transformation_6Matrix_20__str__’:
/tmp/easy_install-MMi2Fv/Kivy-1.4.1/kivy/graphics/transformation.c:3674:13: error: incompatible types when assigning to type ‘__pyx_t_4kivy_8graphics_14transformation_matrix_t’ from type ‘double *’
 error: Setup script exited with error: command 'gcc' failed with exit status 1

After failing to find an answer in the web I began to investigate the files which generated the error: transformation.c, transformation.pyx and transformation.pyd. I also read a little about Cython.

Firstly, all errors are of the same kind:

error: incompatible types when assigning to type ‘__pyx_t_4kivy_8graphics_14transformation_matrix_t’ from type ‘double *’

The first error is raised here:

__pyx_t_3 = __pyx_v_self->mat;

The type of __pyx_t_3 is:

__pyx_t_4kivy_8graphics_14transformation_matrix_t

It has this weird name because it was generated automatically from the transformation.pxd file:

ctypedef double matrix_t[16]

So, type(__pyx_t_3) == type(matrix_t) == double *.

The type of __pyx_v_self is:

struct __pyx_obj_4kivy_8graphics_14transformation_Matrix *

Again, it was generated from transformation.pxd:

ctypedef double matrix_t[16]

cdef class Matrix:
    cdef matrix_t mat
    ...

Therefore, type(__pyx_v_self->mat) == type(Matrix.mat) == type(matrix_t) == double *

As we can see, both sides of the assignment:

__pyx_t_3 = __pyx_v_self->mat;

are of (double *) type.

Why is this error:

error: incompatible types when assigning to type ‘__pyx_t_4kivy_8graphics_14transformation_matrix_t’ from type ‘double *’

being raised then?

It looks like the compiler is not recognizing the type of matrix_t as a double *.


Source: (StackOverflow)

Error packaging Kivy with numpy library for Android using buildozer

I am trying to create an Android package of my Kivy application using buildozer but I am getting this error when I try to include the numpy:

resume of the error:

compile options: '-DNO_ATLAS_INFO=1 -Inumpy/core/include -Ibuild/src.linux-x86_64-2.7/numpy/core/include/numpy -Inumpy/core/src/private -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -Inumpy/core/include -I/home/joao/github/buildozer/.buildozer/android/platform/python-for-android/build/python-install/include/python2.7 -Ibuild/src.linux-x86_64-2.7/numpy/core/src/multiarray -Ibuild/src.linux-x86_64-2.7/numpy/core/src/umath -c'
ccache: numpy/linalg/lapack_litemodule.c
ccache: numpy/linalg/python_xerbla.c
/usr/bin/gfortran -Wall -lm build/temp.linux-x86_64-2.7/numpy/linalg/lapack_litemodule.o build/temp.linux-x86_64-2.7/numpy/linalg/python_xerbla.o -L/usr/lib -L/home/joao/github/buildozer/.buildozer/android/platform/python-for-android/build/python-install/lib -Lbuild/temp.linux-x86_64-2.7 -llapack -lblas -lpython2.7 -lgfortran -o build/lib.linux-x86_64-2.7/numpy/linalg/lapack_lite.so
/usr/bin/ld: build/temp.linux-x86_64-2.7/numpy/linalg/lapack_litemodule.o: Relocations in generic ELF (EM: 40)
/usr/bin/ld: build/temp.linux-x86_64-2.7/numpy/linalg/lapack_litemodule.o: Relocations in generic ELF (EM: 40)
build/temp.linux-x86_64-2.7/numpy/linalg/lapack_litemodule.o: error adding symbols: File in wrong format
collect2: error: ld returned 1 exit status
/usr/bin/ld: build/temp.linux-x86_64-2.7/numpy/linalg/lapack_litemodule.o: Relocations in generic ELF (EM: 40)
/usr/bin/ld: build/temp.linux-x86_64-2.7/numpy/linalg/lapack_litemodule.o: Relocations in generic ELF (EM: 40)
build/temp.linux-x86_64-2.7/numpy/linalg/lapack_litemodule.o: error adding symbols: File in wrong format
collect2: error: ld returned 1 exit status
unable to execute _configtest: Exec format error
error: Command "/usr/bin/gfortran -Wall -lm build/temp.linux-x86_64-2.7/numpy/linalg/lapack_litemodule.o build/temp.linux-x86_64-2.7/numpy/linalg/python_xerbla.o -L/usr/lib -L/home/joao/github/buildozer/.buildozer/android/platform/python-for-android/build/python-install/lib -Lbuild/temp.linux-x86_64-2.7 -llapack -lblas -lpython2.7 -lgfortran -o build/lib.linux-x86_64-2.7/numpy/linalg/lapack_lite.so" failed with exit status 1

does anyone knows how to solve it?

P.S. I am using Ubuntu 14.04 64-bit


Source: (StackOverflow)

Kivy for Android apps

I've just started diving into the Android world. I have a lot of experience programming apps in Python, so I've searching for a good combination "Android + Python", and I think I've found it: Kivy.

I need to make applications that are able to download and upload content from the internet, maybe some connection with the map component included in Android and more stuff to make a nice Android app.

But I really don't want to waste my time on something that maybe won't work. So, does anyone has some experience developing Android apps using Kivy? Is it really useful, simple, possible? Or is there a better option you have in mind?


Source: (StackOverflow)

Difference between Kivy and PY4A

I'm new to android development, and I have had some experience with Java, C#, Python, etc. Python being my favourite, I'd like to code Android app with it.
Then I saw this question:
Is there any way to run Python on Android?
The most voted answers mentioned Kivy and ASE(which is now SL4A and includes PY4A).
However, after some googling, I wasn't able to find any useful info about the difference between Kivy and PY4A. Searching for difference between Kivy and SL4A was fruitless, too.

So, as for Kivy and PY4A,
can someone explain, in easy terms:
- What are the similarity and difference between them?
- What are their good and bad parts?
- Are there any other good alternatives?


Source: (StackOverflow)

How to configure Python Kivy for PyCharm on Windows?

I'm having trouble getting Kivy to work with PyCharm on Windows 7. I've managed to add most of the external libraries through File > Settings > Python interpreters > Paths Tab.

I'm using the Kivy version of Python. When I run a Kivy app that works fine with using the [right click > send to > kivy.bat] method in PyCharm, it gives me this error:

Failed modules
Python 2.7.3 (C:/Python27/python.exe) 
_imagingtk
dde
gtk._gtk
pangocairo
Generation of skeletons for the modules above will be tried again when the modules are updated or a new version of generator is available

I think that the problem might by something to do with cython, as my file fails to recognise the kivy.properties file, which is of the Cython *.pxd format.

If someone could please pointer me over to a windows config tutorial for PyCharm and Kivy or give me the solution to my problem, I would greatly appreciate it!


Source: (StackOverflow)

QPython or Kivy for Android programming with Python - producing installable apk

Having read several Q&A's on SO, I realize that one has 2 options i.e. QPython and Kivy to do programming for Android, however, apparently both take different approaches. I am trying to validate my understanding and see if I am missing some key piece of information.

  • QPython allows usage of Kivy library for developing graphical applications
  • QPython and Kivy both use SL4A, while QPython has expanded standard SL4A (or it's bindings for Python) by adding some NFC and similar functions
  • QPython is used to create python scripts that can use wide range of modules, libraries, but they need QPython installed to be executed on target device. There is no way to package script into an apk.
  • Kivy OTOH, allows developer to write applications that compile to apk, using their cloud based build system (alternative - local build system can be set up on Ubuntu Linux) [However, I noticed that most of the sample apk's that use Kivy are pretty large, in the 40MB range. Did I miss anything ?]
  • QPython apk has 2 version i.e. one for Python-2.7 and another one for Python-3.x. For Kivy, I'm not sure which version it is.
  • QPython example script (HelloWorld.py) doesn't seem to behave as expected, from latest QPython-3.x from Market, on an Android Kitkat (4.4.2) system. I get the dialog to enter text, but then I expect a Toast to popup, but nothing happens.
  • Get the impression that both QPython and Kivy are developed by a single developer each (or only one person is really active at present), and don't yet have a biggish community. [This is my biggest concern] I notice that there are 3-4 questions with 'qpython' tag on SO, and more than thousand with 'kivy'!
  • Also get the impression that at this moment Kivy development is somewhat more active (perhaps quite active), but for QPython I don't have a clear picture.
  • Kivy seems to be trying to expand the nature of application that could possibly be written using it, compare to QPython. There are API's like plyer and pyjnius that help expand the possibilities. Perhaps quite significantly, compared to QPython.
  • Both QPython and Kivy seem to be heavily under development. Program (/ script) crashes (/ failures) seem to be reported on both set of tools.

Overall, the opinion as a result (of above points) appears to swing in favour of Kivy, a bit more. Is the understanding correct ? Did I miss any crucial point ? This is not a rhetorical question, and I am looking for factual answers only.


Source: (StackOverflow)

Kivy, Eclipse and PyDev (also PyPy)

According to this post: https://groups.google.com/forum/?fromgroups#!topic/kivy-users/n7c3thksnzg, it is possible to use Eclipse as an IDE for Kivy through PyDev. However, I didn't understand the instructions. Can anyone please elaborate on how to connect Kivy with Eclipse.

Note: I'm on a Windows machine. Also, is it possible to use PyPy instead of the Python Interpreter?

Thanks~!


Source: (StackOverflow)

Rotating an object on a touch event in kivy

I'm working on making a circle that will spin kind of like a large dial. Currently, I have an arrow at the top to show which direction the dial is facing. I'd like its behavior to be kind of like an old timey rotary phone, such that while your finger/cursor is down you can rotate it, but it'll (slowly) yank back to top after you let go.

Here's what my object looks like:

enter image description here

And here's my code:

#!/usr/bin/kivy
import kivy
kivy.require('1.7.2')
import math

from random import random
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.gridlayout import GridLayout
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.relativelayout import RelativeLayout
from kivy.graphics import Color, Ellipse, Rectangle

class MinimalApp(App):
    title = 'My App'
    def build(self):
        root = RootLayout()
        return(root)

class RootLayout(AnchorLayout):
    pass

class Circley(RelativeLayout):
    angle = 0
    def on_touch_down(self, touch):
        ud = touch.ud
        ud['group'] = g = str(touch.uid)
        return True
    def on_touch_move(self, touch):
        ud = touch.ud
#        print(touch.x, 0)
#        print(self.center)
#        print(0, touch.y)
#        print(touch.x - self.center[0], touch.y - self.center[1])
        y = (touch.y - self.center[1])
        x = (touch.x - self.center[0])
        calc = math.degrees(math.atan2(y,x))
        angle = calc if calc > 0 else (360 + calc)
        print(angle)
    def on_touch_up(self, touch):
        touch.ungrab(self)
        ud = touch.ud
        return True

if __name__ == '__main__':
    MinimalApp().run()

And the kv:

#:kivy 1.7.2
#:import kivy kivy

<RootLayout>:
    anchor_x: 'center'                              # I think this /is/ centered
    anchor_y: 'center' 
    canvas.before:
        Color:
            rgba: 0.4, 0.4, 0.4, 1
        Rectangle:
            pos: self.pos
            size: self.size
    Circley:
        anchor_x: 'center'                          # this is /not/ centered.
        anchor_y: 'center' 
        canvas.before:
            PushMatrix
            Color:
                rgba: 0.94, 0.94, 0.94, 1
            Rotate:
                angle: self.angle
                axis: 0, 0, 1
                origin: self.center
            Ellipse:
                source: 'arrow.png'
                size: min(self.size), min(self.size)
                pos: 0.5*self.size[0] - 0.5*min(self.size), 0.5*self.size[1] - 0.5*min(self.size)
                Label:
                    text: unicode(self.size)    # this is /not/ appearing
                    color: 1,0,0,1
        canvas.after:
            PopMatrix

Parts of that are borrowed from the kivy touchtracer demo, and from this SO question.

You can see I have a calculation that is correctly printing the angle between the origin of the circle and the touch event (not sure how this'll respond to multiple fingers, haven't thought that far through), but not sure how to integrate this into a "spinning" feedback event in the interface.


Source: (StackOverflow)

Kivy button text alignment issue

I am trying to develop an email application in Kivy, basically just as an exercise to learn the in's and out's of the framework... I am trying to create the initial window and have reached a bit of a stumbling block! The idea is that it will simply display a list of emails in the inbox, much like any basic email app on a mobile device.

The problem I'm having is that I can't figure out how to get the text of each list item (which is a just a button) to align properly. Using "halign='left'" in my button will make the text align left, but only relative to each button; it's still centered within each button.

My actual app is a bit large to post, so this is a quick and dirty example I made from a stock Kivy example. (I realize this code isn't perfect... like I said quick and dirty for examples sake... it does work though!) So as you can see, the two rows of text on each button align with each other, but they don't all align overall. Can anyone suggest what I would do to make all the text align at, say, 10px from the left of each button? I did find one relative sounding item on StackOverflow, but it didn't really answer the question for example, it seemed to deal more with using images on buttons. I am new to Kivy, but I've read through the tutorials and documentation, as well as searched Google extensively - so any help would be greatly appreciated!

import kivy
kivy.require('1.0.8')

from kivy.app import App
from kivy.core.window import Window
from kivy.uix.button import Button
from kivy.uix.scrollview import ScrollView
from kivy.uix.gridlayout import GridLayout

import random


class ScrollViewApp(App):

    def build(self):
        # create a default grid layout with custom width/height
        layout = GridLayout(cols=1, spacing=10, size_hint=(None, None),
                            width=Window.width)

        # when we add children to the grid layout, its size doesn't change at
        # all. we need to ensure that the height will be the minimum required to
        # contain all the childs. (otherwise, we'll child outside the bounding
        # box of the childs)
        layout.bind(minimum_height=layout.setter('height'))

        # add button into that grid
        for i in range(30):
            btn = Button(text=str(i * random.random()) + '\n' + str(i * random.random()),
                         size=(300, 40),
                         size_hint=(None, None),
                         halign='left')
            layout.add_widget(btn)

        # create a scroll view, with a size < size of the grid
        root = ScrollView(size_hint=(None, None))
        root.size = (Window.width, Window.height)
        root.center = Window.center
        root.add_widget(layout)

        return root

if __name__ == '__main__':

    ScrollViewApp().run()

Source: (StackOverflow)