EzDevInfo.com

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.

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)

Advertisements

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)

fatal: could not create work tree dir 'kivy'

I'm trying to clone my fork of the kivy git, but it's not working. I've made the fork correctly, I believe, but when I type this into my Mac terminal:

git clone https://github.com/mygitusername/kivy.git

I get this error:

fatal: could not create work tree dir 'kivy.: Permission denied

Anyone see what I am doing wrong? Thanks!


Source: (StackOverflow)

Kivy ObjectProperty to update label text

I am working on creating a kivy user interface to display the values generated by a data model I've written as a standard python object. In essence, I would like the user to be able to press a button, which would change the underlying data model and the results of this change would be automatically updated and displayed. It is my understanding that this can be implemented using kivy properties (in this case, ObjectProperty).

Here is some example code:

import kivy
kivy.require('1.7.0')

from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.properties import ObjectProperty
from kivy.lang import Builder

Builder.load_string("""
<RootWidget>:
    cols: 2
    Label:
        text: "Attribute a:"
    Label:
        text: root.data_model.a
    Label:
        text: "Attribute b:"
    Label:
        text: root.data_model.b
    Label:
        text: "Attribute c:"
    Label:
        text: root.data_model.c
    Button:
        text: "Make data_model.a longer"
        on_press: root.button_press()
    Button:
        text: "Make data_model.b shorter"
        on_press: root.button_press2()
""")


class DataModel(object):
    def __init__(self):
        self.a = 'This is a'
        self.b ='This is b'

    @property
    def c(self):
        return self.a + ' and ' + self.b

class RootWidget(GridLayout):
    data_model = ObjectProperty(DataModel())

    def button_press(self, *args):
        self.data_model.a = 'This is a and it is really long now'
        print self.data_model.c

    def button_press2(self, *args):
        self.data_model.b = 'B'
        print self.data_model.c

class TestApp(App):
    def build(self):
        return RootWidget()

app = TestApp()
app.run()

The desired result is for when user presses either button, the labels would automatically update to show the new properties. As can be seen by the print statements, the data_model is getting updated correctly. However, none of the labels are updating. Can someone clarify how to do this?


Source: (StackOverflow)

Custom syntax highlighting in Geany

I am trying to create custom syntax highlighting for Kivy '.kv' files in the Geany editor. Although the specific filetype seems irrelavant to the issue I'm having, as any efforts I make at getting syntax highlighting to work for a custom filetype results in a completely non-highlighted file. I believe I have done my homework on this, and nothing seems to work.

I have added the following to ~/.config/geany/filetype_extensions.conf

Kivy=*.kv;

I also have a custom type definition file named 'filetypes.Kivy.conf' in ~/.config/geany/filedefs/. I have tried basing this file off several of the stock type definition files in /usr/share/geany/ and the file never gets any syntax highlighting applied in Geany. Right now, just for experimentation's sake, my 'filetypes.Kivy.conf' file looks like this:

# For complete documentation of this file, please see Geany's main documentation
[settings]
# default extension used when saving files
extension=kv

# single comments, like # in this file
comment_single=#

[keywords]
# all items must be in one line
primary=size canvas
secondary=pos size

[indentation]
width=4
# 0 is spaces, 1 is tabs, 2 is tab & spaces
type=0

This is very loosly based on the stock XML definition file, but like I said I've tried many other stock files. In many cases I only changed the 'extension=' value to kv and still no highlighting was applied, even though going to Document>Set Filetype in Geany and choosing virtually any random filetype (besides my custom entry) would yeild some sort of highlighting within my .kv file. This is even the case when using the unmodified contents of a stock definition which otherwise works fine on my .kv file when specifically selected in Geany!

Also, the Kivy filetype is listed and selected by default in Document>Set Filetype within Geany, so I must be doing something right here!

I realize this similar question has been asked, but the solutions seem irrelavent to my case, as I've tried every related topic on this and many other sites. My Geany version is 1.22 and I'm running Arch Linux. This is driving me nuts - any suggestions?

Thank you!


Source: (StackOverflow)

No Android SDK environment set for Kivy in Ubuntu 12.04

I've written a game for Android using Python and Kivy. I have downloaded android-sdk-linux and added its path to .bashrc. I've also cloned the python-for-android project to create an apk package of my program. But when I write the following command as instructed in the Kivy manual, I get an error:

./distubute.sh -m "kivy"

error:
    Check build dependencies for Ubuntu
    Check enviromnent
    No ANDROIDSDK environment set, abort

Why?

This is a picture of my ./android.sh in $android-sdk-linux/tools:

Screenshot


Source: (StackOverflow)

Simple kivy tab example

I am new to Android development using Kivy. I have created a tab structure like below:

from kivy.app import App
from kivy.uix.tabbedpanel import TabbedPanel
from kivy.uix.tabbedpanel import TabbedPanelHeader
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.image import Image

class TabbedPanelApp(App):
  def build(self):
      tb_panel= TabbedPanel()

      # Create text tab          
      th_text_head = TabbedPanelHeader(text='Text tab')
      th_text_head.content= Label(text='This is my text content')

      # Create image tab
      th_img_head= TabbedPanelHeader(text='Image tab')
      th_img_head.content= Image(source='sample.jpg',pos=(400, 100), size=(400, 400))

      # Create button tab
      th_btn_head = TabbedPanelHeader(text='Button tab')
      th_btn_head.content= Button(text='This is my button',font_size=20)

      tb_panel.add_widget(th_text_head)
      tb_panel.add_widget(th_img_head)
      tb_panel.add_widget(th_btn_head)          

      return tb_panel

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

I want to add the login widget to the default tab. The code for login widget is:

import kivy 
kivy.require('1.0.5')

from kivy.uix.gridlayout import GridLayout 
from kivy.uix.boxlayout import BoxLayout 
from kivy.uix.button import Button 
from kivy.app import App 
from kivy.lang import Builder 
from kivy.uix.widget import Widget 
from kivy.properties import ObjectProperty, StringProperty 

class loginView(Widget): 
    status=ObjectProperty(None) 
    def validate(self,username,password): 
        print "user - ", username
        print "pwd - ", password
        if username == password: 
            print "in if - ", username,password     
            self.status.text="Login sucess" 
        #mainClass().run() 
        else: 
            self.status.text="Login failed" 

class afterLogin(Widget): 
    def dumb(self): 
        l = BoxLayout(cols="2") 
        btn = Button(text="ad") 
        l.add_widget(btn) 
        print "flag" 

class mainClass(App): 
    def build(self): 
        return loginView()  

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

and the kv file is :

#:kivy 1.0.5 

<loginView>: 
    status:result 
    Label: 
         text:"Contacts Manager" 
         pos:600,600 
         font_size:40 


    Label: 
         text:"Username" 
         pos:450,400 

    Label: 
         text:"Password" 
         pos:450,300 

    TextInput: 
         multiline:False 
         pos:600,425 
         size:200,45 
         font_size:20 
         id:username 

    TextInput: 
         multiline:False 
         pos:600,325 
         password:True 
         size:200,45 
         font_size:20 
         id:password 
    Button: 
         text:"Login" 
         size:100,50 
         pos:600,250 
         on_press:root.validate(username.text,password.text) 
    Label: 
         text:"" 
         pos:600,100 
         id:result 
<afterLogin>: 
    Label: 
         text:"Welcome" 

How can I add this code into the default tab?


Source: (StackOverflow)

Kivy: crossplatform notification icon

I want to create a cross-platform application (Ubuntu and Android) with a notification icon. Is there a standard way to create such an app using Kivy?


Source: (StackOverflow)

Changing the background color of a Button in Kivy

I'm new to Kivy and having trouble specifying the background color of a Button. Here's my simple example:

# custombutton.py

from kivy.app import App
from kivy.uix.widget import Widget


class MyWidget(Widget):
    pass


class CustomButtonApp(App):
    def build(self):
        return MyWidget()


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

And the accompanying kv file custombutton.kv:

#:kivy 1.7.2

<MyWidget>:
    canvas:
        Color:
            rgb: (0.93, 0.93, 0.93)
        Rectangle:
            pos: self.pos
            size: self.size

    Button:
        center: self.parent.center
        font_size: 14
        height: 28
        background_color: (1.0, 0.0, 0.0, 1.0)
        text: "I'm a Button"

I'm sure I'm missing something obvious, but I've been messing with this for over an hour now and getting nowhere. The button seems to get colored a hint of very dark red:

enter image description here

Is this not the way to specify the background color for a Button in Kivy?

Thanks!


Source: (StackOverflow)

Tab/Enter (and other keystrokes) handling in Kivy's TextInput widgets

I'm writing an app using Kivy framework and I stumbled upon a minor but annoying problem: I don't know how to handle Tab/Enter/Arrow keys in text fields so that pressing either of them would dispatch an event, eg. switch the focus (jump) to another TextInput or launch something like send_form()

Could anyone please shed some light on this issue?


Source: (StackOverflow)

why does right-clicking create an orange dot in the center of the circle?

Why does the first widget example in kivy lead to an orange circle in the middle of the yellow one when you right click on the canvas and a pure yellow one when you left click?

    from kivy.app import App
    from kivy.uix.widget import Widget
    from kivy.graphics import Color, Ellipse

    class MyPaintWidget(Widget):
        def on_touch_down(self, touch):
            with self.canvas:
                Color(1, 1, 0)
                d = 30.
                Ellipse(pos=(touch.x - d/2, touch.y - d/2), size=(d, d))


    class MyPaintApp(App):
        def build(self):
            return MyPaintWidget()


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


Source: (StackOverflow)