Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
idlelib.TreeWidget.TreeNode Class Reference

List of all members.

Public Member Functions

def __init__
def destroy
def geticonimage
def select
def deselect
def deselectall
def deselecttree
def flip
def expand
def collapse
def view
def lastvisiblechild
def update
def draw
def drawicon
def drawtext
def select_or_edit
def edit
def edit_finish
def edit_cancel

Public Attributes

 canvas
 parent
 item
 state
 selected
 children
 x
 y
 iconimages
 image_id
 label
 text_id
 entry

Detailed Description

Definition at line 59 of file TreeWidget.py.


Constructor & Destructor Documentation

def idlelib.TreeWidget.TreeNode.__init__ (   self,
  canvas,
  parent,
  item 
)

Definition at line 61 of file TreeWidget.py.

00061 
00062     def __init__(self, canvas, parent, item):
00063         self.canvas = canvas
00064         self.parent = parent
00065         self.item = item
00066         self.state = 'collapsed'
00067         self.selected = False
00068         self.children = []
00069         self.x = self.y = None
00070         self.iconimages = {} # cache of PhotoImage instances for icons

Here is the caller graph for this function:


Member Function Documentation

def idlelib.TreeWidget.TreeNode.collapse (   self,
  event = None 
)

Definition at line 134 of file TreeWidget.py.

00134 
00135     def collapse(self, event=None):
00136         if self.state != 'collapsed':
00137             self.state = 'collapsed'
00138             self.update()

Here is the call graph for this function:

Here is the caller graph for this function:

def idlelib.TreeWidget.TreeNode.deselect (   self,
  event = None 
)

Definition at line 98 of file TreeWidget.py.

00098 
00099     def deselect(self, event=None):
00100         if not self.selected:
00101             return
00102         self.selected = False
00103         self.canvas.delete(self.image_id)
00104         self.drawicon()
00105         self.drawtext()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 106 of file TreeWidget.py.

00106 
00107     def deselectall(self):
00108         if self.parent:
00109             self.parent.deselectall()
00110         else:
00111             self.deselecttree()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 112 of file TreeWidget.py.

00112 
00113     def deselecttree(self):
00114         if self.selected:
00115             self.deselect()
00116         for child in self.children:
00117             child.deselecttree()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 71 of file TreeWidget.py.

00071 
00072     def destroy(self):
00073         for c in self.children[:]:
00074             self.children.remove(c)
00075             c.destroy()
00076         self.parent = None

Here is the caller graph for this function:

def idlelib.TreeWidget.TreeNode.draw (   self,
  x,
  y 
)

Definition at line 175 of file TreeWidget.py.

00175 
00176     def draw(self, x, y):
00177         # XXX This hard-codes too many geometry constants!
00178         self.x, self.y = x, y
00179         self.drawicon()
00180         self.drawtext()
00181         if self.state != 'expanded':
00182             return y+17
00183         # draw children
00184         if not self.children:
00185             sublist = self.item._GetSubList()
00186             if not sublist:
00187                 # _IsExpandable() was mistaken; that's allowed
00188                 return y+17
00189             for item in sublist:
00190                 child = self.__class__(self.canvas, self, item)
00191                 self.children.append(child)
00192         cx = x+20
00193         cy = y+17
00194         cylast = 0
00195         for child in self.children:
00196             cylast = cy
00197             self.canvas.create_line(x+9, cy+7, cx, cy+7, fill="gray50")
00198             cy = child.draw(cx, cy)
00199             if child.item._IsExpandable():
00200                 if child.state == 'expanded':
00201                     iconname = "minusnode"
00202                     callback = child.collapse
00203                 else:
00204                     iconname = "plusnode"
00205                     callback = child.expand
00206                 image = self.geticonimage(iconname)
00207                 id = self.canvas.create_image(x+9, cylast+7, image=image)
00208                 # XXX This leaks bindings until canvas is deleted:
00209                 self.canvas.tag_bind(id, "<1>", callback)
00210                 self.canvas.tag_bind(id, "<Double-1>", lambda x: None)
00211         id = self.canvas.create_line(x+9, y+10, x+9, cylast+7,
00212             ##stipple="gray50",     # XXX Seems broken in Tk 8.0.x
00213             fill="gray50")
00214         self.canvas.tag_lower(id) # XXX .lower(id) before Python 1.5.2
00215         return cy

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 216 of file TreeWidget.py.

00216 
00217     def drawicon(self):
00218         if self.selected:
00219             imagename = (self.item.GetSelectedIconName() or
00220                          self.item.GetIconName() or
00221                          "openfolder")
00222         else:
00223             imagename = self.item.GetIconName() or "folder"
00224         image = self.geticonimage(imagename)
00225         id = self.canvas.create_image(self.x, self.y, anchor="nw", image=image)
00226         self.image_id = id
00227         self.canvas.tag_bind(id, "<1>", self.select)
00228         self.canvas.tag_bind(id, "<Double-1>", self.flip)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 229 of file TreeWidget.py.

00229 
00230     def drawtext(self):
00231         textx = self.x+20-1
00232         texty = self.y-1
00233         labeltext = self.item.GetLabelText()
00234         if labeltext:
00235             id = self.canvas.create_text(textx, texty, anchor="nw",
00236                                          text=labeltext)
00237             self.canvas.tag_bind(id, "<1>", self.select)
00238             self.canvas.tag_bind(id, "<Double-1>", self.flip)
00239             x0, y0, x1, y1 = self.canvas.bbox(id)
00240             textx = max(x1, 200) + 10
00241         text = self.item.GetText() or "<no text>"
00242         try:
00243             self.entry
00244         except AttributeError:
00245             pass
00246         else:
00247             self.edit_finish()
00248         try:
00249             label = self.label
00250         except AttributeError:
00251             # padding carefully selected (on Windows) to match Entry widget:
00252             self.label = Label(self.canvas, text=text, bd=0, padx=2, pady=2)
00253         theme = idleConf.GetOption('main','Theme','name')
00254         if self.selected:
00255             self.label.configure(idleConf.GetHighlight(theme, 'hilite'))
00256         else:
00257             self.label.configure(idleConf.GetHighlight(theme, 'normal'))
00258         id = self.canvas.create_window(textx, texty,
00259                                        anchor="nw", window=self.label)
00260         self.label.bind("<1>", self.select_or_edit)
00261         self.label.bind("<Double-1>", self.flip)
00262         self.text_id = id

Here is the call graph for this function:

Here is the caller graph for this function:

def idlelib.TreeWidget.TreeNode.edit (   self,
  event = None 
)

Definition at line 269 of file TreeWidget.py.

00269 
00270     def edit(self, event=None):
00271         self.entry = Entry(self.label, bd=0, highlightthickness=1, width=0)
00272         self.entry.insert(0, self.label['text'])
00273         self.entry.selection_range(0, END)
00274         self.entry.pack(ipadx=5)
00275         self.entry.focus_set()
00276         self.entry.bind("<Return>", self.edit_finish)
00277         self.entry.bind("<Escape>", self.edit_cancel)

Here is the caller graph for this function:

def idlelib.TreeWidget.TreeNode.edit_cancel (   self,
  event = None 
)

Definition at line 293 of file TreeWidget.py.

00293 
00294     def edit_cancel(self, event=None):
00295         try:
00296             entry = self.entry
00297             del self.entry
00298         except AttributeError:
00299             return
00300         entry.destroy()
00301         self.drawtext()
00302         self.canvas.focus_set()
00303 

Here is the call graph for this function:

def idlelib.TreeWidget.TreeNode.edit_finish (   self,
  event = None 
)

Definition at line 278 of file TreeWidget.py.

00278 
00279     def edit_finish(self, event=None):
00280         try:
00281             entry = self.entry
00282             del self.entry
00283         except AttributeError:
00284             return
00285         text = entry.get()
00286         entry.destroy()
00287         if text and text != self.item.GetText():
00288             self.item.SetText(text)
00289         text = self.item.GetText()
00290         self.label['text'] = text
00291         self.drawtext()
00292         self.canvas.focus_set()

Here is the call graph for this function:

Here is the caller graph for this function:

def idlelib.TreeWidget.TreeNode.expand (   self,
  event = None 
)

Definition at line 126 of file TreeWidget.py.

00126 
00127     def expand(self, event=None):
00128         if not self.item._IsExpandable():
00129             return
00130         if self.state != 'expanded':
00131             self.state = 'expanded'
00132             self.update()
00133             self.view()

Here is the call graph for this function:

Here is the caller graph for this function:

def idlelib.TreeWidget.TreeNode.flip (   self,
  event = None 
)

Definition at line 118 of file TreeWidget.py.

00118 
00119     def flip(self, event=None):
00120         if self.state == 'expanded':
00121             self.collapse()
00122         else:
00123             self.expand()
00124         self.item.OnDoubleClick()
00125         return "break"

Here is the call graph for this function:

Here is the caller graph for this function:

def idlelib.TreeWidget.TreeNode.geticonimage (   self,
  name 
)

Definition at line 77 of file TreeWidget.py.

00077 
00078     def geticonimage(self, name):
00079         try:
00080             return self.iconimages[name]
00081         except KeyError:
00082             pass
00083         file, ext = os.path.splitext(name)
00084         ext = ext or ".gif"
00085         fullname = os.path.join(ICONDIR, file + ext)
00086         image = PhotoImage(master=self.canvas, file=fullname)
00087         self.iconimages[name] = image
00088         return image

Here is the caller graph for this function:

Definition at line 156 of file TreeWidget.py.

00156 
00157     def lastvisiblechild(self):
00158         if self.children and self.state == 'expanded':
00159             return self.children[-1].lastvisiblechild()
00160         else:
00161             return self

Here is the caller graph for this function:

def idlelib.TreeWidget.TreeNode.select (   self,
  event = None 
)

Definition at line 89 of file TreeWidget.py.

00089 
00090     def select(self, event=None):
00091         if self.selected:
00092             return
00093         self.deselectall()
00094         self.selected = True
00095         self.canvas.delete(self.image_id)
00096         self.drawicon()
00097         self.drawtext()

Here is the call graph for this function:

Here is the caller graph for this function:

def idlelib.TreeWidget.TreeNode.select_or_edit (   self,
  event = None 
)

Definition at line 263 of file TreeWidget.py.

00263 
00264     def select_or_edit(self, event=None):
00265         if self.selected and self.item.IsEditable():
00266             self.edit(event)
00267         else:
00268             self.select(event)

Here is the call graph for this function:

Definition at line 162 of file TreeWidget.py.

00162 
00163     def update(self):
00164         if self.parent:
00165             self.parent.update()
00166         else:
00167             oldcursor = self.canvas['cursor']
00168             self.canvas['cursor'] = "watch"
00169             self.canvas.update()
00170             self.canvas.delete(ALL)     # XXX could be more subtle
00171             self.draw(7, 2)
00172             x0, y0, x1, y1 = self.canvas.bbox(ALL)
00173             self.canvas.configure(scrollregion=(0, 0, x1, y1))
00174             self.canvas['cursor'] = oldcursor

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 139 of file TreeWidget.py.

00139 
00140     def view(self):
00141         top = self.y - 2
00142         bottom = self.lastvisiblechild().y + 17
00143         height = bottom - top
00144         visible_top = self.canvas.canvasy(0)
00145         visible_height = self.canvas.winfo_height()
00146         visible_bottom = self.canvas.canvasy(visible_height)
00147         if visible_top <= top and bottom <= visible_bottom:
00148             return
00149         x0, y0, x1, y1 = self.canvas._getints(self.canvas['scrollregion'])
00150         if top >= visible_top and height <= visible_height:
00151             fraction = top + height - visible_height
00152         else:
00153             fraction = top
00154         fraction = float(fraction) / y1
00155         self.canvas.yview_moveto(fraction)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 62 of file TreeWidget.py.

Definition at line 67 of file TreeWidget.py.

Definition at line 270 of file TreeWidget.py.

Definition at line 69 of file TreeWidget.py.

Definition at line 225 of file TreeWidget.py.

Definition at line 64 of file TreeWidget.py.

Definition at line 251 of file TreeWidget.py.

Definition at line 63 of file TreeWidget.py.

Definition at line 66 of file TreeWidget.py.

Definition at line 65 of file TreeWidget.py.

Definition at line 261 of file TreeWidget.py.

Definition at line 68 of file TreeWidget.py.

Definition at line 68 of file TreeWidget.py.


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