MCPcopy Index your code
hub / github.com/python/cpython / FileTreeItem

Class FileTreeItem

Lib/idlelib/tree.py:400–441  ·  view source on GitHub ↗

Example TreeItem subclass -- browse the file system.

Source from the content-addressed store, hash-verified

398# Example application
399
400class FileTreeItem(TreeItem):
401
402 """Example TreeItem subclass -- browse the file system."""
403
404 def __init__(self, path):
405 self.path = path
406
407 def GetText(self):
408 return os.path.basename(self.path) or self.path
409
410 def IsEditable(self):
411 return os.path.basename(self.path) != ""
412
413 def SetText(self, text):
414 newpath = os.path.dirname(self.path)
415 newpath = os.path.join(newpath, text)
416 if os.path.dirname(newpath) != os.path.dirname(self.path):
417 return
418 try:
419 os.rename(self.path, newpath)
420 self.path = newpath
421 except OSError:
422 pass
423
424 def GetIconName(self):
425 if not self.IsExpandable():
426 return "python" # XXX wish there was a "file" icon
427
428 def IsExpandable(self):
429 return os.path.isdir(self.path)
430
431 def GetSubList(self):
432 try:
433 names = os.listdir(self.path)
434 except OSError:
435 return []
436 names.sort(key = os.path.normcase)
437 sublist = []
438 for name in names:
439 item = FileTreeItem(os.path.join(self.path, name))
440 sublist.append(item)
441 return sublist
442
443
444# A canvas widget with scroll bars and some useful bindings

Callers 2

GetSubListMethod · 0.85
_tree_widgetFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…