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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
|
#!/usr/bin/env python
# -*- coding:UTF-8 -*-
import os
import Archivos
import gi
from gi.repository import Gtk
from gi.repository import GObject
from gi.repository import GdkPixbuf
from gi.repository import Gio
from gi.repository import Pango
COPIAR = None
class AreadeMontajes(Gtk.TreeView):
"""Parte de la entana en la que se muestran
los montajes actualmente introducidos"""
__gsinglas__ = {'change-directory': (GObject.SIGNAL_RUN_FIRST,
GObject.TYPE_NONE, (GObject.TYPE_STRING,))}
def __init__(self, padre):
"""Inicia la clase"""
Gtk.TreeView.__init__(self)
self.padre = padre
self.montajes = []
self.volume_monitor = Gio.VolumeMonitor.get()
self.numero = 0
nombre = Gtk.TreeViewColumn('Montajes')
direccion = Gtk.TreeViewColumn('Dirección')
self.modelo = Gtk.ListStore(str, str)
self.set_model(self.modelo)
celda1 = Gtk.CellRendererText()
nombre.pack_start(celda1, True)
nombre.set_attributes(celda1, text=0)
celda2 = Gtk.CellRendererText()
direccion.pack_start(celda2, True)
direccion.set_attributes(celda2, text=1)
self.append_column(nombre)
self.append_column(direccion)
self.connect('button-press-event', self.click)
self.volume_monitor.connect('mount-added', self.agregar_montaje)
self.volume_monitor.connect('mount-removed', self.montaje_desconectado)
def montaje_desconectado(self, demonio, unidad):
iter = self.modelo.get_iter_first()
self.borrar_montaje(iter, unidad)
def borrar_montaje(self, iter, unidad):
"""Cuando se desconecta una unidad, se quita de la lista."""
directorio = self.modelo.get_value(iter, 1)
if directorio == self.montajes[self.numero]:
self.modelo.remove(iter)
self.numero = 0
else:
iter = self.modelo.iter_next(iter)
self.numero += 1
self.borrar_montaje(iter, unidad)
def agregar_montaje(self, demonio, unidad, *args):
"""Agrega una columna por montaje
que se encuentre actualmene"""
direccion = unidad.get_default_location().get_path()
texto = direccion.split('/')[-1]
self.modelo.append([texto, direccion])
self.montajes.append(direccion)
def click(self, widget, event):
"""Cuando se hace clic en el Widget clase,
reacciona según el botón del mouse que se presionó"""
boton = event.button
tiempo = event.time
try:
path, columna, xdefondo, ydefondo = widget.get_path_at_pos(event.x,
event.y)
if boton == 1:
direccion = self.montajes[path.get_indices()[0]]
self.abrir(None, direccion)
if boton == 3:
self.crear_menu_emergente(boton, tiempo, path)
return True
except TypeError:
pass
def crear_menu_emergente(self, boton, tiempo, path):
"""Crea un menú emergente desde la columna actual"""
iter = self.modelo.get_iter(path)
nombre = self.modelo.get_value(iter, 0)
direccion = self.modelo.get_value(iter, 1)
item = Gtk.MenuItem('Montaje %s' % nombre)
menu = Gtk.Menu()
item.set_submenu(menu)
abrir = Gtk.MenuItem('Abrir')
copiar = Gtk.MenuItem('Copiar')
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(copiar)
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('change-directory', direccion)
def copiar(self, widget, direccion):
COPIAR = direccion
def propiedades(self, widget, direccion):
dialogo = Archivos.Propiedades(direccion)
dialogo.show_all()
class Area(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, padre):
"""Inicia la clase"""
Gtk.IconView.__init__(self)
self.padre = padre
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.connect('button-press-event', self.click)
self.connect('selection-changed', self.changed)
def changed(self, widget):
"""Emite la señal 'cambio-de-mensaje' con una cadena
que muestra información del archivo o carpeta seleccionada"""
if self.get_selected_items():
direccion = self.padre.direccion
path = self.get_selected_items()[0]
iter = self.modelo.get_iter(path)
direccion = os.path.join(direccion, self.modelo.get_value(iter, 0))
lectura, escritura, ejecucion = Archivos.get_permisos(direccion)
if os.path.isfile(direccion):
tamanio = Archivos.get_tamanio(direccion)
string = ' - ' + tamanio
elif os.path.isdir(direccion) or os.path.ismount(direccion):
archivos = Archivos.get_tamanio(direccion)
string = ' - ' + archivos
mensaje = 'se ha seleccionada: ' + direccion + string
self.emit('cambio-de-mensaje', mensaje)
else:
self.emit('cambio-de-mensaje', '')
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.padre.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
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.padre.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)
for item in [abrir, cortar, copiar, pegar, propiedades]:
item.set_use_underline(True)
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 'propiedades'."""
self.emit('propiedades', direccion)
class Toolbar(Gtk.Toolbar):
"""Barra de herramientas."""
__gsignals__ = {
'accion': (GObject.SIGNAL_RUN_FIRST, None, (str,))
}
def __init__(self):
Gtk.Toolbar.__init__(self)
self.toolbutton(
Gtk.STOCK_HARDDISK, 'Dirigirse al directorio raíz', 'raiz')
self.toolbutton(Gtk.STOCK_HOME,
'Dirigirse al directorio personal', 'personal')
self.toolbutton(Gtk.STOCK_GO_UP,
'Dirigirse al directorio padre del actual', 'arriba')
self.toolbutton(Gtk.STOCK_REFRESH, 'Recargar', 'recargar')
img_mas = Gtk.Image()
img_menos = Gtk.Image()
img_preferencias = Gtk.Image()
b_create = Gtk.ToolButton()
b_remove = Gtk.ToolButton()
b_preferences = Gtk.ToolButton()
#item = Gtk.ToolItem()
#item.add(self.spinner)
#self.add(item)
"""
b_ocults.connect('clicked', self.change_ocultos)
b_create.connect('clicked', self.crear_directorio)
b_remove.connect('clicked', self.borrar_archivo)
b_preferences.connect('clicked', self.preferencias)
"""
def toolbutton(self, imagen, tooltip, string):
boton = Gtk.ToolButton(imagen)
boton.set_tooltip_text(tooltip)
boton.connect('clicked', self.emit_accion, string)
self.add(boton)
def emit_accion(self, widget, string):
self.emit('accion', string)
class Entrada(Gtk.Entry):
"""Entrada de navegación"""
def __init__(self):
"""Inicia la clase"""
Gtk.Entry.__init__(self)
self.modelo = Gtk.ListStore(str)
completion = Gtk.EntryCompletion()
completion.set_model(self.modelo)
completion.set_text_column(0)
self.set_size_request(400, 40)
self.set_placeholder_text(os.path.expanduser('Dirección'))
self.set_completion(completion)
self.connect('changed', self.changed)
def changed(self, widget):
"""Sí el usuario escribe '/' como último caracter, agrega
un item al modelo del completion por cada carpeta que se
encuentra en la dirección introducida"""
texto = widget.get_text()
if os.path.exists(texto) and \
not os.path.isfile(texto) and texto[-1] == '/':
lista = os.listdir(texto)
self.modelo.clear()
for x in lista:
self.modelo.append([texto + x])
self.show_all()
class BarradeEstado(Gtk.Statusbar):
"""Un GtkStatusbar para mostrar la
información del elemento seleccionado"""
def __init__(self):
Gtk.Statusbar.__init__(self)
def set_text(self, *args):
"""Le pasa 'pop' y 'push' al Widget clase"""
texto = ''
for x in args:
texto += x
self.pop(0)
self.push(0, texto)
def borrar(self, *args):
"""Llama a la función "set_text()" con '' como parámetro"""
self.set_text('')
class DialogoError(Gtk.Dialog):
"""Un diálogo que muestra errores."""
def __init__(self, error, direccion, padre):
Gtk.Dialog.__init__(self, parent=padre, flags=Gtk.DialogFlags.MODAL)
self.set_text('Error')
if error == 'inexistente':
texto = 'Al parecer la dirección:\n"%s"\nno existe, compruebe lo introducido, eh intente de nuevo' % direccion
elif error == 'abrir archivo':
texto = 'No tiene un programa instalado para abrir:\n"%s"' % direccion
label1 = Gtk.Label('Error al abrir la dirección...')
label2 = Gtk.Label(texto)
label1.modify_font(Pango.FontDescription('bold 15'))
label2.modify_font(Pango.FontDescription('12'))
self.vbox.pack_start(label1, False, False, 10)
self.vbox.pack_start(label2, False, False, 0)
boton = Gtk.Button(None, Gtk.STOCK_OK)
boton.connect('clicked', self.cerrar)
self.action_area.add(boton)
def cerrar(self, widget):
self.destroy()
|