$71 GRAYBYTE WORDPRESS FILE MANAGER $94

SERVER : premium201.web-hosting.com #1 SMP Wed Mar 26 12:08:09 UTC 2025
SERVER IP : 172.67.217.254 | ADMIN IP 216.73.216.180
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : mail

/opt/alt/python34/lib64/python3.4/idlelib/

HOME
Current File : /opt/alt/python34/lib64/python3.4/idlelib//ClassBrowser.py
"""Class browser.

XXX TO DO:

- reparse when source changed (maybe just a button would be OK?)
    (or recheck on window popup)
- add popup menu with more options (e.g. doc strings, base classes, imports)
- show function argument list? (have to do pattern matching on source)
- should the classes and methods lists also be in the module's menu bar?
- add base classes to class browser tree
"""

import os
import sys
import pyclbr

from idlelib import PyShell
from idlelib.WindowList import ListedToplevel
from idlelib.TreeWidget import TreeNode, TreeItem, ScrolledCanvas
from idlelib.configHandler import idleConf

file_open = None  # Method...Item and Class...Item use this.
# Normally PyShell.flist.open, but there is no PyShell.flist for htest.

class ClassBrowser:

    def __init__(self, flist, name, path, _htest=False):
        # XXX This API should change, if the file doesn't end in ".py"
        # XXX the code here is bogus!
        """
        _htest - bool, change box when location running htest.
        """
        global file_open
        if not _htest:
            file_open = PyShell.flist.open
        self.name = name
        self.file = os.path.join(path[0], self.name + ".py")
        self._htest = _htest
        self.init(flist)

    def close(self, event=None):
        self.top.destroy()
        self.node.destroy()

    def init(self, flist):
        self.flist = flist
        # reset pyclbr
        pyclbr._modules.clear()
        # create top
        self.top = top = ListedToplevel(flist.root)
        top.protocol("WM_DELETE_WINDOW", self.close)
        top.bind("<Escape>", self.close)
        if self._htest: # place dialog below parent if running htest
            top.geometry("+%d+%d" %
                (flist.root.winfo_rootx(), flist.root.winfo_rooty() + 200))
        self.settitle()
        top.focus_set()
        # create scrolled canvas
        theme = idleConf.CurrentTheme()
        background = idleConf.GetHighlight(theme, 'normal')['background']
        sc = ScrolledCanvas(top, bg=background, highlightthickness=0, takefocus=1)
        sc.frame.pack(expand=1, fill="both")
        item = self.rootnode()
        self.node = node = TreeNode(sc.canvas, None, item)
        node.update()
        node.expand()

    def settitle(self):
        self.top.wm_title("Class Browser - " + self.name)
        self.top.wm_iconname("Class Browser")

    def rootnode(self):
        return ModuleBrowserTreeItem(self.file)

class ModuleBrowserTreeItem(TreeItem):

    def __init__(self, file):
        self.file = file

    def GetText(self):
        return os.path.basename(self.file)

    def GetIconName(self):
        return "python"

    def GetSubList(self):
        sublist = []
        for name in self.listclasses():
            item = ClassBrowserTreeItem(name, self.classes, self.file)
            sublist.append(item)
        return sublist

    def OnDoubleClick(self):
        if os.path.normcase(self.file[-3:]) != ".py":
            return
        if not os.path.exists(self.file):
            return
        PyShell.flist.open(self.file)

    def IsExpandable(self):
        return os.path.normcase(self.file[-3:]) == ".py"

    def listclasses(self):
        dir, file = os.path.split(self.file)
        name, ext = os.path.splitext(file)
        if os.path.normcase(ext) != ".py":
            return []
        try:
            dict = pyclbr.readmodule_ex(name, [dir] + sys.path)
        except ImportError:
            return []
        items = []
        self.classes = {}
        for key, cl in dict.items():
            if cl.module == name:
                s = key
                if hasattr(cl, 'super') and cl.super:
                    supers = []
                    for sup in cl.super:
                        if type(sup) is type(''):
                            sname = sup
                        else:
                            sname = sup.name
                            if sup.module != cl.module:
                                sname = "%s.%s" % (sup.module, sname)
                        supers.append(sname)
                    s = s + "(%s)" % ", ".join(supers)
                items.append((cl.lineno, s))
                self.classes[s] = cl
        items.sort()
        list = []
        for item, s in items:
            list.append(s)
        return list

class ClassBrowserTreeItem(TreeItem):

    def __init__(self, name, classes, file):
        self.name = name
        self.classes = classes
        self.file = file
        try:
            self.cl = self.classes[self.name]
        except (IndexError, KeyError):
            self.cl = None
        self.isfunction = isinstance(self.cl, pyclbr.Function)

    def GetText(self):
        if self.isfunction:
            return "def " + self.name + "(...)"
        else:
            return "class " + self.name

    def GetIconName(self):
        if self.isfunction:
            return "python"
        else:
            return "folder"

    def IsExpandable(self):
        if self.cl:
            try:
                return not not self.cl.methods
            except AttributeError:
                return False

    def GetSubList(self):
        if not self.cl:
            return []
        sublist = []
        for name in self.listmethods():
            item = MethodBrowserTreeItem(name, self.cl, self.file)
            sublist.append(item)
        return sublist

    def OnDoubleClick(self):
        if not os.path.exists(self.file):
            return
        edit = file_open(self.file)
        if hasattr(self.cl, 'lineno'):
            lineno = self.cl.lineno
            edit.gotoline(lineno)

    def listmethods(self):
        if not self.cl:
            return []
        items = []
        for name, lineno in self.cl.methods.items():
            items.append((lineno, name))
        items.sort()
        list = []
        for item, name in items:
            list.append(name)
        return list

class MethodBrowserTreeItem(TreeItem):

    def __init__(self, name, cl, file):
        self.name = name
        self.cl = cl
        self.file = file

    def GetText(self):
        return "def " + self.name + "(...)"

    def GetIconName(self):
        return "python" # XXX

    def IsExpandable(self):
        return 0

    def OnDoubleClick(self):
        if not os.path.exists(self.file):
            return
        edit = file_open(self.file)
        edit.gotoline(self.cl.methods[self.name])

def _class_browser(parent): #Wrapper for htest
    try:
        file = __file__
    except NameError:
        file = sys.argv[0]
        if sys.argv[1:]:
            file = sys.argv[1]
        else:
            file = sys.argv[0]
    dir, file = os.path.split(file)
    name = os.path.splitext(file)[0]
    flist = PyShell.PyShellFileList(parent)
    global file_open
    file_open = flist.open
    ClassBrowser(flist, name, [dir], _htest=True)

if __name__ == "__main__":
    from idlelib.idle_test.htest import run
    run(_class_browser)


Current_dir [ NOT WRITEABLE ] Document_root [ NOT WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
24 May 2024 8.33 AM
root / linksafe
0755
Icons
--
24 May 2024 8.33 AM
root / linksafe
0755
__pycache__
--
24 May 2024 8.33 AM
root / linksafe
0755
idle_test
--
24 May 2024 8.33 AM
root / linksafe
0755
AutoComplete.py
8.986 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
AutoCompleteWindow.py
17.323 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
AutoExpand.py
3.315 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
Bindings.py
2.975 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
CREDITS.txt
1.821 KB
18 Mar 2019 4.51 PM
root / linksafe
0644
CallTipWindow.py
5.893 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
CallTips.py
5.793 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
ChangeLog
55.071 KB
18 Mar 2019 4.51 PM
root / linksafe
0644
ClassBrowser.py
6.835 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
CodeContext.py
8.152 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
ColorDelegator.py
9.468 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
Debugger.py
18.319 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
Delegator.py
0.649 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
EditorWindow.py
64.511 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
FileList.py
3.724 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
FormatParagraph.py
7.116 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
GrepDialog.py
5.004 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
HISTORY.txt
10.075 KB
18 Mar 2019 4.51 PM
root / linksafe
0644
HyperParser.py
12.575 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
IOBinding.py
19.31 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
IdleHistory.py
3.957 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
MultiCall.py
18.136 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
MultiStatusBar.py
1.316 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
NEWS.txt
38.901 KB
18 Mar 2019 4.51 PM
root / linksafe
0644
ObjectBrowser.py
3.882 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
OutputWindow.py
4.291 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
ParenMatch.py
6.556 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
PathBrowser.py
3.132 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
Percolator.py
3.168 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
PyParse.py
19.981 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
PyShell.py
57.08 KB
17 Apr 2024 5.09 PM
root / linksafe
0755
README.txt
7.528 KB
18 Mar 2019 4.51 PM
root / linksafe
0644
RemoteDebugger.py
11.726 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
RemoteObjectBrowser.py
0.941 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
ReplaceDialog.py
6.484 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
RstripExtension.py
1.025 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
ScriptBinding.py
7.872 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
ScrolledList.py
4.272 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
SearchDialog.py
2.568 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
SearchDialogBase.py
6.845 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
SearchEngine.py
7.31 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
StackViewer.py
4.322 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
TODO.txt
8.279 KB
18 Mar 2019 4.51 PM
root / linksafe
0644
ToolTip.py
3.099 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
TreeWidget.py
14.672 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
UndoDelegator.py
10.562 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
WidgetRedirector.py
6.708 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
WindowList.py
2.414 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
ZoomHeight.py
1.27 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
__init__.py
0.281 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
__main__.py
0.155 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
aboutDialog.py
6.531 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
config-extensions.def
2.896 KB
18 Mar 2019 4.51 PM
root / linksafe
0644
config-highlight.def
2.456 KB
18 Mar 2019 4.51 PM
root / linksafe
0644
config-keys.def
7.595 KB
18 Mar 2019 4.51 PM
root / linksafe
0644
config-main.def
2.503 KB
18 Mar 2019 4.51 PM
root / linksafe
0644
configDialog.py
62.798 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
configHandler.py
31.442 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
configHelpSourceEdit.py
6.514 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
configSectionNameDialog.py
3.913 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
dynOptionMenuWidget.py
1.943 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
extend.txt
3.557 KB
18 Mar 2019 4.51 PM
root / linksafe
0644
help.html
40.162 KB
18 Mar 2019 4.51 PM
root / linksafe
0644
help.py
9.474 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
help.txt
17.48 KB
18 Mar 2019 4.51 PM
root / linksafe
0644
idle.py
0.391 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
idle.pyw
0.557 KB
18 Mar 2019 4.51 PM
root / linksafe
0644
idlever.py
0.405 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
keybindingDialog.py
12.125 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
macosxSupport.py
8.48 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
rpc.py
20.295 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
run.py
13.353 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
tabbedpages.py
17.986 KB
17 Apr 2024 5.09 PM
root / linksafe
0644
textView.py
3.149 KB
17 Apr 2024 5.09 PM
root / linksafe
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2025 CONTACT ME
Static GIF