• tmm

    I've seen several forum posts and reviews that claim you can export Pythonista code to Xcode and create standalone iPad/iPhone apps (by using http://omz-software.com/pythonista/download/PythonistaProjectTemplate.zip, I guess?). Would an app that uses the UI and Scene classes be exportable this way, since those are specific to Pythonista?

    I ask because I recently started writing a game in Pythonista, but since I don't really want to have to have Pythonista installed in order to run the game, I'm wondering if I should abandon this effort and do it in something I know will work, like kivy. I'd hate to have to start over, but better than confining myself to having to run it from the Pythonista app.

    posted in Pythonista read more
  • tmm

    Thanks - you're right, I didn't find that in the search. I'll give it a try before I continue writing.

    posted in Pythonista read more
  • tmm

    I figured out how to add an image to Pythonista using the "+" icon at the top of the edit screen, but is there any way to add a whole lot of images at once? I have over 100 that I want to use in a game, and adding them one at a time is seriously tedious.

    posted in Pythonista read more
  • tmm

    Yeah, I'm using an iPad. Luckily, other helpful people have the iPhone version. :-)

    posted in Pythonista read more
  • tmm

    JonB and ccc: Thanks!

    zencuke: When you're editing a script, make sure the keyboard is showing and then look at the top right side of the screen. There should be 4 icons: "+", "?", a wrench, and a right-pointing triangle. If you tap the "+", it'll show you all images that come with Pythonista. If you then select "My Images", there's an option at the top to add an image -- it has to be in your clipboard, and you give it a name, and then you can use it as a scene.image or whatever.

    posted in Pythonista read more
  • tmm

    So I'm trying to learn the ins and outs of Scene, SceneView, ui, etc., and the kinds of things that can be done with them, especially combining elements from the ui and console modules with the Scene functionality. I haven't been able to find many examples of this sort of thing, so in this test script (which started as one of the examples from the Pythonista docs), I'm trying to do the following:

    • Create a SceneView with a simple scene (rectangle with image inside it).
    • Add a touch function so when you touch anywhere, it pops up a ui.Button in the center of the image created above.
    • When you press the new button, it pops up a console.hud_alert() box in acknowledgement.
    • After that acknowledgement, it sleeps a few seconds and then pops up a console.alert() box and shows the result as a console.hud_alert().

    I got the first three items above working, and the alert box does come up, but then things get weird: pressing either of the buttons on the alert box has no effect, nor does anything else -- in fact, I can't even exit the application; I have to completely close and reopen Pythonista. The code is below.

    Why does it freeze this way? Is there something I'm missing about the interaction between the console functions and the ui/Scene ones?


    Edit: Based on this post: https://omz-forums.appspot.com/pythonista/post/5301659244691456, I tried using ui.delay() on the call to self.alert; I had to add the @ui.background decorator on the self.alert() method, but the end result was the same as before: the alert box popped up but then froze everything.

    from scene import *
    import ui
    import console
    import time
    class MyScene(Scene):
        def setup(self):
            self.root_layer = Layer(self.bounds)
            # Draw a 200px square with a white background and an image
            self.layer = Layer(Rect(self.size.w * 0.5 - 100, self.size.h * 0.5 - 100, 200, 200))
            self.layer.background = Color(1, 1, 1) # white background for square
            self.layer.image = 'Cat_Face'
            # Grow square to twice its size
            self.layer.animate('scale_x', 2.0, duration=1.0, autoreverse=False)
            self.layer.animate('scale_y', 2.0, duration=1.0, autoreverse=False)
        def draw(self):
            background(0, 0, 0)  # black background for screen
        def touch_began(self, touch):
            # Add a new button when screen is touched anywhere
            b = ui.Button()
            b.title = 'Hi'
            b.action = self.hi_pressed
            b.center = (self.layer.frame.x + self.layer.frame.w/2, 
                        self.layer.frame.y + self.layer.frame.h/2)
            b.width = 30
            b.height = 20
            b.flex = 'LRTB'
            b.background_color = 'white'
            b.tint_color = 'black'
        # callback function for "Hi" button
        def hi_pressed(self, sender):
            console.hud_alert('Hi yourself!')
            a = self.alert()
            if a == 1:
                console.hud_alert('Got OK')
                console.hud_alert('Got Cancel')
        def alert(self):
                a = console.alert('Alert', 'Boo!', 'OK')
                return a
            except KeyboardInterrupt:
                return -1
    sv = SceneView()
    sv.scene = MyScene()

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!