• technoway

    @omz - Thank you for the workaround.

    You do not have to apologize for anything.

    Pythonista would have to have many, many, more bugs before it would stop being my favorite App. Thanks for making Python programming available on IOS.

    posted in Pythonista read more
  • technoway

    With the latest Pythonista Beta v. 3.3 (330025), installed today, i.e. 20 Feb., 2020, I get the same crash in my App I got with the last Beta.

    I tracked it down to the very first line of code that executes in my App! I commented out that line, and my App runs successfully.

    That line is:

    A great many lines of code are omitted both before and after the code snippet shown.

            # Prevent iPhone from going to sleep while this program runs.
            # Create an instance of a class that derives from ui.View.
            # <code-omitted>

    If I comment out that one line of code, the program does not crash.

    I am running that on an iPhone 6s running IOS 13.3.1

    posted in Pythonista read more
  • technoway

    @mikael - Thank you for the reply. I could make that work, but I'd have to change the signalling method. I need both up and down events now.

    I'll continue to use the screen, and I'll look for other solutions. Perhaps there's a way to signal the screen with a device attached to the phone. I'll keep looking for a solution.

    posted in Pythonista read more
  • technoway

    Is it possible to use Pythonista APIs to get notifications for the the volume-up and volume-down switches that are on an earphone set plugged into the earphone jack of an iPhone 6s? I want to access just one button, and get up and down notifications, similar to the touch_began and touch_ended notifications for a screen button.

    I am currently using tapping on the screen to control something. I have an electrical engineering background, so I can wire a button up and plug that in, while satifying the impedances for the other connections on the plug. I'd like to be able to push that button to control something, rather than having to push on the screen of the phone.

    I have no idea how to do this. Note, I do not care if this also affects the audio volume. I can have the audio muted. I just want to access the up-event and down-event when the button is depressed and let go.

    I found this page, but it does not appear to have the information for the volume control switches that are plugged in with earphones.

    posted in Pythonista read more
  • technoway

    brumm - Thank you. With the first change you proposed, the touch_began method is now called when I touch the screen. The image is now too large, but I'll figure that out.

    JonB, than you for identifying the source of the problem. I didn't think of that.

    mikael - Thank you for the response. Whatever changed, it was a while ago.

    I only recently had time to work on this again. It occurs to me this also might have broken because of an IOS upgrade. I think both an IOS upgrade and a Pythonista beta update happened before I noticed it was broken.

    Note, one of the things I can control is what is on the screen. In the main program, the following can be called.


    and in another place in the code:


    That's why I chose an ImageView.

    I have a background in digital signal processing, so I know something about images, but I have a weak understanding of Pythonista's image classes. I got things to work mostly by copying examples.

    The image is now scaled way too big. I think I might need a frame? I tried setting the size a couple of ways, but that had no effect.

    In any event, thanks. I will fix the image size issue - the touch_began problem had me stumped. I was looking in all the wrong places. The word "View" in "ImageView" should have given me a clue as to what was wrong.

    posted in Pythonista read more
  • technoway

    I am running the Pythonista 3 beta.

    I have a class that creates a full screen button, which I can use to covertly control something else. This is a sanitized version of the program. It's a very large program, but this smaller version demonstrates the issue I am encountering.

    For the first beta, the touch_began method was called when I touched the screen, but after one of the subsequent updates, that method is no longer being called.

    I am not asking for anyone to debug my program. All I want to know is should a ui.View derived class work in this case, i.e. did something break in the beta, or do I need to change to something else, perhaps a Scene?

    Or, it's possible that I deleted something by mistake that made this work before?

    """ testview.py
        Author: Bill Hallahan
    import os
    import time
    import speech
    import ui
    import motion
    from ui import Image
    from ui import ImageView
    import types
    import console
    from objc_util import *
    class TESTButtonView(ui.View):
        """ This user interface class forms a full-screen
            button that ... .
        def __init__(self, *args, **kwargs):
            """ Initialize the user interface """
            super().__init__(*args, **kwargs)
            self.update_interval = 1.0
            # Set up an image view.
            self.width, self.height = ui.get_window_size()
            self.iv = ImageView()
            self.iv.background_color = '#000000'
            self.iv.width = self.width
            self.iv.height = self.height
            self.iv.image = Image('lock_screen.png')
        def update(self):
            """ This update function is called once a second
                 to ...
            # code omitted. This method is being called.
        def change_title_bar_color(self, hex_color):
            """ Change the title bar color to the passed color.
            vv = ObjCInstance(self)
            bar_bckgnd = vv.superview().superview().superview().subviews()[1].subviews()[0]
            bar_bckgnd.backgroundColor = UIColor.colorWithHexString_(hex_color)
        def touch_began(self, touch):
            """ This function is called when the user
                touches the screen.
        def touch_ended(self, touch):
            """ This function is called when the user
                stops touching the screen.
    def wait_for_portrait_mode():
        """ Do not return until the device is held in portrait mode. """
        msg = 'Hold your phone in portrait mode.'
        console.hud_alert(msg, duration=3)
            while True:
                x, y, z = motion.get_gravity()
                count += 1
                if count > 2:
                    if abs(x) < abs(y):
                        console.hud_alert(msg, duration=2)
    if __name__ == "__main__":
        # Prevent the iPhone from going to sleep while this program runs.
        # Is the phone positioned correctly?
        # Create and display the full-screen Morse code input button.
        v = TESTButtonView()

    Note, just to be sure there was no issue with the speech.say method being called there, I replaced that with os._exit(0). If I put that in the update method, the program exited. If I put it in the touch_began method, ran the program, and touched the screen, nothing happened.

    posted in Pythonista read more
  • technoway

    I would be distressed. I use a file transfer program that runs only under Python 2, and so I have this line at the top of the file:


    at the top of the file.

    Sure, I could take some time and rewrite the file transfer program for Python 3, although given that I often want to transfer ASCII, that would take time away from the actual programming I want to do - and I barely have enough time for that. I want to work on my primary application, not on tools.

    I also wrote python 2 programs for many years, and I like being able to transfer them and just run them. That's one reason I purchased Pythonista 2 separately before I purchased Pythonista 3. (Or whatever the official product names are - you get the idea).

    I don't care if Python 2 is never improved, but I do hope it never goes away.

    posted in Pythonista read more
  • technoway

    Thank you mikael and JonB for the help.

    @JonB said:

    You sure you have update_interval set?

    Yes. I have:

    self.update_interval = 1.0

    in my derived class's __init__ method.

    It likely I did something to break code that was working, but I don't see anything wrong. I'll debug my application - if this works for others, then I'm sure I introduced a bug somewhere. It's odd though, because I only made two very small changes and then updated the OS.

    Next time, before I upgrade the OS, I'll test before to make sure it's the OS that breaks code, and not my code changes.

    posted in Pythonista read more
  • technoway

    I just updated my iPhone 6s to IOS 12.0.1, and the 'update' method is not longer called in my ui.View derived class.

    I wonder if anyone else has encountered this?

    posted in Pythonista read more
  • technoway

    dgelessus - Good catch. I missed the missing space at first when I read the first post.

    That is def__init__-ly the problem.

    Sorry, I couldn't resist the bad pun.

    In my defense, I would have tried to help too, but I just got here.

    posted in Pythonista read more
  • technoway

    @omz - Thank you for the reply. That will stop me from trying to remove something I cannot remove.

    posted in Pythonista read more
  • technoway

    @JonB - In every case described below, I am starting the application using a shortcut .

    When my app calls os._exit(0), I see no windows. If I click the home button, I see two windows in the background.

    I can run my application by clicking on one of the windows.

    If I use os._exit(0), I still see two windows, and just as before, I can still restart my app by clicking on one of the windows. (It's the mostly all white (console?) window,- my application sets a black background which shows in the other window). Note, I call console.exit(), so I though I closed the console window.

    I am also still able to reopen Pythonista using the Pythonista icon while that other window is present.

    I must not be cleaning something up?

    posted in Pythonista read more
  • technoway

    cvp - That is what I meant. When os.abort() or os._exit(0) is called, the app shuts down, the home screen shows, but, depending on the Pythonista app, there are one or two windows running in the background.

    It's not a big deal. I can launch Pythonista again without closing these windows.

    posted in Pythonista read more
  • technoway

    @ccc - I did some searching, and apparently Apple discourages calling exit(0) in objective C to close an app, because that appears similar to an app crashing.

    My issue is that when I use a shortcut URL to launch my GUI application, when I hit the home button to close the app, there are two windows to close, not just one like most (all?) other apps.

    Is there a way I can make my app so that it does not show the second window when I start the app this way?

    I am using a uiView-derived window in my app.

    posted in Pythonista read more
  • technoway

    JonB - Thanks for the reply. Unfortunately, os.abort() appears to do the same thing as os.exit(0). The app goes away, but the console window, and one other window, presumably the main Pythonista window, are running in the background and have to be closed separately.

    I'm running the latest Pythonista beta on an iPhone 6s running IOS 11.2.1

    I'm not complaining. Pythonista is great the way it is. That would be a nice feature though.

    posted in Pythonista read more
  • technoway

    Is there still no function or method to shutdown Pythonista from within a script?

    posted in Pythonista read more
  • technoway

    lukaskollmer posted a link to code to get memory statistics in this topic:

    JonB has another link to code to get memory memory statistics in the same topic. (Although, the current ending comment JonB put there is, "Looks like this code does not work properly on 64 bit... i suspect the structure is not sized correctly." - but if the first code doesn't help, you might want to use JonB's code as a starting point.

    I am not sure any of that will help you detect a leak though.

    Python uses reference-counted objects and garbage collection. There might be a way to force garbage collection, but even if "del" as used to delete an object, and there was some special way to force immediate garbage collection, while the memory will be freed so that Pythonista can reallocate it for another purpose, the memory won't necessarily be freed to the operating system.

    You could use "multiprocessing" and do memory intensive work in a subprocess, and when that process closes, the memory will be returned to the operating system.

    Perhaps someone more familiar with Pythonista's internals can give a better answer. My guess is that what I wrote is correct.

    posted in Pythonista read more
  • technoway

    Thank you for writing this and sharing it. StaSh is great.

    posted in Pythonista read more
  • technoway

    Cool program. Thanks for sharing it.

    posted in Pythonista read more
  • technoway

    These are the differences I encountered with Python 3.

    There are many new libraries. Some deprecated libraries are replaced with better alternatives.

    Python 3 has unicode support for strings. (This is good and bad, as it can require more work porting some Python 2 programs).

    The print statement becomes a function, i.e. you must use curly brackets with print statements.

    There is no "xrange" statement, and "range" behaves like Python 2's "xrange."

    For Pythonista 3, if you push the "run" button and hold it, an option appears that will let you select to run the program with Python 2. Alternatively, if the first line of the program is:


    then you can just push the "run" button, and the program will run under Python 2.

    You probably don't need Python 3 for the problems you're solving, however, as noted, Python 2 is not advancing anymore, so you might want to know Python 3 for the future.

    posted in Pythonista read more
Internal error.

Oops! Looks like something went wrong!