class WorkPanel(Gtk.Paned): __gtype_name__ = 'JAMediaEditorWorkPanel' __gsignals__ = { 'new_select': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, (GObject.TYPE_PYOBJECT, GObject.TYPE_STRING)), 'ejecucion': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, (GObject.TYPE_STRING, GObject.TYPE_BOOLEAN)), 'update': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, (GObject.TYPE_PYOBJECT, )) } def __init__(self): Gtk.Paned.__init__(self, orientation=Gtk.Orientation.VERTICAL) self.notebook_sourceview = Notebook_SourceView() self.terminal = Terminal() # Terminal en ejecución. self.ejecucion = False # Tipo: proyecto o archivo. self.ejecucion_activa = False self.pack1(self.notebook_sourceview, resize=True, shrink=False) self.pack2(self.terminal, resize=False, shrink=True) self.show_all() self.terminal.set_size_request(-1, 170) self.notebook_sourceview.connect('new_select', self.__re_emit_new_select) self.notebook_sourceview.connect('update', self.__re_emit_update) self.terminal.connect("ejecucion", self.__set_ejecucion) self.terminal.connect("reset", self.detener_ejecucion) GLib.idle_add(self.terminal.hide) def __re_emit_update(self, widget, _dict): # Emite una señal con el estado general del archivo. self.emit("update", _dict) def __set_ejecucion(self, widget, terminal): # Cuando se ejecuta un archivo o un proyecto. self.ejecucion = terminal self.terminal.set_sensitive(False) def __re_emit_new_select(self, widget, view, tipo): """ Recibe nombre y contenido de archivo seleccionado en Notebook_SourceView y los envia BasePanel. """ self.emit('new_select', view, tipo) def get_default_path(self): # Devuelve el Directorio del archivo seleccionado en sourceview. return self.notebook_sourceview.get_default_path() def set_linea(self, index, texto): """ Recibe la linea seleccionada en instrospeccion y y la pasa a notebook_sourceview para seleccionarla. """ self.notebook_sourceview.set_linea(index, texto) def abrir_archivo(self, archivo): self.notebook_sourceview.abrir_archivo(archivo) def guardar_archivo(self): self.notebook_sourceview.guardar_archivo() def guardar_archivo_como(self): self.notebook_sourceview.guardar_archivo_como() def ejecutar(self, archivo=None): """ Ejecuta un archivo. Si no se pasa archivo, ejecuta el seleccionado en notebooksourceview. """ if not archivo or archivo == None: # Cuando se ejecuta el archivo seleccionado. pagina = self.notebook_sourceview.get_current_page() view = self.notebook_sourceview.get_children( )[pagina].get_children()[0] archivo = view.archivo # Si el archivo tiene cambios sin guardar o nunca se guardó. if not archivo or archivo == None or \ view.get_buffer().get_modified(): dialog = DialogoAlertaSinGuardar( parent_window=self.get_toplevel()) respuesta = dialog.run() dialog.destroy() if respuesta == Gtk.ResponseType.ACCEPT: self.guardar_archivo() elif respuesta == Gtk.ResponseType.CANCEL: return elif respuesta == Gtk.ResponseType.CLOSE: return archivo = view.archivo self.ejecucion_activa = "archivo" self.emit("ejecucion", self.ejecucion_activa, True) else: # Cuando se ejecuta el main de proyecto. source = None for view in self.get_archivos_de_proyecto( self.get_parent().get_parent().proyecto["path"]): if view.archivo == archivo: source = view break if source: if source.get_buffer().get_modified(): dialog = DialogoAlertaSinGuardar( parent_window=self.get_toplevel()) respuesta = dialog.run() dialog.destroy() if respuesta == Gtk.ResponseType.ACCEPT: source.guardar() elif respuesta == Gtk.ResponseType.CANCEL: return elif respuesta == Gtk.ResponseType.CLOSE: return self.ejecucion_activa = "proyecto" self.emit("ejecucion", self.ejecucion_activa, True) if archivo: self.terminal.ejecutar(archivo) def detener_ejecucion(self, widget=None, notebook=None, terminal=None, pag_indice=None): if self.ejecucion: self.ejecucion.set_interprete() self.ejecucion = False self.terminal.set_sensitive(True) self.emit("ejecucion", self.ejecucion_activa, False) self.ejecucion_activa = False def set_accion_codigo(self, accion): # Ejecuta acciones sobre el código del archivo seleccionado. self.notebook_sourceview.set_accion(accion) def set_accion_archivos(self, accion): # Ejecuta acciones sobre el archivo seleccionado. self.notebook_sourceview.set_accion(accion) def set_accion_ver(self, accion, valor): # Ejecuta acciones sobre el archivo seleccionado. if accion == "Panel inferior": if not valor: self.terminal.hide() else: self.terminal.show() elif accion == "Numeracion": self.notebook_sourceview.set_accion(accion, valor) def get_archivos_de_proyecto(self, proyecto_path): """ Devuelve sourceview de todos los archivos abiertos de un proyecto según proyecto_path. """ return self.notebook_sourceview.get_archivos_de_proyecto(proyecto_path) def remove_proyect(self, proyecto_path): # Cuando se elimina el proyecto desde la vista de estructura. self.notebook_sourceview.remove_proyect(proyecto_path)
class DialogoInstall(Gtk.Dialog): """ Dialogo para mostrar proceso de construcción de Instalador gnome. """ __gtype_name__ = 'JAMediaEditorDialogoInstall' def __init__(self, parent_window=None, dirpath=None, destino_path=None): Gtk.Dialog.__init__(self, parent=parent_window, title="Generador de Instaladores", flags=Gtk.DialogFlags.MODAL, buttons=["Cerrar", Gtk.ResponseType.ACCEPT]) self.set_size_request(640, 480) self.set_border_width(15) self.destino_path = destino_path self.dirpath = dirpath from JAMediaTerminal.Terminal import Terminal self.terminal = Terminal() self.vbox.pack_start(self.terminal, True, True, 0) self.terminal.toolbar.hide() notebook = self.terminal.notebook cerrar = notebook.get_tab_label( notebook.get_children()[0]).get_children()[1] cerrar.set_sensitive(False) self.maximize() self.terminal.connect("reset", self.__end_make) GLib.idle_add(self.__run_gnome_install) def __end_make(self, jamediaterminal, notebook, terminal, pag_indice): """ Cuando Finaliza el proceso de construcción del instalador, se informa al usuario. """ dialog = DialogoInfoInstall(parent_window=self.get_toplevel(), distpath=os.path.join( self.destino_path, "dist")) dialog.run() dialog.destroy() def __run_gnome_install(self): """ Ejecuta: python setup.py sdist Construyendo el instalador gnome. """ python_path = "/usr/bin/python" if os.path.exists(os.path.join("/bin", "python")): python_path = os.path.join("/bin", "python") elif os.path.exists(os.path.join("/usr/bin", "python")): python_path = os.path.join("/usr/bin", "python") elif os.path.exists(os.path.join("/sbin", "python")): python_path = os.path.join("/sbin", "python") elif os.path.exists(os.path.join("/usr/local", "python")): python_path = os.path.join("/usr/local", "python") self.terminal.ejecute_script(self.dirpath, python_path, os.path.join(self.dirpath, "setup.py"), "sdist") return False
class DialogoInstall(Gtk.Dialog): """ Dialogo para mostrar proceso de construcción de Instalador gnome. """ __gtype_name__ = 'JAMediaEditorDialogoInstall' def __init__(self, parent_window=None, dirpath=None, destino_path=None): Gtk.Dialog.__init__(self, parent=parent_window, title="Generador de Instaladores", flags=Gtk.DialogFlags.MODAL, buttons=["Cerrar", Gtk.ResponseType.ACCEPT]) self.set_size_request(640, 480) self.set_border_width(15) self.destino_path = destino_path self.dirpath = dirpath from JAMediaTerminal.Terminal import Terminal self.terminal = Terminal() self.vbox.pack_start(self.terminal, True, True, 0) self.terminal.toolbar.hide() notebook = self.terminal.notebook cerrar = notebook.get_tab_label( notebook.get_children()[0]).get_children()[1] cerrar.set_sensitive(False) self.maximize() self.terminal.connect("reset", self.__end_make) GLib.idle_add(self.__run_gnome_install) def __end_make(self, jamediaterminal, notebook, terminal, pag_indice): """ Cuando Finaliza el proceso de construcción del instalador, se informa al usuario. """ dialog = DialogoInfoInstall(parent_window=self.get_toplevel(), distpath=os.path.join(self.destino_path, "dist")) dialog.run() dialog.destroy() def __run_gnome_install(self): """ Ejecuta: python setup.py sdist Construyendo el instalador gnome. """ python_path = "/usr/bin/python" if os.path.exists(os.path.join("/bin", "python")): python_path = os.path.join("/bin", "python") elif os.path.exists(os.path.join("/usr/bin", "python")): python_path = os.path.join("/usr/bin", "python") elif os.path.exists(os.path.join("/sbin", "python")): python_path = os.path.join("/sbin", "python") elif os.path.exists(os.path.join("/usr/local", "python")): python_path = os.path.join("/usr/local", "python") self.terminal.ejecute_script(self.dirpath, python_path, os.path.join(self.dirpath, "setup.py"), "sdist") return False
class WorkPanel(Gtk.Paned): __gtype_name__ = 'JAMediaEditorWorkPanel' __gsignals__ = { 'new_select': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, (GObject.TYPE_PYOBJECT, GObject.TYPE_STRING)), 'ejecucion': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, (GObject.TYPE_STRING, GObject.TYPE_BOOLEAN)), 'update': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, (GObject.TYPE_PYOBJECT,))} def __init__(self): Gtk.Paned.__init__(self, orientation=Gtk.Orientation.VERTICAL) self.notebook_sourceview = Notebook_SourceView() self.terminal = Terminal() # Terminal en ejecución. self.ejecucion = False # Tipo: proyecto o archivo. self.ejecucion_activa = False self.pack1(self.notebook_sourceview, resize=True, shrink=False) self.pack2(self.terminal, resize=False, shrink=True) self.show_all() self.terminal.set_size_request(-1, 170) self.notebook_sourceview.connect('new_select', self.__re_emit_new_select) self.notebook_sourceview.connect('update', self.__re_emit_update) self.terminal.connect("ejecucion", self.__set_ejecucion) self.terminal.connect("reset", self.detener_ejecucion) GLib.idle_add(self.terminal.hide) def __re_emit_update(self, widget, _dict): # Emite una señal con el estado general del archivo. self.emit("update", _dict) def __set_ejecucion(self, widget, terminal): # Cuando se ejecuta un archivo o un proyecto. self.ejecucion = terminal self.terminal.set_sensitive(False) def __re_emit_new_select(self, widget, view, tipo): """ Recibe nombre y contenido de archivo seleccionado en Notebook_SourceView y los envia BasePanel. """ self.emit('new_select', view, tipo) def get_default_path(self): # Devuelve el Directorio del archivo seleccionado en sourceview. return self.notebook_sourceview.get_default_path() def set_linea(self, index, texto): """ Recibe la linea seleccionada en instrospeccion y y la pasa a notebook_sourceview para seleccionarla. """ self.notebook_sourceview.set_linea(index, texto) def abrir_archivo(self, archivo): self.notebook_sourceview.abrir_archivo(archivo) def guardar_archivo(self): self.notebook_sourceview.guardar_archivo() def guardar_archivo_como(self): self.notebook_sourceview.guardar_archivo_como() def ejecutar(self, archivo=None): """ Ejecuta un archivo. Si no se pasa archivo, ejecuta el seleccionado en notebooksourceview. """ if not archivo or archivo == None: # Cuando se ejecuta el archivo seleccionado. pagina = self.notebook_sourceview.get_current_page() view = self.notebook_sourceview.get_children()[ pagina].get_children()[0] archivo = view.archivo # Si el archivo tiene cambios sin guardar o nunca se guardó. if not archivo or archivo == None or \ view.get_buffer().get_modified(): dialog = DialogoAlertaSinGuardar( parent_window=self.get_toplevel()) respuesta = dialog.run() dialog.destroy() if respuesta == Gtk.ResponseType.ACCEPT: self.guardar_archivo() elif respuesta == Gtk.ResponseType.CANCEL: return elif respuesta == Gtk.ResponseType.CLOSE: return archivo = view.archivo self.ejecucion_activa = "archivo" self.emit("ejecucion", self.ejecucion_activa, True) else: # Cuando se ejecuta el main de proyecto. source = None for view in self.get_archivos_de_proyecto( self.get_parent().get_parent().proyecto["path"]): if view.archivo == archivo: source = view break if source: if source.get_buffer().get_modified(): dialog = DialogoAlertaSinGuardar( parent_window=self.get_toplevel()) respuesta = dialog.run() dialog.destroy() if respuesta == Gtk.ResponseType.ACCEPT: source.guardar() elif respuesta == Gtk.ResponseType.CANCEL: return elif respuesta == Gtk.ResponseType.CLOSE: return self.ejecucion_activa = "proyecto" self.emit("ejecucion", self.ejecucion_activa, True) if archivo: self.terminal.ejecutar(archivo) def detener_ejecucion(self, widget=None, notebook=None, terminal=None, pag_indice=None): if self.ejecucion: self.ejecucion.set_interprete() self.ejecucion = False self.terminal.set_sensitive(True) self.emit("ejecucion", self.ejecucion_activa, False) self.ejecucion_activa = False def set_accion_codigo(self, accion): # Ejecuta acciones sobre el código del archivo seleccionado. self.notebook_sourceview.set_accion(accion) def set_accion_archivos(self, accion): # Ejecuta acciones sobre el archivo seleccionado. self.notebook_sourceview.set_accion(accion) def set_accion_ver(self, accion, valor): # Ejecuta acciones sobre el archivo seleccionado. if accion == "Panel inferior": if not valor: self.terminal.hide() else: self.terminal.show() elif accion == "Numeracion": self.notebook_sourceview.set_accion(accion, valor) def get_archivos_de_proyecto(self, proyecto_path): """ Devuelve sourceview de todos los archivos abiertos de un proyecto según proyecto_path. """ return self.notebook_sourceview.get_archivos_de_proyecto(proyecto_path) def remove_proyect(self, proyecto_path): # Cuando se elimina el proyecto desde la vista de estructura. self.notebook_sourceview.remove_proyect(proyecto_path)