• metawops

    @omz said:

    @zenz Too much complicated, mostly, but I think I'll get to it eventually.

    Hi @omz!
    Itβ€˜s two years later – any progress/updates for us about pandas, seaborn? 😳
    Pythonista 4 anywhere on the horizon?

    posted in Pythonista read more
  • metawops

    @Phuket2 Hi, Iβ€˜m on the beta program, too, and will have a look at this library! Thanks for the hint! πŸ˜ƒ

    posted in Pythonista read more
  • metawops

    @JonB Awesome, that did the trick! Iβ€˜m glad my code works now exactly as I wanted it to work! πŸ˜ƒ Thanks so much for that missing puzzle piece!!

    posted in Pythonista read more
  • metawops

    Hi,

    I have a date as a string in the form β€ždd/mm/yyyyβ€œ and need to convert it to the form β€ždd. MMMM yyyyβ€œ so that the verbose month is printed out in German.
    Now, because we still have the locale bug in Pythonista ...

    >>> import locale
    >>> locale.setlocale(locale.LC_ALL, 'de')
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/var/containers/Bundle/Application/4D653312-79ED-4473-B63A-522E9EA8C250/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/locale.py", line 599, in setlocale
        return _setlocale(category, locale)
    locale.Error: unsupported locale setting
    >>> locale.setlocale(locale.LC_ALL, 'de_DE')
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/var/containers/Bundle/Application/4D653312-79ED-4473-B63A-522E9EA8C250/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/locale.py", line 599, in setlocale
        return _setlocale(category, locale)
    locale.Error: unsupported locale setting
    

    ... I guess Iβ€˜m forced to find a workaround. So I opted for the objc_util module and tried this (variable gebDatum holds the initial date string in the above mentioned format):

    from objc_util import *
    NSDateFormatter = ObjCClass('NSDateFormatter')
    dateFormatter = NSDateFormatter.alloc().init()
    NSLocale = ObjCClass('NSLocale')
    deLocale = NSLocale.alloc().initWithLocaleIdentifier_(ns('de'))
    dateFormatter.setLocale_(deLocale)
    NSDate = ObjCClass('NSDate')
    date = NSDate.alloc().init()
    
    dateFormatter.setDateFormat_('dd/MM/yyyy')
    date = dateFormatter.dateFromString_(gebDatum)
    dateFormatter.setDateFormat_('dd. MMMM yyyy')
    gebDatumVerbose = dateFormatter.stringFromDate_(date)
    

    Now when I want to print out the variable gebDatumVerbose I get the error must be str, not ObjCInstance.

    Any help / hint / explanation / other (shorter) solution for my problem?

    Thanks a lot!
    Stefan.

    posted in Pythonista read more
  • metawops

    @omz Thanks again, Ole! Works perfectly, time stamp is now correct. πŸ˜€

    A bit off-topic extra question: is it possible to launch Photos, go to the album I created and show the image I saved?

    posted in Pythonista read more
  • metawops

    @omz WOW!
    Never ever would I've been able to write such a line like you did in the try statment! I have no idea why & how this syntax works, that remains as a brain teaser for the weekend! πŸ˜‰

    Thanks so much for this quick help, Ole!! SO much appreciated! (Just a mini error: the parameter in the create_image_asset() call has to be image_path. πŸ˜‰

    However, I discovered a time stamp problem: I just saved an image to an album. When I did this the time was 03.03.2017, 20:07. When I launched the Photos app and opened my album I saw the one image in it but Photos said the image was dated from yesterday (02.03.2017) and from 22:12 ... πŸ€”
    Anyone any idea why this might be the case (and how to fix it)?

    posted in Pythonista read more
  • metawops

    Hi,
    I'd like to kindly ask for a few lines of sample code. I want to achieve this:
    I have a custom ui.View where I draw things to.
    I want to save the contents of this view as a PNG to my own, new album inside the device's Photos library.
    The next time the user wants to save an image it should go into the – now existing – album.

    So I assume it goes like this:

    1. Check if the album "my album" exists
    2. If it does not exist, create it (photos.create_album())
    3. Create the PNG image somehow from the ui.View contents (found this, works, writes a file local to Pythonista's sandboxed file system)
    4. Save this file into the album "my album" using AssetCollection.add_assets() somehow

    Questions:

    • Do I need to create this temporary PNG file?
    • How do I check if an album exists? get_albums() only gives all albums. πŸ˜’
    • How, exactly, do I add an image into "my album"?

    Being still a Python starter it would be great if someone could help!
    Thanks a lot!
    Stefan.

    posted in Pythonista read more
  • metawops

    Aweseom hints, guys! Didn't know about the dialogs module at all. The dialogs.list_dialog() looks good and suits my needs. πŸ˜€
    Thanks a lot!!

    posted in Pythonista read more
  • metawops

    Got a ui View.
    It contains a TableView and nothing else.
    The view gets presented via present('sheet').
    Immediately after presenting it I wait via wait_modal().
    Now the user should tap on one item in the TableView and the view should close.
    The closing of the view works (tableview.superview.close()) but I don't know how to transport the information about the tapped row back to the main thread so that I can work with it after the wait_modal() returns ...?

    This is my delegate (with debug output):

    class MyTableViewDelegate (object):
        def tableview_did_select(self, tableview, section, row):
            # Called when a row was selected.
            print("tableview_did_select: row=", row)
            print(tableview.data_source.items[row])
            tableview.superview.close()
            pass        
    

    Any help regarding how to get the tableview.data_source.items[row] information out of this delegate method back to my main program would be awesome! πŸ˜€

    posted in Pythonista read more
  • metawops

    Guys,
    still a beginner at Python, so please be patient.
    I'm using the twitter.request function for a Twitter API request.
    The result is a tuple consisting of a return code and the actual JSON result.
    I want to get hold of that JSON result like this:

    if status == 200:
        result = json.loads(data)
    

    However, I get this error:

    Traceback (most recent call last):
    File "/private/var/mobile/Containers/Shared/AppGroup/9D2704E0-434A-4879-8FB0-30594FA3A28D/Pythonista3/Documents/addToCollectionIK.py", line 17, in <module>
    result = json.loads(data)
    File "/var/containers/Bundle/Application/B09EF8B7-CE0F-4572-9748-EC15615DEA7A/Pythonista3.app/Frameworks/PythonistaKit3.framework/pylib/json/init.py", line 312, in loads
    s.class.name))
    TypeError: the JSON object must be str, not 'bytes'

    Why is that and what can I do about it? From what I understand the twitter.request function doesn't seem to return the JSON object as a string but as 'bytes' (what's that?). So I need to make a string out of that bytes, right? But how?
    (btw, the json.load(data) function doesn't work, either ...)

    Thanks a lot,
    Stefan.

    posted in Pythonista read more
  • metawops

    It's not possible to write Python scripts in Editorial's editor.
    So if I need to write a module and import it in a Python action in a workflow – how would I achieve this?
    Please don't let the answer be "You cant!"

    Thanks so much,
    Stefan.

    posted in Editorial read more
  • metawops

    Hi,

    in the UI editor of a Python script action I created a ScrollView and inside that ScrollView I embedded an ImageView.
    At design time I have to set the dimensions of that image view. Currently it's the default square (200x200).

    Via the Image URL property I loaded a non-square image that's displayed distorted now because the view want to make both, the width & the height to fit.

    Is there a way to tell the IamgeView not to squeeze my non-square image into the square view?
    I want to add several more ImageViews later and they all should be square but the actual images won't be square most of the time.

    Thanks,
    Stefan.

    posted in Editorial read more
  • metawops

    Oh! I found something!
    Looks like I have to set the property content_mode of the ImageView.
    Like this:

    view.subviews[0].subviews[0].content_mode = ui.CONTENT_SCALE_ASPECT_FIT
    

    I can't find this property in the UI editor. So I have to set it at run time?

    posted in Editorial read more
Internal error.

Oops! Looks like something went wrong!