1
2 """
3 Table Dialog classes.
4 Created Oct 2008
5 Copyright (C) Damien Farrell
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 """
21
22 from Tkinter import *
23 import types
24 import tkSimpleDialog, tkFileDialog, tkMessageBox
25
27 """Dialog for viewing and editing table records"""
28
29 - def __init__(self, parent, title=None, table=None, row=None):
30 if table != None:
31 self.table = table
32 self.model = table.getModel()
33 self.row = row
34 self.recdata = self.model.getRecordAtRow(row)
35 self.recname = self.model.getRecName(row)
36 else:
37 return
38 tkSimpleDialog.Dialog.__init__(self, parent, title)
39 return
40
41 - def body(self, master):
42 """Show all record fields in entry fields or labels"""
43 model = self.model
44 cols = self.recdata.keys()
45 self.editable = []
46 self.fieldnames = {}
47 self.fieldvars = {}
48 self.fieldvars['Name'] = StringVar()
49 self.fieldvars['Name'].set(self.recname)
50 Label(master, text='Rec Name:').grid(row=0,column=0,padx=2,pady=2,sticky='news')
51 Entry(master, textvariable=self.fieldvars['Name'],
52 relief=GROOVE,bg='yellow').grid(row=0,column=1,padx=2,pady=2,sticky='news')
53 i=1
54 for col in cols:
55 self.fieldvars[col] = StringVar()
56 if self.recdata.has_key(col):
57 val = self.recdata[col]
58 self.fieldvars[col].set(val)
59 self.fieldnames[col] = Label(master, text=col).grid(row=i,column=0,padx=2,pady=2,sticky='news')
60 ent = Entry(master, textvariable=self.fieldvars[col], relief=GROOVE,bg='white')
61 ent.grid(row=i,column=1,padx=2,pady=2,sticky='news')
62 if not type(self.recdata[col]) is types.StringType:
63 ent.config(state=DISABLED)
64 else:
65 self.editable.append(col)
66 i+=1
67 top=self.winfo_toplevel()
68 top.columnconfigure(1,weight=1)
69 return
70
72 """apply"""
73 cols = self.table.cols
74 model = self.model
75 absrow = self.table.get_AbsoluteRow(self.row)
76 newname = self.fieldvars['Name'].get()
77 if newname != self.recname:
78 model.setRecName(newname, absrow)
79
80 for col in range(cols):
81 colname = model.getColumnName(col)
82 if not colname in self.editable:
83 continue
84 if not self.fieldvars.has_key(colname):
85 continue
86 val = self.fieldvars[colname].get()
87 model.setValueAt(val, absrow, col)
88
89
90 self.table.redrawTable()
91 return
92
94 """Simple dialog to get multiple values"""
95
96 - def __init__(self, parent, title=None, initialvalues=None, labels=None, types=None):
97 if labels != None and types != NoneType:
98 self.initialvalues = initialvalues
99 self.labels = labels
100 self.types = types
101 tkSimpleDialog.Dialog.__init__(self, parent, title)
102
103 - def body(self, master):
104
105 r=0
106 self.vrs=[];self.entries=[]
107 for i in range(len(self.labels)):
108 Label(master, text=self.labels[i]).grid(row=r, column=0,sticky='news')
109 if self.types[i] == 'int':
110 self.vrs.append(IntVar())
111 else:
112 self.vrs.append(StringVar())
113 if self.types[i] == 'password':
114 s='*'
115 else:
116 s=None
117
118 if self.types[i] == 'list':
119 button=Menubutton(master, textvariable=self.vrs[i],relief=RAISED)
120 menu=Menu(button,tearoff=0)
121 button['menu']=menu
122 choices=self.initialvalues[i]
123 for c in choices:
124 menu.add_radiobutton(label=c,
125 variable=self.vrs[i],
126 value=c,
127 indicatoron=1)
128 self.entries.append(button)
129 self.vrs[i].set(self.initialvalues[i][0])
130 else:
131 self.vrs[i].set(self.initialvalues[i])
132 self.entries.append(Entry(master, textvariable=self.vrs[i], show=s, bg='white'))
133 self.entries[i].grid(row=r, column=1,padx=2,pady=2,sticky='news')
134 r+=1
135
136 return self.entries[0]
137
139 self.result = True
140 self.results = []
141 for i in range(len(self.labels)):
142 self.results.append(self.vrs[i].get())
143 return
144