try: # python 2
import Tkinter as tk
import tkFont
import ttk
except ImportError: # Python 3
import tkinter as tk
import tkinter.font as tkFont
import tkinter.ttk as ttk
import collections
import json
textFont1 = ("Arial", 10, "bold italic")
textFont2 = ("Arial", 16, "bold")
textFont3 = ("Arial", 8, "bold")
kkk = None
[docs]class EntryWidget(tk.Entry):
def __init__(self, master, x, y):
tk.Entry.__init__(self, master=master)
self.value = tk.StringVar()
self.config(textvariable=self.value, width=8,
relief="ridge", font=textFont1,
bg="#ddddddddd", fg="#000000000",
justify='center')
self.grid(column=x, row=y)
self.value.set("")
[docs]class EntryGrid:
""" Dialog box with Entry widgets arranged in columns and rows."""
def __init__(self, colList, rowList, form, formAttribute, title="Entry Grid"):
self.cols = colList[:]
self.colList = colList[:]
self.colList.insert(0, "")
self.rowList = rowList
self.win = tk.Toplevel()
self.form = form
self.formAttribute = formAttribute
self.win.wm_title(title)
self.mainFrame = tk.Frame(self.win)
self.mainFrame.config(padx='3.0m', pady='3.0m')
self.mainFrame.grid()
self.make_header()
self.gridDict = collections.OrderedDict()
for i in range(1, len(self.colList)):
for j in range(len(self.rowList)):
w = EntryWidget(self.mainFrame, i, j + 1)
self.gridDict[(i - 1, j)] = w.value
def handler(event, col=i - 1, row=j):
return self.__entryhandler(col, row)
w.bind(sequence="<FocusOut>", func=handler)
self.okButton = tk.Button(self.mainFrame, text="OK",
command=self.quit).grid(row=j + 2, column=1, pady=4)
self.data = collections.OrderedDict()
def __entryhandler(self, col, row):
s = self.gridDict[(col, row)].get()
if s.upper().strip() == "EXIT":
self.win.destroy()
elif s.upper().strip() == "TEST":
self.test()
elif s.upper().strip() == "ADENO":
self.ico()
[docs] def ico(self):
""" enter right values for icosahedron """
labelDict = collections.OrderedDict()
labelDict['A'] = 'h1'
labelDict['B'] = 'h1'
labelDict['C'] = 'h1'
labelDict['D'] = 'h2'
labelDict['E'] = 'h2'
labelDict['F'] = 'h2'
labelDict['G'] = 'h3'
labelDict['H'] = 'h3'
labelDict['I'] = 'h3'
labelDict['J'] = 'h4'
labelDict['K'] = 'h4'
labelDict['L'] = 'h4'
labelDict['M'] = 'p'
labelDict['N'] = 'iiia'
labelDict['O'] = 'viiiO'
labelDict['P'] = 'viiiP'
labelDict['Q'] = 'lh3psdeudo'
labelDict['R'] = 'lh3psdeudo'
labelDict['S'] = 'lh3psdeudo'
labelDict['T'] = 'lh3sym'
counter = 0
for row in self.rowList:
# print counter, row, labelDict[row]
self.set(0, counter, labelDict[row])
counter += 1
[docs] def test(self):
""" enter right values for icosahedron """
for i in range(len(self.cols)):
for j in range(len(self.rowList)):
self.set(i, j, "")
self.win.update_idletasks()
self.set(i, j, i + 1 + j)
self.win.update_idletasks()
def __str__(self):
return "data = {}".format(self.data)
[docs] def quit(self):
for k, v in zip(self.rowList, self.gridDict.values()):
# for k, v in zip(self.rowList, list(self.gridDict.values())):
self.data[k] = v.get()
value = json.dumps(self.data)
self.form.setVar(self.formAttribute, value)
self.win.destroy()
def __headerhandler(self, col, row, text):
""" has no effect when Entry state=readonly """
self.hdrDict[(col, row)].text.set(text)
[docs] def get(self, x, y):
return self.gridDict[(x, y)].get()
[docs] def set(self, x, y, v):
self.gridDict[(x, y)].set(v)
return v