1 #!/usr/bin/python 2 3 import os 4 from gi.repository import Gtk 5 6 filepattern = ( 7 ("MP3","*.mp3"), 8 ("AVI","*.avi"), 9 ("MPEG-4","*.mp4"), 10 ("FLV ","*.flv"), 11 ("OGG","*.ogg"), 12 ) 13 14 pattern = (".mp3",".mp4",".avi",".flv",".ogg") 15 16 class main: 17 18 def __init__(self): 19 # Crea la ventana de trabajo Principal y obtiene los objetos en Glade 20 builder = Gtk.Builder() 21 builder.add_from_file("Multiplay.ui") 22 self.addfile = builder.get_object("Add") 23 self.addfolder = builder.get_object("AddFolder") 24 self.save = builder.get_object("Save") 25 self.about = builder.get_object("About") 26 self.medialist = builder.get_object("MediaList") 27 self.treeview = builder.get_object("TextView") 28 self.up = builder.get_object("Up") 29 self.down = builder.get_object("Down") 30 self.filterbox = Gtk.FileFilter() 31 32 # Diccionario de eventos y Conexion de los mismos. 33 dict = {"on_Add_clicked": self.showAddFile, 34 "on_AddFolder_clicked": self.showAddFolder, 35 "on_Saved_clicked": self.showSave, 36 "on_About_clicked": self.showAbout, 37 "on_Clearone_clicked": self.clearone, 38 "on_Clearlist_clicked": self.clearlist, 39 "on_Up_clicked": self.updown_move, 40 "on_Down_clicked": self.updown_move, 41 42 } 43 builder.connect_signals(dict) 44 45 #Definicion del comando Agregar 46 def showAddFile(self, widget): 47 self.filterbox.set_name("Media Files") 48 for name, pattern in filepattern: 49 self.filterbox.add_pattern(pattern) 50 51 self.addfile.add_filter(self.filterbox) 52 53 respt = self.addfile.run() 54 self.addfile.remove_filter(self.filterbox) 55 self.addfile.hide() 56 if respt == -5: 57 fileselected = self.addfile.get_filenames() 58 for files in fileselected: 59 (dirs,files)= os.path.split(files) 60 self.medialist.append([files,dirs]) 61 62 63 #Definicion del comando Abrir Carpeta 64 def showAddFolder(self, widget): 65 self.filterbox.set_name("All Media Files") 66 for names, patterns in filepattern: 67 self.filterbox.add_pattern(patterns) 68 69 self.addfolder.add_filter(self.filterbox) 70 71 respt = self.addfolder.run() 72 self.addfolder.remove_filter(self.filterbox) 73 self.addfolder.hide() 74 75 if respt == -5: 76 addmultiple = self.addfolder.get_filename() 77 78 for root, dirs, filelist in os.walk(addmultiple): 79 for allfiles in [f for f in filelist if f.endswith(pattern)]: 80 self.medialist.append([allfiles,root]) 81 82 #Definicion del comando Borrar un Archivo 83 def clearone(self, *args): 84 clearone = self.treeview.get_selection() 85 (model, rows) = clearone.get_selected_rows() 86 for i in rows: 87 iteration=model.get_iter(i) 88 print iteration 89 self.medialist.remove(iteration) 90 91 #Definicion del comando Borrar Lista 92 def clearlist(self, *args): 93 self.medialist.clear() 94 95 #Definicion del comando Arriba y Abajo 96 def updown_move(self, button): 97 line = self.treeview.get_selection() 98 (model, rows) = line.get_selected_rows() 99 if button == self.up: 100 for path1 in rows: 101 path2 = int(str(path1))-1 102 if path2 < 0: 103 return 104 else: 105 iter1 = model.get_iter(path1) 106 iter2 = model.get_iter(path2) 107 model.swap(iter1,iter2) 108 109 if button == self.down: 110 for path1 in rows: 111 iter1 = model.get_iter(path1) 112 iter2 = model.iter_next(iter1) 113 if iter2 == None: 114 return 115 else: 116 model.swap(iter1,iter2) 117 118 119 #Definicion del comando Guardar Permite guardar una lista 120 def showSave(self, widget): 121 self.save.run() 122 self.save.hide() 123 124 #Definicion del Comando Acerca de: 125 def showAbout(self, widget, data=None): 126 self.about.run() 127 self.about.hide() 128 129 130 #Ejecucion del programa 131 if __name__ == "__main__": 132 main() 133 Gtk.main() 134