summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/EditorWindow.py
diff options
context:
space:
mode:
authorKurt B. Kaiser <kbk@shore.net>2004-04-24 03:01:48 (GMT)
committerKurt B. Kaiser <kbk@shore.net>2004-04-24 03:01:48 (GMT)
commit610c7e07f3e41e1f4baf7303edc8124269c01250 (patch)
tree1e0dfe0712059f9ccf4ff6d96da42ef36a8bc01d /Lib/idlelib/EditorWindow.py
parent46a16f297f0249bbb0c446a80bf2ae927f971e97 (diff)
downloadcpython-610c7e07f3e41e1f4baf7303edc8124269c01250.zip
cpython-610c7e07f3e41e1f4baf7303edc8124269c01250.tar.gz
cpython-610c7e07f3e41e1f4baf7303edc8124269c01250.tar.bz2
1. Polish variables in EditorWindow extension loading and Tkinter variable code.
2. Add exception handling to EditorWindow Tkinter variable setvar() and getvar() fcns. 3. EditorWindow: remove some unneeded comments. 4. Add a separator to the Options menu 5. extend.txt: describe how to create a menu entry which has no keybinding. M Bindings.py M EditorWindow.py M extend.txt
Diffstat (limited to 'Lib/idlelib/EditorWindow.py')
-rw-r--r--Lib/idlelib/EditorWindow.py55
1 files changed, 30 insertions, 25 deletions
diff --git a/Lib/idlelib/EditorWindow.py b/Lib/idlelib/EditorWindow.py
index ca52ccb..605d34c 100644
--- a/Lib/idlelib/EditorWindow.py
+++ b/Lib/idlelib/EditorWindow.py
@@ -46,7 +46,6 @@ class EditorWindow:
from Tkinter import Toplevel
from MultiStatusBar import MultiStatusBar
- vars = {}
help_url = None
def __init__(self, flist=None, filename=None, key=None, root=None):
@@ -78,10 +77,13 @@ class EditorWindow:
self.menubar = Menu(root)
self.top = top = self.Toplevel(root, menu=self.menubar)
if flist:
- self.vars = flist.vars
+ self.tkinter_vars = flist.vars
#self.top.instance_dict makes flist.inversedict avalable to
#configDialog.py so it can access all EditorWindow instaces
self.top.instance_dict=flist.inversedict
+ else:
+ self.tkinter_vars = {} # keys: Tkinter event names
+ # values: Tkinter variable instances
self.recent_files_path=os.path.join(idleConf.GetUserCfgDir(),
'recent-files.lst')
self.vbar = vbar = Scrollbar(top, name='vbar')
@@ -553,10 +555,8 @@ class EditorWindow:
if menuEventDict[menubarItem].has_key(itemName):
event=menuEventDict[menubarItem][itemName]
if event:
- #print 'accel was:',accel
accel=get_accelerator(keydefs, event)
menu.entryconfig(index,accelerator=accel)
- #print 'accel now:',accel,'\n'
def reset_help_menu_entries(self):
"Update the additional help entries on the Help menu"
@@ -711,7 +711,6 @@ class EditorWindow:
return reply
def _close(self):
- #print self.io.filename
if self.io.filename:
self.update_recent_files_list(new_file=self.io.filename)
WindowList.unregister_callback(self.postwindowsmenu)
@@ -727,7 +726,7 @@ class EditorWindow:
doh = colorizing and self.top
self.color.close(doh) # Cancel colorization
self.text = None
- self.vars = None
+ self.tkinter_vars = None
self.per.close(); self.per = None
if not colorizing:
self.top.destroy()
@@ -784,35 +783,35 @@ class EditorWindow:
if keylist:
text.event_add(event, *keylist)
- def fill_menus(self, defs=None, keydefs=None):
+ def fill_menus(self, menudefs=None, keydefs=None):
"""Add appropriate entries to the menus and submenus
Menus that are absent or None in self.menudict are ignored.
"""
- if defs is None:
- defs = self.Bindings.menudefs
+ if menudefs is None:
+ menudefs = self.Bindings.menudefs
if keydefs is None:
keydefs = self.Bindings.default_keydefs
menudict = self.menudict
text = self.text
- for mname, itemlist in defs:
+ for mname, entrylist in menudefs:
menu = menudict.get(mname)
if not menu:
continue
- for item in itemlist:
- if not item:
+ for entry in entrylist:
+ if not entry:
menu.add_separator()
else:
- label, event = item
+ label, eventname = entry
checkbutton = (label[:1] == '!')
if checkbutton:
label = label[1:]
underline, label = prepstr(label)
- accelerator = get_accelerator(keydefs, event)
- def command(text=text, event=event):
- text.event_generate(event)
+ accelerator = get_accelerator(keydefs, eventname)
+ def command(text=text, eventname=eventname):
+ text.event_generate(eventname)
if checkbutton:
- var = self.getrawvar(event, BooleanVar)
+ var = self.get_var_obj(eventname, BooleanVar)
menu.add_checkbutton(label=label, underline=underline,
command=command, accelerator=accelerator,
variable=var)
@@ -822,19 +821,25 @@ class EditorWindow:
accelerator=accelerator)
def getvar(self, name):
- var = self.getrawvar(name)
+ var = self.get_var_obj(name)
if var:
- return var.get()
+ value = var.get()
+ return value
+ else:
+ raise NameError, name
def setvar(self, name, value, vartype=None):
- var = self.getrawvar(name, vartype)
+ var = self.get_var_obj(name, vartype)
if var:
var.set(value)
+ else:
+ raise NameError, name
- def getrawvar(self, name, vartype=None):
- var = self.vars.get(name)
+ def get_var_obj(self, name, vartype=None):
+ var = self.tkinter_vars.get(name)
if not var and vartype:
- self.vars[name] = var = vartype(self.text)
+ # create a Tkinter variable object with self.text as master:
+ self.tkinter_vars[name] = var = vartype(self.text)
return var
# Tk implementations of "virtual text methods" -- each platform
@@ -1367,8 +1372,8 @@ keynames = {
'slash': '/',
}
-def get_accelerator(keydefs, event):
- keylist = keydefs.get(event)
+def get_accelerator(keydefs, eventname):
+ keylist = keydefs.get(eventname)
if not keylist:
return ""
s = keylist[0]