Thứ Năm, 26 tháng 7, 2012

How To Use the Three20 Photo Viewer

1. Install Three20 viewer:
git clone git://github.com/facebook/three20.git

2. Configure thre20 for your project
python three20/src/scripts/ttmodule.py -p PhotoViewer/PhotoViewer.xcodeproj Three20

refer more at: http://three20.info/article/2010-10-06-Adding-Three20-To-Your-Project

3. Write sample:
http://www.raywenderlich.com/1430/how-to-use-the-three20-photo-viewer

Note: if you can not configure the sample code in this link. Please create new project, configure follow step 1, 2 then copy code. I did like that, work like a charm.

How to load image from camera roll:
Can not load directly, must use UIImagePickerController to pick then save it to document
Then use url: documents://paht to file to load into Photo object


Thứ Ba, 24 tháng 7, 2012

Download of a file-like python object in web2py

Copy from:http://thadeusb.com/weblog/2010/1/17/download_of_a_filelike_python_object_in_web2py

Here are a couple of ways to expose any python file-like object as download-able in a web2py controller.
You might want to do this if you have a generated pdf report, or allowing an export of the sites content.
From your controller, you can stream a large file by using the stream function of the response object.
Select
return response.stream(filelikeobject, chunk_size=64*1024)
You might also want to set the content type of what you are returning, as well as a new disposition (filename).
Select
def export():
    from gluon.contenttype import contenttype
    response.headers['Content-Type'] = contenttype('.csv')
    response.headers['Content-disposition'] = 'attachment; filename=%s_database.csv' % (
        request.now
    )
    import csv, cStringIO
    s = cStringIO.StringIO()
    db.export_to_csv_file(s, delimiter=',', quotechar='"', quoting=csv.QUOTE_NONNUMERIC)
    return s.getvalue()