def __init__(self, path): Gtk.EventBox.__init__(self) self.path = path # Directorio base_box = Gtk.VBox() self.toolbar = ToolbarPreviews(path) self.iconview = IconView(path) self.toolbartry = ToolbarTry() base_box.pack_start(self.toolbar, False, False, 0) scroll = Gtk.ScrolledWindow() scroll.set_policy( Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) scroll.add_with_viewport(self.iconview) base_box.pack_start(scroll, True, True, 0) base_box.pack_end(self.toolbartry, False, False, 0) self.add(base_box) self.show_all() self.iconview.connect('switch_to', self.__emit_switch) self.toolbar.connect('camara', self.__emit_camara) self.toolbar.connect('switch_to', self.__emit_switch) self.toolbar.connect('salir', self.__salir) self.toolbar.connect('open', self.__emit_switch) ### Activar botón atras solo si no se está en home del usuario. if os.path.dirname(self.path) == os.path.dirname(os.environ["HOME"]): self.toolbar.hide_button_back() self.connect("motion-notify-event", self.__do_motion_notify_event) self.iconview.connect('motion', self.__do_motion_notify_event) self.iconview.connect("button-press-event", self.__click_derecho_en_lista)
class Previews (Gtk.EventBox): """ Vista Preview de directorios con imágenes y albumes. """ __gtype_name__ = 'JAMediaImagenesPreviews' __gsignals__ = { 'salir': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, []), 'switch_to': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, (GObject.TYPE_STRING,)), 'camara': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, [])} def __init__(self, path): Gtk.EventBox.__init__(self) self.path = path # Directorio base_box = Gtk.VBox() self.toolbar = ToolbarPreviews(path) self.iconview = IconView(path) self.toolbartry = ToolbarTry() base_box.pack_start(self.toolbar, False, False, 0) scroll = Gtk.ScrolledWindow() scroll.set_policy( Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) scroll.add_with_viewport(self.iconview) base_box.pack_start(scroll, True, True, 0) base_box.pack_end(self.toolbartry, False, False, 0) self.add(base_box) self.show_all() self.iconview.connect('switch_to', self.__emit_switch) self.toolbar.connect('camara', self.__emit_camara) self.toolbar.connect('switch_to', self.__emit_switch) self.toolbar.connect('salir', self.__salir) self.toolbar.connect('open', self.__emit_switch) ### Activar botón atras solo si no se está en home del usuario. if os.path.dirname(self.path) == os.path.dirname(os.environ["HOME"]): self.toolbar.hide_button_back() self.connect("motion-notify-event", self.__do_motion_notify_event) self.iconview.connect('motion', self.__do_motion_notify_event) self.iconview.connect("button-press-event", self.__click_derecho_en_lista) def __click_derecho_en_lista(self, widget, event): """ Esto es para abrir un menu de opciones cuando el usuario hace click derecho sobre un elemento en la lista de imágenes, permitiendo copiar, mover y borrar el archivo o simplemente quitarlo de la lista. """ boton = event.button pos = (event.x, event.y) tiempo = event.time if boton == 1: return elif boton == 3: path = widget.get_path_at_pos( int(pos[0]), int(pos[1])) #iter = widget.get_model().get_iter(path) from Widgets import MenuList menu = MenuList( widget, boton, pos, tiempo, path, widget.get_model(), self.path) menu.connect('accion', self.__set_menu_accion) menu.popup(None, None, None, None, boton, tiempo) elif boton == 2: return def __set_menu_accion(self, widget, widget_item, accion, iter, file_path): if accion == "Quitar": widget_item.get_model().remove(iter) elif accion == "Borrar": from JAMediaObjects.JAMFileSystem import borrar widget_item.get_model().remove(iter) borrar(file_path) elif accion == "Copiar": from Globales import get_imagenes_directory from JAMediaObjects.JAMFileSystem import copiar copiar(file_path, get_imagenes_directory()) elif accion == "Mover": from Globales import get_imagenes_directory from JAMediaObjects.JAMFileSystem import mover widget_item.get_model().remove(iter) mover(file_path, get_imagenes_directory()) def __do_motion_notify_event(self, widget, event): """ Cuando se mueve el mouse sobre la ventana se muestran u ocultan las toolbars. """ rect = self.toolbar.get_allocation() arriba = range(0, rect.height) root_rect = self.get_toplevel().get_allocation() rect = self.toolbartry.get_allocation() abajo = range(root_rect.height - rect.height, root_rect.height) x, y = self.get_toplevel().get_pointer() if y in arriba or y in abajo: self.toolbar.show() self.toolbartry.show() return else: self.toolbar.hide() self.toolbartry.hide() return def __emit_camara(self, widget): self.emit("camara") def __emit_switch(self, widget, path): self.emit("switch_to", path) def __salir(self, widget): self.emit("salir") def run(self): self.iconview.load_previews(self.path) self.toolbartry.set_info("Directorio: %s" % self.path)