Select to view content in your preferred language

Adding messaging to Python Add-in

2861
5
Jump to solution
05-15-2014 08:18 AM
MattMcLees
New Contributor III
I recently created a Python add-in that completes several gp tasks for a user. The issue is that when the user presses a button on a toolbar to execute the task, nothing displays saying that processing is taking place. I know how to add messaging to a tool in a toolbox, but not to an add-in button. The user is very novice hence using the 1 button add-in versus a gp tool with multiple inputs. Does anybody have experience printing messaging via an add-in that notifys the user processing is taking place?

- We are both using ArcGIS Desktop 10.2.1
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JamesCrandall
MVP Frequent Contributor
Depends on where in the Add-In you are wanting to generate the message popup.  Here is the onMouseDownMap event of a ToolClass implementation:

import pythonaddins   def onMouseDownMap(self, x, y, button, shift):        msg = "You just clicked in the map display"    pythonaddins.MessageBox(msg, 'Report Click Event', 0) 

View solution in original post

0 Kudos
5 Replies
JamesCrandall
MVP Frequent Contributor
Depends on where in the Add-In you are wanting to generate the message popup.  Here is the onMouseDownMap event of a ToolClass implementation:

import pythonaddins   def onMouseDownMap(self, x, y, button, shift):        msg = "You just clicked in the map display"    pythonaddins.MessageBox(msg, 'Report Click Event', 0) 
0 Kudos
JasonScheirer
Regular Contributor II
For the time being, you'll probably just want to use print statements to let your users know you're doing work in a non-blocking manner and tell people to look at the Python window for some indication of progress. James' message box solution works well, too, but the script will block on the dialog until the user has pressed OK.

In 10.3 we've thought about this and we're adding a progress dialog into the pythonaddins module. Its usage will look something like this:

with pythonaddins.ProgressDialog as dialog:
    dialog.title = "Doing work..."
    dialog.label = "Opening cursor..."
    # Do some work here
    dialog.label = "Working..."
    # More work here
    dialog.label = "Cleaning up..."


as long as your code is inside that with block the dialog will display on-screen, giving you a way to indicate that you're working and automatically clean up/hide the dialog window when you're done.
0 Kudos
JamesCrandall
MVP Frequent Contributor
...In 10.3 we've thought about this and we're adding a progress dialog into the pythonaddins module.


kewl. 

Now about those UI's.....
0 Kudos
MattMcLees
New Contributor III
Thanks. I understand the concept and am glad there will be improved status reporting. However I still can't get either method to work. Here is the code:

class PostReconcile(object):
    """Implementation for street_centerlines_addin.btn1 (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
            arcpy.ReconcileVersions_management(db,"ALL_VERSIONS","SDE.Default","CD_LYN.lyn","LOCK_ACQUIRED","NO_ABORT","BY_OBJECT","FAVOR_TARGET_VERSION","POST","KEEP_VERSION")
            arcpy.CopyFeatures_management(fc,shp1)
            arcpy.CopyFeatures_management(fc,shp2)
            arcpy.CopyFeatures_management(fc,shp3)
            arcpy.CopyFeatures_management(fc,shp4)
            arcpy.CopyFeatures_management(fc,shp5)
            pythonaddins.MessageBox('Copied files to local drive', 'INFO', 0)

When I press the button, it just runs with no message popup. I also tried a print statement, but nothing shows in the Python window. Must have it in the wrong spot...
0 Kudos
JamesCrandall
MVP Frequent Contributor
Thanks. I understand the concept and am glad there will be improved status reporting. However I still can't get either method to work. Here is the code:

class PostReconcile(object):
    """Implementation for street_centerlines_addin.btn1 (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
            arcpy.ReconcileVersions_management(db,"ALL_VERSIONS","SDE.Default","CD_LYN.lyn","LOCK_ACQUIRED","NO_ABORT","BY_OBJECT","FAVOR_TARGET_VERSION","POST","KEEP_VERSION")
            arcpy.CopyFeatures_management(fc,shp1)
            arcpy.CopyFeatures_management(fc,shp2)
            arcpy.CopyFeatures_management(fc,shp3)
            arcpy.CopyFeatures_management(fc,shp4)
            arcpy.CopyFeatures_management(fc,shp5)
            pythonaddins.MessageBox('Copied files to local drive', 'INFO', 0)


When I press the button, it just runs with no message popup. I also tried a print statement, but nothing shows in the Python window. Must have it in the wrong spot...


Just as a test, try eliminating everything except for your message --- maybe something in the code above it is failing and causing the message to not display?


class PostReconcile(object):
    """Implementation for street_centerlines_addin.btn1 (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        pythonaddins.MessageBox('Copied files to local drive', 'INFO', 0)
0 Kudos