Solved! Go to Solution.
y = 0 TestString = str (y + 1) + ': ' + str(SelectedWRs) + '= ' + str (Values ) + ' cfs' x = 1 counter = count.getOutput(0) counter2 = int (counter) while x < counter2: y += 1 TestString = TestString + '\n' + str (y + 1) + ': ' + str(SelectedWRs ) + '= ' + str (Values ) + ' cfs' x = x + 1 ProtectedWaterBoolean = pythonaddins.MessageBox('Selected Management Point: ' + str(selection) + '\n\n' + 'Water Rights with Protected Water on ' + str(SelectedDate) + ':' + '\n' + TestString + '\n\n' + 'Total CFS Protected: ' + str(ValuesSum) + '\n\n', 4)
from Tkinter import *
from ttk import *
import tkMessageBox
class DisplayResults():
def __init__(self):
self.root = Tk()
self.root.title("Geoprocessing Results")
self.root.minsize(width=770, height=300)
self.root.config(padx=10, pady=10)
Style().configure(".", font=("Helvetica", 10))
self.frame = Frame()
self.frame.pack(fill="both", expand=1)
self.createWidgets()
self.root.protocol("WM_DELETE_WINDOW", self.quitCallback)
def createWidgets(self):
self.textbox = Text(self.frame, height=20, width=120, relief="sunken", state="normal")
self.textbox.pack(fill="both", expand=1)
self.yscrollbar = Scrollbar(self.textbox, orient="vertical", cursor="arrow" ,command=self.textbox.yview)
self.yscrollbar.pack(side="right", fill="y")
self.textbox["yscrollcommand"]=self.yscrollbar.set
def printToScreen(self, content):
self.textbox.insert("end", content + "\n")
def quitCallback(self):
"""
If user closes the prompt window, the program will exit on 'OK'
"""
if tkMessageBox.askokcancel("Quit", "Do you really wish to quit?"):
self.root.destroy()
sys.exit(1)
gui = DisplayResults()
gui.printToScreen("data")
gui.root.mainloop()
visibleFields = ["ID", "DesiredField1", "DesiredField2"]
field_info = arcpy.Describe("FeatureLayer").fieldInfo
for index in xrange(0, field_info.count):
if field_info.getfieldname(index) not in visibleFields:
field_info.setvisible(index,"HIDDEN")
arcpy.MakeFeatureLayer_management("FeatureLayer","Feature_Layer_With_New_Visibilities","","",field_info)
# Run your reporting process on your new feature layer
# Clean up your feature layer with new visibilities when you're done with it.
arcpy.Delete_management("Feature_Layer_With_New_Visibilities")
dateField = # Method to get the date field you want
# Method that puts each row into a dictionary
def rows_as_dicts(cursor):
colnames = cursor.fields
for row in cursor:
yield dict(zip(colnames, row))
# Record of the data you want in your new table
fields = ["id",dateField]
data = [row for row in rows_as_dicts(arcpy.da.SearchCursor("Your Table",fields))
# Create your new table -- Mine is "in_memory"
table = arcpy.CreateTable_management("in_memory", tableName)
arcpy.AddField_management(table, "id", "LONG", 9)
arcpy.AddField_management(table, dateField, "TEXT")
# Populate your table
with arcpy.da.InsertCursor(table, fields) as cursor:
for row in data:
cursor.insertRow([row["id"], row[dateField]])
# Run your reporting with your new in_memory table
# Clean up your temporary table
arcpy.Delete_management(table)import arcpy
import pythonaddins
import pickle, os
from subprocess import Popen, PIPE
class YourPythonAddinClass(object):
"""
Implementation for Create_New_Point_addin.createNewXYPoint (Button)
"""
def __init__(self):
...
...
...
def yourOnClickFunction(self):
featureClass = arcpy.mapping.Layer("Your Feature Class")
dateField = # Method to get the date field you want
fields = ["id",dateField]
data = [row for row in arcpy.da.SearchCursor(featureClass,fields)]
data.insert(0, tuple(fields))
dataDumpFile = os.path.join(os.path.dirname(os.path.abspath(__file__)), "datadump.p")
pickle.dump(data, open(dataDumpFile,"wb"))
open_GUI("listViewGUI.py",dataDumpFile)
def open_GUI(gui_file_name, file_location):
file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), gui_file_name)
proc = Popen([file_path,file_location], shell=True, stdout=PIPE, bufsize=1)
stdoutdata, stderrdata = proc.communicate()
return stdoutdata
import Tkinter as tk
import tkFont, ttk, tkMessageBox
import math, pickle, sys
class ListBox(object):
"""use a ttk.TreeView as a multicolumn ListBox"""
sampleHeader = ["Column 1","Column 2"]
sampleData = [("data1","data1"),("data2","data2")]
def __init__(self, header=sampleHeader, data=sampleData):
self.root = tk.Tk()
self.root.wm_title("Table Output")
self.root.minsize(width=300, height=300)
ttk.Style().configure('.', font=('Courier', 10))
self.header = header
self.data = data
self.tree = None
self._setup_widgets()
self._build_tree()
self.root.protocol("WM_DELETE_WINDOW", self.quitCallback)
self.root.mainloop()
def _setup_widgets(self):
container = ttk.Frame()
container.pack(fill='both', expand=True)
# create a treeview with dual scrollbars
self.tree = ttk.Treeview(columns=self.header, show="headings")
vsb = ttk.Scrollbar(orient="vertical", command=self.tree.yview)
self.tree.configure(yscrollcommand=vsb.set)
self.tree.grid(column=0, row=0, sticky='nsew', in_=container)
vsb.grid(column=1, row=0, sticky='ns', in_=container)
container.grid_columnconfigure(0, weight=1)
container.grid_rowconfigure(0, weight=1)
def _build_tree(self):
for col in self.header:
self.tree.heading(col, text=col.title())
# adjust the column's width to the header string
self.tree.column(col, width=tkFont.Font().measure(col.title()))
for item in self.data:
self.tree.insert('', 'end', values=item)
# adjust column's width if necessary to fit each value
for ix, val in enumerate(item):
col_w = tkFont.Font().measure(val)
if self.tree.column(self.header[ix], width=None) < col_w:
self.tree.column(self.header[ix], width=int(math.floor(col_w * 1.75)))
def quitCallback(self):
"""
If user closes the prompt window, the program will exit on 'OK'
"""
if tkMessageBox.askokcancel("Quit", "Do you really wish to quit?"):
self.root.destroy()
sys.exit(1)
def main(argv):
data = pickle.load(open(argv[1], "rb"))
header = data[0]
data_list = data[1:]
guiTable = ListBox(header=header, data=data_list)
main(sys.argv)y = 0 TestString = str (y + 1) + ': ' + str(SelectedWRs) + '= ' + str (Values ) + ' cfs' x = 1 counter = count.getOutput(0) counter2 = int (counter) while x < counter2: y += 1 TestString = TestString + '\n' + str (y + 1) + ': ' + str(SelectedWRs ) + '= ' + str (Values ) + ' cfs' x = x + 1 ProtectedWaterBoolean = pythonaddins.MessageBox('Selected Management Point: ' + str(selection) + '\n\n' + 'Water Rights with Protected Water on ' + str(SelectedDate) + ':' + '\n' + TestString + '\n\n' + 'Total CFS Protected: ' + str(ValuesSum) + '\n\n', 4)