#!/usr/bin/env python # -*- coding: utf-8 -*- # CristianEdit.py por: # Cristian García # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import sys import os from gi.repository import Gtk from gi.repository import Gdk from gi.repository import Gio from gi.repository import GObject from CristianEdit.CristianEdit import CristianEdit from CristianEdit.objetos import DialogoCerrar screen = Gdk.Screen.get_default() css_provider = Gtk.CssProvider() style = os.path.join(os.path.dirname(__file__), 'CristianEdit/CristianEdit.css') css_provider.load_from_path(style) context = Gtk.StyleContext() context.add_provider_for_screen( screen, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER) class Ventana(Gtk.Window): def __init__(self, direcciones): Gtk.Window.__init__(self, title='CristianEdit') self.set_icon_from_file(os.path.join(os.path.dirname(__file__), 'Iconos/CristianEdit.svg')) self.set_size_request(600, 450) self.set_position(Gtk.WindowPosition.CENTER) self.socket = Gtk.Socket() self.add(self.socket) self.cristianedit = CristianEdit() self.socket.add_id(self.cristianedit.get_id()) self.show_all() self.realize() self.cristianedit.setup_init(direcciones) self.connect('delete-event', self.salir) self.cristianedit.connect('cerrar', self.salir) def salir(self, *args): """Consulta buffer por buffer si es que no está modificado, si no hay archivos modificados sin guardar, cierra, de lo contrario consulta al usuario si guardar, cerrar sin guardar o cancelar.""" notebook = self.cristianedit.get_objeto('self.notebook') buffers = self.cristianedit.get_objeto('self.buffers') direcciones = self.cristianedit.get_objeto('self.lugares') labels = self.cristianedit.get_objeto('self.etiquetas') self.cristianedit.guardar_configuracion() for buffer in buffers: if_cerrar = buffers.index(buffer) == buffers.index(buffers[-1]) if buffer.get_modified(): numero = buffers.index(buffer) direccion = direcciones[numero] dialog = DialogoCerrar( direccion, numero, notebook, direcciones, labels, self) dialog.add_label( 'El archivo:\n%s\ntiene cambios sin guardar.' % direccion) dialog.add_label('¿Desea guardar antes de cerrar?') respuesta = dialog.run() dialog.destroy() if respuesta == Gtk.ResponseType.YES: dialog.guardar(direcciones[numero]) if if_cerrar: Gtk.main_quit() elif respuesta == Gtk.ResponseType.CANCEL: return True else: if if_cerrar: Gtk.main_quit() elif not buffer.get_modified() and if_cerrar: sys.exit(0) if __name__ == '__main__': lista = sys.argv[1:] for lugar in lista: if os.path.exists(lugar) and os.path.isfile(lugar): lista[lista.index(lugar)] = os.path.realpath(lugar) else: lista.remove(lugar) Ventana(lista) Gtk.main()