Exemple #1
0
    def __init__(self):

        gtk.TreeView.__init__(
            self,
            gtk.ListStore(gtk.gdk.Pixbuf, gobject.TYPE_STRING,
                          gobject.TYPE_STRING))

        self.modify_bg(0, gtk.gdk.color_parse("#e3f2f2"))

        self.set_property("rules-hint", True)
        self.set_headers_clickable(False)
        self.set_headers_visible(False)

        self.dir_select = None
        self.demonio_unidades = DeviceManager()

        self.__setear_columnas()
        self.__Llenar_ListStore()

        self.connect("button-press-event", self.__handler_click)
        self.show_all()
        self.demonio_unidades.connect('update', self.__update_unidades)
        gobject.idle_add(self.select_home)
Exemple #2
0
    def __init__(self):

        gtk.TreeView.__init__(self,
            gtk.ListStore(gtk.gdk.Pixbuf,
            gobject.TYPE_STRING, gobject.TYPE_STRING))

        self.modify_bg(0, gtk.gdk.color_parse("#e3f2f2"))

        self.set_property("rules-hint", True)
        self.set_headers_clickable(False)
        self.set_headers_visible(False)

        self.dir_select = None
        self.demonio_unidades = DeviceManager()

        self.__setear_columnas()
        self.__Llenar_ListStore()

        self.connect("button-press-event", self.__handler_click)
        self.show_all()
        self.demonio_unidades.connect('update', self.__update_unidades)
        gobject.idle_add(self.select_home)
Exemple #3
0
class Unidades(gtk.TreeView):
    """
    Treview para unidades y directorios.
    """

    __gsignals__ = {
    "leer": (gobject.SIGNAL_RUN_LAST,
        gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, )),
    "add-leer": (gobject.SIGNAL_RUN_LAST,
        gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, )),
    "info": (gobject.SIGNAL_RUN_LAST,
        gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, )),
    "remove_explorers": (gobject.SIGNAL_RUN_LAST,
        gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, ))}

    def __init__(self):

        gtk.TreeView.__init__(self,
            gtk.ListStore(gtk.gdk.Pixbuf,
            gobject.TYPE_STRING, gobject.TYPE_STRING))

        self.modify_bg(0, gtk.gdk.color_parse("#e3f2f2"))

        self.set_property("rules-hint", True)
        self.set_headers_clickable(False)
        self.set_headers_visible(False)

        self.dir_select = None
        self.demonio_unidades = DeviceManager()

        self.__setear_columnas()
        self.__Llenar_ListStore()

        self.connect("button-press-event", self.__handler_click)
        self.show_all()
        self.demonio_unidades.connect('update', self.__update_unidades)
        gobject.idle_add(self.select_home)

    def __handler_click(self, widget, event):
        boton = event.button
        pos = (event.x, event.y)
        tiempo = event.time
        path, columna, xdefondo, ydefondo = (None, None, None, None)
        try:
            path, columna, xdefondo, ydefondo = widget.get_path_at_pos(
                int(pos[0]), int(pos[1]))
        except:
            return
        if boton == 1:
            iter_ = self.get_model().get_iter(path)
            directorio = self.get_model().get_value(iter_, 2)
            self.dir_select = directorio
            self.emit('leer', self.dir_select)
            self.emit('info', self.dir_select)
            return
        elif boton == 3:
            menu = MenuListUnidades(
                widget, boton, pos, tiempo, path, self.get_model())
            menu.connect('accion', self.__get_accion)
            gtk.Menu.popup(menu, None, None, None, boton, tiempo)
        elif boton == 2:
            return

    def __get_accion(self, widget, path, accion):
        notebookdirectorios = self.get_parent().get_parent(
            ).notebookdirectorios
        iter_ = self.get_model().get_iter(path)
        direccion = self.get_model().get_value(iter_, 2)
        if accion == "Abrir":
            self.dir_select = direccion
            self.emit('add-leer', self.dir_select)
            self.emit('info', self.dir_select)
        elif accion == "Pegar":
            if notebookdirectorios.copiando:
                oldpath = notebookdirectorios.copiando
                if copiar(oldpath, direccion):
                    print "Copiado:", oldpath,"En:", direccion
            elif notebookdirectorios.cortando:
                oldpath = notebookdirectorios.cortando[0]
                if mover(oldpath, direccion):
                    print "Movido:", oldpath,"A:", direccion
                # FIXME: mover y actualizar notebookdirectorios
                #if mover(dire, direccion):
                #    widget.collapse_row(path)
                #    widget.expand_to_path(path)
            notebookdirectorios.cortando = False
            self.dir_select = direccion
            self.emit('leer', self.dir_select)
            self.emit('info', self.dir_select)

    def __update_unidades(self, widget):
        """
        Cuando se Conecta o Desconecta una Unidad.
        """
        unidades = self.demonio_unidades.get_unidades()
        lista = {}
        for unidad in unidades.keys():
            dic = unidades.get(unidad, False)
            if dic:
                mount_path = dic.get('mount_path', "")
                lista[mount_path.split("/")[-1]] = mount_path
        gobject.timeout_add(1000, self.__update_unidades2, lista)

    def __update_unidades2(self, lista):
        """
        Actualizar lista de unidades.
        """
        model = self.get_model()
        item = model.get_iter_first()
        mounts = []
        remove_explorers = []
        while item:
            # Remover Unidades desmontadas.
            item_remove = False
            if not os.path.exists(model.get_value(item, 2)):
                remove_explorers.append(model.get_value(item, 2))
                item_remove = item
            else:
                mounts.append(model.get_value(item, 1))
            item = model.iter_next(item)
            if item_remove:
                model.remove(item_remove)
        for it in lista.keys():
            # Agregar Unidades nuevas.
            if not it in mounts:
                icono = os.path.join(ICONOS, "drive-removable-media-usb.svg")
                pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icono, 30, -1)
                model.append([pixbuf, it, lista[it]])
        if remove_explorers:
            self.emit('remove_explorers', remove_explorers)
        return False

    def __setear_columnas(self):
        self.append_column(self.__construir_columa_icono('Icono', 0, True))
        self.append_column(self.__construir_columa('Nombre', 1, True))
        self.append_column(self.__construir_columa('Directorio', 2, False))

    def __construir_columa(self, text, index, visible):
        render = gtk.CellRendererText()
        column = gtk.TreeViewColumn(text, render, text=index)
        column.set_sort_column_id(index)
        column.set_property('visible', visible)
        return column

    def __construir_columa_icono(self, text, index, visible):
        render = gtk.CellRendererPixbuf()
        column = gtk.TreeViewColumn(text, render, pixbuf=index)
        column.set_property('visible', visible)
        return column

    def __Llenar_ListStore(self):
        self.get_toplevel().set_sensitive(False)

        icono = os.path.join(ICONOS, "def.svg")
        pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icono, 30, -1)
        self.get_model().append([pixbuf, 'Raiz', ROOT])

        icono = os.path.join(ICONOS, "stock-home.svg")
        pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icono, 30, -1)
        self.get_model().append([pixbuf, commands.getoutput('whoami'), HOME])

        if describe_uri(ACTIVITIES):
            icono = os.path.join(ICONOS, "stock-home.svg")
            pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icono, 30, -1)
            self.get_model().append([pixbuf, 'Actividades', ACTIVITIES])

        if describe_uri(JAMEDIA):
            icono = os.path.join(ICONOS, "JAMedia.svg")
            pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icono, 30, -1)
            self.get_model().append([pixbuf, 'JAMediaDatos', JAMEDIA])

        if describe_uri(DIARIO):
            icono = os.path.join(ICONOS, "diario.svg")
            pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icono, 30, -1)
            self.get_model().append([pixbuf, 'Diario', DIARIO])

        if describe_uri(LOGS):
            icono = os.path.join(ICONOS, "diario.svg")
            pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icono, 30, -1)
            self.get_model().append([pixbuf, 'Logs', LOGS])

        icono = os.path.join(ICONOS, "drive-removable-media-usb.svg")
        pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icono, 30, -1)

        unidades = self.demonio_unidades.get_unidades()
        for unidad in unidades.keys():
            dic = unidades.get(unidad, False)
            if dic:
                mount_path = dic.get('mount_path', "")
                self.get_model().append([
                    pixbuf, mount_path.split("/")[-1], mount_path])
        self.get_toplevel().set_sensitive(True)

    def select_home(self):
        self.get_toplevel().set_sensitive(False)
        self.get_selection().select_path(1)
        modelo, iter_ = self.get_selection().get_selected()
        if iter_:
            self.get_selection().select_iter(iter_)
            self.dir_select = self.get_model().get_value(iter_, 2)
            self.emit('leer', self.dir_select)
            self.emit('info', self.dir_select)
        self.get_toplevel().set_sensitive(True)
        return False
Exemple #4
0
class Unidades(gtk.TreeView):
    """
    Treview para unidades y directorios.
    """

    __gsignals__ = {
        "leer": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
                 (gobject.TYPE_PYOBJECT, )),
        "add-leer": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
                     (gobject.TYPE_PYOBJECT, )),
        "info": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
                 (gobject.TYPE_PYOBJECT, )),
        "remove_explorers":
        (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, ))
    }

    def __init__(self):

        gtk.TreeView.__init__(
            self,
            gtk.ListStore(gtk.gdk.Pixbuf, gobject.TYPE_STRING,
                          gobject.TYPE_STRING))

        self.modify_bg(0, gtk.gdk.color_parse("#e3f2f2"))

        self.set_property("rules-hint", True)
        self.set_headers_clickable(False)
        self.set_headers_visible(False)

        self.dir_select = None
        self.demonio_unidades = DeviceManager()

        self.__setear_columnas()
        self.__Llenar_ListStore()

        self.connect("button-press-event", self.__handler_click)
        self.show_all()
        self.demonio_unidades.connect('update', self.__update_unidades)
        gobject.idle_add(self.select_home)

    def __handler_click(self, widget, event):
        boton = event.button
        pos = (event.x, event.y)
        tiempo = event.time
        path, columna, xdefondo, ydefondo = (None, None, None, None)
        try:
            path, columna, xdefondo, ydefondo = widget.get_path_at_pos(
                int(pos[0]), int(pos[1]))
        except:
            return
        if boton == 1:
            iter_ = self.get_model().get_iter(path)
            directorio = self.get_model().get_value(iter_, 2)
            self.dir_select = directorio
            self.emit('leer', self.dir_select)
            self.emit('info', self.dir_select)
            return
        elif boton == 3:
            menu = MenuListUnidades(widget, boton, pos, tiempo, path,
                                    self.get_model())
            menu.connect('accion', self.__get_accion)
            gtk.Menu.popup(menu, None, None, None, boton, tiempo)
        elif boton == 2:
            return

    def __get_accion(self, widget, path, accion):
        notebookdirectorios = self.get_parent().get_parent(
        ).notebookdirectorios
        iter_ = self.get_model().get_iter(path)
        direccion = self.get_model().get_value(iter_, 2)
        if accion == "Abrir":
            self.dir_select = direccion
            self.emit('add-leer', self.dir_select)
            self.emit('info', self.dir_select)
        elif accion == "Pegar":
            if notebookdirectorios.copiando:
                oldpath = notebookdirectorios.copiando
                if copiar(oldpath, direccion):
                    print "Copiado:", oldpath, "En:", direccion
            elif notebookdirectorios.cortando:
                oldpath = notebookdirectorios.cortando[0]
                if mover(oldpath, direccion):
                    print "Movido:", oldpath, "A:", direccion
                # FIXME: mover y actualizar notebookdirectorios
                #if mover(dire, direccion):
                #    widget.collapse_row(path)
                #    widget.expand_to_path(path)
            notebookdirectorios.cortando = False
            self.dir_select = direccion
            self.emit('leer', self.dir_select)
            self.emit('info', self.dir_select)

    def __update_unidades(self, widget):
        """
        Cuando se Conecta o Desconecta una Unidad.
        """
        unidades = self.demonio_unidades.get_unidades()
        lista = {}
        for unidad in unidades.keys():
            dic = unidades.get(unidad, False)
            if dic:
                mount_path = dic.get('mount_path', "")
                lista[mount_path.split("/")[-1]] = mount_path
        gobject.timeout_add(1000, self.__update_unidades2, lista)

    def __update_unidades2(self, lista):
        """
        Actualizar lista de unidades.
        """
        model = self.get_model()
        item = model.get_iter_first()
        mounts = []
        remove_explorers = []
        while item:
            # Remover Unidades desmontadas.
            item_remove = False
            if not os.path.exists(model.get_value(item, 2)):
                remove_explorers.append(model.get_value(item, 2))
                item_remove = item
            else:
                mounts.append(model.get_value(item, 1))
            item = model.iter_next(item)
            if item_remove:
                model.remove(item_remove)
        for it in lista.keys():
            # Agregar Unidades nuevas.
            if not it in mounts:
                icono = os.path.join(ICONOS, "drive-removable-media-usb.svg")
                pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icono, 30, -1)
                model.append([pixbuf, it, lista[it]])
        if remove_explorers:
            self.emit('remove_explorers', remove_explorers)
        return False

    def __setear_columnas(self):
        self.append_column(self.__construir_columa_icono('Icono', 0, True))
        self.append_column(self.__construir_columa('Nombre', 1, True))
        self.append_column(self.__construir_columa('Directorio', 2, False))

    def __construir_columa(self, text, index, visible):
        render = gtk.CellRendererText()
        column = gtk.TreeViewColumn(text, render, text=index)
        column.set_sort_column_id(index)
        column.set_property('visible', visible)
        return column

    def __construir_columa_icono(self, text, index, visible):
        render = gtk.CellRendererPixbuf()
        column = gtk.TreeViewColumn(text, render, pixbuf=index)
        column.set_property('visible', visible)
        return column

    def __Llenar_ListStore(self):
        self.get_toplevel().set_sensitive(False)

        icono = os.path.join(ICONOS, "def.svg")
        pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icono, 30, -1)
        self.get_model().append([pixbuf, 'Raiz', ROOT])

        icono = os.path.join(ICONOS, "stock-home.svg")
        pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icono, 30, -1)
        self.get_model().append([pixbuf, commands.getoutput('whoami'), HOME])

        if describe_uri(ACTIVITIES):
            icono = os.path.join(ICONOS, "stock-home.svg")
            pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icono, 30, -1)
            self.get_model().append([pixbuf, 'Actividades', ACTIVITIES])

        if describe_uri(JAMEDIA):
            icono = os.path.join(ICONOS, "JAMedia.svg")
            pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icono, 30, -1)
            self.get_model().append([pixbuf, 'JAMediaDatos', JAMEDIA])

        if describe_uri(DIARIO):
            icono = os.path.join(ICONOS, "diario.svg")
            pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icono, 30, -1)
            self.get_model().append([pixbuf, 'Diario', DIARIO])

        if describe_uri(LOGS):
            icono = os.path.join(ICONOS, "diario.svg")
            pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icono, 30, -1)
            self.get_model().append([pixbuf, 'Logs', LOGS])

        icono = os.path.join(ICONOS, "drive-removable-media-usb.svg")
        pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icono, 30, -1)

        unidades = self.demonio_unidades.get_unidades()
        for unidad in unidades.keys():
            dic = unidades.get(unidad, False)
            if dic:
                mount_path = dic.get('mount_path', "")
                self.get_model().append(
                    [pixbuf, mount_path.split("/")[-1], mount_path])
        self.get_toplevel().set_sensitive(True)

    def select_home(self):
        self.get_toplevel().set_sensitive(False)
        self.get_selection().select_path(1)
        modelo, iter_ = self.get_selection().get_selected()
        if iter_:
            self.get_selection().select_iter(iter_)
            self.dir_select = self.get_model().get_value(iter_, 2)
            self.emit('leer', self.dir_select)
            self.emit('info', self.dir_select)
        self.get_toplevel().set_sensitive(True)
        return False