wxPython hooked to arcmap?

4969
9
10-17-2011 12:32 PM
KevinBell
Occasional Contributor III
Any of you genius mind know how to hook a wxPython GUI back up to arcmap?
Tags (2)
0 Kudos
9 Replies
JasonPardy
New Contributor
Hi Kevin,

Unfortunately, this currenly does not work and is not supported. The low-levels of integrating any Python UI framework (including wxPython) with the event loop of the desktop applications is very difficult. It is something we are researching to fix, but the scope of such a project is very big and isn't something that we feel can be done in the 10.1 timeframe. We do hope to support wxPython in the future as the Python UI Framework for hooking into ArcGIS Desktop.

Thanks,
Jason Pardy
Esri
0 Kudos
TedCronin
MVP Honored Contributor
We do hope to support wxPython in the future as the Python UI Framework for hooking into ArcGIS Desktop.

Thanks,
Jason Pardy
Esri


Alright!!!
0 Kudos
MarkCederholm
Occasional Contributor III
I notice that threading.Timer, or indeed any implementation of threading, doesn't work in ArcMap Python.  I'm assuming this is a related issue?
0 Kudos
MarkCederholm
Occasional Contributor III
I can get wxPython to work in an add-in, EXCEPT that Destroy() doesn't work.  For example:

import arcpy
import pythonaddins
import wx

class TestButtonClass(object):
    """Implementation for wxTest_addin.TestButton (Button)"""
    dlg = None
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        if self.dlg is None:
            self.dlg = TestDialog()
        else:
            self.dlg.Show(True)
        return

class TestDialog(wx.Frame):
    def __init__(self):
        wxStyle = wx.CAPTION | wx.RESIZE_BORDER | wx.MINIMIZE_BOX |wx.CLOSE_BOX | wx.SYSTEM_MENU
        wx.Frame.__init__(self, None, -1, "Set DataFrame Name", style=wxStyle, size=(300, 120))
        self.SetMaxSize((300, 120))
        self.SetMinSize((300, 120))
        self.Bind(wx.EVT_CLOSE, self.OnClose)
        panel = wx.Panel(self, -1)
        self.lblStatus = wx.StaticText(panel, -1, "OK", pos=(8, 8))
        wx.StaticText(panel, -1, "Title:", pos=(8,36))
        self.tbTitle = wx.TextCtrl(panel, -1, value="", pos=(36, 36), size=(200,21))
        self.btnSet = wx.Button(panel, label="Set", pos=(8, 66))
        self.Bind(wx.EVT_BUTTON, self.OnSet, id=self.btnSet.GetId())
        self.Show(True)
        
    def OnClose(self, event):
        self.Show(False) # self.Destroy() doesn't work

    def OnSet(self, event):
        # Use str() to strip away Unicode crap
        sTitle = str(self.tbTitle.GetValue())
        mxd = arcpy.mapping.MapDocument("CURRENT")
        df = mxd.activeDataFrame
        df.name = sTitle
        arcpy.RefreshTOC()

app = wx.PySimpleApp()
app.MainLoop()


I haven't yet investigated the consequences of having more than one add-in using wxPython.
0 Kudos
MarkCederholm
Occasional Contributor III
Multiple add-ins, multiple dialogs, no problem.  Button, ComboBox, and RadioButton events work fine; I haven't tested any others.  One other quirk I noticed:  print, when executed from a dialog, does not output to the Python window.
0 Kudos
ifgiEDC
New Contributor
Thank you Mark,

it works like a charm.
0 Kudos
NikolasStevenson-Molnar
New Contributor
We do hope to support wxPython in the future as the Python UI Framework for hooking into ArcGIS Desktop.

Thanks,
Jason Pardy
Esri

Alright!!!


I second that 'Alright!' 🙂

_Nik
0 Kudos
IbraheemKhan1
New Contributor III
I am using wxPython and problem lies in closing the main frame.
'self.Show(False)' isn't closing the main frame. Do you suggest any way to close main frame without crashing arcmap. Thanks!
0 Kudos
JohnMorgan1
New Contributor II

I have written a Python script using wxPython that runs inside ArcMap.  It runs fine from the Python Command Line inside ArcMap, but if it is launched from an ArcMap Add-In, it runs once without a problem, but if it is run a second time in the same ArcMap session, it crashes ArcMap.  If it is launched from a Toolbar Tool, it crashes ArcMap immediately.  More details here:

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

0 Kudos