def __new_jamedia_converter(self, codec, dirpath_destino): if PR: print "WidgetConvert", "__new_jamedia_converter" self.player = JAMediaConverter(self.path_origen, codec, dirpath_destino) self.player.connect("endfile", self.__play_stack_tareas) self.player.connect("newposicion", self.__process_tarea) self.player.connect("info", self.__info_tarea) self.player.play() return False
def __new_jamedia_converter(self, codec, dirpath_destino): if PR: print "WidgetConvert", "__new_jamedia_converter" self.player = JAMediaConverter( self.path_origen, codec, dirpath_destino) self.player.connect("endfile", self.__play_stack_tareas) self.player.connect("newposicion", self.__process_tarea) self.player.connect("info", self.__info_tarea) self.player.play() return False
class WidgetArchivo(gtk.Frame): __gsignals__ = { 'clear-tareas': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), 'accion-tarea': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING, )) } def __init__(self, path): gtk.Frame.__init__(self) self.path_origen = path self.temp_tareas = [] self.player = False self.set_label(" %s " % os.path.basename(self.path_origen)) self.set_border_width(5) self.modify_bg(0, get_colors("drawingplayer")) self.panel = gtk.HPaned() self.panel.modify_bg(0, get_colors("windows")) self.iz_box = gtk.VBox() self.buttonsbox = ButtonsBox() self.panel.pack1(self.iz_box, resize=False, shrink=True) self.panel.pack2(self.buttonsbox, resize=True, shrink=False) datos = describe_archivo(self.path_origen) if 'video' in datos or 'application/ogg' in datos: imageframe = ImageFrame(" Extraer Imágenes en Formato: ", self.path_origen) self.iz_box.pack_start(imageframe, False, False, 0) imageframe.connect("tarea", self.__sensitive_buttons) videoframe = VideoFrame(" Convertir Video a Formato: ", self.path_origen) self.iz_box.pack_start(videoframe, False, False, 0) videoframe.connect("tarea", self.__sensitive_buttons) audioframe = AudioFrame(" Extraer Audio en Formato: ", self.path_origen) self.iz_box.pack_start(audioframe, False, False, 0) audioframe.connect("tarea", self.__sensitive_buttons) elif "audio" in datos or 'application/octet-stream' in datos: audioframe = AudioFrame(" Convertir Audio a Formato: ", self.path_origen) self.iz_box.pack_start(audioframe, False, False, 0) audioframe.connect("tarea", self.__sensitive_buttons) else: print "Tipo de Archivo Desconocido:", self.path_origen, datos self.add(self.panel) self.show_all() self.buttonsbox.connect("accion", self.__set_accion) def __sensitive_buttons(self, widget): """ Botones de acciones iniciar y copiar tarea, se activan solo si hay una tarea configurada. """ for frame in self.iz_box.get_children(): event = frame.get_child() vbox = event.get_child() for check in vbox.get_children(): if check.get_active(): self.buttonsbox.activar(True) return self.buttonsbox.activar(False) def __set_accion(self, widget, accion): """ Cuando se hace click sobre un botón de acciones. """ if accion == "Ejecutar Tarea en Archivo": self.emit("accion-tarea", accion) elif accion == "Ejecutar Tareas en la Lista": self.emit("accion-tarea", accion) elif accion == "Copiar Tarea a Toda la Lista": self.emit("accion-tarea", accion) elif accion == "Eliminar Tarea": vbox = self.get_parent() vbox.remove(self) self.destroy() elif accion == "Eliminar Todas las Tareas": self.emit("clear-tareas") else: print "Tarea sin Definir:", self.__set_accion, accion def __play_stack_tareas(self, player=False): if PR: print "WidgetConvert", "__play_stack_tareas" if self.player: self.player.disconnect_by_func(self.__play_stack_tareas) self.player.disconnect_by_func(self.__process_tarea) self.player.disconnect_by_func(self.__info_tarea) self.player.stop() del (self.player) self.player = False if not self.temp_tareas: self.emit("accion-tarea", "end") self.__in_run(False) self.buttonsbox.set_info(" Tareas Procesadas ") self.buttonsbox.progress.set_progress(100.0) return False codec = self.temp_tareas[0] self.temp_tareas.remove(codec) dirpath_destino = "" if codec in ["jpg", "png"]: dirpath_destino = get_imagenes_directory() elif codec in ["ogg", "mp3", "wav"]: dirpath_destino = get_audio_directory() elif codec in ["ogv", "mpeg", "avi"]: dirpath_destino = get_video_directory() self.__in_run(True) gobject.idle_add(self.__new_jamedia_converter, codec, dirpath_destino) return False def __new_jamedia_converter(self, codec, dirpath_destino): if PR: print "WidgetConvert", "__new_jamedia_converter" self.player = JAMediaConverter(self.path_origen, codec, dirpath_destino) self.player.connect("endfile", self.__play_stack_tareas) self.player.connect("newposicion", self.__process_tarea) self.player.connect("info", self.__info_tarea) self.player.play() return False def __info_tarea(self, player, info): self.buttonsbox.set_info(info) def __process_tarea(self, player, posicion): self.buttonsbox.set_progress(float(posicion)) def __in_run(self, valor): """ Cuando se ejecutan tareas, se desactivan las botoneras. """ for frame in self.iz_box.get_children(): vbox = frame.get_child() for check in vbox.get_children(): check.set_sensitive(not valor) self.buttonsbox.set_sensitive(not valor) def get_tareas(self): """ Devuelve las tareas configuradas para un determinado archivo. """ tareas = [] for frame in self.iz_box.get_children(): event = frame.get_child() vbox = event.get_child() for check in vbox.get_children(): if check.get_active(): tareas.append(check.get_label()) return tareas def copy_tarea(self, tareas): """ Setea una lista de tareas a realizar. """ for frame in self.iz_box.get_children(): event = frame.get_child() vbox = event.get_child() for check in vbox.get_children(): if check.get_label() in tareas: check.set_active(True) else: check.set_active(False) def salir(self): if self.player: self.player.disconnect_by_func(self.__play_stack_tareas) self.player.disconnect_by_func(self.__process_tarea) self.player.disconnect_by_func(self.__info_tarea) self.player.stop() del (self.player) self.player = False def play(self): self.temp_tareas = self.get_tareas() self.__play_stack_tareas()
class WidgetArchivo(gtk.Frame): __gsignals__ = { 'clear-tareas': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), 'accion-tarea': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING,))} def __init__(self, path): gtk.Frame.__init__(self) self.path_origen = path self.temp_tareas = [] self.player = False self.set_label(" %s " % os.path.basename(self.path_origen)) self.set_border_width(5) self.modify_bg(0, get_colors("drawingplayer")) self.panel = gtk.HPaned() self.panel.modify_bg(0, get_colors("windows")) self.iz_box = gtk.VBox() self.buttonsbox = ButtonsBox() self.panel.pack1(self.iz_box, resize=False, shrink=True) self.panel.pack2(self.buttonsbox, resize=True, shrink=False) datos = describe_archivo(self.path_origen) if 'video' in datos or 'application/ogg' in datos: #imageframe = ImageFrame( # " Extraer Imágenes en Formato: ", self.path_origen) #self.iz_box.pack_start(imageframe, False, False, 0) #imageframe.connect("tarea", self.__sensitive_buttons) videoframe = VideoFrame( " Convertir Video a Formato: ", self.path_origen) self.iz_box.pack_start(videoframe, False, False, 0) videoframe.connect("tarea", self.__sensitive_buttons) audioframe = AudioFrame( " Extraer Audio en Formato: ", self.path_origen) self.iz_box.pack_start(audioframe, False, False, 0) audioframe.connect("tarea", self.__sensitive_buttons) elif "audio" in datos or 'application/octet-stream' in datos: audioframe = AudioFrame( " Convertir Audio a Formato: ", self.path_origen) self.iz_box.pack_start(audioframe, False, False, 0) audioframe.connect("tarea", self.__sensitive_buttons) else: print "Tipo de Archivo Desconocido:", self.path_origen, datos self.add(self.panel) self.show_all() self.buttonsbox.connect("accion", self.__set_accion) def __sensitive_buttons(self, widget): """ Botones de acciones iniciar y copiar tarea, se activan solo si hay una tarea configurada. """ for frame in self.iz_box.get_children(): event = frame.get_child() vbox = event.get_child() for check in vbox.get_children(): if check.get_active(): self.buttonsbox.activar(True) return self.buttonsbox.activar(False) def __set_accion(self, widget, accion): """ Cuando se hace click sobre un botón de acciones. """ if accion == "Ejecutar Tarea en Archivo": self.emit("accion-tarea", accion) elif accion == "Ejecutar Tareas en la Lista": self.emit("accion-tarea", accion) elif accion == "Copiar Tarea a Toda la Lista": self.emit("accion-tarea", accion) elif accion == "Eliminar Tarea": vbox = self.get_parent() vbox.remove(self) self.destroy() elif accion == "Eliminar Todas las Tareas": self.emit("clear-tareas") else: print "Tarea sin Definir:", self.__set_accion, accion def __play_stack_tareas(self, player=False): if PR: print "WidgetConvert", "__play_stack_tareas" if self.player: self.player.disconnect_by_func(self.__play_stack_tareas) self.player.disconnect_by_func(self.__process_tarea) self.player.disconnect_by_func(self.__info_tarea) self.player.stop() del(self.player) self.player = False if not self.temp_tareas: self.emit("accion-tarea", "end") self.__in_run(False) self.buttonsbox.set_info(" Tareas Procesadas ") self.buttonsbox.progress.set_progress(100.0) return False codec = self.temp_tareas[0] self.temp_tareas.remove(codec) dirpath_destino = "" if codec in ["jpg", "png"]: dirpath_destino = get_imagenes_directory() elif codec in ["ogg", "mp3", "wav"]: dirpath_destino = get_audio_directory() elif codec in ["ogv", "mpeg", "avi"]: dirpath_destino = get_video_directory() self.__in_run(True) gobject.idle_add(self.__new_jamedia_converter, codec, dirpath_destino) return False def __new_jamedia_converter(self, codec, dirpath_destino): if PR: print "WidgetConvert", "__new_jamedia_converter" self.player = JAMediaConverter( self.path_origen, codec, dirpath_destino) self.player.connect("endfile", self.__play_stack_tareas) self.player.connect("newposicion", self.__process_tarea) self.player.connect("info", self.__info_tarea) self.player.play() return False def __info_tarea(self, player, info): self.buttonsbox.set_info(info) def __process_tarea(self, player, posicion): self.buttonsbox.set_progress(float(posicion)) def __in_run(self, valor): """ Cuando se ejecutan tareas, se desactivan las botoneras. """ for frame in self.iz_box.get_children(): vbox = frame.get_child() for check in vbox.get_children(): check.set_sensitive(not valor) self.buttonsbox.set_sensitive(not valor) def get_tareas(self): """ Devuelve las tareas configuradas para un determinado archivo. """ tareas = [] for frame in self.iz_box.get_children(): event = frame.get_child() vbox = event.get_child() for check in vbox.get_children(): if check.get_active(): tareas.append(check.get_label()) return tareas def copy_tarea(self, tareas): """ Setea una lista de tareas a realizar. """ for frame in self.iz_box.get_children(): event = frame.get_child() vbox = event.get_child() for check in vbox.get_children(): if check.get_label() in tareas: check.set_active(True) else: check.set_active(False) def salir(self): if self.player: self.player.disconnect_by_func(self.__play_stack_tareas) self.player.disconnect_by_func(self.__process_tarea) self.player.disconnect_by_func(self.__info_tarea) self.player.stop() del(self.player) self.player = False def play(self): self.temp_tareas = self.get_tareas() self.__play_stack_tareas()