-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilelist.py
330 lines (303 loc) · 10.2 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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
import os, stat, time
import pygtk
pygtk.require('2.0')
import gtk
class FileListModel(gtk.GenericTreeModel):
folderxpm = [
"17 16 7 1",
" c #000000",
". c #808000",
"X c yellow",
"o c #808080",
"O c #c0c0c0",
"+ c white",
"@ c None",
"@@@@@@@@@@@@@@@@@",
"@@@@@@@@@@@@@@@@@",
"@@+XXXX.@@@@@@@@@",
"@+OOOOOO.@@@@@@@@",
"@+OXOXOXOXOXOXO. ",
"@+XOXOXOXOXOXOX. ",
"@+OXOXOXOXOXOXO. ",
"@+XOXOXOXOXOXOX. ",
"@+OXOXOXOXOXOXO. ",
"@+XOXOXOXOXOXOX. ",
"@+OXOXOXOXOXOXO. ",
"@+XOXOXOXOXOXOX. ",
"@+OOOOOOOOOOOOO. ",
"@ ",
"@@@@@@@@@@@@@@@@@",
"@@@@@@@@@@@@@@@@@"
]
folderpb = gtk.gdk.pixbuf_new_from_xpm_data(folderxpm)
filexpm = [
"12 12 3 1",
" c #000000",
". c #ffff04",
"X c #b2c0dc",
"X XXX",
"X ...... XXX",
"X ...... X",
"X . ... X",
"X ........ X",
"X . .... X",
"X ........ X",
"X . .. X",
"X ........ X",
"X . .. X",
"X ........ X",
"X X"
]
filepb = gtk.gdk.pixbuf_new_from_xpm_data(filexpm)
newxpm = [
"12 12 5 1",
" c #000000",
". c #ffff04",
"X c #b2c0dc",
"g c green",
"w c white",
"X gg gg",
"X ....gg gg",
"X .... ",
"X . . ",
"X ....gg gg",
"X . gg gg",
"X ........ X",
"X . .. X",
"X ........ X",
"X . .. X",
"X ........ X",
"X X"
]
newpb = gtk.gdk.pixbuf_new_from_xpm_data(newxpm)
renamedxpm = [
"12 12 4 1",
" c #000000",
". c #ffff04",
"X c #b2c0dc",
"o c #ff6600",
"X oooooo",
"X ....oooooo",
"X ....oooooo",
"X . oooooo",
"X ....oooooo",
"X . oooooo",
"X ........ X",
"X . .. X",
"X ........ X",
"X . .. X",
"X ........ X",
"X X"
]
renamedpb = gtk.gdk.pixbuf_new_from_xpm_data(renamedxpm)
changedxpm = [
"12 12 5 1",
" c #000000",
". c #ffff04",
"X c #b2c0dc",
"g c #00ff00",
"h c #33ff00",
"X ghghgh",
"X ....hghghg",
"X ....ghghgh",
"X . hghghg",
"X ....ghghgh",
"X . hghghg",
"X ........ X",
"X . .. X",
"X ........ X",
"X . .. X",
"X ........ X",
"X X"
]
changedpb = gtk.gdk.pixbuf_new_from_xpm_data(changedxpm)
column_types = (gtk.gdk.Pixbuf, str, str, str)
column_names = ['Name', 'Status', 'Last Changed']
def __init__(self,globalclass, dname=None, root=False, rootpath=None):
gtk.GenericTreeModel.__init__(self)
self.globalclass = globalclass
self.changed = []
self.renamed = []
self.newfiles = []
if self.globalclass.gitisactive:
for x in globalclass.Repo.index.diff(None):
fullpath = globalclass.Repo.working_dir+"/"+x.a_blob.path
if x.renamed:
fullpath = globalclass.Repo.working_dir+"/"+x.renamed_to
self.renamed.append(fullpath)
elif x.new_file:
self.newfiles.append(fullpath)
else:
self.changed.append(fullpath)
for x in globalclass.Repo.untracked_files:
fullpath = globalclass.Repo.working_dir+"/"+x
self.newfiles.append(fullpath)
if not dname:
self.dirname = os.path.expanduser('~')
else:
self.dirname = os.path.abspath(dname)
self.dirsfiles = [f for f in os.listdir(self.dirname) if f[0] <> '.']
self.dirsfiles.sort(key=str.lower)
self.files = []
self.dirs = []
for x in self.dirsfiles:
fname = os.path.join(self.dirname, x)
try:
filestat = os.stat(fname)
except OSError:
return None
mode = filestat.st_mode
if stat.S_ISDIR(mode):
self.dirs.append(x)
else:
self.files.append(x)
if root:
self.files = self.dirs + self.files
self.rootpath = self.dirname
else:
self.files = ['..'] + self.dirs + self.files
self.rootpath = rootpath
return
def get_pathname(self, path):
filename = self.files[path[0]]
return os.path.join(self.dirname, filename)
def is_folder(self, path):
filename = self.files[path[0]]
pathname = os.path.join(self.dirname, filename)
filestat = os.stat(pathname)
if stat.S_ISDIR(filestat.st_mode):
return True
return False
def get_column_names(self):
return self.column_names[:]
def on_get_flags(self):
return gtk.TREE_MODEL_LIST_ONLY|gtk.TREE_MODEL_ITERS_PERSIST
def on_get_n_columns(self):
return len(self.column_types)
def on_get_column_type(self, n):
return self.column_types[n]
def on_get_iter(self, path):
return self.files[path[0]]
def on_get_path(self, rowref):
return self.files.index(rowref)
def on_get_value(self, rowref, column):
fname = os.path.join(self.dirname, rowref)
try:
filestat = os.stat(fname)
except OSError:
return None
mode = filestat.st_mode
if column is 0:
if stat.S_ISDIR(mode):
return self.folderpb
elif fname in self.changed:
return self.changedpb
elif fname in self.newfiles:
return self.newpb
elif fname in self.renamed:
return self.renamedpb
else:
return self.filepb
elif column is 1:
return rowref
elif column is 2:
if stat.S_ISDIR(mode):
return ""
elif fname in self.changed:
return "File Has Changed"
elif fname in self.newfiles:
return "New File"
elif fname in self.renamed:
return "Renamed"
else:
return "Unchanged"
return time.ctime(filestat.st_mtime)
def on_iter_next(self, rowref):
try:
i = self.files.index(rowref)+1
return self.files[i]
except IndexError:
return None
def on_iter_children(self, rowref):
if rowref:
return None
return self.files[0]
def on_iter_has_child(self, rowref):
return False
def on_iter_n_children(self, rowref):
if rowref:
return 0
return len(self.files)
def on_iter_nth_child(self, rowref, n):
if rowref:
return None
try:
return self.files[n]
except IndexError:
return None
def on_iter_parent(child):
return None
class FileList:
def __init__(self,dirname,globalclass):
self.globalclass = globalclass
self.listmodel = FileListModel(globalclass,dirname,True,None)
# create the TreeView
self.treeview = gtk.TreeView()
treeselection = self.treeview.get_selection()
treeselection.set_mode(gtk.SELECTION_SINGLE)
# create the TreeViewColumns to display the data
column_names = self.listmodel.get_column_names()
self.tvcolumn = [None] * len(column_names)
cellpb = gtk.CellRendererPixbuf()
self.tvcolumn[0] = gtk.TreeViewColumn(column_names[0],
cellpb, pixbuf=0)
cell = gtk.CellRendererText()
self.tvcolumn[0].pack_start(cell, False)
self.tvcolumn[0].add_attribute(cell, 'text', 1)
self.treeview.append_column(self.tvcolumn[0])
for n in range(1, len(column_names)):
cell = gtk.CellRendererText()
if n == 1:
cell.set_property('xalign', 1.0)
self.tvcolumn[n] = gtk.TreeViewColumn(column_names[n],
cell, text=n+1)
self.treeview.append_column(self.tvcolumn[n])
self.treeview.connect('row-activated', self.open_file)
self.treeview.connect('cursor-changed', self.change_cursor)
self.treeview.set_model(self.listmodel)
return
def open_file(self, treeview, path, column):
model = treeview.get_model()
if model.is_folder(path):
pathname = model.get_pathname(path)
if os.path.exists(pathname+'/.git'):
self.globalclass.btnInit.set_sensitive(False)
else:
self.globalclass.btnInit.set_sensitive(True)
if os.path.abspath(pathname) == os.path.abspath(model.rootpath):
new_model = FileListModel(self.globalclass,pathname,True,None)
else:
new_model = FileListModel(self.globalclass,pathname,False,model.rootpath)
treeview.set_model(new_model)
self.globalclass.parent.window.set_title("TheProject - " + os.path.abspath(pathname))
return
def change_cursor(self, treeview):
model = treeview.get_model()
self.currpath = model.get_pathname(treeview.get_cursor()[0])
print self.currpath
if self.globalclass.gitisactive:
workdir = self.globalclass.Repo.working_dir + '/'
self.gitpath = self.currpath.replace(workdir,'')
filestat = os.stat(self.currpath)
if stat.S_ISDIR(filestat.st_mode):
self.globalclass.btnAdd.set_sensitive(False)
self.globalclass.btnRemove.set_sensitive(False)
else:
print self.gitpath
if self.globalclass.Repo.index.entries.has_key((self.gitpath, 0)):
self.globalclass.btnAdd.set_sensitive(False)
self.globalclass.btnRemove.set_sensitive(True)
else:
self.globalclass.btnAdd.set_sensitive(True)
self.globalclass.btnRemove.set_sensitive(False)
return