Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Multiple image tiles
-
@Webmaster4o If you want to get the data of a binary Requests response, use
response.content
, notresponse.text
. The first one is guaranteed to be the raw byte data (str
in Python 2,bytes
in Python 3), and the second one may have been incorrectly decoded as if it were text. -
Opening BytesIO without closing them can cause you to leaka lot of memory.
See: https://forum.omz-software.com/topic/1457/camera-to-dropbox/7
-
This seems to imply that it might be otherwise, does Pythonista have a garbage collector?
-
The answer that you site does mention the preferred way which is what I advocated. Try cycling thru a long list of large images and see if problems emerge.
Pythonista is an implementation of cPython so it does indeed have a garbage collector. However Apple only allows iOS apps to have a single thread of execution (still true in iOS9?) so Python instances tend run longer in Pythonista than they would on your Mac or PC. On those other platforms garbage collection is less disruptive because it can be done in a separate thread of execution. This means that GC is run less often in Pythonista makes it more sensitive to unclosed resources than other platforms. Images can take up a lot of memory compounds the issue.
-
pythonista uses ref counting, so no close is needed. here is a way to check, using weakref handlers:
# coding: utf-8 import io, weakref def handler(ref): print 'buffer closed' def f(): buffer = io.BytesIO() ref = weakref.ref(buffer, handler) buffer.write('something') return buffer.getvalue() for i in xrange(5): print 'before' f() print 'after'
as an aside, i think ios does allow threads, just not multiple processes.
-
@Webmaster4o Note: Garbage Collection (GC) is not a universal panacea. If, for example, you hang on to objects or handles you might (inadvertently) defeat GC.
And I like @ccc's response on GC pragmatics.
Pedagogical point: GC schemes are a big factor in (languages like) java's performance. They've evolved over the years.
-
@ccc the url is
https://itunes.apple.com/us/rss/topsongs/limit=10/json
And I'm requesting the "im:image" url
-
@Webmaster4o sounds great. I'll try this ASAP. Also what if I didn't want a cover flow, I was thinking more of a table of images.
-
@ccc i would this the ui module would be more appropriate. Isn't scene and canvas more for a game interface?
-
Part I: Get the image URLs for the Top 10 iTunes songs:
import feedparser url = 'https://itunes.apple.com/us/rss/topsongs/limit=10/xml' def get_image_urls(itunes_url): for entry in feedparser.parse(itunes_url).entries: yield entry['summary'].partition('src="')[2].partition('"')[0] print('\n'.join(get_image_urls(url)))
-
Part II: Adds a ui.View... https://github.com/cclauss/Pythonista_ui/blob/master/TopTenView.py
-
@ccc wow! I didn't know it was so simple. Thanks for the sample code!!
-
@ccc one question. Where did you get the number 128 in the image_view.x and y?
-
It has to do with the spacing between the pictures. Try adjusting the value and seeing what happens.
-
This post is deleted!