Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2..../idlelib
File: configSectionNameDialog.py
"""
[0] Fix | Delete
Dialog that allows user to specify a new config file section name.
[1] Fix | Delete
Used to get new highlight theme and keybinding set names.
[2] Fix | Delete
The 'return value' for the dialog, used two placed in configDialog.py,
[3] Fix | Delete
is the .result attribute set in the Ok and Cancel methods.
[4] Fix | Delete
"""
[5] Fix | Delete
from Tkinter import *
[6] Fix | Delete
import tkMessageBox
[7] Fix | Delete
class GetCfgSectionNameDialog(Toplevel):
[8] Fix | Delete
def __init__(self, parent, title, message, used_names, _htest=False):
[9] Fix | Delete
"""
[10] Fix | Delete
message - string, informational message to display
[11] Fix | Delete
used_names - string collection, names already in use for validity check
[12] Fix | Delete
_htest - bool, change box location when running htest
[13] Fix | Delete
"""
[14] Fix | Delete
Toplevel.__init__(self, parent)
[15] Fix | Delete
self.configure(borderwidth=5)
[16] Fix | Delete
self.resizable(height=FALSE, width=FALSE)
[17] Fix | Delete
self.title(title)
[18] Fix | Delete
self.transient(parent)
[19] Fix | Delete
self.grab_set()
[20] Fix | Delete
self.protocol("WM_DELETE_WINDOW", self.Cancel)
[21] Fix | Delete
self.parent = parent
[22] Fix | Delete
self.message = message
[23] Fix | Delete
self.used_names = used_names
[24] Fix | Delete
self.create_widgets()
[25] Fix | Delete
self.withdraw() #hide while setting geometry
[26] Fix | Delete
self.update_idletasks()
[27] Fix | Delete
#needs to be done here so that the winfo_reqwidth is valid
[28] Fix | Delete
self.messageInfo.config(width=self.frameMain.winfo_reqwidth())
[29] Fix | Delete
self.geometry(
[30] Fix | Delete
"+%d+%d" % (
[31] Fix | Delete
parent.winfo_rootx() +
[32] Fix | Delete
(parent.winfo_width()/2 - self.winfo_reqwidth()/2),
[33] Fix | Delete
parent.winfo_rooty() +
[34] Fix | Delete
((parent.winfo_height()/2 - self.winfo_reqheight()/2)
[35] Fix | Delete
if not _htest else 100)
[36] Fix | Delete
) ) #centre dialog over parent (or below htest box)
[37] Fix | Delete
self.deiconify() #geometry set, unhide
[38] Fix | Delete
self.wait_window()
[39] Fix | Delete
def create_widgets(self):
[40] Fix | Delete
self.name = StringVar(self.parent)
[41] Fix | Delete
self.fontSize = StringVar(self.parent)
[42] Fix | Delete
self.frameMain = Frame(self, borderwidth=2, relief=SUNKEN)
[43] Fix | Delete
self.frameMain.pack(side=TOP, expand=TRUE, fill=BOTH)
[44] Fix | Delete
self.messageInfo = Message(self.frameMain, anchor=W, justify=LEFT,
[45] Fix | Delete
padx=5, pady=5, text=self.message) #,aspect=200)
[46] Fix | Delete
entryName = Entry(self.frameMain, textvariable=self.name, width=30)
[47] Fix | Delete
entryName.focus_set()
[48] Fix | Delete
self.messageInfo.pack(padx=5, pady=5) #, expand=TRUE, fill=BOTH)
[49] Fix | Delete
entryName.pack(padx=5, pady=5)
[50] Fix | Delete
frameButtons = Frame(self, pady=2)
[51] Fix | Delete
frameButtons.pack(side=BOTTOM)
[52] Fix | Delete
self.buttonOk = Button(frameButtons, text='Ok',
[53] Fix | Delete
width=8, command=self.Ok)
[54] Fix | Delete
self.buttonOk.pack(side=LEFT, padx=5)
[55] Fix | Delete
self.buttonCancel = Button(frameButtons, text='Cancel',
[56] Fix | Delete
width=8, command=self.Cancel)
[57] Fix | Delete
self.buttonCancel.pack(side=RIGHT, padx=5)
[58] Fix | Delete
[59] Fix | Delete
def name_ok(self):
[60] Fix | Delete
''' After stripping entered name, check that it is a sensible
[61] Fix | Delete
ConfigParser file section name. Return it if it is, '' if not.
[62] Fix | Delete
'''
[63] Fix | Delete
name = self.name.get().strip()
[64] Fix | Delete
if not name: #no name specified
[65] Fix | Delete
tkMessageBox.showerror(title='Name Error',
[66] Fix | Delete
message='No name specified.', parent=self)
[67] Fix | Delete
elif len(name)>30: #name too long
[68] Fix | Delete
tkMessageBox.showerror(title='Name Error',
[69] Fix | Delete
message='Name too long. It should be no more than '+
[70] Fix | Delete
'30 characters.', parent=self)
[71] Fix | Delete
name = ''
[72] Fix | Delete
elif name in self.used_names:
[73] Fix | Delete
tkMessageBox.showerror(title='Name Error',
[74] Fix | Delete
message='This name is already in use.', parent=self)
[75] Fix | Delete
name = ''
[76] Fix | Delete
return name
[77] Fix | Delete
def Ok(self, event=None):
[78] Fix | Delete
name = self.name_ok()
[79] Fix | Delete
if name:
[80] Fix | Delete
self.result = name
[81] Fix | Delete
self.grab_release()
[82] Fix | Delete
self.destroy()
[83] Fix | Delete
def Cancel(self, event=None):
[84] Fix | Delete
self.result = ''
[85] Fix | Delete
self.grab_release()
[86] Fix | Delete
self.destroy()
[87] Fix | Delete
[88] Fix | Delete
if __name__ == '__main__':
[89] Fix | Delete
import unittest
[90] Fix | Delete
unittest.main('idlelib.idle_test.test_config_name', verbosity=2, exit=False)
[91] Fix | Delete
[92] Fix | Delete
from idlelib.idle_test.htest import run
[93] Fix | Delete
run(GetCfgSectionNameDialog)
[94] Fix | Delete
[95] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function