diff options
author | Cristian Garcia <cristian99garcia@gmail.com> | 2013-05-05 21:29:55 (GMT) |
---|---|---|
committer | Cristian Garcia <cristian99garcia@gmail.com> | 2013-05-05 21:29:55 (GMT) |
commit | d2f8caf9757f0c0c3937ca0a43bcff7a8b5564b1 (patch) | |
tree | 62288ada23aa5285bd078f9efcb21b942930c72e | |
parent | dbdd554d59727102799a22b111c3cd1801662a9b (diff) |
IconView.py sin terminar
-rw-r--r-- | IconView.py | 164 |
1 files changed, 164 insertions, 0 deletions
diff --git a/IconView.py b/IconView.py new file mode 100644 index 0000000..2f63a2d --- /dev/null +++ b/IconView.py @@ -0,0 +1,164 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# GnomExplorer.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 GObject +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.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.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) + +if __name__ == "__main__": + Scroll = Gtk.ScrolledWindow() + Scroll.add_with_viewport(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() |