4
# Copyright (C) 2001-2002 Jean-Baptiste LAMY -- jiba@tuxfamily
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
from editobj.treewidget import *
22
import os, os.path, sys, string, imp
23
import editobj.treewidget
25
# Gets the default icons directory (shipped with TreeWidget).
26
iconsdir = IconsDir(os.path.join(os.path.dirname(editobj.treewidget.__file__), "icons"))
29
"""Example Node subclass -- browse the file system."""
30
def __init__(self, parent, path):
32
Node.__init__(self, parent)
34
def __str__(self): return os.path.basename(self.path) or self.path
36
# One may explicitely choose the icon as following (TreeWidget use those as default) :
39
if self.isexpandable():
40
if self.expanded: return iconsdir["openfolder.pgm"]
41
else: return iconsdir["folder.pgm"]
42
else: return iconsdir["python.pgm"]
44
def iseditable(self): return os.path.basename(self.path) != ""
45
def isexpandable(self): return os.path.isdir(self.path)
46
def createchildren(self, oldchildren = None):
47
try: files = os.listdir(self.path)
48
except os.error: return []
49
files.sort(lambda a, b: cmp(os.path.normcase(a), os.path.normcase(b)))
51
for file in files: children.append(FileNode(self, os.path.join(self.path, file)))
54
def settext(self, text):
55
newpath = os.path.dirname(self.path)
56
newpath = os.path.join(newpath, text)
57
if os.path.dirname(newpath) != os.path.dirname(self.path): return
59
os.rename(self.path, newpath)
61
except os.error: print "Cannot rename !"
66
tree.frame.pack(expand=1, fill="both")
68
node = FileNode(tree, os.curdir)