-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileList.py
74 lines (54 loc) · 2.12 KB
/
fileList.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
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
import os
import rlcompleter
import pdb
from gi.repository import GtkSource
from gi.repository import Gio
pdb.Pdb.complete= rlcompleter.Completer(locals()).complete
class FileList(Gtk.TreeView):
def buttonCallback(self, path, view_column , userPar):
#pdb.Pdb.complete= rlcompleter.Completer(locals()).complete
#pdb.set_trace()
fileName = self.fileTable[view_column.to_string()]
bufferText = self.sourceViewer.get_buffer()
bufferText.set_text(open(fileName).read())
self.tabs.append_page(self.sourceViewer)
self.tabs.show()
self.sourceViewer.show()
print fileName
def __init__(self, mainDirectory, sourceViewer, tabs):
Gtk.TreeView.__init__(self)
self.tabs = tabs
fileList = Gtk.TreeStore(str)
self.sourceViewer = sourceViewer
dirHash = {}
self.fileTable = {}
for root, dirs, files in os.walk(mainDirectory, topdown = True):
print "iteration"
for name in files:
if root in dirHash:
parent = dirHash[root]
else:
parent = None
lbl = name
fileIter = fileList.append(parent,[lbl])
pathStr = fileList.get_string_from_iter(fileIter)
self.fileTable[pathStr] = os.path.join(root, name)
#print (os.path.join(root, name))
for name in dirs:
if root in dirHash:
parent = dirHash[root]
else:
parent = None
lbl = name
thisDir = fileList.append(parent,[lbl])
indexStr = os.path.join(root, name)
dirHash[indexStr] = thisDir
#print (os.path.join(root, name))
self.connect('row-activated', self.buttonCallback)
self.set_model(fileList)
renderer = Gtk.CellRendererText()
column = Gtk.TreeViewColumn("File", renderer, text=0)
self.append_column(column)