diff options
author | Ignacio Rodríguez <ignaciorodriguez@sugarlabs.org> | 2013-05-05 22:24:36 (GMT) |
---|---|---|
committer | Ignacio Rodríguez <ignaciorodriguez@sugarlabs.org> | 2013-05-05 22:24:36 (GMT) |
commit | 072ad34d980168b3b88e5f619c71510ba7a57f2c (patch) | |
tree | 13adb9768331657e3366a81fbe76b6c162327b08 | |
parent | d2f8caf9757f0c0c3937ca0a43bcff7a8b5564b1 (diff) |
Vista de iconos.
-rw-r--r-- | IconView.py | 150 |
1 files changed, 22 insertions, 128 deletions
diff --git a/IconView.py b/IconView.py index 2f63a2d..70d7f10 100644 --- a/IconView.py +++ b/IconView.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# GnomExplorer.py by: +# IconView.py by: # Cristian García <cristian99garcia@gmail.com> # Ignacio Rodríguez <nachoel01@gmail.com> # Python Joven - CeibalJAM! Uruguay @@ -9,153 +9,47 @@ import os import Globales as G from gi.repository import Gtk -from gi.repository import GObject +from gi.repository import Gdk from gi.repository import GdkPixbuf class IconView(Gtk.IconView): - """Area de navegación""" - - __gsignals__ = { - 'cambio-de-direccion': (GObject.SIGNAL_RUN_FIRST, - GObject.TYPE_NONE, (GObject.TYPE_STRING,)), - 'cambio-de-mensaje': (GObject.SIGNAL_RUN_FIRST, - GObject.TYPE_NONE, (GObject.TYPE_STRING,)), - 'copiar': (GObject.SIGNAL_RUN_FIRST, - GObject.TYPE_NONE, (GObject.TYPE_STRING,)), - 'propiedades': (GObject.SIGNAL_RUN_FIRST, - GObject.TYPE_NONE, (GObject.TYPE_STRING,))} def __init__(self): - """Inicia la clase""" Gtk.IconView.__init__(self) - self.direccion = G.USUARIO - self.modelo = Gtk.ListStore(str, GdkPixbuf.Pixbuf) + self.modelo = Gtk.ListStore(str, GdkPixbuf.Pixbuf, str) - self.set_selection_mode(Gtk.SelectionMode(1)) self.set_model(self.modelo) self.set_text_column(0) self.set_pixbuf_column(1) - self.lista_carpetas = [] - self.lista_archivos = [] - - self.abrir(self.usuario) - - self.connect('button-press-event', self.click) - - def agregar(self, nombre, direccion): - """Agrega el icono de una carpeta o un archivo""" - - if not list(direccion)[-1] == '/': - direccion += '/' - - dir = direccion + nombre - - if ' ' in dir: - dir.replace(' ', '\ ') - - pixbuf = Archivos.get_pixbuf(dir) - - self.modelo.append([nombre, pixbuf]) - def borrar_area(self): - """Borra todos los objetos en el modelo""" + self.__actualizar(G.USUARIO) + def __actualizar(self, path): self.modelo.clear() - - def click(self, widget, event): - """Reacciona cuando se le hace clic, obteniendo con - que botón se le hizo clic y que debe hacer después""" - - boton = event.button - posx = event.x - posy = event.y - tiempo = event.time - - try: - path = widget.get_path_at_pos(int(posx), int(posy)) - - direccion = self.direccion - if list(direccion)[-1] != '/': - direccion += '/' - - iter = self.modelo.get_iter(path) - direccion += self.modelo.get_value(iter, 0) - - if boton == 3: - self.crear_menu_emergente(boton, tiempo, path) - return True - - if event.type.value_name == "GDK_2BUTTON_PRESS" and boton == 1: - self.emit('cambio-de-direccion', direccion) - - except TypeError: - - # Solo sucede cuando se le hace clic fuera de un iter, - # por eso lo dejo pasar - - pass - - def crear_menu_emergente(self, boton, tiempo, path): - """Crea un menú emergente desde la iter actual""" - - iter = self.modelo.get_iter(path) - nombre = self.modelo.get_value(iter, 0) - direccion = self.direccion - - if direccion[-1] != '/': - direccion += '/' - - direccion += nombre - - item = Gtk.MenuItem('') - menu = Gtk.Menu() - item.set_submenu(menu) - - abrir = Gtk.MenuItem('Abrir') - cortar = Gtk.MenuItem('Cor_tar') - copiar = Gtk.MenuItem('_Copiar') - pegar = Gtk.MenuItem('Pegar') - propiedades = Gtk.MenuItem('Proiedades') - - abrir.connect('activate', self.abrir, direccion) - copiar.connect('activate', self.copiar, direccion) - propiedades.connect('activate', self.propiedades, direccion) - - menu.append(abrir) - menu.append(Gtk.SeparatorMenuItem()) - menu.append(cortar) - menu.append(copiar) - menu.append(pegar) - menu.append(Gtk.SeparatorMenuItem()) - menu.append(propiedades) - - menu.show_all() - menu.popup(None, None, None, None, boton, tiempo) - - def abrir(self, widget, direccion): - """Abre la dirección del montaje seleccionado""" - - self.emit('cambio-de-direccion', direccion) - - def copiar(self, widget, direccion): - """Emite la señal 'copiar' con la - dirección recibida como parámetro""" - - self.emit('copiar', direccion) - - def propiedades(self, widget, direccion): - """Emite la señal 'copiar' con la - dirección recibida como parámetro""" - - self.emit('propiedades', direccion) + tema = Gtk.IconTheme.get_default() + + archivos = os.listdir(path) + archivos.sort() + for archivo in archivos: + path_nueva = os.path.join(path, archivo) + if os.path.isdir(path_nueva): + icono = tema.lookup_icon(Gtk.STOCK_DIRECTORY, + 256, + Gtk.IconLookupFlags.NO_SVG).get_filename() + else: + 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(0, [archivo, pixbuf, path_nueva]) if __name__ == "__main__": Scroll = Gtk.ScrolledWindow() Scroll.add_with_viewport(IconView()) - Scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) + Scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) Ventana = Gtk.Window() Ventana.connect("delete-event", lambda x, i: exit()) |