forked from dmnfarrell/tkintertable
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDialogs.py
More file actions
149 lines (131 loc) · 5.41 KB
/
Dialogs.py
File metadata and controls
149 lines (131 loc) · 5.41 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env python
"""
Table Dialog classes.
Created Oct 2008
Copyright (C) Damien Farrell
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
try:
import Tkinter as tkinter
from Tkinter import *
except:
import tkinter as tkinter
from tkinter import *
import types
import tkinter.simpledialog, tkinter.filedialog, tkinter.messagebox
class RecordViewDialog(tkinter.simpledialog.Dialog):
"""Dialog for viewing and editing table records"""
def __init__(self, parent, title=None, table=None, row=None):
if table != None:
self.table = table
self.model = table.getModel()
self.row = row
self.recdata = self.model.getRecordAtRow(row)
self.recname = self.model.getRecName(row)
else:
return
tkinter.simpledialog.Dialog.__init__(self, parent, title)
return
def body(self, master):
"""Show all record fields in entry fields or labels"""
model = self.model
cols = list(self.recdata.keys())
self.editable = []
self.fieldnames = {}
self.fieldvars = {}
self.fieldvars['Name'] = StringVar()
self.fieldvars['Name'].set(self.recname)
Label(master, text='Rec Name:').grid(row=0,column=0,padx=2,pady=2,sticky='news')
Entry(master, textvariable=self.fieldvars['Name'],
relief=GROOVE,bg='yellow').grid(row=0,column=1,padx=2,pady=2,sticky='news')
i=1
for col in cols:
self.fieldvars[col] = StringVar()
if col in self.recdata:
val = self.recdata[col]
self.fieldvars[col].set(val)
self.fieldnames[col] = Label(master, text=col).grid(row=i,column=0,padx=2,pady=2,sticky='news')
ent = Entry(master, textvariable=self.fieldvars[col], relief=GROOVE,bg='white')
ent.grid(row=i,column=1,padx=2,pady=2,sticky='news')
if not type(self.recdata[col]) is bytes:
ent.config(state=DISABLED)
else:
self.editable.append(col)
i+=1
top=self.winfo_toplevel()
top.columnconfigure(1,weight=1)
return
def apply(self):
"""apply"""
cols = self.table.cols
model = self.model
absrow = self.table.get_AbsoluteRow(self.row)
newname = self.fieldvars['Name'].get()
if newname != self.recname:
model.setRecName(newname, absrow)
for col in range(cols):
colname = model.getColumnName(col)
if not colname in self.editable:
continue
if colname not in self.fieldvars:
continue
val = self.fieldvars[colname].get()
model.setValueAt(val, absrow, col)
#print 'changed field', colname
self.table.redrawTable()
return
class MultipleValDialog(tkinter.simpledialog.Dialog):
"""Simple dialog to get multiple values"""
def __init__(self, parent, title=None, initialvalues=None, labels=None, types=None):
if labels != None and types != NoneType:
self.initialvalues = initialvalues
self.labels = labels
self.types = types
tkinter.simpledialog.Dialog.__init__(self, parent, title)
def body(self, master):
r=0
self.vrs=[];self.entries=[]
for i in range(len(self.labels)):
Label(master, text=self.labels[i]).grid(row=r, column=0,sticky='news')
if self.types[i] == 'int':
self.vrs.append(IntVar())
else:
self.vrs.append(StringVar())
if self.types[i] == 'password':
s='*'
else:
s=None
if self.types[i] == 'list':
button=Menubutton(master, textvariable=self.vrs[i],relief=RAISED)
menu=Menu(button,tearoff=0)
button['menu']=menu
choices=self.initialvalues[i]
for c in choices:
menu.add_radiobutton(label=c,
variable=self.vrs[i],
value=c,
indicatoron=1)
self.entries.append(button)
self.vrs[i].set(self.initialvalues[i][0])
else:
self.vrs[i].set(self.initialvalues[i])
self.entries.append(Entry(master, textvariable=self.vrs[i], show=s, bg='white'))
self.entries[i].grid(row=r, column=1,padx=2,pady=2,sticky='news')
r+=1
return self.entries[0] # initial focus
def apply(self):
self.result = True
self.results = []
for i in range(len(self.labels)):
self.results.append(self.vrs[i].get())
return