• lachlantula

    Hi all,
    I’m developing an application with the ui module, but have realised something that I’m not sure is either intentional or just overlooked; background_color can be animated, whilst text_color can’t.
    Here’s an example. You can see that the text colour-changing is out of sync with the smooth background. The text changes to contrast with the background at the time.

    Here is my code for the colour-changing functionality:

    while True:
        r = lambda: random.randint(0, 255)
        colour = '%02X%02X%02X' % (r(), r(), r())
        def determine_colour2(colour):
            (r, g, b) = (colour[:2], colour[2:4], colour[4:])
            # This next bit is pretty complicated, but its basically just an algorithm to find out what colour is needed for text
            if 1 - (int(r, 16) * 0.299 + int(g, 16) * 0.587 + int(b, 16) * 0.114) / 255 < 0.5:
                return '333333'
            else:
                return 'efefef'
        colour2 = determine_colour2(colour)  
        def animation():
            v.background_color = colour
            v['chrome']['logo'].text_color = colour2
        ui.animate(animation, duration = 3)
        time.sleep(3)
    

    If anyone can let me know if I’m doing something wrong or if this functionality isn’t implemented into Pythonista at all, it would be appreciated. Thanks!

    posted in Pythonista read more
  • lachlantula

    Hi all,
    A while ago Pythonista got the pycrypto module added in, which has been very useful. Unfortunately, though, this module is dead and is starting to gain security holes. PyCryptodome is a drop-in replacement, and all code should be backwards compatible. It also adds extra features and is being regularly updated. Check it out. Would be great if we could see this in Pythonista!
    Thanks

    posted in Pythonista read more
  • lachlantula

    Hi everyone, do we know if there's any plans for Pythonista to add features that increase compatibility with iOS 11 (ie. drag-and-drop, support for the Files app, etc)? Thanks

    posted in Pythonista read more
  • lachlantula

    good work! I'll definitely check this out.

    posted in Pythonista read more
  • lachlantula

    I would be very surprised if Apple never tried to make a 'UWP for Apple products'. Maybe it'll happen one day?

    posted in General Discussion read more
  • lachlantula

    Did you ever figure anything out?

    posted in Pythonista read more
  • lachlantula

    @omz will old packages still work if 3.6 is pushed to everyone? I need my pycrypto 🙂

    posted in Pythonista read more
  • lachlantula

    It seems like the "import file" function now available inside the share sheet only works 1/3 of the time for me and my mate. Is there a trick I'm missing or something?

    posted in Pythonista read more
  • lachlantula

    What @bennr01 said is probably the best choice, but if you ever want to download something else, use:

    import urllib.request
    urllib.request.urlretrieve("direct link to file", "filename.extension")
    

    posted in Pythonista read more
  • lachlantula

    I just checked the app store updates today on my device and to my surprise there was a Pythonista update - featuring a huge list of great new features. Thank you very much for your hard work!

    posted in Pythonista read more
  • lachlantula

    This won't work all apps, but the appex module is able to get some information from certain apps (eg. URLs from web browsers). APIs that can be installed via StaSH might work for other apps (eg. Twitter, Imgur, Reddit).

    posted in General Discussion read more
  • lachlantula

    I'll give it a try, thanks.

    posted in Pythonista read more
  • lachlantula

    I know this has been asked before, but I have a different scenario where the solutions suggested won't work. The app crashes when certain functions featuring sleep are run. Pythonista 3.

    Here's a sample of code that can sometimes crash the app:

    import time
    import sound
    
    vol = 0.1
    for _ in range(3):
        sound.play_effect('rpg:Footstep01', vol)
        vol += 0.1
        time.sleep(1)
        sound.play_effect('rpg:Footstep02', vol)
        vol += 0.1
        time.sleep(1)
        sound.play_effect('rpg:Footstep03', vol)
        vol += 0.1
        time.sleep(1)
    

    Any ideas? This function is decorated by @ui_in_background as it is called by the update function built into scene.

    (No, that doesn't mean there are footsteps playing all the time, it's part of an AI I'm working on:p)

    posted in Pythonista read more
  • lachlantula

    You can use a class. eg:

    class Example:
            def demo():
                Example.a = input('text: ')
            def check_input():
                print(Example.a)
    

    To run these functions:

    x = Example()
    Example.demo()
    Example.check_input()
    

    You can make a UI implementation quite simply based off of that.

    posted in Pythonista read more
  • lachlantula

    This works decently.

    import time, ui
    
    class Interface():
    
        @ui.in_background
        def Switch(sender):
            if Interface.bgcolour == 'red':
                Interface.bgcolour = 'blue'
                Interface.btn.title = 'Red!'
            else:
                Interface.bgcolour = 'red'
                Interface.btn.title = 'Blue!'
            Interface.v.close()
            time.sleep(1)
            Interface.v.background_color = Interface.bgcolour
            Interface.v.present('sheet', title_bar_color = Interface.bgcolour)
    
        btn = ui.Button()
        btn.title = 'Blue!'
        btn.x = 0
        btn.y = 0
        btn.width = 300
        btn.height = 300
        btn.action = Switch
    
        bgcolour = 'red'
        v = ui.View(background_color = bgcolour)
        v.add_subview(btn)
        v.width = 300
        v.height = 300
        
    x = Interface()
    x.v.present('sheet', title_bar_color = 'red')
    

    posted in Pythonista read more
  • lachlantula

    Try use pip instead.
    Enter this in stash:

    pip install python-telegram-bot
    

    posted in Pythonista read more
  • lachlantula

    I love to use Atom on my PC, but couldn't really find a similar theme for Pythonista. Cool Glow's background was a bit too harsh for my light-sensitive eyes, so I was using Gold, which had a decent compromise between the two. Today I learnt you can make your own themes, so I tried to make something somewhat similar. Let me know what you think!

    Theme.

    posted in Pythonista read more
  • lachlantula

    That's interesting, I'm busy writing a ~2000 line script with no sign of poor performance in the editor ¯\_(ツ)_/¯ What device are you using?

    posted in Pythonista read more
  • lachlantula

    @omz Your fork crashes my Pythonista 3 unfortunately, however I've tried HyShai's fix with no change. Here's my implementation.

    from func import TouchID
    cfg['touchIDEnabled'] = True
    ...
    
    if cfg['touchIDEnabled'] == True:
        fp = TouchID.authenticate('To continue to x, please use fingerprint.', allow_passcode=False)
        
    

    My TouchID file is the exact same as the original, besides the change HyShai suggested. Probably worth mentioning that my actual script is 1100+ lines long (main reason being I have a very complex UI that I did manually rather than using the builder), which I imagine doesn't help. Any ideas?

    Pythonista 3, iOS 10.1.1.

    Edit: looks like there's nothing wrong with the module, I tried a similar implementation in another file (obviously massively shorter) and it worked fine. I might have to work on some optimisation, see what happens. I'm on an air2.

    Edit2: Simply commenting stuff out, running, uncommenting seems to fix the crashes. Strange but it's happened before to me. ¯\_(ツ)_/¯

    posted in Pythonista read more
Internal error.

Oops! Looks like something went wrong!