[Python-checkins] r65531 - sandbox/trunk/ttk-gsoc/src/idlelib/EditorWindow.py
guilherme.polo
python-checkins at python.org
Tue Aug 5 00:32:32 CEST 2008
Author: guilherme.polo
Date: Tue Aug 5 00:32:32 2008
New Revision: 65531
Log:
Marking load_extension as a private method now, since it is used only by
EditorWindow;
Fixed menu creation during extension loading in order to not recreate them;
Fixed new bindings during extension loading in order to not miss any new tabs;
Modified:
sandbox/trunk/ttk-gsoc/src/idlelib/EditorWindow.py
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 Tue Aug 5 00:32:32 2008
@@ -508,34 +508,6 @@
# unless override: unregister from flist, terminate if last window
self.close_hook()
- def load_extension(self, name, tab):
- load_only_once = ['CodeContext']
- if name in load_only_once and self.extensions.get(name, None):
- return
-
- try:
- mod = __import__(name, globals(), locals(), [])
- except ImportError:
- print "\nFailed to import extension: ", name
- return
- cls = getattr(mod, name)
- keydefs = idleConf.GetExtensionBindings(name)
- if hasattr(cls, "menudefs"):
- self._fill_menus(cls.menudefs, keydefs)
- ins = cls(tab.editpage)
- self.extensions.setdefault(name, []).append(ins)
- if keydefs:
- self.apply_bindings(keydefs, tab)
- for vevent in keydefs.keys():
- methodname = vevent.replace("-", "_")
- while methodname[:1] == '<':
- methodname = methodname[1:]
- while methodname[-1:] == '>':
- methodname = methodname[:-1]
- methodname = methodname + "_event"
- if hasattr(ins, methodname):
- tab.editpage.text.bind(vevent, getattr(ins, methodname))
-
def apply_bindings(self, keydefs=None, tab=None):
if keydefs is None:
keydefs = Bindings.default_keydefs
@@ -620,7 +592,10 @@
indentsmall = indentlarge = 0
return indentlarge - indentsmall
- # Private methods
+ # Private methods/attributes
+
+ # extensions won't have more than one instance per window
+ _unique_extensions = ['CodeContext', 'ScriptBinding', 'FormatParagraph']
def _unload_extensions(self):
for ins in self.extensions.values():
@@ -628,13 +603,50 @@
ins.close()
self.extensions = {}
+ def _load_extension(self, name, tab):
+ ext_loaded = self.extensions.get(name, None)
+
+ try:
+ mod = __import__(name, globals(), locals(), [])
+ except ImportError:
+ print "\nFailed to import extension: ", name
+ return
+
+ keydefs = idleConf.GetExtensionBindings(name)
+
+ if name not in self._unique_extensions or not ext_loaded:
+ # create a new instance
+ cls = getattr(mod, name)
+ ins = cls(tab.editpage)
+ self.extensions.setdefault(name, []).append(ins)
+ if not ext_loaded:
+ # create new items in menu only if this is the first time this
+ # extension is being loaded in this window
+ if hasattr(cls, "menudefs"):
+ self._fill_menus(cls.menudefs, keydefs)
+ elif name in self._unique_extensions and ext_loaded:
+ # get an existing instance
+ ins = self.extensions[name][0]
+
+ if keydefs:
+ self.apply_bindings(keydefs, tab)
+ for vevent in keydefs.keys():
+ methodname = vevent.replace("-", "_")
+ while methodname[:1] == '<':
+ methodname = methodname[1:]
+ while methodname[-1:] == '>':
+ methodname = methodname[:-1]
+ methodname = methodname + "_event"
+ if hasattr(ins, methodname):
+ tab.editpage.text.bind(vevent, getattr(ins, methodname))
+
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)
+ self._load_extension(name, tab)
except:
print "Failed to load extension", repr(name)
traceback.print_exc()
@@ -659,8 +671,10 @@
self.set_line_and_column()
# update references in extensions that are loaded only once
- if 'CodeContext' in self.extensions:
- ext = self.extensions['CodeContext'][0]
+ for ext in self._unique_extensions:
+ if ext not in self.extensions:
+ continue
+ ext = self.extensions[ext][0]
ext.editpage = curr_page
def _create_statusbar(self):
More information about the Python-checkins
mailing list