File: DirList.py

package info (click to toggle)
python 1.5.1-7
  • links: PTS
  • area: main
  • in suites: slink
  • size: 11,616 kB
  • ctags: 32,701
  • sloc: ansic: 90,293; python: 74,171; makefile: 2,449; lisp: 2,097; sh: 702
file content (58 lines) | stat: -rwxr-xr-x 1,305 bytes parent folder | download | duplicates (4)
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
# DirList -- Directory Listing widget

# XXX Displays messy paths when following '..'

import os
import stdwin, rect
from stdwinevents import *
from Buttons import PushButton
from WindowParent import WindowParent
from HVSplit import HSplit, VSplit

class DirList(VSplit):
	#
	def create(self, parent, dirname):
		self = VSplit.create(self, parent)
		names = os.listdir(dirname)
		for name in names:
			if os.path.isdir(os.path.join(dirname, name)):
				fullname = os.path.join(dirname, name)
				btn = SubdirButton().definetext(self, fullname)
			elif name[-3:] == '.py':
				btn = ModuleButton().definetext(self, name)
			else:
				btn = FileButton().definetext(self, name)
		return self
	#

class DirListWindow(WindowParent):
	#
	def create(self, dirname):
		self = WindowParent.create(self, dirname, (0, 0))
		child = DirList().create(self, dirname)
		self.realize()
		return self
	#

class SubdirButton(PushButton):
	#
	def drawpict(self, d):
		PushButton.drawpict(self, d)
		d.box(rect.inset(self.bounds, (3, 1)))
	#
	def up_trigger(self):
		window = DirListWindow().create(self.text)
	#

class FileButton(PushButton):
	#
	def up_trigger(self):
		stdwin.fleep()
	#

class ModuleButton(FileButton):
	#
	def drawpict(self, d):
		PushButton.drawpict(self, d)
		d.box(rect.inset(self.bounds, (1, 3)))
	#