-
Notifications
You must be signed in to change notification settings - Fork 0
/
FilesWindow.py
159 lines (122 loc) · 5.6 KB
/
FilesWindow.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
#!/usr/bin/env python
# -*- coding: cp1250 -*-
import os, stat, time
import pygtk
import gtk
import Graphics
import ChosenFile
FolderIcon, FileIcon = Graphics.FolderIcon, Graphics.FileIcon
class FilesWindow(gtk.Window):
chosenFilePath = ''
def __init__(self, dname = None, path_to_file = None):
super(FilesWindow, self).__init__()
self.set_default_size(400, 600)
self.set_position(gtk.WIN_POS_CENTER)
"""nazwy kolumn"""
column_names = ['Name', 'Size', 'Mode', 'Last Changed']
self.connect("destroy", gtk.main_quit)
"""tworzy okno plików"""
treeview = gtk.TreeView()
listmodel = self.make_list(dname)
"""tworzy kolumny. cell_data_func pomija pierwsz¹ kolumnê."""
cell_data_funcs = (None, self.file_size, self.file_mode, self.file_last_changed)
tvcolumn = [None] * len(column_names)
"""pierwsza kolumna. dodanie nazwy kolumny i ikonek w tej kolumnie"""
cellpb = gtk.CellRendererPixbuf()
tvcolumn[0] = gtk.TreeViewColumn(column_names[0], cellpb)
tvcolumn[0].set_cell_data_func(cellpb, self.file_pixbuf)
"""pierwsza kolumna. dodanie nazwy plików"""
cell = gtk.CellRendererText()
tvcolumn[0].pack_start(cell, False)
tvcolumn[0].set_cell_data_func(cell, self.file_name)
treeview.append_column(tvcolumn[0])
"""dodawanie nazw kolumn. dodaje do ka¿dego pliku/pozycji rozmiar, kod dostêpu pliku, ostatni¹ zmianê w pliku."""
for n in range(1, len(column_names)):
cell = gtk.CellRendererText()
tvcolumn[n] = gtk.TreeViewColumn(column_names[n], cell)
if n == 1:
cell.set_property('xalign', 1.0)
tvcolumn[n].set_cell_data_func(cell, cell_data_funcs[n])
treeview.append_column(tvcolumn[n])
"""funkcyjnoœæ okienka po podwójnym klikniêciu. zahaszowane linie s¹ jeszcze do dopracowania"""
treeview.connect("row-activated", self.open_file)
treeview.set_model(listmodel)
"""umieszczenie okna plików w przewijanym okienku"""
sw=gtk.ScrolledWindow()
sw.add(treeview)
self.add(sw)
self.show_all()
return
def make_list(self, dname=None):
"""zwraca pe³n¹ listê plików z wybranej œcie¿ki"""
if not dname:
"""zwraca user home directory, czyli Documents and Settings/IBM"""
self.dirname = os.path.expanduser('~')
else:
"""zwraca bie¿¹c¹ œcie¿ke, chyba do folderu z plikiem"""
self.dirname = os.path.abspath(dname)
"""wyœwitla œcie¿kê w nag³ówku okienka"""
#self.set_title(self.dirname)
"""exploring the path. zahaszowane to eksperymenty"""
files = [f for f in os.listdir(self.dirname) if f[0] <> '.']
#files.sort()
files = ['..'] + files
listmodel = gtk.ListStore(object)
for f in files:
listmodel.append([f])
return listmodel
def open_file(self, treeview, path, column):
"""zwraca powi¹zany model, czyli treeview od gtk.TreeView"""
model = treeview.get_model()
"""nie mam pojêcia co to robi"""
iter = model.get_iter(path)
filename = os.path.join(self.dirname, model.get_value(iter, 0))
self.path_to_file = filename
FilesWindow.chosenFilePath = filename
self.set_title(filename)
filestat = os.stat(filename)
if stat.S_ISDIR(filestat.st_mode):
new_model = self.make_list(filename)
treeview.set_model(new_model)
if filestat.st_size > 0 :
potwierdz_plik = ChosenFile.ChosenFile(filename)
return
def file_pixbuf(self, column, cell, model, iter):
"""dobiera ikonki dla plików. sk¹d iter?"""
"""pobiera nazwe pliku z pierwszej kolumny i ³¹czy go ze œcie¿k¹"""
filename = os.path.join(self.dirname, model.get_value(iter, 0))
"""zwraca ca³¹ liste stat() dla pliku"""
filestat = os.stat(filename)
"""dobiera ikonki dla folder/plik"""
if stat.S_ISDIR(filestat.st_mode):
pb = FolderIcon
else:
pb = FileIcon
cell.set_property('pixbuf', pb)
return
def file_name(self, column, cell, model, iter):
"""'text' - text to render. """
cell.set_property('text', model.get_value(iter, 0))
return
def file_size(self, column, cell, model, iter):
"""zwraca rozmiar pliku"""
filename = os.path.join(self.dirname, model.get_value(iter, 0))
filestat = os.stat(filename)
"""wyœwietla rozmiar pliku"""
cell.set_property('text', filestat.st_size)
return
def file_mode(self, column, cell, model, iter):
"""zwraca file system permision numeric notation"""
filename = os.path.join(self.dirname, model.get_value(iter, 0))
filestat = os.stat(filename)
cell.set_property('text', oct(stat.S_IMODE(filestat.st_mode)))
return
def file_last_changed(self, column, cell, model, iter):
"""zwraca czas ostaniej zmiany w pliku"""
filename = os.path.join(self.dirname, model.get_value(iter, 0))
filestat = os.stat(filename)
"""zamienia sekundy na standardowy format jako True. 'text' to specyfikacja, domyœlnie None. """
cell.set_property('text', time.ctime(filestat.st_mtime))
def launch():
FilesWindow()
gtk.main()