• henryiii

    @ccc: No, the code will not run with an exception. I've been caught by that before. This is the correct way to use the context manager if you want to be exception safe. (See context manager's docs)

    import contextlib
    
    @contextlib.contextmanager
    def battery_monitoring_enabled():
        set_battery_monitoring_enabled(True)
        try:
            yield
        finally:
            set_battery_monitoring_enabled(False)
    

    posted in Pythonista read more
  • henryiii

    I've never had good luck with trying to import the Unicode literals in Python 2. It usually works better for me to leave that out, usually code still works on both without it. It tends to break libraries.

    And, I very much doubt that an introductory computer science book would be covering anything that would be different with old-style classes, much less with the absolute import. For that matter, it might use the new style super, etc; those tend to be more advanced concepts.

    To use new style classes: replace class Something: with class Something(object):

    posted in Pythonista read more
  • henryiii

    Just put

    from __future__ import division, print_function
    

    at the top of your scripts, and I bet you'll be close enough to follow basic examples. Most good Python works in both 2 and 3 (That's especially true for good Python 3). If you come across input, rename that to raw_input. You might want to grab a downloadable version of a Python 2/3 comparison (which there are plenty) if you run into odd errors.

    I've finally made all my work and personal scripts 2/3 compatible, and have switched to Python 3 everywhere except Pythonista. The new 3.5 version finally has some useful new tools, so I want to be ready for them. Still hoping eventually for a Pythonista 3! :)

    posted in Pythonista read more
  • henryiii

    On the new scenekit, I haven't been able to get gravity to work. I tried to modify the Physics Clock demo to add gravity from motion, but using self.physics_gravity = motion.get_gravity()[:2] doesn't seem to work; in fact self.physics_gravity = (5,-5) or something similar does not work either. Numbers still fall straight down. Am I missing something?

    posted in Pythonista read more
  • henryiii

    I've discovered a very irritating hang-up bug. The following code demonstrates it:

    import ui
    
    v = ui.View()
    im = ui.ImageView()
    im.load_from_url('http://upload.wikimedia.org/wikipedia/commons/d/db/Patern_test.jpg')
    im.flex = 'LRTBWH'
    v.add_subview(im)
    
    v.present()
    

    Simply run this, then exit, then run again. Pythonista will hang up the second time. The only way to fix it is to multitask and force pythonista to close. This was happening in a larger program. I've fixed it in my program by loading images separately and then viewing the data (slower and lengthy code).

    Smaller bug: If you start running from landscape mode, neither portrait or landscape UI will have the little clock bar at the top, causing the dimensions to be different than if you started from portrait.

    Also, if there was a way to have an action run on orientation change, that would be great. Currently I have an "ori" ButtonItem at the top that recalculates the frames based on the parent frame dimensions, and it has to be manually pushed.

    posted in Pythonista read more
  • henryiii

    Scipy has to be compiled, since most of it is written in C, not Python. Apple does not allow code to be compiled on iOS devices, so OMZ is the only one who can add scipy, pandas, etc. Try my script on a pure Python package.

    PS: the next step would be to run "python setup.py build" from the command line if you were on a computer.

    PPS: actually, much of scipy may be fortran, actually, now that I think of it. That is even harder to get to work, I think, because iOS is written in a C derivative.

    posted in Pythonista read more
  • henryiii

    I've got a bad image loading related bug. If you do this:

    import ui
    
    imageurl = 'http://s9.postimage.org/n92phj9tr/image1.jpg'
    
    v = ui.View()
    v.background_color = 'white'
        
    im = ui.ImageView()
    im.flex = 'LRTBWH'
    im.load_from_url(imageurl)
    
    v.add_subview(im)
    v.present()
    

    Then run, cancel, and run again, Pythonista hangs and has to be closed from multitasking, then often the icon has to be pressed twice just to open it again.

    posted in Pythonista read more
  • henryiii

    A minor suggestion: the gui doesn't have presets for iPhone 6 or 6+. I haven't been able to run too much, though my standard scripts seem to work fine.

    posted in Pythonista read more
  • henryiii

    What happens if I get added? Will it be listed as an update, etc... I sent an email.

    posted in Pythonista read more
  • henryiii

    Here is a little 2048 clone. It is focused more on being a simple example than being graphically advanced. Swipes would be nice, as would sliding tiles, but the later would complicate the class code, and the former I'm not sure how to do cleanly, except maybe with a custom view for the top level view. It also has a text only mode for consoles.

    Writing a 2048 clone is a good programming exercise. :)

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!