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
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# IconView.py by:
# Cristian García <cristian99garcia@gmail.com>
# Ignacio Rodríguez <nachoel01@gmail.com>
# Python Joven - CeibalJAM! Uruguay
import os
import Globales as G
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GdkPixbuf
class IconView(Gtk.IconView):
def __init__(self):
Gtk.IconView.__init__(self)
self.modelo = Gtk.ListStore(str, GdkPixbuf.Pixbuf, str)
self.set_model(self.modelo)
self.set_text_column(0)
self.set_pixbuf_column(1)
self.__actualizar(G.USUARIO)
def __actualizar(self, path):
archivos = []
carpetas = []
self.modelo.clear()
tema = Gtk.IconTheme.get_default()
contenido = os.listdir(path)
contenido.sort()
for archivo in contenido:
direccion = os.path.join(path, archivo)
if os.path.isfile(direccion):
archivos.append(archivo)
else:
carpetas.append(archivo)
carpetas.sort()
archivos.sort()
for carpeta in carpetas:
direccion = os.path.join(path, carpeta)
icono = tema.lookup_icon(Gtk.STOCK_DIRECTORY,
256,
Gtk.IconLookupFlags.NO_SVG).get_filename()
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(icono, 55, 55)
self.modelo.insert(-1, [carpeta, pixbuf, direccion])
for archivo in archivos:
direccion = os.path.join(path, archivo)
icono = tema.lookup_icon(Gtk.STOCK_FILE,
256,
Gtk.IconLookupFlags.NO_SVG).get_filename()
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(icono, 55, 55)
self.modelo.insert(-1, [archivo, pixbuf, direccion])
if __name__ == "__main__":
Scroll = Gtk.ScrolledWindow()
Scroll.add(IconView())
Scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
Ventana = Gtk.Window()
Ventana.connect("delete-event", lambda x, i: exit())
Ventana.add(Scroll)
Ventana.show_all()
Gtk.main()
|