Merged revisions 56443-56466 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk
................
r56454 | kurt.kaiser | 2007-07-18 22:26:14 -0700 (Wed, 18 Jul 2007) | 2 lines
Make relative imports explicit for py3k
................
r56455 | kurt.kaiser | 2007-07-18 23:12:15 -0700 (Wed, 18 Jul 2007) | 2 lines
Was modifying dict during iteration.
................
r56457 | guido.van.rossum | 2007-07-19 07:33:19 -0700 (Thu, 19 Jul 2007) | 2 lines
Fix failing test.
................
r56466 | guido.van.rossum | 2007-07-19 20:58:16 -0700 (Thu, 19 Jul 2007) | 35 lines
Merged revisions 56413-56465 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r56439 | georg.brandl | 2007-07-17 23:37:55 -0700 (Tue, 17 Jul 2007) | 2 lines
Use "Unix" as platform name, not "UNIX".
........
r56441 | guido.van.rossum | 2007-07-18 10:19:14 -0700 (Wed, 18 Jul 2007) | 3 lines
SF patch# 1755885 by Kurt Kaiser: show location of Unicode escape errors.
(Slightly tweaked for style and refcounts.)
........
r56444 | kurt.kaiser | 2007-07-18 12:58:42 -0700 (Wed, 18 Jul 2007) | 2 lines
Fix failing unicode test caused by change to ast.c at r56441
........
r56451 | georg.brandl | 2007-07-18 15:36:53 -0700 (Wed, 18 Jul 2007) | 2 lines
Add description for wave.setcomptype() values
........
r56456 | walter.doerwald | 2007-07-19 06:04:38 -0700 (Thu, 19 Jul 2007) | 3 lines
Document that codecs.lookup() returns a CodecInfo object.
(fixes SF bug #1754453).
........
r56463 | facundo.batista | 2007-07-19 16:57:38 -0700 (Thu, 19 Jul 2007) | 6 lines
Added a select.select call in the test server loop to make sure the
socket is ready to be read from before attempting a read (this
prevents an error 10035 on some Windows platforms). [GSoC - Alan
McIntyre]
........
................
2007-07-20 01:05:57 -03:00
|
|
|
from .configHandler import idleConf
|
2005-02-02 21:37:14 -04:00
|
|
|
|
2000-08-14 22:13:23 -03:00
|
|
|
class History:
|
|
|
|
|
|
|
|
def __init__(self, text, output_sep = "\n"):
|
|
|
|
self.text = text
|
|
|
|
self.history = []
|
|
|
|
self.history_prefix = None
|
|
|
|
self.history_pointer = None
|
|
|
|
self.output_sep = output_sep
|
2005-02-02 21:37:14 -04:00
|
|
|
self.cyclic = idleConf.GetOption("main", "History", "cyclic", 1, "bool")
|
2000-08-14 22:13:23 -03:00
|
|
|
text.bind("<<history-previous>>", self.history_prev)
|
|
|
|
text.bind("<<history-next>>", self.history_next)
|
|
|
|
|
|
|
|
def history_next(self, event):
|
|
|
|
self.history_do(0)
|
|
|
|
return "break"
|
|
|
|
|
|
|
|
def history_prev(self, event):
|
|
|
|
self.history_do(1)
|
|
|
|
return "break"
|
|
|
|
|
|
|
|
def _get_source(self, start, end):
|
|
|
|
# Get source code from start index to end index. Lines in the
|
|
|
|
# text control may be separated by sys.ps2 .
|
2002-09-16 19:09:19 -03:00
|
|
|
lines = self.text.get(start, end).split(self.output_sep)
|
|
|
|
return "\n".join(lines)
|
2000-08-14 22:13:23 -03:00
|
|
|
|
|
|
|
def _put_source(self, where, source):
|
2002-09-16 19:09:19 -03:00
|
|
|
output = self.output_sep.join(source.split("\n"))
|
2000-08-14 22:13:23 -03:00
|
|
|
self.text.insert(where, output)
|
|
|
|
|
|
|
|
def history_do(self, reverse):
|
|
|
|
nhist = len(self.history)
|
|
|
|
pointer = self.history_pointer
|
|
|
|
prefix = self.history_prefix
|
|
|
|
if pointer is not None and prefix is not None:
|
|
|
|
if self.text.compare("insert", "!=", "end-1c") or \
|
|
|
|
self._get_source("iomark", "end-1c") != self.history[pointer]:
|
|
|
|
pointer = prefix = None
|
|
|
|
if pointer is None or prefix is None:
|
|
|
|
prefix = self._get_source("iomark", "end-1c")
|
|
|
|
if reverse:
|
|
|
|
pointer = nhist
|
|
|
|
else:
|
2005-02-02 21:37:14 -04:00
|
|
|
if self.cyclic:
|
|
|
|
pointer = -1
|
|
|
|
else:
|
|
|
|
self.text.bell()
|
|
|
|
return
|
2000-08-14 22:13:23 -03:00
|
|
|
nprefix = len(prefix)
|
|
|
|
while 1:
|
|
|
|
if reverse:
|
|
|
|
pointer = pointer - 1
|
|
|
|
else:
|
|
|
|
pointer = pointer + 1
|
|
|
|
if pointer < 0 or pointer >= nhist:
|
|
|
|
self.text.bell()
|
2005-02-02 21:37:14 -04:00
|
|
|
if not self.cyclic and pointer < 0:
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
if self._get_source("iomark", "end-1c") != prefix:
|
|
|
|
self.text.delete("iomark", "end-1c")
|
|
|
|
self._put_source("iomark", prefix)
|
|
|
|
pointer = prefix = None
|
2000-08-14 22:13:23 -03:00
|
|
|
break
|
|
|
|
item = self.history[pointer]
|
|
|
|
if item[:nprefix] == prefix and len(item) > nprefix:
|
|
|
|
self.text.delete("iomark", "end-1c")
|
|
|
|
self._put_source("iomark", item)
|
|
|
|
break
|
|
|
|
self.text.mark_set("insert", "end-1c")
|
|
|
|
self.text.see("insert")
|
|
|
|
self.text.tag_remove("sel", "1.0", "end")
|
|
|
|
self.history_pointer = pointer
|
|
|
|
self.history_prefix = prefix
|
|
|
|
|
|
|
|
def history_store(self, source):
|
2002-09-16 19:09:19 -03:00
|
|
|
source = source.strip()
|
2000-08-14 22:13:23 -03:00
|
|
|
if len(source) > 2:
|
|
|
|
# avoid duplicates
|
|
|
|
try:
|
|
|
|
self.history.remove(source)
|
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
self.history.append(source)
|
|
|
|
self.history_pointer = None
|
|
|
|
self.history_prefix = None
|