[Python-checkins] r65448 - in sandbox/trunk/ttk-gsoc/src/idlelib: AutoComplete.py AutoExpand.py CallTips.py EditorWindow.py FormatParagraph.py HyperParser.py ParenMatch.py ScriptBinding.py ZoomHeight.py
guilherme.polo
python-checkins at python.org
Mon Aug 4 01:15:31 CEST 2008
Author: guilherme.polo
Date: Mon Aug 4 01:15:31 2008
New Revision: 65448
Log:
Extensions work with tabs now
Modified:
sandbox/trunk/ttk-gsoc/src/idlelib/AutoComplete.py
sandbox/trunk/ttk-gsoc/src/idlelib/AutoExpand.py
sandbox/trunk/ttk-gsoc/src/idlelib/CallTips.py
sandbox/trunk/ttk-gsoc/src/idlelib/EditorWindow.py
sandbox/trunk/ttk-gsoc/src/idlelib/FormatParagraph.py
sandbox/trunk/ttk-gsoc/src/idlelib/HyperParser.py
sandbox/trunk/ttk-gsoc/src/idlelib/ParenMatch.py
sandbox/trunk/ttk-gsoc/src/idlelib/ScriptBinding.py
sandbox/trunk/ttk-gsoc/src/idlelib/ZoomHeight.py
Modified: sandbox/trunk/ttk-gsoc/src/idlelib/AutoComplete.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/AutoComplete.py (original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/AutoComplete.py Mon Aug 4 01:15:31 2008
@@ -38,11 +38,11 @@
popupwait = idleConf.GetOption("extensions", "AutoComplete",
"popupwait", type="int", default=0)
- def __init__(self, editwin=None):
- self.editwin = editwin
- if editwin is None: # subprocess and test
+ def __init__(self, editpage=None):
+ self.editpage = editpage
+ if editpage is None: # subprocess and test
return
- self.text = editwin.text
+ self.text = editpage.text
self.autocompletewindow = None
# id of delayed call, and the index of the text insert when the delayed
@@ -120,7 +120,7 @@
self.text.after_cancel(self._delayed_completion_id)
self._delayed_completion_id = None
- hp = HyperParser(self.editwin, "insert")
+ hp = HyperParser(self.editpage, "insert")
curline = self.text.get("insert linestart", "insert")
i = j = len(curline)
if hp.is_in_string() and (not mode or mode==COMPLETE_FILES):
@@ -176,7 +176,7 @@
module may be inoperative if the module was not the last to run.
"""
try:
- rpcclt = self.editwin.flist.pyshell.interp.rpcclt
+ rpcclt = self.editpage.editwin.flist.pyshell.interp.rpcclt
except:
rpcclt = None
if rpcclt:
Modified: sandbox/trunk/ttk-gsoc/src/idlelib/AutoExpand.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/AutoExpand.py (original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/AutoExpand.py Mon Aug 4 01:15:31 2008
@@ -15,8 +15,8 @@
wordchars = string.ascii_letters + string.digits + "_"
- def __init__(self, editwin):
- self.text = editwin.text
+ def __init__(self, editpage):
+ self.text = editpage.text
self.state = None
def expand_word_event(self, event):
Modified: sandbox/trunk/ttk-gsoc/src/idlelib/CallTips.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/CallTips.py (original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/CallTips.py Mon Aug 4 01:15:31 2008
@@ -22,12 +22,12 @@
])
]
- def __init__(self, editwin=None):
- if editwin is None: # subprocess and test
- self.editwin = None
+ def __init__(self, editpage=None):
+ if editpage is None: # subprocess and test
+ self.editpage = None
return
- self.editwin = editwin
- self.text = editwin.text
+ self.editpage = editpage
+ self.text = editpage.text
self.calltip = None
self._make_calltip_window = self._make_tk_calltip_window
@@ -66,7 +66,7 @@
def open_calltip(self, evalfuncs):
self._remove_calltip_window()
- hp = HyperParser(self.editwin, "insert")
+ hp = HyperParser(self.editpage, "insert")
sur_paren = hp.get_surrounding_brackets('(')
if not sur_paren:
return
@@ -95,7 +95,7 @@
"""
try:
- rpcclt = self.editwin.flist.pyshell.interp.rpcclt
+ rpcclt = self.editpage.editwin.flist.pyshell.interp.rpcclt
except:
rpcclt = None
if rpcclt:
Modified: sandbox/trunk/ttk-gsoc/src/idlelib/EditorWindow.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/EditorWindow.py (original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/EditorWindow.py Mon Aug 4 01:15:31 2008
@@ -105,13 +105,12 @@
# create a Notebook where the text pages for this EditorWindow will
# reside
self.text_notebook = TabbedPageSet(self.top)
- self.text_notebook.bind('<<NotebookTabChanged>>',
- self._update_controls)
- self.new_tab(filename=filename)
+ self.text_notebook.pack(fill=BOTH, expand=True)
+ self.text_notebook.bind('<<NotebookTabChanged>>', self._update_controls)
+ self.new_tab(filename=filename, load_ext=False)
self.text = self.current_page.text # XXX
self.top.focused_widget = self.text
self.top.bind('<<tab-closed>>', self._post_tab_close)
- self.text_notebook.pack(fill=BOTH, expand=True)
# The following "width" attribute is used by PyShell, so keep it here
self.width = idleConf.GetOption('main', 'EditorPage', 'width')
@@ -175,7 +174,8 @@
self.set_indentation_params(self.ispythonsource(filename))
- self.load_extensions()
+ self.extensions = {}
+ self._load_extensions()
menu = self.menudict.get('windows')
if menu:
@@ -225,7 +225,7 @@
return
self.text_notebook.select(index - 1)
- def new_tab(self, event=None, filename=None):
+ def new_tab(self, event=None, filename=None, load_ext=True):
"""Create a new EditorPage and insert it into the notebook."""
page_title = "#%d" % (len(self.text_notebook.pages) + 1)
page = self.text_notebook.add_page(page_title)
@@ -249,9 +249,10 @@
text.pack(side=TOP, fill=BOTH, expand=1)
text.focus_set()
- self.apply_bindings()
+ self.apply_bindings(tab=page)
+ if load_ext:
+ self._load_extensions()
self.top.event_generate('<<tab-created>>')
-
return "break"
def new_callback(self, event, page):
@@ -492,7 +493,7 @@
def _close(self):
WindowList.unregister_callback(self.postwindowsmenu)
- self.unload_extensions()
+ self._unload_extensions()
self.tkinter_vars = None
for page in self.text_notebook.pages.itervalues():
@@ -503,28 +504,8 @@
# unless override: unregister from flist, terminate if last window
self.close_hook()
- def load_extensions(self):
- self.extensions = {}
- self.load_standard_extensions()
-
- def unload_extensions(self):
- for ins in self.extensions.values():
- if hasattr(ins, "close"):
- ins.close()
- self.extensions = {}
-
- def load_standard_extensions(self):
- for name in self.get_standard_extension_names():
- try:
- self.load_extension(name)
- except:
- print "Failed to load extension", repr(name)
- traceback.print_exc()
-
- def get_standard_extension_names(self):
- return idleConf.GetExtensions(editor_only=True)
-
- def load_extension(self, name):
+ def load_extension(self, name, tab):
+ #print "load extension", name, tab
try:
mod = __import__(name, globals(), locals(), [])
except ImportError:
@@ -534,10 +515,10 @@
keydefs = idleConf.GetExtensionBindings(name)
if hasattr(cls, "menudefs"):
self._fill_menus(cls.menudefs, keydefs)
- ins = cls(self)
- self.extensions[name] = ins
+ ins = cls(tab.editpage)
+ self.extensions.setdefault(name, []).append(ins)
if keydefs:
- self.apply_bindings(keydefs)
+ self.apply_bindings(keydefs, tab)
for vevent in keydefs.keys():
methodname = vevent.replace("-", "_")
while methodname[:1] == '<':
@@ -545,16 +526,19 @@
while methodname[-1:] == '>':
methodname = methodname[:-1]
methodname = methodname + "_event"
- for page in self.text_notebook.pages.itervalues():
- text = page.editpage.text
- if hasattr(ins, methodname):
- text.bind(vevent, getattr(ins, methodname))
+ if hasattr(ins, methodname):
+ tab.editpage.text.bind(vevent, getattr(ins, methodname))
- def apply_bindings(self, keydefs=None):
+ def apply_bindings(self, keydefs=None, tab=None):
if keydefs is None:
keydefs = Bindings.default_keydefs
- for page in self.text_notebook.pages.itervalues():
+ if tab:
+ iter_over = [tab]
+ else:
+ iter_over = self.text_notebook.pages.itervalues()
+
+ for page in iter_over:
text = page.editpage.text
text.keydefs = keydefs
for event, keylist in keydefs.items():
@@ -631,6 +615,26 @@
# Private methods
+ def _unload_extensions(self):
+ for ins in self.extensions.values():
+ if hasattr(ins, "close"):
+ ins.close()
+ self.extensions = {}
+
+ def _load_extensions(self):
+ self._load_standard_extensions(self.text_notebook.last_page())
+
+ def _load_standard_extensions(self, tab):
+ for name in self._get_standard_extension_names():
+ try:
+ self.load_extension(name, tab)
+ except:
+ print "Failed to load extension", repr(name)
+ traceback.print_exc()
+
+ def _get_standard_extension_names(self):
+ return idleConf.GetExtensions(editor_only=True)
+
def _post_tab_close(self, event):
if not self.current_page:
# no tabs now, close window
Modified: sandbox/trunk/ttk-gsoc/src/idlelib/FormatParagraph.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/FormatParagraph.py (original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/FormatParagraph.py Mon Aug 4 01:15:31 2008
@@ -25,28 +25,30 @@
])
]
- def __init__(self, editwin):
- self.editwin = editwin
+ def __init__(self, editpage):
+ self.editpage = editpage
def close(self):
- self.editwin = None
+ self.editpage = None
def format_paragraph_event(self, event):
- maxformatwidth = int(idleConf.GetOption('main','FormatParagraph','paragraph'))
- text = self.editwin.text
- first, last = self.editwin.get_selection_indices()
+ maxformatwidth = int(idleConf.GetOption('main', 'FormatParagraph',
+ 'paragraph'))
+ text = self.editpage.text
+ first, last = self.editpage.get_selection_indices()
if first and last:
data = text.get(first, last)
comment_header = ''
else:
- first, last, comment_header, data = \
- find_paragraph(text, text.index("insert"))
+ first, last, comment_header, data = find_paragraph(text,
+ text.index("insert"))
if comment_header:
# Reformat the comment lines - convert to text sans header.
lines = data.split("\n")
lines = map(lambda st, l=len(comment_header): st[l:], lines)
data = "\n".join(lines)
- # Reformat to maxformatwidth chars or a 20 char width, whichever is greater.
+ # Reformat to maxformatwidth chars or a 20 char width, whichever is
+ # greater.
format_width = max(maxformatwidth - len(comment_header), 20)
newdata = reformat_paragraph(data, format_width)
# re-split and re-insert the comment header.
Modified: sandbox/trunk/ttk-gsoc/src/idlelib/HyperParser.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/HyperParser.py (original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/HyperParser.py Mon Aug 4 01:15:31 2008
@@ -16,13 +16,13 @@
class HyperParser:
- def __init__(self, editwin, index):
+ def __init__(self, editpage, index):
"""Initialize the HyperParser to analyze the surroundings of the given
index.
"""
- self.editwin = editwin
- self.text = text = editwin.text
+ self.editwin = editwin = editpage.editwin
+ self.text = text = editpage.text
parser = PyParse.Parser(editwin.indentwidth, editwin.tabwidth)
Modified: sandbox/trunk/ttk-gsoc/src/idlelib/ParenMatch.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/ParenMatch.py (original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/ParenMatch.py Mon Aug 4 01:15:31 2008
@@ -56,14 +56,13 @@
RESTORE_SEQUENCES = ("<KeyPress>", "<ButtonPress>",
"<Key-Return>", "<Key-BackSpace>")
- def __init__(self, editwin):
- self.editwin = editwin
- self.text = editwin.text
+ def __init__(self, editpage):
+ self.editpage = editpage
+ self.text = editpage.text
# Bind the check-restore event to the function restore_event,
# so that we can then use activate_restore (which calls event_add)
# and deactivate_restore (which calls event_delete).
- editwin.text.bind(self.RESTORE_VIRTUAL_EVENT_NAME,
- self.restore_event)
+ editpage.text.bind(self.RESTORE_VIRTUAL_EVENT_NAME, self.restore_event)
self.counter = 0
self.is_restore_active = 0
self.set_style(self.STYLE)
@@ -90,7 +89,7 @@
self.set_timeout = self.set_timeout_none
def flash_paren_event(self, event):
- indices = HyperParser(self.editwin, "insert").get_surrounding_brackets()
+ indices = HyperParser(self.editpage, "insert").get_surrounding_brackets()
if indices is None:
self.warn_mismatched()
return
@@ -103,7 +102,7 @@
closer = self.text.get("insert-1c")
if closer not in _openers:
return
- hp = HyperParser(self.editwin, "insert-1c")
+ hp = HyperParser(self.editpage, "insert-1c")
if not hp.is_in_code():
return
indices = hp.get_surrounding_brackets(_openers[closer], True)
@@ -159,14 +158,13 @@
if index != self.text.index("insert"):
self.handle_restore_timer(c)
else:
- self.editwin.text_notebook.after(CHECK_DELAY, callme, callme)
- self.editwin.text_notebook.after(CHECK_DELAY, callme, callme)
+ self.text.master.after(CHECK_DELAY, callme, callme)
+ self.text.master.after(CHECK_DELAY, callme, callme)
def set_timeout_last(self):
"""The last highlight created will be removed after .5 sec"""
# associate a counter with an event; only disable the "paren"
# tag if the event is for the most recent timer.
self.counter += 1
- self.editwin.text_notebook.after(self.FLASH_DELAY,
- lambda self=self, c=self.counter: \
- self.handle_restore_timer(c))
+ self.text.master.after(self.FLASH_DELAY,
+ lambda self=self, c=self.counter: self.handle_restore_timer(c))
Modified: sandbox/trunk/ttk-gsoc/src/idlelib/ScriptBinding.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/ScriptBinding.py (original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/ScriptBinding.py Mon Aug 4 01:15:31 2008
@@ -46,8 +46,9 @@
('Check Module', '<<check-module>>'),
('Run Module', '<<run-module>>'), ]), ]
- def __init__(self, editwin):
- self.editwin = editwin
+ def __init__(self, editpage):
+ self.editpage = editpage
+ self.editwin = editpage.editwin
# Provide instance variables referenced by Debugger
# XXX This should be done differently
self.flist = self.editwin.flist
@@ -91,7 +92,7 @@
source = re.sub(r"\r", "\n", source)
if source and source[-1] != '\n':
source = source + '\n'
- text = self.editwin.current_page.text # XXX check this!
+ text = self.editpage.text
text.tag_remove("ERROR", "1.0", "end")
try:
try:
@@ -113,7 +114,7 @@
shell.set_warning_stream(saved_stream)
def colorize_syntax_error(self, msg, lineno, offset):
- text = self.editwin.current_page.text # XXX check this!
+ text = self.editpage.text
pos = "0.0 + %d lines + %d chars" % (lineno-1, offset-1)
text.tag_add("ERROR", pos)
char = text.get(pos)
@@ -176,7 +177,7 @@
If the user has configured IDLE for Autosave, the file will be
silently saved if it already exists and is dirty.
"""
- page = self.editwin.current_page
+ page = self.editpage
filename = page.io.filename
if not page.get_saved():
autosave = idleConf.GetOption('main', 'General',
@@ -198,11 +199,10 @@
mb = tkMessageBox.Message(title="Save Before Run or Check",
message=msg, icon=tkMessageBox.QUESTION,
type=tkMessageBox.OKCANCEL, default=tkMessageBox.OK,
- master=self.editwin.text_notebook)
+ master=self.editpage.text)
return mb.show()
def errorbox(self, title, message):
# XXX This should really be a function of EditorWindow...
- tkMessageBox.showerror(title, message,
- master=self.editwin.text_notebook)
- self.editwin.current_page.text.focus_set()
+ tkMessageBox.showerror(title, message, master=self.editpage.text)
+ self.editpage.text.focus_set()
Modified: sandbox/trunk/ttk-gsoc/src/idlelib/ZoomHeight.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/ZoomHeight.py (original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/ZoomHeight.py Mon Aug 4 01:15:31 2008
@@ -12,11 +12,11 @@
])
]
- def __init__(self, editwin):
- self.editwin = editwin
+ def __init__(self, editpage):
+ self.editpage = editpage
def zoom_height_event(self, event):
- top = self.editwin.top
+ top = self.editpage.editwin.top
zoom_height(top)
def zoom_height(top):
More information about the Python-checkins
mailing list