forked from golddoushi/mcsolver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
toolbox.py
109 lines (83 loc) · 3.44 KB
/
toolbox.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
from tkinter import *
import re
class NoteFrm:
frm_base=None
label_list=[]
entry_list=[]
data_list=[]
totn=2
row=False
def __init__(self,frm_base,init_notes=[],init_data=[0,0],totn=2,row=False,entryWidth=8,labelWidth=8):
self.frm_base=frm_base
self.totn=len(init_data)
self.row=row
self.entryWidth=entryWidth
self.labelWidth=labelWidth
self.loadlabel(frm_base,init_notes)
self.loadentries(frm_base,init_data)
def loadlabel(self,frm_base,init_notes):
self.label_list=[]
for i in range(self.totn):
label=Label(frm_base,text=init_notes[i])
self.label_list.append(label)
if self.row:
for i in range(self.totn):
self.label_list[i].grid(row=0,column=2*i)
#self.label_list[i+1].grid(row=0,column=3*i+2)
else:
for i in range(self.totn):
self.label_list[i].grid(row=i,column=0)
#self.label_list[2*i+1].grid(row=i,column=2)
def loadentries(self,frm_base,init_data):
self.entry_list=[]
for i in range(self.totn):
entry=Entry(frm_base,width=self.entryWidth)
entry.insert(0,init_data[i])
self.entry_list.append(entry)
if self.row:
for i in range(self.totn):
self.entry_list[i].grid(row=0,column=2*i+1)
else:
for i in range(self.totn):
self.entry_list[i].grid(row=i,column=1)
def setValue(self,data=[1,600]):
#print data
for i in range(self.totn):
self.entry_list[i].delete(0,END)
self.entry_list[i].insert(0,data[i])
def report(self,strrep=False):
self.data_list=[]
if strrep:
for ele in self.entry_list:
value=ele.get()
#value=value if value else '0'
self.data_list.append(value)
else:
for ele in self.entry_list:
value=ele.get()
self.data_list.append(float(value))
return self.data_list
class InfoList:
def __init__(self,baseFrame, selectEvent, dataFormat, initialInfo=[],width=30,height=5):
self.infoData=initialInfo
self.dataFormat=dataFormat
self.infoList=Listbox(baseFrame,width=width,height=height,listvariable=StringVar(value=[ele[0] for ele in self.infoData]))
self.infoList.bind('<<ListboxSelect>>',selectEvent)
self.infoList.grid(row=0,column=0)
self.scrollbar=Scrollbar(baseFrame,orient=VERTICAL, command=self.infoList.yview)
self.scrollbar.grid(row=0,column=1,sticky=(N,S))
self.infoList['yscrollcommand']=self.scrollbar.set
self.updateInfo(self.infoData)
def updateInfo(self,infoData=[]):
self.infoList.delete(0,len(self.infoData)-1)
self.infoData=infoData
for iinfo, info in enumerate(self.infoData):
info[0]=iinfo
self.infoList.insert(iinfo,self.dataFormat(info))
for i in range(0,len(self.infoData),2):
self.infoList.itemconfigure(i, background='#f0f0ff')
def report(self):
idxs = self.infoList.curselection()
if len(idxs)==1:
return self.infoData[idxs[0]]
return []