Select to view content in your preferred language

Why don't Python add-ins provide a dialog box for user input?

7591
11
05-04-2015 10:53 AM
IanBroad
Deactivated User

Currently, we have:

OpenDialog

SaveDialog

GPToolDialog

MessageBox

But there's no way to actually get user input. Why is this? Does ESRI plan on eventually providing a way to get user input?

0 Kudos
11 Replies
JamesCrandall
MVP Frequent Contributor

What are the input requirements?

One solution is to create a new tool in a Toolbox.tbx and setup input parameters.  Then you can open/popup this as a UI with:

pythonaddins.GPToolDialog(r'<path>\<toolboxname.tbx>', '<tool name>')

Here's how it might look hooked into an add-in with a button tool:

class ButtonClass_CreateSHP(object):
    """Implementation for my_addin.button_1 (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        pythonaddins.GPToolDialog(r'<path>\<toolboxname.tbx>', 'CreateShapefile')
0 Kudos
IanBroad
Deactivated User

Yeah, I've thought about that. I just see it as kind of a clunky, unattractive way of doing it. I'd be nice to just have a dialog box that the user could enter a value into- it seems simple enough.

One example is that I'd like to have a button that when clicked takes an OID of a specific layer for input, and zooms to that feature based on the OID entered. Easy enough to do, but the whole user input part is missing.

0 Kudos
JamesCrandall
MVP Frequent Contributor

I think you can accomplish this with the Tool Validator and set the input parameter when you launch the tool:

pythonaddins.GPToolDialog(r'<path>\<toolboxname.tbx>', '<tool name>', '<arg1>', '<arg2') 

0 Kudos
IanBroad
Deactivated User

Right. I guess my main point is that I'd like to have a way of getting user input without needing to use an existing toolbox.

0 Kudos
JamesCrandall
MVP Frequent Contributor

Tkinter maybe?  Not sure how well it behaves though.

0 Kudos
TI
by
Frequent Contributor

ArcMap does not play nicely with any Python modules that have a non-ArcMap GUI.  I've tried Tkinter and others, before finding that it just randomly crashes ArcMap.  Subsequent Googling found that other people have concluded that non-ArcMap GUI's in Python add-ins clash with ArcMap and cause it to crash.

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

Do you have it in a Toolbox?  It's easy to create a Python addin from a tools box that will have a user interface.  For what it's worth, I have some steps listed in a power point Python add-ins vs. .NET add-ins?

And there is a tech session Python Add-ins: Tips and Tricks   that might be worth checking out.

0 Kudos
DanPatterson_Retired
MVP Emeritus

Rebecca, Jason's presentation is still just a bunch of blank screens with titles..I suspect some iThingy problem.  There are still a bunch of posts on that thread...Do you have a link that can be read with all content?

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

Dan, your right. I looked at it a while ago and just copied the link.  I'll edit my post.

0 Kudos