I'm trying to prepare a Python add-in using "Python Add-In Wizard". I want my add-in to perform some geoprocessing but first it should take data from a user and there's already a problem. I'm displaying a wxpython GUI and it loses focus and hides behind the arcmap window almost immediately after it's shown. I have no idea how to debug it and what could cause the problem. I decided to go this way after getting hands on this example.

My code is here:


from dialogs.import_dialog import ImportDialog

class ImportButton(object):
    """Runs the import function."""
    dlg = None

    def __init__(self):
        self.enabled = True
        self.checked = False

    def onClick(self):
        if self.dlg is None:
            self.dlg = ImportDialog()


class ImportDialog(wx.Frame):
    def __init__(self):
        wxStyle = wx.CAPTION | wx.CLOSE_BOX | wx.SYSTEM_MENU
        wx.Frame.__init__(self, None, wx.ID_ANY, "some msg", style=wxStyle, size=(350, 200))
        self.panel = wx.Panel(self, wx.ID_ANY)

        self.path_label = wx.StaticText(self.panel, wx.ID_ANY, u"some msg", pos=(8, 8))
        self.input_path = wx.TextCtrl(self.panel, wx.ID_ANY, value="", pos=(8, 36), size=(330, 21))

        self.path_label = wx.StaticText(self.panel, wx.ID_ANY,
                                        u"some msg",
                                        pos=(8, 65))

        self.group_layers = wx.ComboBox(self.panel, wx.ID_ANY, pos=(8, 93), size=(330, 21))

        self.ok_button = wx.Button(self.panel, label="OK", pos=(8, 130))

        self.Bind(wx.EVT_CLOSE, self.OnClose)


    def OnClose(self, event):
  • You might be able to use wx.Window.Reparent() to make the dialog a child window of ArcMap, but never having tried it I couldn't say for sure. Also see this SO question: stackoverflow.com/a/15863617/386205 Basically you need to import wx before the ArcMap event loop starts by implementing an extension in your add-in. – blah238 Oct 16 '13 at 17:51
  • Did you ever figure out how to prevent the losing focus on your dialog? I looked into the Reparenting but am unsure of how to get the ArcMap Window to Reparent with. – user30558 May 23 '14 at 14:14
  • @user30558 Unfortunately not, I'm not sure how one could reparent the arcmap window since it's not wx compatible. – Michal May 24 '14 at 8:27