Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
idlelib.CodeContext.CodeContext Class Reference

List of all members.

Public Member Functions

def __init__
def toggle_code_context_event
def get_line_info
def get_context
def update_code_context
def timer_event
def font_timer_event

Public Attributes

 editwin
 text
 textfont
 label
 info
 topvisible

Static Public Attributes

list menudefs = [('options', [('!Code Conte_xt', '<<toggle-code-context>>')])]
tuple context_depth
tuple bgcolor
tuple fgcolor

Detailed Description

Definition at line 26 of file CodeContext.py.


Constructor & Destructor Documentation

def idlelib.CodeContext.CodeContext.__init__ (   self,
  editwin 
)

Definition at line 34 of file CodeContext.py.

00034 
00035     def __init__(self, editwin):
00036         self.editwin = editwin
00037         self.text = editwin.text
00038         self.textfont = self.text["font"]
00039         self.label = None
00040         # self.info is a list of (line number, indent level, line text, block
00041         # keyword) tuples providing the block structure associated with
00042         # self.topvisible (the linenumber of the line displayed at the top of
00043         # the edit window). self.info[0] is initialized as a 'dummy' line which
00044         # starts the toplevel 'block' of the module.
00045         self.info = [(0, -1, "", False)]
00046         self.topvisible = 1
00047         visible = idleConf.GetOption("extensions", "CodeContext",
00048                                      "visible", type="bool", default=False)
00049         if visible:
00050             self.toggle_code_context_event()
00051             self.editwin.setvar('<<toggle-code-context>>', True)
00052         # Start two update cycles, one for context lines, one for font changes.
00053         self.text.after(UPDATEINTERVAL, self.timer_event)
00054         self.text.after(FONTUPDATEINTERVAL, self.font_timer_event)

Here is the caller graph for this function:


Member Function Documentation

Definition at line 171 of file CodeContext.py.

00171 
00172     def font_timer_event(self):
00173         newtextfont = self.text["font"]
00174         if self.label and newtextfont != self.textfont:
00175             self.textfont = newtextfont
00176             self.label["font"] = self.textfont
00177         self.text.after(FONTUPDATEINTERVAL, self.font_timer_event)

Here is the call graph for this function:

Here is the caller graph for this function:

def idlelib.CodeContext.CodeContext.get_context (   self,
  new_topvisible,
  stopline = 1,
  stopindent = 0 
)
Get context lines, starting at new_topvisible and working backwards.

Stop when stopline or stopindent is reached. Return a tuple of context
data and the indent level at the top of the region inspected.

Definition at line 107 of file CodeContext.py.

00107 
00108     def get_context(self, new_topvisible, stopline=1, stopindent=0):
00109         """Get context lines, starting at new_topvisible and working backwards.
00110 
00111         Stop when stopline or stopindent is reached. Return a tuple of context
00112         data and the indent level at the top of the region inspected.
00113 
00114         """
00115         assert stopline > 0
00116         lines = []
00117         # The indentation level we are currently in:
00118         lastindent = INFINITY
00119         # For a line to be interesting, it must begin with a block opening
00120         # keyword, and have less indentation than lastindent.
00121         for linenum in range(new_topvisible, stopline-1, -1):
00122             indent, text, opener = self.get_line_info(linenum)
00123             if indent < lastindent:
00124                 lastindent = indent
00125                 if opener in ("else", "elif"):
00126                     # We also show the if statement
00127                     lastindent += 1
00128                 if opener and linenum < new_topvisible and indent >= stopindent:
00129                     lines.append((linenum, indent, text, opener))
00130                 if lastindent <= stopindent:
00131                     break
00132         lines.reverse()
00133         return lines, lastindent

Here is the call graph for this function:

Here is the caller graph for this function:

def idlelib.CodeContext.CodeContext.get_line_info (   self,
  linenum 
)
Get the line indent value, text, and any block start keyword

If the line does not start a block, the keyword value is False.
The indentation of empty lines (or comment lines) is INFINITY.

Definition at line 91 of file CodeContext.py.

00091 
00092     def get_line_info(self, linenum):
00093         """Get the line indent value, text, and any block start keyword
00094 
00095         If the line does not start a block, the keyword value is False.
00096         The indentation of empty lines (or comment lines) is INFINITY.
00097 
00098         """
00099         text = self.text.get("%d.0" % linenum, "%d.end" % linenum)
00100         spaces, firstword = getspacesfirstword(text)
00101         opener = firstword in BLOCKOPENERS and firstword
00102         if len(text) == len(spaces) or text[len(spaces)] == '#':
00103             indent = INFINITY
00104         else:
00105             indent = len(spaces)
00106         return indent, text, opener

Here is the caller graph for this function:

Definition at line 166 of file CodeContext.py.

00166 
00167     def timer_event(self):
00168         if self.label:
00169             self.update_code_context()
00170         self.text.after(UPDATEINTERVAL, self.timer_event)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 55 of file CodeContext.py.

00055 
00056     def toggle_code_context_event(self, event=None):
00057         if not self.label:
00058             # Calculate the border width and horizontal padding required to
00059             # align the context with the text in the main Text widget.
00060             #
00061             # All values are passed through int(str(<value>)), since some
00062             # values may be pixel objects, which can't simply be added to ints.
00063             widgets = self.editwin.text, self.editwin.text_frame
00064             # Calculate the required vertical padding
00065             padx = 0
00066             for widget in widgets:
00067                 padx += int(str( widget.pack_info()['padx'] ))
00068                 padx += int(str( widget.cget('padx') ))
00069             # Calculate the required border width
00070             border = 0
00071             for widget in widgets:
00072                 border += int(str( widget.cget('border') ))
00073             self.label = tkinter.Label(self.editwin.top,
00074                                        text="\n" * (self.context_depth - 1),
00075                                        anchor=W, justify=LEFT,
00076                                        font=self.textfont,
00077                                        bg=self.bgcolor, fg=self.fgcolor,
00078                                        width=1, #don't request more than we get
00079                                        padx=padx, border=border,
00080                                        relief=SUNKEN)
00081             # Pack the label widget before and above the text_frame widget,
00082             # thus ensuring that it will appear directly above text_frame
00083             self.label.pack(side=TOP, fill=X, expand=False,
00084                             before=self.editwin.text_frame)
00085         else:
00086             self.label.destroy()
00087             self.label = None
00088         idleConf.SetOption("extensions", "CodeContext", "visible",
00089                            str(self.label is not None))
00090         idleConf.SaveUserCfgFiles()

Update context information and lines visible in the context pane.

Definition at line 134 of file CodeContext.py.

00134 
00135     def update_code_context(self):
00136         """Update context information and lines visible in the context pane.
00137 
00138         """
00139         new_topvisible = int(self.text.index("@0,0").split('.')[0])
00140         if self.topvisible == new_topvisible:      # haven't scrolled
00141             return
00142         if self.topvisible < new_topvisible:       # scroll down
00143             lines, lastindent = self.get_context(new_topvisible,
00144                                                  self.topvisible)
00145             # retain only context info applicable to the region
00146             # between topvisible and new_topvisible:
00147             while self.info[-1][1] >= lastindent:
00148                 del self.info[-1]
00149         elif self.topvisible > new_topvisible:     # scroll up
00150             stopindent = self.info[-1][1] + 1
00151             # retain only context info associated
00152             # with lines above new_topvisible:
00153             while self.info[-1][0] >= new_topvisible:
00154                 stopindent = self.info[-1][1]
00155                 del self.info[-1]
00156             lines, lastindent = self.get_context(new_topvisible,
00157                                                  self.info[-1][0]+1,
00158                                                  stopindent)
00159         self.info.extend(lines)
00160         self.topvisible = new_topvisible
00161         # empty lines in context pane:
00162         context_strings = [""] * max(0, self.context_depth - len(self.info))
00163         # followed by the context hint lines:
00164         context_strings += [x[2] for x in self.info[-self.context_depth:]]
00165         self.label["text"] = '\n'.join(context_strings)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Initial value:
idleConf.GetOption("extensions", "CodeContext",
                                 "bgcolor", type="str", default="LightGray")

Definition at line 30 of file CodeContext.py.

Initial value:
idleConf.GetOption("extensions", "CodeContext",
                                       "numlines", type="int", default=3)

Definition at line 28 of file CodeContext.py.

Definition at line 35 of file CodeContext.py.

Initial value:
idleConf.GetOption("extensions", "CodeContext",
                                 "fgcolor", type="str", default="Black")

Definition at line 32 of file CodeContext.py.

Definition at line 44 of file CodeContext.py.

Definition at line 38 of file CodeContext.py.

list idlelib.CodeContext.CodeContext.menudefs = [('options', [('!Code Conte_xt', '<<toggle-code-context>>')])] [static]

Definition at line 27 of file CodeContext.py.

Definition at line 36 of file CodeContext.py.

Definition at line 37 of file CodeContext.py.

Definition at line 45 of file CodeContext.py.


The documentation for this class was generated from the following file: