Python GUI Arc10?

5396
8
05-07-2010 10:33 AM
LT
by
Occasional Contributor
Hi Folks,

Maybe this is a dumb question that will become obvious when I get my hands on the new software but...

I'm looking forward to improvements in Python capability in Arc10.  I think we'll be reaching a point where we can do all the geoprocessing and much of our basic mapping by learning one easy language, Python.  In the past, I've gotten away with knowing how to do all geoprocessing in Python and then using vba to build an interface, do some basic mapping, and calling Python to do the rest. 
Python geoprocessing --easy;
VBA --forms easy;
VBA mapping basics --slightly painful;
VBA calling Python very buggy. 

With arcpy we can now do
Python geoprocessing
Python basic mapping (hurray!)
now...how are we supposed to build forms for graphical user interfaces?
how are we supposed to trigger the Python with arcmap?  i.e., what's replacing the easy-peasy uicommand buttons?
Are we going to know have to learn VB.NET or C# and IDE's (such as the overly complex Visual Studio) for those?  Yes, those are powerful, but this means they are complicated.  This seems like learning to fly a plane when a bike's all that's needed.  This seems like a step backwards since most of the people that want to program arcmap will not have a programming background or want to spend a great deal of time learning a bunch of programming languages. 

Can anyone tell me how easy VBA forms and UIcontrolbuttons are going to be replaced, so that people can continue to customize ArcMap with ease?   If we at least have UI control buttons then we could use WxPython or something like that to build the forms.  (yes, I understand you can still install VBA, but since that won't come bundled any more, we won't be able to count on others having it--hindering code sharing, etc.)
0 Kudos
8 Replies
DeeleshMandloi
Esri Contributor
Script Tools at 9.3

At 9.3 and earlier script tools have been the main way to provide UI for your python scripts. Also at 9.3 or later, the script tools run in the same process as ArcMap. So script tools are sort of the framework to build UI for python scripts. The script tools allow you to create new geoprocessing tools similar to other system tools in ArcToolbox. Note that the script tools are part of the geoprocessing framework. So they have the same UI as the system tools. They don't provide an event driven programming model that VBA forms are capable of doing. Having said that you can still achieve a lot of UI functionality like browsing to inputs without any code and even complex input validation with some python code (using ToolValidator class).

Have a look at these help topics to know more about script tools. Most of the script tools stuff has been common between 9.3 and 10.

What's new at 10

At 10, as you are already aware, there is the new mapping module with arcpy. However, there is no special UI framework that allows you to create VBA form like interface for python scripts. You still have script tools as the best choice to run your python scripts from within ArcMap. One new feature is that you can take a model or a script tool from your toolbox and create a UI button from it using the Customize dialog. That way you can have a toolbar and the buttons launch the script tools (which have a gp tool UI) and can execute them (no coding necessary for this)

Add in framework

To create VBA form like event driven interfaces, you have to use the Add in framework. Addins can be developed using C#, VB.NET or Java and has the requirement of using Visual studio or Eclipse IDEs. But the add in framework and the IDE support for creating addins makes creating customizations for ArcMap at 10 a lot easier (and we hope you will find it as easy as VBA forms:)).

Hope this helps
Deelesh
0 Kudos
JasonScheirer
Occasional Contributor III
In 10, you can add Geoprocessing tools to your toolbars from the Customize window. Any tool that has no parameters will execute immediately when you click its button, giving you a way to get command buttons more-or-less for free with your script tools. You can then code a wxPython or PyQT or TkIinter UI in the geoprocessing script.
0 Kudos
TedCronin
MVP Honored Contributor
Or use clrtypes with IronPython, and run from within c# 4 using dynamic:) and skip arcpy altogether.
0 Kudos
DavidPeters
New Contributor
@jscheirer - Great idea about putting a wxPython script onto the toolbar but I cannot get this to work.

No matter what I try, the GP executing window always pops up and interferes with the focus of my wxFrame so it doesn't function properly. If I turn off the 'run in process option' then I just get an error.

Have you had any success with this?
0 Kudos
GraceCai
New Contributor
@GeoDaveyboy

Hi there, I was wondering if you or anyone here has found a solution to this UI issue. My Tkinter code runs but I'm not able to enter any text fields due to competing cursor priority.
0 Kudos
JasonScheirer
Occasional Contributor III
You can mark the GP tool to run out-of-process in the script tool configuration dialog (uncheck run in process) and the focus contention issue should go away. And I believe PyQT behaves pretty well when run in process, but I have not done extensive testing.
0 Kudos
TimLeach
New Contributor II
This may be a workaround (apparently until 10.1). I simply wanted to get a Tkinter form to work with an entry box called from a script tool from ArcToolbox. I had interface problems as mentioned earlier in the thread. Focus wouldn't allow me to enter anything in the entry box.

I tried a few things and this seemed to be a fix for now (I only tested on one form). The object of my script was to update a database table in a file geodatabase. I wasn't doing anything with TOC layers, so this solution may not work for you. Also, this could be bad practice, but I was more concerned with the form working to update the database table.

My solution was to create a separate python script that is accessed by a tool, that in turn calls my real tool with the tkinter form. The script launches my real tool from the operating system using os.system. This seems to provide a buffer from interference with ArcMap's GUI.

Here's the code of a separate python program called PyLauncher.py. PyLauncher.py runs my real tool with tkinter forms within the script called UpdtProjectDB.py from the operating system via a seperate process or shell:

import os
runin = os.system("C:\\Python26\\ArcGIS10.0\\python C:\\Tim\\ArcGIS\\TableRelate\\py\\UpdtProjectDB.py")

I add the launcher to my ArcToolbox as a script tool and am then able to interact with the Tkinter form from UpdtProjectDB.py. I have not done any research to see if this might be problematic, so use this technique at your own risk. It's not fast, but in my case it works and I can look forward to the improvements in 10.1.
0 Kudos
JohnMorgan1
New Contributor II

I have used wxPython to build a dialog box with GUI controls that runs from the Python command line inside ArcMap, but when I try to connect it to a Toolbox Python Tool, it crashes ArcMap when I try to run it.  If I attach it to an ArcMap Python Add-In, it runs exactly once without error.  The second time I run it in an ArcMap session, it crashes ArcMap.

More details:

https://community.esri.com/thread/214273-is-wxpython-incompatible-with-arcmap-add-ins-and-tools

0 Kudos