Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2..../idlelib
File: configHelpSourceEdit.py
"Dialog to specify or edit the parameters for a user configured help source."
[0] Fix | Delete
[1] Fix | Delete
import os
[2] Fix | Delete
import sys
[3] Fix | Delete
[4] Fix | Delete
from Tkinter import *
[5] Fix | Delete
import tkMessageBox
[6] Fix | Delete
import tkFileDialog
[7] Fix | Delete
[8] Fix | Delete
class GetHelpSourceDialog(Toplevel):
[9] Fix | Delete
def __init__(self, parent, title, menuItem='', filePath='', _htest=False):
[10] Fix | Delete
"""Get menu entry and url/ local file location for Additional Help
[11] Fix | Delete
[12] Fix | Delete
User selects a name for the Help resource and provides a web url
[13] Fix | Delete
or a local file as its source. The user can enter a url or browse
[14] Fix | Delete
for the file.
[15] Fix | Delete
[16] Fix | Delete
_htest - bool, change box location when running htest
[17] Fix | Delete
"""
[18] Fix | Delete
Toplevel.__init__(self, parent)
[19] Fix | Delete
self.configure(borderwidth=5)
[20] Fix | Delete
self.resizable(height=FALSE, width=FALSE)
[21] Fix | Delete
self.title(title)
[22] Fix | Delete
self.transient(parent)
[23] Fix | Delete
self.grab_set()
[24] Fix | Delete
self.protocol("WM_DELETE_WINDOW", self.Cancel)
[25] Fix | Delete
self.parent = parent
[26] Fix | Delete
self.result = None
[27] Fix | Delete
self.CreateWidgets()
[28] Fix | Delete
self.menu.set(menuItem)
[29] Fix | Delete
self.path.set(filePath)
[30] Fix | Delete
self.withdraw() #hide while setting geometry
[31] Fix | Delete
#needs to be done here so that the winfo_reqwidth is valid
[32] Fix | Delete
self.update_idletasks()
[33] Fix | Delete
#centre dialog over parent. below parent if running htest.
[34] Fix | Delete
self.geometry(
[35] Fix | Delete
"+%d+%d" % (
[36] Fix | Delete
parent.winfo_rootx() +
[37] Fix | Delete
(parent.winfo_width()/2 - self.winfo_reqwidth()/2),
[38] Fix | Delete
parent.winfo_rooty() +
[39] Fix | Delete
((parent.winfo_height()/2 - self.winfo_reqheight()/2)
[40] Fix | Delete
if not _htest else 150)))
[41] Fix | Delete
self.deiconify() #geometry set, unhide
[42] Fix | Delete
self.bind('<Return>', self.Ok)
[43] Fix | Delete
self.wait_window()
[44] Fix | Delete
[45] Fix | Delete
def CreateWidgets(self):
[46] Fix | Delete
self.menu = StringVar(self)
[47] Fix | Delete
self.path = StringVar(self)
[48] Fix | Delete
self.fontSize = StringVar(self)
[49] Fix | Delete
self.frameMain = Frame(self, borderwidth=2, relief=GROOVE)
[50] Fix | Delete
self.frameMain.pack(side=TOP, expand=TRUE, fill=BOTH)
[51] Fix | Delete
labelMenu = Label(self.frameMain, anchor=W, justify=LEFT,
[52] Fix | Delete
text='Menu Item:')
[53] Fix | Delete
self.entryMenu = Entry(self.frameMain, textvariable=self.menu,
[54] Fix | Delete
width=30)
[55] Fix | Delete
self.entryMenu.focus_set()
[56] Fix | Delete
labelPath = Label(self.frameMain, anchor=W, justify=LEFT,
[57] Fix | Delete
text='Help File Path: Enter URL or browse for file')
[58] Fix | Delete
self.entryPath = Entry(self.frameMain, textvariable=self.path,
[59] Fix | Delete
width=40)
[60] Fix | Delete
self.entryMenu.focus_set()
[61] Fix | Delete
labelMenu.pack(anchor=W, padx=5, pady=3)
[62] Fix | Delete
self.entryMenu.pack(anchor=W, padx=5, pady=3)
[63] Fix | Delete
labelPath.pack(anchor=W, padx=5, pady=3)
[64] Fix | Delete
self.entryPath.pack(anchor=W, padx=5, pady=3)
[65] Fix | Delete
browseButton = Button(self.frameMain, text='Browse', width=8,
[66] Fix | Delete
command=self.browseFile)
[67] Fix | Delete
browseButton.pack(pady=3)
[68] Fix | Delete
frameButtons = Frame(self)
[69] Fix | Delete
frameButtons.pack(side=BOTTOM, fill=X)
[70] Fix | Delete
self.buttonOk = Button(frameButtons, text='OK',
[71] Fix | Delete
width=8, default=ACTIVE, command=self.Ok)
[72] Fix | Delete
self.buttonOk.grid(row=0, column=0, padx=5,pady=5)
[73] Fix | Delete
self.buttonCancel = Button(frameButtons, text='Cancel',
[74] Fix | Delete
width=8, command=self.Cancel)
[75] Fix | Delete
self.buttonCancel.grid(row=0, column=1, padx=5, pady=5)
[76] Fix | Delete
[77] Fix | Delete
def browseFile(self):
[78] Fix | Delete
filetypes = [
[79] Fix | Delete
("HTML Files", "*.htm *.html", "TEXT"),
[80] Fix | Delete
("PDF Files", "*.pdf", "TEXT"),
[81] Fix | Delete
("Windows Help Files", "*.chm"),
[82] Fix | Delete
("Text Files", "*.txt", "TEXT"),
[83] Fix | Delete
("All Files", "*")]
[84] Fix | Delete
path = self.path.get()
[85] Fix | Delete
if path:
[86] Fix | Delete
dir, base = os.path.split(path)
[87] Fix | Delete
else:
[88] Fix | Delete
base = None
[89] Fix | Delete
if sys.platform[:3] == 'win':
[90] Fix | Delete
dir = os.path.join(os.path.dirname(sys.executable), 'Doc')
[91] Fix | Delete
if not os.path.isdir(dir):
[92] Fix | Delete
dir = os.getcwd()
[93] Fix | Delete
else:
[94] Fix | Delete
dir = os.getcwd()
[95] Fix | Delete
opendialog = tkFileDialog.Open(parent=self, filetypes=filetypes)
[96] Fix | Delete
file = opendialog.show(initialdir=dir, initialfile=base)
[97] Fix | Delete
if file:
[98] Fix | Delete
self.path.set(file)
[99] Fix | Delete
[100] Fix | Delete
def MenuOk(self):
[101] Fix | Delete
"Simple validity check for a sensible menu item name"
[102] Fix | Delete
menuOk = True
[103] Fix | Delete
menu = self.menu.get()
[104] Fix | Delete
menu.strip()
[105] Fix | Delete
if not menu:
[106] Fix | Delete
tkMessageBox.showerror(title='Menu Item Error',
[107] Fix | Delete
message='No menu item specified',
[108] Fix | Delete
parent=self)
[109] Fix | Delete
self.entryMenu.focus_set()
[110] Fix | Delete
menuOk = False
[111] Fix | Delete
elif len(menu) > 30:
[112] Fix | Delete
tkMessageBox.showerror(title='Menu Item Error',
[113] Fix | Delete
message='Menu item too long:'
[114] Fix | Delete
'\nLimit 30 characters.',
[115] Fix | Delete
parent=self)
[116] Fix | Delete
self.entryMenu.focus_set()
[117] Fix | Delete
menuOk = False
[118] Fix | Delete
return menuOk
[119] Fix | Delete
[120] Fix | Delete
def PathOk(self):
[121] Fix | Delete
"Simple validity check for menu file path"
[122] Fix | Delete
pathOk = True
[123] Fix | Delete
path = self.path.get()
[124] Fix | Delete
path.strip()
[125] Fix | Delete
if not path: #no path specified
[126] Fix | Delete
tkMessageBox.showerror(title='File Path Error',
[127] Fix | Delete
message='No help file path specified.',
[128] Fix | Delete
parent=self)
[129] Fix | Delete
self.entryPath.focus_set()
[130] Fix | Delete
pathOk = False
[131] Fix | Delete
elif path.startswith(('www.', 'http')):
[132] Fix | Delete
pass
[133] Fix | Delete
else:
[134] Fix | Delete
if path[:5] == 'file:':
[135] Fix | Delete
path = path[5:]
[136] Fix | Delete
if not os.path.exists(path):
[137] Fix | Delete
tkMessageBox.showerror(title='File Path Error',
[138] Fix | Delete
message='Help file path does not exist.',
[139] Fix | Delete
parent=self)
[140] Fix | Delete
self.entryPath.focus_set()
[141] Fix | Delete
pathOk = False
[142] Fix | Delete
return pathOk
[143] Fix | Delete
[144] Fix | Delete
def Ok(self, event=None):
[145] Fix | Delete
if self.MenuOk() and self.PathOk():
[146] Fix | Delete
self.result = (self.menu.get().strip(),
[147] Fix | Delete
self.path.get().strip())
[148] Fix | Delete
if sys.platform == 'darwin':
[149] Fix | Delete
path = self.result[1]
[150] Fix | Delete
if path.startswith(('www', 'file:', 'http:')):
[151] Fix | Delete
pass
[152] Fix | Delete
else:
[153] Fix | Delete
# Mac Safari insists on using the URI form for local files
[154] Fix | Delete
self.result = list(self.result)
[155] Fix | Delete
self.result[1] = "file://" + path
[156] Fix | Delete
self.grab_release()
[157] Fix | Delete
self.destroy()
[158] Fix | Delete
[159] Fix | Delete
def Cancel(self, event=None):
[160] Fix | Delete
self.result = None
[161] Fix | Delete
self.grab_release()
[162] Fix | Delete
self.destroy()
[163] Fix | Delete
[164] Fix | Delete
if __name__ == '__main__':
[165] Fix | Delete
from idlelib.idle_test.htest import run
[166] Fix | Delete
run(GetHelpSourceDialog)
[167] Fix | Delete
[168] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function