2
Dialog that allows user to specify a new config file section name.
3
Used to get new highlight theme and keybinding set names.
8
class GetCfgSectionNameDialog(Toplevel):
9
def __init__(self,parent,title,message,usedNames):
11
message - string, informational message to display
12
usedNames - list, list of names already in use for validity check
14
Toplevel.__init__(self, parent)
15
self.configure(borderwidth=5)
16
self.resizable(height=FALSE,width=FALSE)
18
self.transient(parent)
20
self.protocol("WM_DELETE_WINDOW", self.Cancel)
23
self.usedNames=usedNames
26
self.withdraw() #hide while setting geometry
27
self.update_idletasks()
28
#needs to be done here so that the winfo_reqwidth is valid
29
self.messageInfo.config(width=self.frameMain.winfo_reqwidth())
30
self.geometry("+%d+%d" %
31
((parent.winfo_rootx()+((parent.winfo_width()/2)
32
-(self.winfo_reqwidth()/2)),
33
parent.winfo_rooty()+((parent.winfo_height()/2)
34
-(self.winfo_reqheight()/2)) )) ) #centre dialog over parent
35
self.deiconify() #geometry set, unhide
38
def CreateWidgets(self):
39
self.name=StringVar(self)
40
self.fontSize=StringVar(self)
41
self.frameMain = Frame(self,borderwidth=2,relief=SUNKEN)
42
self.frameMain.pack(side=TOP,expand=TRUE,fill=BOTH)
43
self.messageInfo=Message(self.frameMain,anchor=W,justify=LEFT,padx=5,pady=5,
44
text=self.message)#,aspect=200)
45
entryName=Entry(self.frameMain,textvariable=self.name,width=30)
47
self.messageInfo.pack(padx=5,pady=5)#,expand=TRUE,fill=BOTH)
48
entryName.pack(padx=5,pady=5)
49
frameButtons=Frame(self)
50
frameButtons.pack(side=BOTTOM,fill=X)
51
self.buttonOk = Button(frameButtons,text='Ok',
52
width=8,command=self.Ok)
53
self.buttonOk.grid(row=0,column=0,padx=5,pady=5)
54
self.buttonCancel = Button(frameButtons,text='Cancel',
55
width=8,command=self.Cancel)
56
self.buttonCancel.grid(row=0,column=1,padx=5,pady=5)
59
#simple validity check for a sensible
60
#ConfigParser file section name
64
if not name: #no name specified
65
tkMessageBox.showerror(title='Name Error',
66
message='No name specified.', parent=self)
68
elif len(name)>30: #name too long
69
tkMessageBox.showerror(title='Name Error',
70
message='Name too long. It should be no more than '+
71
'30 characters.', parent=self)
73
elif name in self.usedNames:
74
tkMessageBox.showerror(title='Name Error',
75
message='This name is already in use.', parent=self)
79
def Ok(self, event=None):
81
self.result=self.name.get().strip()
84
def Cancel(self, event=None):
88
if __name__ == '__main__':
93
dlg=GetCfgSectionNameDialog(root,'Get Name',
94
'The information here should need to be word wrapped. Test.')
96
Button(root,text='Dialog',command=run).pack()