• HeyItsJono

    A few weeks ago I was getting a similar weird issue where I was testing an isolated snippet of code involving the <code>time.sleep()</code> command for inclusion in my actual program. I found that the code ran perfectly when tested as an isolated snippet but as soon as I threw it into the main program I ran into the problem of <code>time.sleep(1)</code> throwing a <code>TypeError: Expected callable/function</code> even though I was providing it with the correct argument type; an integer. So not knowing what was causing the issue, I decided just to play along and implement a hacky fix by providing a lambda returning the value I wanted. Then another TypeError popped up, this time asking for a float (?) instead of a function. So I just wrote a try: .. except: .. tree to handle the type errors. Mine ending up looking something like this:

    from time import sleep
            sleep(lambda: 1)

    This ended up fixing my issue and after I provided it with a float it didn't throw any more type errors.

    Not sure how to fix it for yours since passing <code>lambda: ">>>>>>=======true"</code> to the print statement will just make it print the function object but maybe you could try using the <code>print()</code> function from the <code>future</code> module. Something like this?

    from __future__ import print_function
    def main():
    def timerCount():
        arbitrary = 345
        for i in xrange(arbitrary): 
            timenow = time.time()
            timeThen= 1421929025.21
            timeSince = timenow-timeThen
            if lastTimeSince <= round(timeSince,0):
                lastTimeSince = round(timeSince,0)
        return lastTimeSince

    posted in Pythonista read more
  • HeyItsJono

    Funny, I just finished a script yesterday which would parse and import my uni timetable into my iPad's calendar via Pythonista. I used the icalendar module to create the .ics file (it can be imported into Pythonista, just download it from pypi and throw it into the site-packages folder in pythonista) and then I used a simple server to host the .ics file on localhost and pythonista's webserver.open() to import it directly into the calendar from pythonista. You can also use pythonista's console.quicklook() to view the .ics file and e-mail it to yourself which allows you to import any events in it on an individual basis unlike the webserver method that just straight up imports them all. The script I wrote covers all of this and you can find it <a href='https://github.com/HeyItsJono/csesoc-website-v2/blob/master/app/timetable/ical_generator_gui.uipack.py'>here.</a>

    Just make sure there's a file called 'UNSW.ics' in the same folder as the script and use fake credentials like 'test' for both the username and password on the details screen. When you get to the import screen, pressing import will detect that there's an existing calendar file in the directory and let you bypass the part that actually requires real credentials at my uni since I'm guessing you don't have those.

    posted in Pythonista read more
  • HeyItsJono

    Thank you, that worked brilliantly! Neither threading.Timer nor ui.delay were working properly; they just hung the program.<Br>
    <Br>worked perfectly though.

    posted in Pythonista read more
  • HeyItsJono

    Hi there,
    In my program I have a GUI with a button which, when pressed, is supposed to bring up a Quick Look of a particular file. I decorated the button function with @ui.in_background and yet when the button is pressed, no Quick Look view pops up. On the first press, nothing happens and on the second press Pythonista as a whole hangs and needs to be force-closed via the app switcher. An example is the following, where the pyui file just contains a single button whose action references the button function.

    # coding: utf-8
    import ui
    import console
    def button(sender):
    ui.load_view('Untitled 2').present('sheet')

    posted in Pythonista read more
  • HeyItsJono

    The file is in the same directory as the script so that is the full path of the file. The statement works just fine when it's not called from a ui function or when it's called from the console, it's just something about being called via a button action that prevents it from working.

    posted in Pythonista read more
  • HeyItsJono

    Hey everyone, ever since I bought Pythonista I've been getting more and more into learning Python, generally by creating scripts to fix any little problems or inconveniences I come across in my day-to-day digital life. So far I've made scripts which enable pretty much one-tap image sharing across most messaging services on iOS, automatic file creation and downloading and conversion of any files to text which I find useful for reading files which Pythonista doesn't support opening, but which are readable in .txt format.

    All of these can be found over at my GitHub repo here.

    I would be very thankful for any constructive criticism as I'm basically using all this as a learning experience to better my programming skills. Thank you!

    posted in Pythonista read more
  • HeyItsJono

    @TutorialDoctor: The path is indeed relative to the location of Script _ Downloader.py. I'm not sure how to ignore the working directory of the Downloader script as I'd have to know the root directory to do that but I've updated Script _ Downloader to now support paths. In the filename box, just add your path like so:
    Master.zip in directory temp/zip-files would be "temp/zip-files/master.zip"
    And the script will download the file to that directory. If the directory does not exist, it will make it and any parent directories as necessary. Again, this is probably going to be relative to the working directory of the script and I'm not too sure how to work around that. One hacky fix is to just have Script_Downloader in the root directory so it can work with any path but that's all I can really think of. I also made a few housekeeping changes to the code which are listed on GitHub but another main change is the inclusion of _ in the name instead of ' ' so it can be imported more easily in the console.

    Sadly I do not have Editorial so I can't test this stuff myself.

    posted in Pythonista read more
  • HeyItsJono

    @TutorialDoctor: Thanks for the bug report, I just uploaded the fix to both the uipack file and the normal .py, it was an error stemming from some experimentation I did with the ui.in_background() function that I forgot to remove before uploading. It's tested and working again, please let me know if you have any other issues with it :)

    @SpotlightKid: I'll definitely look into those and attempt a re-write. Thank you for the advice!

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!