MySQL MTWall with Kivy

1,180 views
Skip to first unread message

Omar Juarez Ortiz

unread,
Nov 4, 2011, 5:04:32 AM11/4/11
to kivy-...@googlegroups.com
Hello all Kivy developers,

Im about to start a project in which we use a 90" multitouch screen powered by Kivy to display Images and Videos, with categories and a filter nice interface. We are totally new to Kivy and actually its our first multitouch wall/table.

The thing in this project is that this MTwall will access content from a local Mysql database (could be other if needed)
this content is meant to be Images and Videos, displayed as a big grid of content that can be filtered.. Cooliris like. Also to Select and image, zoom in etc..

We will also develop a simple Web CMS for an Administrator to Insert, Delete, and Update announcements (images/videos) to the DB. So this content should be accessed by the Kivy application.

We are considering running everything on Local network, so Administrator could just access a local IP for the CMS to control, which will also be the same computer running the Kivy app which will be accessing local DB.

SO FELLOWS....
Any ideas where should I begin making tests ??? is it easy thing to do with Kivy to access a local database content? like images and I guess videos could be more difficult. 

is there any code samples or templates or something similar ?

would be pretty much appreciated... its for a school project.


Thank you.

Mathieu Virbel

unread,
Nov 4, 2011, 5:37:47 AM11/4/11
to kivy-...@googlegroups.com
Hi Omar,

Kivy is written in Python, so you can use any mysql libraries in python.
I suggest you to take a look at sqlalchemy (http://www.sqlalchemy.org/)
for an high level access to database, or if you prefer to write sql
request by hand, you can use directly
http://mysql-python.sourceforge.net/MySQLdb.html.
But both libraries are not standard, and so, not shipped with Kivy.

I can also suggest another way of working with kivy. Use json !
If you create webpage that output json, or data, you can use it in a
simpler manner.
Check: http://kivy.org/docs/api-kivy.network.urlrequest.html
You have 2 examples that demonstrate how to make a request and get the
content. If you output json with good Content-Type, the result will be a
python object. So you can use it directly for creating the list.

Example of web output

URL: /api/get_medias
[
{
'title': 'Image number 1',
'type': 'image',
'url': 'http://yourhost/uploads/image1.jpg' }
{
'title': 'Video number 1',
'type': 'video',
'url': 'http://yourhost/uploads/video.mkv'
}
]

And how you can use it in Kivy (not tested, must be improved, but just
for the logic.):

from kivy.network.urlrequest import UrlRequest
from kivy.uix.image import Image
from kivy.uix.video import Video
from random import random

class MyApp(App):

def create_objects(self, req, result):
for item in result:
if item['type'] == 'image':
# create image
widget = Image(source=result['url'])
elif item['type'] == 'video':
# create video
widget = Video(source=result['url'])
else:
print 'unknown type for', result
continue
widget.pos = random() * 500, random() * 500
self.root.add_widget(widget)

def build(self):
root = FloatLayout()
req = UrlRequest('http://yourhost/api/get_medias',
self.create_objects)
return root

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


Hope that will give you some tips !

Regards,

Mathieu

Message has been deleted

Björn Wingman

unread,
Jan 17, 2012, 4:44:45 AM1/17/12
to kivy-...@googlegroups.com

The result object is not a dict, but in fact a list of dicts. result[0]['trends'] should give you what you want.

Print out the result object to see the structure.

  

On Jan 17, 2012 8:38 AM, "Omar Juarez Ortiz" <omar...@gmail.com> wrote:
Thanks very much for your reply, 
Im experimenting with the urlrequest class
specially the twitter example. I found out that the url for twitter trends have just changed to a new one: https://api.twitter.com/1/trends/1.json

but also.. I get an error when trying to run: 

     trends = result['trends']
 TypeError: list indices must be integers, not str


Im new to json and python, so I dont know whats wrong with the array.

Also I have a question...
My app is supose to filter media by categories, so Im planning on using json to get categories from DB and generate a Tree interface menu or something, then also use json to get all media from selected Category.

So I guess I will need to create a site that outputs json for all categories but also a site that generates json for a specific category...because getting ALL media from all categories when you only need few? i think it could generate a very large json file, and probably not the must efficient way to make a sql selection. I Found this : http://craftyman.net/mysql-to-json/


so much Thanks in advance.




Reply all
Reply to author
Forward
0 new messages