from idlelib.TreeWidget import TreeItem
from idlelib.ClassBrowser import ClassBrowser, ModuleBrowserTreeItem
from idlelib.PyShell import PyShellFileList
class PathBrowser(ClassBrowser):
def __init__(self, flist, _htest=False):
_htest - bool, change box location when running htest
self.top.wm_title("Path Browser")
self.top.wm_iconname("Path Browser")
return PathBrowserTreeItem()
class PathBrowserTreeItem(TreeItem):
item = DirBrowserTreeItem(dir)
class DirBrowserTreeItem(TreeItem):
def __init__(self, dir, packages=[]):
return self.packages[-1] + ": package"
names = os.listdir(self.dir or os.curdir)
file = os.path.join(self.dir, name)
if self.ispackagedir(file):
nn = os.path.normcase(name)
packages.append((nn, name, file))
for nn, name, file in packages:
item = DirBrowserTreeItem(file, self.packages + [name])
for nn, name in self.listmodules(names):
item = ModuleBrowserTreeItem(os.path.join(self.dir, name))
def ispackagedir(self, file):
if not os.path.isdir(file):
init = os.path.join(file, "__init__.py")
return os.path.exists(init)
def listmodules(self, allnames):
suffixes = imp.get_suffixes()
for suff, mode, flag in suffixes:
normed_name = os.path.normcase(name)
if normed_name[i:] == suff:
if mod_name not in modules:
sorted.append((normed_name, name))
def _path_browser(parent): # htest #
flist = PyShellFileList(parent)
PathBrowser(flist, _htest=True)
if __name__ == "__main__":
from unittest import main
main('idlelib.idle_test.test_pathbrowser', verbosity=2, exit=False)
from idlelib.idle_test.htest import run