-
Notifications
You must be signed in to change notification settings - Fork 0
/
025_directories.py
112 lines (75 loc) · 3.08 KB
/
025_directories.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/ipy
import clr
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
from System.Windows.Forms import Application, Form, StatusBar
from System.Windows.Forms import Button, TreeView, TreeNode
from System.Windows.Forms import DockStyle, AnchorStyles
from System.Drawing import Size, Point
from System.IO import Directory, DirectoryInfo
HOME_DIR = 'D:\\'
class IForm(Form):
def __init__(self):
self.Text = 'Directories'
self.Size = Size(400, 400)
self.tv = TreeView()
self.SuspendLayout()
self.tv.Parent = self
self.tv.Location = Point(10,10)
self.tv.Size = Size(self.ClientSize.Width - 20, self.Height - 200)
self.tv.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right
self.tv.FullRowSelect = False
self.tv.ShowLines = True
self.tv.ShowPlusMinus = True
self.tv.Scrollable = True
self.tv.AfterSelect += self.AfterSelect
expand = Button()
expand.Parent = self
expand.Location = Point(20, self.tv.Bottom + 20)
expand.Text = 'Expand'
expand.Anchor = AnchorStyles.Left | AnchorStyles.Top
expand.Click += self.OnExpand
expandAll = Button()
expandAll.Parent = self
expandAll.Location = Point(20, expand.Bottom + 5)
expandAll.Text = 'Expand All'
expandAll.Anchor = AnchorStyles.Left | AnchorStyles.Top
expandAll.Click += self.OnExpandAll
collapse = Button()
collapse.Parent = self
collapse.Location = Point(expandAll.Right + 5, expand.Top)
collapse.Text = 'Collapse'
collapse.Anchor = AnchorStyles.Left | AnchorStyles.Top
collapse.Click += self.OnCollapse
collapseAll = Button()
collapseAll.Parent = self
collapseAll.Location = Point(collapse.Left, collapse.Bottom + 5)
collapseAll.Text = 'Collapse All'
collapseAll.Anchor = AnchorStyles.Left | AnchorStyles.Top
collapseAll.Click += self.OnCollapseAll
self.sb = StatusBar()
self.sb.Parent = self
self.ShowDirectories(self.tv.Nodes, HOME_DIR)
self.ResumeLayout()
self.CenterToScreen()
def AfterSelect(self, sender, event):
self.sb.Text = event.Node.Text
def ShowDirectories(self, trvNode, path):
dirInfo = DirectoryInfo(path)
if (dirInfo != None):
subDirs = dirInfo.GetDirectories()
tr = TreeNode(dirInfo.Name)
if (subDirs.Length > 0):
for dr in subDirs:
if not dr.Name.StartsWith("."):
self.ShowDirectories(tr.Nodes, dr.FullName)
trvNode.Add(tr)
def OnExpand(self, sender, event):
self.tv.SelectedNode.Expand()
def OnExpandAll(self, sender, event):
self.tv.ExpandAll()
def OnCollapse(self, sender, event):
self.tv.SelectedNode.Collapse()
def OnCollapseAll(self, sender, event):
self.tv.CollapseAll()
Application.Run(IForm())