Search code examples
wxpythonarcgisarcpy

How to construct an interactive dialog using wxPython?


I have a table displayed below within a dialog box with several options on right -- I want to re-create it using wxpython within ArcGIS pythonaddins framework. First item is to display table within a dialog box with scroll down option. Second thing is to change "Cond." column based on any choice from "Update" column -- like for example, If I click on 'G' then "Cond." will change to 'Good' and will subsequently change 'A', 'B', 'C', and 'D' values (this is what I mean by interactive). Finally I want to write this modified table to a text file. I can create a dialog box but displaying table with interactive functionality is beyond my ken. Any suggestions would be highly appreciative.

table


Solution

  • If I were you, I would start out by getting the wxPython demo package. The demo allows you to see examples of 99% of the widgets including the code. It also includes a few folders of decent example applications.

    The primary widget I would use for table is probably some type of ListCtrl in report mode. There are several different versions of this control, from the plain wx.ListCtrl to the DVC versions in wxPython 2.9+ to the pure Python UltimateListCtrl. Regardless of the one you choose, you will need to monitor changes in a specific column. If a cell in that column changes, you can change the other cell's value.

    I would probably have a dictionary that maps the single letter values to the full string values.

    Theoretically, you could use a wx.grid.Grid, but I find that widget to be more complex to use.

    To save the data to disk, you will likely need to iterate over the columns and cells and extract the data and then save it in your format of choice. I would think a CSV file would suffice. Python provides a csv module that you can use for just this sort of thing.