Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2..../idlelib
File: EditorWindow.py
import sys
[0] Fix | Delete
import os
[1] Fix | Delete
import platform
[2] Fix | Delete
import re
[3] Fix | Delete
import imp
[4] Fix | Delete
from Tkinter import *
[5] Fix | Delete
import tkSimpleDialog
[6] Fix | Delete
import tkMessageBox
[7] Fix | Delete
import webbrowser
[8] Fix | Delete
[9] Fix | Delete
from idlelib.MultiCall import MultiCallCreator
[10] Fix | Delete
from idlelib import WindowList
[11] Fix | Delete
from idlelib import SearchDialog
[12] Fix | Delete
from idlelib import GrepDialog
[13] Fix | Delete
from idlelib import ReplaceDialog
[14] Fix | Delete
from idlelib import PyParse
[15] Fix | Delete
from idlelib.configHandler import idleConf
[16] Fix | Delete
from idlelib import aboutDialog, textView, configDialog
[17] Fix | Delete
from idlelib import macosxSupport
[18] Fix | Delete
from idlelib import help
[19] Fix | Delete
[20] Fix | Delete
# The default tab setting for a Text widget, in average-width characters.
[21] Fix | Delete
TK_TABWIDTH_DEFAULT = 8
[22] Fix | Delete
[23] Fix | Delete
_py_version = ' (%s)' % platform.python_version()
[24] Fix | Delete
[25] Fix | Delete
def _sphinx_version():
[26] Fix | Delete
"Format sys.version_info to produce the Sphinx version string used to install the chm docs"
[27] Fix | Delete
major, minor, micro, level, serial = sys.version_info
[28] Fix | Delete
release = '%s%s' % (major, minor)
[29] Fix | Delete
if micro:
[30] Fix | Delete
release += '%s' % (micro,)
[31] Fix | Delete
if level == 'candidate':
[32] Fix | Delete
release += 'rc%s' % (serial,)
[33] Fix | Delete
elif level != 'final':
[34] Fix | Delete
release += '%s%s' % (level[0], serial)
[35] Fix | Delete
return release
[36] Fix | Delete
[37] Fix | Delete
def _find_module(fullname, path=None):
[38] Fix | Delete
"""Version of imp.find_module() that handles hierarchical module names"""
[39] Fix | Delete
[40] Fix | Delete
file = None
[41] Fix | Delete
for tgt in fullname.split('.'):
[42] Fix | Delete
if file is not None:
[43] Fix | Delete
file.close() # close intermediate files
[44] Fix | Delete
(file, filename, descr) = imp.find_module(tgt, path)
[45] Fix | Delete
if descr[2] == imp.PY_SOURCE:
[46] Fix | Delete
break # find but not load the source file
[47] Fix | Delete
module = imp.load_module(tgt, file, filename, descr)
[48] Fix | Delete
try:
[49] Fix | Delete
path = module.__path__
[50] Fix | Delete
except AttributeError:
[51] Fix | Delete
raise ImportError, 'No source for module ' + module.__name__
[52] Fix | Delete
if descr[2] != imp.PY_SOURCE:
[53] Fix | Delete
# If all of the above fails and didn't raise an exception,fallback
[54] Fix | Delete
# to a straight import which can find __init__.py in a package.
[55] Fix | Delete
m = __import__(fullname)
[56] Fix | Delete
try:
[57] Fix | Delete
filename = m.__file__
[58] Fix | Delete
except AttributeError:
[59] Fix | Delete
pass
[60] Fix | Delete
else:
[61] Fix | Delete
file = None
[62] Fix | Delete
base, ext = os.path.splitext(filename)
[63] Fix | Delete
if ext == '.pyc':
[64] Fix | Delete
ext = '.py'
[65] Fix | Delete
filename = base + ext
[66] Fix | Delete
descr = filename, None, imp.PY_SOURCE
[67] Fix | Delete
return file, filename, descr
[68] Fix | Delete
[69] Fix | Delete
[70] Fix | Delete
class HelpDialog(object):
[71] Fix | Delete
[72] Fix | Delete
def __init__(self):
[73] Fix | Delete
self.parent = None # parent of help window
[74] Fix | Delete
self.dlg = None # the help window iteself
[75] Fix | Delete
[76] Fix | Delete
def display(self, parent, near=None):
[77] Fix | Delete
""" Display the help dialog.
[78] Fix | Delete
[79] Fix | Delete
parent - parent widget for the help window
[80] Fix | Delete
[81] Fix | Delete
near - a Toplevel widget (e.g. EditorWindow or PyShell)
[82] Fix | Delete
to use as a reference for placing the help window
[83] Fix | Delete
"""
[84] Fix | Delete
import warnings as w
[85] Fix | Delete
w.warn("EditorWindow.HelpDialog is no longer used by Idle.\n"
[86] Fix | Delete
"It will be removed in 3.6 or later.\n"
[87] Fix | Delete
"It has been replaced by private help.HelpWindow\n",
[88] Fix | Delete
DeprecationWarning, stacklevel=2)
[89] Fix | Delete
if self.dlg is None:
[90] Fix | Delete
self.show_dialog(parent)
[91] Fix | Delete
if near:
[92] Fix | Delete
self.nearwindow(near)
[93] Fix | Delete
[94] Fix | Delete
def show_dialog(self, parent):
[95] Fix | Delete
self.parent = parent
[96] Fix | Delete
fn=os.path.join(os.path.abspath(os.path.dirname(__file__)),'help.txt')
[97] Fix | Delete
self.dlg = dlg = textView.view_file(parent,'Help',fn, modal=False)
[98] Fix | Delete
dlg.bind('<Destroy>', self.destroy, '+')
[99] Fix | Delete
[100] Fix | Delete
def nearwindow(self, near):
[101] Fix | Delete
# Place the help dialog near the window specified by parent.
[102] Fix | Delete
# Note - this may not reposition the window in Metacity
[103] Fix | Delete
# if "/apps/metacity/general/disable_workarounds" is enabled
[104] Fix | Delete
dlg = self.dlg
[105] Fix | Delete
geom = (near.winfo_rootx() + 10, near.winfo_rooty() + 10)
[106] Fix | Delete
dlg.withdraw()
[107] Fix | Delete
dlg.geometry("=+%d+%d" % geom)
[108] Fix | Delete
dlg.deiconify()
[109] Fix | Delete
dlg.lift()
[110] Fix | Delete
[111] Fix | Delete
def destroy(self, ev=None):
[112] Fix | Delete
self.dlg = None
[113] Fix | Delete
self.parent = None
[114] Fix | Delete
[115] Fix | Delete
helpDialog = HelpDialog() # singleton instance, no longer used
[116] Fix | Delete
[117] Fix | Delete
[118] Fix | Delete
class EditorWindow(object):
[119] Fix | Delete
from idlelib.Percolator import Percolator
[120] Fix | Delete
from idlelib.ColorDelegator import ColorDelegator
[121] Fix | Delete
from idlelib.UndoDelegator import UndoDelegator
[122] Fix | Delete
from idlelib.IOBinding import IOBinding, filesystemencoding, encoding
[123] Fix | Delete
from idlelib import Bindings
[124] Fix | Delete
from Tkinter import Toplevel
[125] Fix | Delete
from idlelib.MultiStatusBar import MultiStatusBar
[126] Fix | Delete
[127] Fix | Delete
help_url = None
[128] Fix | Delete
[129] Fix | Delete
def __init__(self, flist=None, filename=None, key=None, root=None):
[130] Fix | Delete
if EditorWindow.help_url is None:
[131] Fix | Delete
dochome = os.path.join(sys.prefix, 'Doc', 'index.html')
[132] Fix | Delete
if sys.platform.count('linux'):
[133] Fix | Delete
# look for html docs in a couple of standard places
[134] Fix | Delete
pyver = 'python-docs-' + '%s.%s.%s' % sys.version_info[:3]
[135] Fix | Delete
if os.path.isdir('/var/www/html/python/'): # "python2" rpm
[136] Fix | Delete
dochome = '/var/www/html/python/index.html'
[137] Fix | Delete
else:
[138] Fix | Delete
basepath = '/usr/share/doc/' # standard location
[139] Fix | Delete
dochome = os.path.join(basepath, pyver,
[140] Fix | Delete
'Doc', 'index.html')
[141] Fix | Delete
elif sys.platform[:3] == 'win':
[142] Fix | Delete
chmfile = os.path.join(sys.prefix, 'Doc',
[143] Fix | Delete
'Python%s.chm' % _sphinx_version())
[144] Fix | Delete
if os.path.isfile(chmfile):
[145] Fix | Delete
dochome = chmfile
[146] Fix | Delete
elif sys.platform == 'darwin':
[147] Fix | Delete
# documentation may be stored inside a python framework
[148] Fix | Delete
dochome = os.path.join(sys.prefix,
[149] Fix | Delete
'Resources/English.lproj/Documentation/index.html')
[150] Fix | Delete
dochome = os.path.normpath(dochome)
[151] Fix | Delete
if os.path.isfile(dochome):
[152] Fix | Delete
EditorWindow.help_url = dochome
[153] Fix | Delete
if sys.platform == 'darwin':
[154] Fix | Delete
# Safari requires real file:-URLs
[155] Fix | Delete
EditorWindow.help_url = 'file://' + EditorWindow.help_url
[156] Fix | Delete
else:
[157] Fix | Delete
EditorWindow.help_url = "https://docs.python.org/%d.%d/" % sys.version_info[:2]
[158] Fix | Delete
self.flist = flist
[159] Fix | Delete
root = root or flist.root
[160] Fix | Delete
self.root = root
[161] Fix | Delete
try:
[162] Fix | Delete
sys.ps1
[163] Fix | Delete
except AttributeError:
[164] Fix | Delete
sys.ps1 = '>>> '
[165] Fix | Delete
self.menubar = Menu(root)
[166] Fix | Delete
self.top = top = WindowList.ListedToplevel(root, menu=self.menubar)
[167] Fix | Delete
if flist:
[168] Fix | Delete
self.tkinter_vars = flist.vars
[169] Fix | Delete
#self.top.instance_dict makes flist.inversedict available to
[170] Fix | Delete
#configDialog.py so it can access all EditorWindow instances
[171] Fix | Delete
self.top.instance_dict = flist.inversedict
[172] Fix | Delete
else:
[173] Fix | Delete
self.tkinter_vars = {} # keys: Tkinter event names
[174] Fix | Delete
# values: Tkinter variable instances
[175] Fix | Delete
self.top.instance_dict = {}
[176] Fix | Delete
self.recent_files_path = os.path.join(idleConf.GetUserCfgDir(),
[177] Fix | Delete
'recent-files.lst')
[178] Fix | Delete
self.text_frame = text_frame = Frame(top)
[179] Fix | Delete
self.vbar = vbar = Scrollbar(text_frame, name='vbar')
[180] Fix | Delete
self.width = idleConf.GetOption('main','EditorWindow','width', type='int')
[181] Fix | Delete
text_options = {
[182] Fix | Delete
'name': 'text',
[183] Fix | Delete
'padx': 5,
[184] Fix | Delete
'wrap': 'none',
[185] Fix | Delete
'highlightthickness': 0,
[186] Fix | Delete
'width': self.width,
[187] Fix | Delete
'height': idleConf.GetOption('main', 'EditorWindow', 'height', type='int')}
[188] Fix | Delete
if TkVersion >= 8.5:
[189] Fix | Delete
# Starting with tk 8.5 we have to set the new tabstyle option
[190] Fix | Delete
# to 'wordprocessor' to achieve the same display of tabs as in
[191] Fix | Delete
# older tk versions.
[192] Fix | Delete
text_options['tabstyle'] = 'wordprocessor'
[193] Fix | Delete
self.text = text = MultiCallCreator(Text)(text_frame, **text_options)
[194] Fix | Delete
self.top.focused_widget = self.text
[195] Fix | Delete
[196] Fix | Delete
self.createmenubar()
[197] Fix | Delete
self.apply_bindings()
[198] Fix | Delete
[199] Fix | Delete
self.top.protocol("WM_DELETE_WINDOW", self.close)
[200] Fix | Delete
self.top.bind("<<close-window>>", self.close_event)
[201] Fix | Delete
if macosxSupport.isAquaTk():
[202] Fix | Delete
# Command-W on editorwindows doesn't work without this.
[203] Fix | Delete
text.bind('<<close-window>>', self.close_event)
[204] Fix | Delete
# Some OS X systems have only one mouse button, so use
[205] Fix | Delete
# control-click for popup context menus there. For two
[206] Fix | Delete
# buttons, AquaTk defines <2> as the right button, not <3>.
[207] Fix | Delete
text.bind("<Control-Button-1>",self.right_menu_event)
[208] Fix | Delete
text.bind("<2>", self.right_menu_event)
[209] Fix | Delete
else:
[210] Fix | Delete
# Elsewhere, use right-click for popup menus.
[211] Fix | Delete
text.bind("<3>",self.right_menu_event)
[212] Fix | Delete
text.bind("<<cut>>", self.cut)
[213] Fix | Delete
text.bind("<<copy>>", self.copy)
[214] Fix | Delete
text.bind("<<paste>>", self.paste)
[215] Fix | Delete
text.bind("<<center-insert>>", self.center_insert_event)
[216] Fix | Delete
text.bind("<<help>>", self.help_dialog)
[217] Fix | Delete
text.bind("<<python-docs>>", self.python_docs)
[218] Fix | Delete
text.bind("<<about-idle>>", self.about_dialog)
[219] Fix | Delete
text.bind("<<open-config-dialog>>", self.config_dialog)
[220] Fix | Delete
text.bind("<<open-module>>", self.open_module)
[221] Fix | Delete
text.bind("<<do-nothing>>", lambda event: "break")
[222] Fix | Delete
text.bind("<<select-all>>", self.select_all)
[223] Fix | Delete
text.bind("<<remove-selection>>", self.remove_selection)
[224] Fix | Delete
text.bind("<<find>>", self.find_event)
[225] Fix | Delete
text.bind("<<find-again>>", self.find_again_event)
[226] Fix | Delete
text.bind("<<find-in-files>>", self.find_in_files_event)
[227] Fix | Delete
text.bind("<<find-selection>>", self.find_selection_event)
[228] Fix | Delete
text.bind("<<replace>>", self.replace_event)
[229] Fix | Delete
text.bind("<<goto-line>>", self.goto_line_event)
[230] Fix | Delete
text.bind("<<smart-backspace>>",self.smart_backspace_event)
[231] Fix | Delete
text.bind("<<newline-and-indent>>",self.newline_and_indent_event)
[232] Fix | Delete
text.bind("<<smart-indent>>",self.smart_indent_event)
[233] Fix | Delete
text.bind("<<indent-region>>",self.indent_region_event)
[234] Fix | Delete
text.bind("<<dedent-region>>",self.dedent_region_event)
[235] Fix | Delete
text.bind("<<comment-region>>",self.comment_region_event)
[236] Fix | Delete
text.bind("<<uncomment-region>>",self.uncomment_region_event)
[237] Fix | Delete
text.bind("<<tabify-region>>",self.tabify_region_event)
[238] Fix | Delete
text.bind("<<untabify-region>>",self.untabify_region_event)
[239] Fix | Delete
text.bind("<<toggle-tabs>>",self.toggle_tabs_event)
[240] Fix | Delete
text.bind("<<change-indentwidth>>",self.change_indentwidth_event)
[241] Fix | Delete
text.bind("<Left>", self.move_at_edge_if_selection(0))
[242] Fix | Delete
text.bind("<Right>", self.move_at_edge_if_selection(1))
[243] Fix | Delete
text.bind("<<del-word-left>>", self.del_word_left)
[244] Fix | Delete
text.bind("<<del-word-right>>", self.del_word_right)
[245] Fix | Delete
text.bind("<<beginning-of-line>>", self.home_callback)
[246] Fix | Delete
[247] Fix | Delete
if flist:
[248] Fix | Delete
flist.inversedict[self] = key
[249] Fix | Delete
if key:
[250] Fix | Delete
flist.dict[key] = self
[251] Fix | Delete
text.bind("<<open-new-window>>", self.new_callback)
[252] Fix | Delete
text.bind("<<close-all-windows>>", self.flist.close_all_callback)
[253] Fix | Delete
text.bind("<<open-class-browser>>", self.open_class_browser)
[254] Fix | Delete
text.bind("<<open-path-browser>>", self.open_path_browser)
[255] Fix | Delete
[256] Fix | Delete
self.set_status_bar()
[257] Fix | Delete
vbar['command'] = text.yview
[258] Fix | Delete
vbar.pack(side=RIGHT, fill=Y)
[259] Fix | Delete
text['yscrollcommand'] = vbar.set
[260] Fix | Delete
text['font'] = idleConf.GetFont(self.root, 'main', 'EditorWindow')
[261] Fix | Delete
text_frame.pack(side=LEFT, fill=BOTH, expand=1)
[262] Fix | Delete
text.pack(side=TOP, fill=BOTH, expand=1)
[263] Fix | Delete
text.focus_set()
[264] Fix | Delete
[265] Fix | Delete
# usetabs true -> literal tab characters are used by indent and
[266] Fix | Delete
# dedent cmds, possibly mixed with spaces if
[267] Fix | Delete
# indentwidth is not a multiple of tabwidth,
[268] Fix | Delete
# which will cause Tabnanny to nag!
[269] Fix | Delete
# false -> tab characters are converted to spaces by indent
[270] Fix | Delete
# and dedent cmds, and ditto TAB keystrokes
[271] Fix | Delete
# Although use-spaces=0 can be configured manually in config-main.def,
[272] Fix | Delete
# configuration of tabs v. spaces is not supported in the configuration
[273] Fix | Delete
# dialog. IDLE promotes the preferred Python indentation: use spaces!
[274] Fix | Delete
usespaces = idleConf.GetOption('main', 'Indent', 'use-spaces', type='bool')
[275] Fix | Delete
self.usetabs = not usespaces
[276] Fix | Delete
[277] Fix | Delete
# tabwidth is the display width of a literal tab character.
[278] Fix | Delete
# CAUTION: telling Tk to use anything other than its default
[279] Fix | Delete
# tab setting causes it to use an entirely different tabbing algorithm,
[280] Fix | Delete
# treating tab stops as fixed distances from the left margin.
[281] Fix | Delete
# Nobody expects this, so for now tabwidth should never be changed.
[282] Fix | Delete
self.tabwidth = 8 # must remain 8 until Tk is fixed.
[283] Fix | Delete
[284] Fix | Delete
# indentwidth is the number of screen characters per indent level.
[285] Fix | Delete
# The recommended Python indentation is four spaces.
[286] Fix | Delete
self.indentwidth = self.tabwidth
[287] Fix | Delete
self.set_notabs_indentwidth()
[288] Fix | Delete
[289] Fix | Delete
# If context_use_ps1 is true, parsing searches back for a ps1 line;
[290] Fix | Delete
# else searches for a popular (if, def, ...) Python stmt.
[291] Fix | Delete
self.context_use_ps1 = False
[292] Fix | Delete
[293] Fix | Delete
# When searching backwards for a reliable place to begin parsing,
[294] Fix | Delete
# first start num_context_lines[0] lines back, then
[295] Fix | Delete
# num_context_lines[1] lines back if that didn't work, and so on.
[296] Fix | Delete
# The last value should be huge (larger than the # of lines in a
[297] Fix | Delete
# conceivable file).
[298] Fix | Delete
# Making the initial values larger slows things down more often.
[299] Fix | Delete
self.num_context_lines = 50, 500, 5000000
[300] Fix | Delete
[301] Fix | Delete
self.per = per = self.Percolator(text)
[302] Fix | Delete
[303] Fix | Delete
self.undo = undo = self.UndoDelegator()
[304] Fix | Delete
per.insertfilter(undo)
[305] Fix | Delete
text.undo_block_start = undo.undo_block_start
[306] Fix | Delete
text.undo_block_stop = undo.undo_block_stop
[307] Fix | Delete
undo.set_saved_change_hook(self.saved_change_hook)
[308] Fix | Delete
[309] Fix | Delete
# IOBinding implements file I/O and printing functionality
[310] Fix | Delete
self.io = io = self.IOBinding(self)
[311] Fix | Delete
io.set_filename_change_hook(self.filename_change_hook)
[312] Fix | Delete
[313] Fix | Delete
# Create the recent files submenu
[314] Fix | Delete
self.recent_files_menu = Menu(self.menubar, tearoff=0)
[315] Fix | Delete
self.menudict['file'].insert_cascade(3, label='Recent Files',
[316] Fix | Delete
underline=0,
[317] Fix | Delete
menu=self.recent_files_menu)
[318] Fix | Delete
self.update_recent_files_list()
[319] Fix | Delete
[320] Fix | Delete
self.color = None # initialized below in self.ResetColorizer
[321] Fix | Delete
if filename:
[322] Fix | Delete
if os.path.exists(filename) and not os.path.isdir(filename):
[323] Fix | Delete
io.loadfile(filename)
[324] Fix | Delete
else:
[325] Fix | Delete
io.set_filename(filename)
[326] Fix | Delete
self.ResetColorizer()
[327] Fix | Delete
self.saved_change_hook()
[328] Fix | Delete
[329] Fix | Delete
self.set_indentation_params(self.ispythonsource(filename))
[330] Fix | Delete
[331] Fix | Delete
self.load_extensions()
[332] Fix | Delete
[333] Fix | Delete
menu = self.menudict.get('windows')
[334] Fix | Delete
if menu:
[335] Fix | Delete
end = menu.index("end")
[336] Fix | Delete
if end is None:
[337] Fix | Delete
end = -1
[338] Fix | Delete
if end >= 0:
[339] Fix | Delete
menu.add_separator()
[340] Fix | Delete
end = end + 1
[341] Fix | Delete
self.wmenu_end = end
[342] Fix | Delete
WindowList.register_callback(self.postwindowsmenu)
[343] Fix | Delete
[344] Fix | Delete
# Some abstractions so IDLE extensions are cross-IDE
[345] Fix | Delete
self.askyesno = tkMessageBox.askyesno
[346] Fix | Delete
self.askinteger = tkSimpleDialog.askinteger
[347] Fix | Delete
self.showerror = tkMessageBox.showerror
[348] Fix | Delete
[349] Fix | Delete
def _filename_to_unicode(self, filename):
[350] Fix | Delete
"""convert filename to unicode in order to display it in Tk"""
[351] Fix | Delete
if isinstance(filename, unicode) or not filename:
[352] Fix | Delete
return filename
[353] Fix | Delete
else:
[354] Fix | Delete
try:
[355] Fix | Delete
return filename.decode(self.filesystemencoding)
[356] Fix | Delete
except UnicodeDecodeError:
[357] Fix | Delete
# XXX
[358] Fix | Delete
try:
[359] Fix | Delete
return filename.decode(self.encoding)
[360] Fix | Delete
except UnicodeDecodeError:
[361] Fix | Delete
# byte-to-byte conversion
[362] Fix | Delete
return filename.decode('iso8859-1')
[363] Fix | Delete
[364] Fix | Delete
def new_callback(self, event):
[365] Fix | Delete
dirname, basename = self.io.defaultfilename()
[366] Fix | Delete
self.flist.new(dirname)
[367] Fix | Delete
return "break"
[368] Fix | Delete
[369] Fix | Delete
def home_callback(self, event):
[370] Fix | Delete
if (event.state & 4) != 0 and event.keysym == "Home":
[371] Fix | Delete
# state&4==Control. If <Control-Home>, use the Tk binding.
[372] Fix | Delete
return
[373] Fix | Delete
if self.text.index("iomark") and \
[374] Fix | Delete
self.text.compare("iomark", "<=", "insert lineend") and \
[375] Fix | Delete
self.text.compare("insert linestart", "<=", "iomark"):
[376] Fix | Delete
# In Shell on input line, go to just after prompt
[377] Fix | Delete
insertpt = int(self.text.index("iomark").split(".")[1])
[378] Fix | Delete
else:
[379] Fix | Delete
line = self.text.get("insert linestart", "insert lineend")
[380] Fix | Delete
for insertpt in xrange(len(line)):
[381] Fix | Delete
if line[insertpt] not in (' ','\t'):
[382] Fix | Delete
break
[383] Fix | Delete
else:
[384] Fix | Delete
insertpt=len(line)
[385] Fix | Delete
lineat = int(self.text.index("insert").split('.')[1])
[386] Fix | Delete
if insertpt == lineat:
[387] Fix | Delete
insertpt = 0
[388] Fix | Delete
dest = "insert linestart+"+str(insertpt)+"c"
[389] Fix | Delete
if (event.state&1) == 0:
[390] Fix | Delete
# shift was not pressed
[391] Fix | Delete
self.text.tag_remove("sel", "1.0", "end")
[392] Fix | Delete
else:
[393] Fix | Delete
if not self.text.index("sel.first"):
[394] Fix | Delete
self.text.mark_set("my_anchor", "insert") # there was no previous selection
[395] Fix | Delete
else:
[396] Fix | Delete
if self.text.compare(self.text.index("sel.first"), "<", self.text.index("insert")):
[397] Fix | Delete
self.text.mark_set("my_anchor", "sel.first") # extend back
[398] Fix | Delete
else:
[399] Fix | Delete
self.text.mark_set("my_anchor", "sel.last") # extend forward
[400] Fix | Delete
first = self.text.index(dest)
[401] Fix | Delete
last = self.text.index("my_anchor")
[402] Fix | Delete
if self.text.compare(first,">",last):
[403] Fix | Delete
first,last = last,first
[404] Fix | Delete
self.text.tag_remove("sel", "1.0", "end")
[405] Fix | Delete
self.text.tag_add("sel", first, last)
[406] Fix | Delete
self.text.mark_set("insert", dest)
[407] Fix | Delete
self.text.see("insert")
[408] Fix | Delete
return "break"
[409] Fix | Delete
[410] Fix | Delete
def set_status_bar(self):
[411] Fix | Delete
self.status_bar = self.MultiStatusBar(self.top)
[412] Fix | Delete
sep = Frame(self.top, height=1, borderwidth=1, background='grey75')
[413] Fix | Delete
if sys.platform == "darwin":
[414] Fix | Delete
# Insert some padding to avoid obscuring some of the statusbar
[415] Fix | Delete
# by the resize widget.
[416] Fix | Delete
self.status_bar.set_label('_padding1', ' ', side=RIGHT)
[417] Fix | Delete
self.status_bar.set_label('column', 'Col: ?', side=RIGHT)
[418] Fix | Delete
self.status_bar.set_label('line', 'Ln: ?', side=RIGHT)
[419] Fix | Delete
self.status_bar.pack(side=BOTTOM, fill=X)
[420] Fix | Delete
sep.pack(side=BOTTOM, fill=X)
[421] Fix | Delete
self.text.bind("<<set-line-and-column>>", self.set_line_and_column)
[422] Fix | Delete
self.text.event_add("<<set-line-and-column>>",
[423] Fix | Delete
"<KeyRelease>", "<ButtonRelease>")
[424] Fix | Delete
self.text.after_idle(self.set_line_and_column)
[425] Fix | Delete
[426] Fix | Delete
def set_line_and_column(self, event=None):
[427] Fix | Delete
line, column = self.text.index(INSERT).split('.')
[428] Fix | Delete
self.status_bar.set_label('column', 'Col: %s' % column)
[429] Fix | Delete
self.status_bar.set_label('line', 'Ln: %s' % line)
[430] Fix | Delete
[431] Fix | Delete
menu_specs = [
[432] Fix | Delete
("file", "_File"),
[433] Fix | Delete
("edit", "_Edit"),
[434] Fix | Delete
("format", "F_ormat"),
[435] Fix | Delete
("run", "_Run"),
[436] Fix | Delete
("options", "_Options"),
[437] Fix | Delete
("windows", "_Window"),
[438] Fix | Delete
("help", "_Help"),
[439] Fix | Delete
]
[440] Fix | Delete
[441] Fix | Delete
[442] Fix | Delete
def createmenubar(self):
[443] Fix | Delete
mbar = self.menubar
[444] Fix | Delete
self.menudict = menudict = {}
[445] Fix | Delete
for name, label in self.menu_specs:
[446] Fix | Delete
underline, label = prepstr(label)
[447] Fix | Delete
menudict[name] = menu = Menu(mbar, name=name, tearoff=0)
[448] Fix | Delete
mbar.add_cascade(label=label, menu=menu, underline=underline)
[449] Fix | Delete
[450] Fix | Delete
if macosxSupport.isCarbonTk():
[451] Fix | Delete
# Insert the application menu
[452] Fix | Delete
menudict['application'] = menu = Menu(mbar, name='apple',
[453] Fix | Delete
tearoff=0)
[454] Fix | Delete
mbar.add_cascade(label='IDLE', menu=menu)
[455] Fix | Delete
[456] Fix | Delete
self.fill_menus()
[457] Fix | Delete
self.base_helpmenu_length = self.menudict['help'].index(END)
[458] Fix | Delete
self.reset_help_menu_entries()
[459] Fix | Delete
[460] Fix | Delete
def postwindowsmenu(self):
[461] Fix | Delete
# Only called when Windows menu exists
[462] Fix | Delete
menu = self.menudict['windows']
[463] Fix | Delete
end = menu.index("end")
[464] Fix | Delete
if end is None:
[465] Fix | Delete
end = -1
[466] Fix | Delete
if end > self.wmenu_end:
[467] Fix | Delete
menu.delete(self.wmenu_end+1, end)
[468] Fix | Delete
WindowList.add_windows_to_menu(menu)
[469] Fix | Delete
[470] Fix | Delete
rmenu = None
[471] Fix | Delete
[472] Fix | Delete
def right_menu_event(self, event):
[473] Fix | Delete
self.text.mark_set("insert", "@%d,%d" % (event.x, event.y))
[474] Fix | Delete
if not self.rmenu:
[475] Fix | Delete
self.make_rmenu()
[476] Fix | Delete
rmenu = self.rmenu
[477] Fix | Delete
self.event = event
[478] Fix | Delete
iswin = sys.platform[:3] == 'win'
[479] Fix | Delete
if iswin:
[480] Fix | Delete
self.text.config(cursor="arrow")
[481] Fix | Delete
[482] Fix | Delete
for item in self.rmenu_specs:
[483] Fix | Delete
try:
[484] Fix | Delete
label, eventname, verify_state = item
[485] Fix | Delete
except ValueError: # see issue1207589
[486] Fix | Delete
continue
[487] Fix | Delete
[488] Fix | Delete
if verify_state is None:
[489] Fix | Delete
continue
[490] Fix | Delete
state = getattr(self, verify_state)()
[491] Fix | Delete
rmenu.entryconfigure(label, state=state)
[492] Fix | Delete
[493] Fix | Delete
rmenu.tk_popup(event.x_root, event.y_root)
[494] Fix | Delete
if iswin:
[495] Fix | Delete
self.text.config(cursor="ibeam")
[496] Fix | Delete
[497] Fix | Delete
rmenu_specs = [
[498] Fix | Delete
# ("Label", "<<virtual-event>>", "statefuncname"), ...
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function