aptonic / dropzone4-actions

Add-on actions and API Docs for Dropzone 4
https://aptonic.com
363 stars 57 forks source link

$dz.inputbox throws error #109

Closed thaikolja closed 4 years ago

thaikolja commented 4 years ago

Hello,

Thanks for this awesome app! It's a joy to work with it and build small helper tools that make life easier.

I'm programming a small script that is supposed to display an input box. However, if I add the code you've provided in the documentation, I get the following error:

Task description file task-27345:

ACTION: "/Users/USERNAME/Library/Application Support/Dropzone/Actions/Image Tagger.dzbundle"
EVENT: "dragged"
VARIABLE: "app_version" "4.0.3"
VARIABLE: "dragged_type" "files"
VARIABLE: "sandboxed" "1"
VARIABLE: "support_folder" "/Users/USERNAME/Library/Application Support/Dropzone"
ITEMS: "/Users/USERNAME/Desktop/image.jpg"

Traceback (most recent call last):
  File "/Applications/Dropzone 4.app/Contents/Actions/lib/python_runner.py", line 13, in <module>
    getattr(action, action_name)()
  File "/Users/USERNAME/Library/Application Support/Dropzone/Actions/Image Tagger.dzbundle/action.py", line 56, in dragged
    filename = dz.inputbox("Filename Required", "Enter filename:")
  **File "/Applications/Dropzone 4.app/Contents/Actions/lib/dropzone.py", line 37, in inputbox
    if result['cb'] == "1":
KeyError: 'cb'**

[Task completed]

I'm using Python 3.7.7.

I hope you can help.

aptonic commented 4 years ago

Interesting. Can you try putting the following as the clicked() method for a new action:

def clicked():
    title = "test"
    prompt_text = "Testing"
    conf = "*.title = " + title + "\n" \
    + "txt.type = textfield" + "\n" \
    + "txt.label = " + prompt_text + "\n" \
    + "cb.type = cancelbutton"

    result = dz.pashua(conf)
    print(result)
    dz.url(False)

And paste the output from the debug console? I'm not getting the same error as you so I suspect this relates to your using Python 3.7.7. How are you using this Python version? Did you replace or symlink /usr/bin/python with an alternative version? Also what macOS version is this under?

thaikolja commented 4 years ago

Hi,

The method gave me this unspectacular output:

[Launching task with command line: runner.rb task-37887]

Task description file task-37887:

ACTION: "/Users/Kolja/Library/Application Support/Dropzone/Actions/Image Tagger.dzbundle"
EVENT: "clicked"
VARIABLE: "app_version" "4.0.3"
VARIABLE: "sandboxed" "1"
VARIABLE: "support_folder" "/Users/kolja/Library/Application Support/Dropzone"

{}
URL: 0

[Task completed]

I use the latest macOS version, 10.15.4.

aptonic commented 4 years ago

OK thanks for that. Can you next please put the following as the clicked() method:

def clicked():
    import sys
    print("Python version")
    print (sys.version)
    print("Version info.")
    print (sys.version_info)

And paste me the output from debug console again.

How did you install Python 3.7.7? I'd like to replicate your configuration myself as I don't have the same issue under 10.14 or 10.15 with the default Python. That {} in your debug output should not be empty.

Also, can you please try adding:

# PythonPath: /usr/bin/python2.7

To your action metadata at the top of the action file. And then run the action again with your original code and see if that fixes it.

thaikolja commented 4 years ago

Thanks for your quick reply and excuse my late answer.

I've started a fresh Action with Clicked trigger and the code you provided:

ACTION: "/Users/kolja/Library/Application Support/Dropzone/Actions/test.dzbundle"
EVENT: "clicked"
VARIABLE: "app_version" "4.0.3"
VARIABLE: "sandboxed" "1"
VARIABLE: "support_folder" "/Users/kolja/Library/Application Support/Dropzone"

Python version
3.7.3 (default, Apr  7 2020, 14:06:47) 
[Clang 11.0.3 (clang-1103.0.32.59)]
Version info.
sys.version_info(major=3, minor=7, micro=3, releaselevel='final')

[Task completed]

With Python 2.7, not much changed:

ACTION: "/Users/kolja/Library/Application Support/Dropzone/Actions/test.dzbundle"
EVENT: "clicked"
VARIABLE: "app_version" "4.0.3"
VARIABLE: "sandboxed" "1"
VARIABLE: "support_folder" "/Users/kolja/Library/Application Support/Dropzone"

Python version
2.7.16 (default, Feb 29 2020, 01:55:37) 
[GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.20) (-macos10.15-objc-
Version info.
sys.version_info(major=2, minor=7, micro=16, releaselevel='final')

I use pyenv to switch between versions. But I do have the binaries of Python 2 and 3 in the /usr/bin/ directory.

aptonic commented 4 years ago

OK, thanks. Do you still get the error with your Image Tagger action if you put the:

# PythonPath: /usr/bin/python2.7

Line in the actions metadata?

thaikolja commented 4 years ago

Yes, all the same, no matter what Python version I use. I tried many things but it just doesn't work. It's quite weird because Dropzone message boxes do work.

aptonic commented 4 years ago

This is pretty puzzling. Can you try running:

/Applications/Dropzone\ 4.app/Contents/Actions/lib/Pashua.app/Contents/MacOS/Pashua

In a Terminal? Let me know if this shows a dialog like this:

Pashua dialog

You might have to change the /Applications/Dropzone\ 4.app/ part at the start of the above command if Dropzone 4 is installed somewhere else. It looks like maybe Pashua (used to display Dropzone dialogs) isn't working properly for some reason, so we will need to investigate this next.

thaikolja commented 4 years ago

Indeed, very puzzling. But I appreciate your great help so far!

Running Pashua directly gives me this unspecified message:

[1] 10244 illegal hardware instruction

aptonic commented 4 years ago

What type of Mac is this on?

thaikolja commented 4 years ago

MacBook Pro 2018, latest macOS version, everything up-to-date.

aptonic commented 4 years ago

OK, thanks. Can you download the Pashua DMG from here:

https://www.bluem.net/en/projects/pashua/

And see if you can run it and get the dialog box I posted a screenshot of. Note you'll have to right-click on the Pashua.app bundle and click 'Open' because it will complain it's from an unidentified developer otherwise.

thaikolja commented 4 years ago

Yeah, I did that before and this worked the way it should.

thaikolja commented 4 years ago

I still haven't been able to resolve this issue.

Installing Pashua and running the core file - either isolated from the desktop or from within Drozone's macOS folder - has no effect. Starting the application gives me the information window that you have posted above.

I've tried Python 2, 2.7 and 3. All the same result (nothing happens).

The DZ output:

[Launching task with command line: runner.rb task-49872]

Task description file task-49872:

ACTION: "/Users/USER/Library/Application Support/Dropzone/Actions/Custom Action.dzbundle"
EVENT: "clicked"
VARIABLE: "app_version" "4.0.3"
VARIABLE: "sandboxed" "1"
VARIABLE: "support_folder" "/Users/USER/Library/Application Support/Dropzone"

{}
URL: 0

[Task completed]

Is it possible that something else is blocking Pashua from displaying anything? I couldn't imagine what that would be.

thaikolja commented 4 years ago

Update: I've managed to display text boxes. The problem was pyenv; I removed it from my .profile file:

#eval "$(pyenv init -)"

That switched me back to 2.7.16. Confusing, because I tried 2.7 before, and it didn't work.

Now a big BUT: The dialogues only work in custom scripts. If I use them inside Dropzone's Action environment, it does display the value but no text box.

Here is my custom script that does display Pashua:

import sys
import Pashua

sys.path.append('/Applications/Dropzone 4.app/Contents/Actions/lib/Pashua.py')

def text():
    config = """
    *.title = Test Dialog
    p.type = textfield
    p.label = Enter some text
    """
    result = Pashua.run(config)

text()

The result: GitHub Logo

I then did the same in the actual Dropzone Action:

def clicked():
    config = """
        *.title = Test Dialog
        p.type = textfield
        p.label = Enter some text
        """
    dz.text(config)
    dz.url(False)

This didn't display anything, but at least the values are in the debug console:

Task description file task-55776:

ACTION: "/Users/USER/Library/Application Support/Dropzone/Actions/Custom Action.dzbundle"
EVENT: "clicked"
VARIABLE: "app_version" "4.0.3"
VARIABLE: "sandboxed" "1"
VARIABLE: "support_folder" "/Users/USER/Library/Application Support/Dropzone"

Text: 
        *.title = Test Dialog
        p.type = textfield
        p.label = Enter some text

URL: 0

[Task completed]

Of course, I have tried all combinations, using dz, not using dz, add/remove some dz methods, removing run() -- pretty much everything, but to no avail.

aptonic commented 4 years ago

That's not the correct way to call Pashua - see https://github.com/aptonic/dropzone4-actions/blob/master/README.md#pashua

dz.text(config) will not do anything useful. It needs to be:

config = """
*.title = Test Dialog
p.type = textfield
p.label = Enter some text
"""
result = dz.pashua(config)

Hopefully with your .profile fix it will work once you call with dz.pashua().

thaikolja commented 4 years ago

Thanks. I already tried so many combinations, even some that seem to be useless, maybe I forgot something. clicked(), dragged(), no difference. But still, Dropzone just doesn't display the dialogues whereas all other Python scripts with almost the same code display it fine.

I'm really running out of ideas. Maybe I should switch to Ruby and try it there?

aptonic commented 4 years ago

Yes I think there's something odd about your Python environment. One more thing to try: If you drag a few images onto the Imgur action does it prompt for an album name? This prompt uses Pashua from Ruby, so if this is working then Pashua is working.

I think this is really only broken with your specific Python configuration as there have been no other reports of Pashua failing from either Python or Ruby. I'm going to close off this issue as I've investigated it as much as I'm going to. Feel free to update here if you figure out what the problem was though 😄