Re-Initializing wxPython GUI without crashing ArcMap - 10.1 Python AddIn

3070
4
Jump to solution
08-02-2012 07:18 AM
MichaelMarkieta
New Contributor III
I am building upon this example of wxPython in ArcGIS 10.1.
http://betablogs.esri.com/beta/arcgis/2012/05/03/custom-wxpython-guis-an-approach-for-arcgis-10-1/

Outside of ArcMap, I can Close() the GUI and re-initialize it in its original state using the following method:

def OnReset(self, event):     self.parent.Close()      frame = myFrame()


Doing this is ArcMap causes it to crash... I think it has to do with the 'extensions' portion of the AddIn.

class WXExtension(object):     """Create a wxPython Extension inside ArcMap"""      def __init__(self):         self._wxApp = None         self._enabled = None      def startup(self):         try:             self._wxApp = wx.App()             self._wxApp.MainLoop()         except Exception:             pythonaddins.MessageBox("Unable to start the Extension.", "Extension Error")      @property     def enabled(self):         if self._enabled == False:             button.enabled = False         else:             button.enabled = True         return self._enabled      @enabled.setter     def enabled(self, value):         self._enabled = value  class Button(object):     """ Create a custom button inside ArcMap"""      _dlg = None      @property     def dlg(self):         if self._dlg is None:             self._dlg = myFrame()         return self._dlg      def __init__(self):         self.enabled = True         self.checked = False      def onClick(self):         try:             self.dlg.Show(True)         except Exception:             pythonaddins.MessageBox("Can't show myFrame.", "Error")             pass


Included the DMP file from the ArcMap crash...
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
4 Replies
JasonScheirer
Occasional Contributor III
0 Kudos
MichaelMarkieta
New Contributor III
Need to use SimpleApp. Here's a blog post that references Mark Cederholm's findings as presented at the Developer Summit.


This works.

Can you clarify why we must use the PySimpleApp class?
0 Kudos
JasonScheirer
Occasional Contributor III
Event loops. The SimpleApp one doesn't assume it's the only one processing events in the program, it plays well with other code that also handles mouse moves/button clicks/etc (like the rest of ArcMap.exe's controls).
0 Kudos
NadeemQazi
New Contributor III
Hi there
I am also trying to use wxpython in arcgis10.1 however when i write import wx the arcgis10.1  python window  it crashed. did u also
have same problem. i  would appreciate your comments  or suggestion to use wxpython in arcgis. the link you mentioned in your
message is not working.
regards
nadeem
0 Kudos