سؤال

I'm trying to use TideSDK and python tp get the user to select a folder from the hard drive. Everything works, but I have no idea how obtain which folder the user selected.

I can't seem to find documentation on what Ti.UI.UserWindow.openFolderChooseDialog returns and what kind of object the callback function uses. I just get errors that "window" in "onopen" in my code below is a None Type object when I try to print it out.

Is there any documentation on the proper use of the openFolderChooseDialog, what signature the callback needs to be and how to get the Folder/directory from the dialog?

My code:

def onopen(window):

    Ti.App.stdout("------------------  Opening Dialog")
    Ti.App.stdout(window)

def burndir():


    try:
        dir = Ti.UI.getCurrentWindow().openFolderChooserDialog(onopen)
        Ti.App.stdout(dir)

    except:
        Ti.App.stderr("------ There was an error: ")

        Ti.App.stderr(sys.exc_info()[0])
        Ti.App.stderr(sys.exc_info()[1])
        Ti.App.stderr(sys.exc_info()[2])

Any help is much appreciated

هل كانت مفيدة؟

المحلول

I found the answer in a Javascript Code example here:

https://github.com/appcelerator/titanium_developer/blob/master/Resources/perspectives/projects/js/projects.js#L1338

It appears that openFolderChooserDialog return nothing (a None object in Python). The callback function passes one argument which is a StaticBoundList (a Tuple object in Python) that contains all of the selected folders (in case of allowing multiple selections)

Here is the updated code:

def onopen(window):

    if (len(window) > 0):
        Ti.App.stdout("------------------  Opening Dialog")
        Ti.App.stdout(window[0])
    else:
        Ti.App.stdout("------------------  Nothing Selected")


def burndir():
    try:
        Ti.UI.getCurrentWindow().openFolderChooserDialog(onopen)

    except:
        Ti.App.stderr("------ There was an error: ")

        Ti.App.stderr(sys.exc_info()[0])
        Ti.App.stderr(sys.exc_info()[1])
        Ti.App.stderr(sys.exc_info()[2])

I hope this helps someone struggling to find the same documentation!

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top