mirror of
https://github.com/python/cpython.git
synced 2025-09-27 18:59:43 +00:00
1. Add an Options menu entry: Code Context
2. Add a <<toggle-code-context>> envent to the [CodeContext] section of config-extensions.def and also a default-on variable, set to 0. 3. Update the help file to include Code Context. M CodeContext.py M config-extensions.def M help.txt
This commit is contained in:
parent
610c7e07f3
commit
d00587a2ed
3 changed files with 43 additions and 27 deletions
|
@ -13,32 +13,47 @@ the context hints pane.
|
||||||
import Tkinter
|
import Tkinter
|
||||||
from configHandler import idleConf
|
from configHandler import idleConf
|
||||||
from PyShell import PyShell
|
from PyShell import PyShell
|
||||||
from string import whitespace
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
BLOCKOPENERS = dict([(x, None) for x in ("class", "def", "elif", "else",
|
BLOCKOPENERS = dict([(x, None) for x in ("class", "def", "elif", "else",
|
||||||
"except", "finally", "for", "if",
|
"except", "finally", "for", "if",
|
||||||
"try", "while")])
|
"try", "while")])
|
||||||
INFINITY = 1 << 30
|
INFINITY = 1 << 30
|
||||||
UPDATEINTERVAL = 100 #ms
|
UPDATEINTERVAL = 100 # millisec
|
||||||
FONTUPDATEINTERVAL = 1000 #ms
|
FONTUPDATEINTERVAL = 1000 # millisec
|
||||||
|
|
||||||
getspacesfirstword = lambda s, c=re.compile(r"^(\s*)(\w*)"): c.match(s).groups()
|
getspacesfirstword = lambda s, c=re.compile(r"^(\s*)(\w*)"): c.match(s).groups()
|
||||||
|
|
||||||
class CodeContext:
|
class CodeContext:
|
||||||
menudefs = []
|
menudefs = [('options', [('!Code Conte_xt', '<<toggle-code-context>>')])]
|
||||||
|
|
||||||
numlines = idleConf.GetOption("extensions", "CodeContext",
|
numlines = idleConf.GetOption("extensions", "CodeContext",
|
||||||
"numlines", type="int", default=3)
|
"numlines", type="int", default=3)
|
||||||
bgcolor = idleConf.GetOption("extensions", "CodeContext",
|
bgcolor = idleConf.GetOption("extensions", "CodeContext",
|
||||||
"bgcolor", type="str", default="LightGray")
|
"bgcolor", type="str", default="LightGray")
|
||||||
fgcolor = idleConf.GetOption("extensions", "CodeContext",
|
fgcolor = idleConf.GetOption("extensions", "CodeContext",
|
||||||
"fgcolor", type="str", default="Black")
|
"fgcolor", type="str", default="Black")
|
||||||
|
default_on = idleConf.GetOption("extensions", "CodeContext",
|
||||||
|
"default_on", type="int", default=0)
|
||||||
def __init__(self, editwin):
|
def __init__(self, editwin):
|
||||||
if isinstance(editwin, PyShell):
|
if isinstance(editwin, PyShell):
|
||||||
return
|
return
|
||||||
self.editwin = editwin
|
self.editwin = editwin
|
||||||
self.text = editwin.text
|
self.text = editwin.text
|
||||||
self.textfont = self.text["font"]
|
self.textfont = self.text["font"]
|
||||||
|
self.label = None
|
||||||
|
# Dummy line, which starts the "block" of the whole document:
|
||||||
|
self.info = list(self.interesting_lines(1))
|
||||||
|
self.lastfirstline = 1
|
||||||
|
if self.default_on:
|
||||||
|
self.toggle_code_context_event()
|
||||||
|
self.editwin.setvar('<<toggle-code-context>>', True)
|
||||||
|
# Start two update cycles, one for context lines, one for font changes.
|
||||||
|
self.text.after(UPDATEINTERVAL, self.timer_event)
|
||||||
|
self.text.after(FONTUPDATEINTERVAL, self.font_timer_event)
|
||||||
|
|
||||||
|
def toggle_code_context_event(self, event=None):
|
||||||
|
if not self.label:
|
||||||
self.label = Tkinter.Label(self.editwin.top,
|
self.label = Tkinter.Label(self.editwin.top,
|
||||||
text="\n" * (self.numlines - 1),
|
text="\n" * (self.numlines - 1),
|
||||||
anchor="w", justify="left",
|
anchor="w", justify="left",
|
||||||
|
@ -49,12 +64,9 @@ class CodeContext:
|
||||||
)
|
)
|
||||||
self.label.pack(side="top", fill="x", expand=0,
|
self.label.pack(side="top", fill="x", expand=0,
|
||||||
after=self.editwin.status_bar)
|
after=self.editwin.status_bar)
|
||||||
# Dummy line, which starts the "block" of the whole document:
|
else:
|
||||||
self.info = list(self.interesting_lines(1))
|
self.label.destroy()
|
||||||
self.lastfirstline = 1
|
self.label = None
|
||||||
# Start two update cycles, one for context lines, one for font changes.
|
|
||||||
self.text.after(UPDATEINTERVAL, self.timer_event)
|
|
||||||
self.text.after(FONTUPDATEINTERVAL, self.font_timer_event)
|
|
||||||
|
|
||||||
def get_line_info(self, linenum):
|
def get_line_info(self, linenum):
|
||||||
"""Get the line indent value, text, and any block start keyword
|
"""Get the line indent value, text, and any block start keyword
|
||||||
|
@ -107,7 +119,6 @@ class CodeContext:
|
||||||
del self.info[-1]
|
del self.info[-1]
|
||||||
if self.info[-1][0] == line_index:
|
if self.info[-1][0] == line_index:
|
||||||
break
|
break
|
||||||
# Add the block starting line info to tmpstack
|
|
||||||
tmpstack.append((line_index, text))
|
tmpstack.append((line_index, text))
|
||||||
while tmpstack:
|
while tmpstack:
|
||||||
self.info.append(tmpstack.pop())
|
self.info.append(tmpstack.pop())
|
||||||
|
@ -116,12 +127,13 @@ class CodeContext:
|
||||||
self.label["text"] = '\n'.join(lines)
|
self.label["text"] = '\n'.join(lines)
|
||||||
|
|
||||||
def timer_event(self):
|
def timer_event(self):
|
||||||
|
if self.label:
|
||||||
self.update_label()
|
self.update_label()
|
||||||
self.text.after(UPDATEINTERVAL, self.timer_event)
|
self.text.after(UPDATEINTERVAL, self.timer_event)
|
||||||
|
|
||||||
def font_timer_event(self):
|
def font_timer_event(self):
|
||||||
newtextfont = self.text["font"]
|
newtextfont = self.text["font"]
|
||||||
if newtextfont != self.textfont:
|
if self.label and newtextfont != self.textfont:
|
||||||
self.textfont = newtextfont
|
self.textfont = newtextfont
|
||||||
self.label["font"] = self.textfont
|
self.label["font"] = self.textfont
|
||||||
self.text.after(FONTUPDATEINTERVAL, self.font_timer_event)
|
self.text.after(FONTUPDATEINTERVAL, self.font_timer_event)
|
||||||
|
|
|
@ -3,13 +3,14 @@
|
||||||
#
|
#
|
||||||
# Each extension must have at least one section, named after the extension
|
# Each extension must have at least one section, named after the extension
|
||||||
# module. This section must contain an 'enable' item (=1 to enable the
|
# module. This section must contain an 'enable' item (=1 to enable the
|
||||||
# extension, =0 to disable it) and also contain any other general
|
# extension, =0 to disable it) and also contain any other general configuration
|
||||||
# configuration items for the extension. Each extension may also define up to
|
# items for the extension. Each extension must define at least one section
|
||||||
# two optional sections named ExtensionName_bindings and
|
# named ExtensionName_bindings or ExtensionName_cfgBindings. If present,
|
||||||
# ExtensionName_cfgBindings. If present, ExtensionName_bindings defines virtual
|
# ExtensionName_bindings defines virtual event bindings for the extension that
|
||||||
# event bindings for the extension that are not sensibly re-configurable. If
|
# are not user re-configurable. If present, ExtensionName_cfgBindings
|
||||||
# present, ExtensionName_cfgBindings defines virtual event bindings for the
|
# defines virtual event bindings for the extension that may be sensibly
|
||||||
# extension that may be sensibly re-configured.
|
# re-configured. If there are no keybindings for a menus' virtual events,
|
||||||
|
# include lines like <<toggle-code-context>>= (See [CodeContext], below.)
|
||||||
|
|
||||||
# Currently it is necessary to manually modify this file to change extension
|
# Currently it is necessary to manually modify this file to change extension
|
||||||
# key bindings and default values. To customize, create
|
# key bindings and default values. To customize, create
|
||||||
|
@ -65,5 +66,8 @@ check-restore=<KeyPress>
|
||||||
[CodeContext]
|
[CodeContext]
|
||||||
enable=1
|
enable=1
|
||||||
numlines=3
|
numlines=3
|
||||||
|
default_on=0
|
||||||
bgcolor=LightGray
|
bgcolor=LightGray
|
||||||
fgcolor=Black
|
fgcolor=Black
|
||||||
|
[CodeContext_bindings]
|
||||||
|
toggle-code-context=
|
||||||
|
|
|
@ -88,9 +88,9 @@ Options Menu:
|
||||||
Startup Preferences may be set, and Additional Help
|
Startup Preferences may be set, and Additional Help
|
||||||
Souces can be specified.
|
Souces can be specified.
|
||||||
---
|
---
|
||||||
Revert to Default Settings -- Restore original settings. Not
|
Code Context -- Open a pane at the top of the edit window which
|
||||||
currently implemented - simply delete
|
shows the block context of the section of code
|
||||||
your .idlerc file.
|
which is scrolling off the top or the window.
|
||||||
|
|
||||||
Windows Menu:
|
Windows Menu:
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue