Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCristian Garcia <cristian99garcia@gmail.com>2013-05-21 18:05:11 (GMT)
committer Cristian Garcia <cristian99garcia@gmail.com>2013-05-21 18:05:11 (GMT)
commit19433c1c14c356dca1b54846e6d1c6373be7081e (patch)
tree54b24a7eb55d3384fe401a260af5d8a68188ac8b
parent2f369433a8d23f28cae5be1b2f7301d60febcd6a (diff)
Sigo corrigiendo...
-rw-r--r--.gitignore2
-rw-r--r--CristianEdit.py5
-rw-r--r--CristianEdit/CristianEdit.py179
-rw-r--r--CristianEdit/objetos.py45
-rw-r--r--CristianEdit/objetos.pycbin46761 -> 47311 bytes
-rw-r--r--CristianEdit/objetos.py~435
6 files changed, 330 insertions, 336 deletions
diff --git a/.gitignore b/.gitignore
index e8a8084..afff5da 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,3 @@
*~
*.pyc
-*-pyw
+*.pyw
diff --git a/CristianEdit.py b/CristianEdit.py
index 704341a..3274f44 100644
--- a/CristianEdit.py
+++ b/CristianEdit.py
@@ -39,7 +39,7 @@ class Ventana(Gtk.Window):
self.set_icon_from_file(os.path.join(os.path.dirname(__file__),
'Iconos/CristianEdit.svg'))
- self.set_size_request(640, 480)
+ self.set_size_request(600, 450)
self.set_position(Gtk.WindowPosition.CENTER)
self.socket = Gtk.Socket()
@@ -61,6 +61,7 @@ class Ventana(Gtk.Window):
antes de cerrar"""
buffers, direcciones, views = self.cristianedit.get_if_exit()
+
for buffer in buffers:
if buffer.get_modified():
@@ -69,6 +70,7 @@ class Ventana(Gtk.Window):
direccion = direcciones[numero]
dialogo = objetos.dialogo_cerrar(direccion, buffer,
self.cristianedit, 'cerrar')
+
numero = 0
self.cristianedit.guardar_configuracion()
@@ -90,3 +92,4 @@ if __name__ == '__main__':
Ventana(direcciones)
Gtk.main()
+
diff --git a/CristianEdit/CristianEdit.py b/CristianEdit/CristianEdit.py
index 85e0e62..3fa55f9 100644
--- a/CristianEdit/CristianEdit.py
+++ b/CristianEdit/CristianEdit.py
@@ -18,7 +18,6 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-import objetos
import os
import ConfigParser
import time
@@ -28,6 +27,19 @@ import thread
import Globales as G
+import objetos
+from objetos import Menu
+from objetos import Buffer
+from objetos import View
+from objetos import Notebook
+from objetos import Barra
+from objetos import Navegador
+from objetos import BarraInferior
+from objetos import DialogoEstado
+from objetos import SelectordeFuente
+from objetos import Configuraciones
+from objetos import Teclado
+
from gi.repository import Gtk
from gi.repository import GObject
from gi.repository import Pango
@@ -35,10 +47,9 @@ from gi.repository import Gdk
class CristianEdit(Gtk.Plug):
- """Clase principal"""
+ """Clase principal."""
def __init__(self):
- """Inicia la clase"""
Gtk.Plug.__init__(self)
@@ -61,7 +72,7 @@ class CristianEdit(Gtk.Plug):
self.connect('embedded', self.embed_event)
def tecla(self, widget, event):
- """Saber sí elusuario presionó una tecla"""
+ """Saber si el usuario presionó una tecla."""
tecla = Gdk.keyval_name(event.keyval)
@@ -105,10 +116,10 @@ class CristianEdit(Gtk.Plug):
#****** <<< Configuraciones ******
self.vbox = Gtk.VBox()
- self.menu = objetos.Menu(self)
+ self.menu = Menu(self)
hbox_toolbar = Gtk.HBox()
- self.toolbar = objetos.Barra()
- self.notebook = objetos.Notebook(self)
+ self.toolbar = Barra()
+ self.notebook = Notebook(self)
self.vbox.pack_start(self.menu, False, False, 0)
self.vbox.pack_start(hbox_toolbar, False, False, 0)
@@ -135,27 +146,33 @@ class CristianEdit(Gtk.Plug):
self.toolbar.connect('nuevo', self.pagina_nueva)
self.toolbar.connect('deshacer', self.deshacer)
self.toolbar.connect('rehacer', self.rehacer)
- self.toolbar.connect('tipografia', self.set_fuente)
+ self.toolbar.connect('tipografia', self.seleccionar_fuente)
self.toolbar.connect('preferencias', self.mostrar_dialogo_configuraciones)
self.toolbar.connect('buscar-changed', self.buscar_changed)
self.toolbar.connect('buscar-activate', self.buscar_enter)
self.notebook.connect('boton-cerrar-clicked', self.cerrar_desde_boton)
+ self.notebook.connect('switch-page', self.algo)
self.add(self.vbox)
self.show_all()
+ def algo(self, widget, *args):
+
+ time.sleep(0.1)
+ print widget.get_current_page()
+
def mostrar_teclado(self, mostrar):
- """Muestra un teclado en pantalla"""
+ """Muestra un teclado en pantalla."""
if mostrar:
- self.teclado = objetos.Teclado(self)
+ self.teclado = Teclado(self)
self.teclado.show_all()
else:
self.teclado.destroy()
def cerrar_desde_boton(self, widget, objeto):
- """Cierra la pestaña desde el botón de cerrado"""
+ """Cierra la pestaña desde el botón de cerrado."""
numero = self.notebook.page_num(objeto)
@@ -180,12 +197,12 @@ class CristianEdit(Gtk.Plug):
self.notebook.borrar_pagina(numero)
def abrir(self, widget, direccion=None):
- """Abrir archivo/s para ver o editar"""
+ """Abrir uno o varios archivo/s."""
pagina = self.notebook.get_current_page()
if not direccion:
- navegador = objetos.Navegador('Abrir archivo de Texto',
+ navegador = Navegador('Abrir archivo de Texto',
self, Gtk.FileChooserAction(0), (Gtk.STOCK_OPEN, 1))
respuesta = navegador.run()
@@ -260,11 +277,12 @@ class CristianEdit(Gtk.Plug):
label.set_text(nombre)
+ print self.lugares
+
def guardar(self, widget, direccion=None):
- """Guardar los cambios o por primera vez el
- archivo que se está mostrando en el GtkNotebook().
- Sí se guarda por primera vez, se llamará a la
- función 'guardar_como()'"""
+ """Guardar el archivo actual. Si se guarda
+ por primera vez, se llamará a la función
+ 'guardar_como()'"""
pagina = self.notebook.get_current_page()
label = self.etiquetas[pagina]
@@ -275,25 +293,30 @@ class CristianEdit(Gtk.Plug):
else:
if not direccion:
archivo = open(self.lugares[pagina], 'w')
+ print '\n\n\n', self.lugares[pagina], '\n\n\n'
else:
+ print '\n\n\n', self.lugares[pagina], '\n\n\n'
+
archivo = open(direccion, 'w')
self.lugares[pagina] = direccion
+
label.set_text(direccion.split('/')[-1])
self.buffers[pagina].set_modified(False)
texto = self.get_texto()
+
archivo.write(texto)
archivo.close()
def guardar_como(self, widget):
- """Guardar copia o por primera vez"""
+ """Guardar copia o por primera vez."""
pagina = self.notebook.get_current_page()
buffer = self.buffers[pagina]
- self.navegador = objetos.Navegador('Guardar archivo', self,
+ self.navegador = Navegador('Guardar archivo', self,
Gtk.FileChooserAction(1), (Gtk.STOCK_SAVE, 1))
respuesta = self.navegador.run()
@@ -312,21 +335,22 @@ class CristianEdit(Gtk.Plug):
self.navegador.destroy()
def estado(self, *args):
- """Mantiene informado al usuario sobre el
- estado actual del archivo actual"""
+ """Muestra un diálogo con los datos
+ del archivo que se está editando actualmente."""
- dialogo = objetos.DialogoEstado(self, self.notebook)
+ dialogo = DialogoEstado(self, self.notebook)
dialogo.show_all()
def get_escritura(self, direccion):
- """Devuelve sí se puede editar el archivo"""
+ """Recibe una dirección de un archivo
+ y devuelve sí se puede editar."""
escritura = os.access(direccion, os.W_OK)
return escritura
def actualizar_b_estado(self, buffer, new_location, mark):
"""Actualiza la barra de estado,
- con la posisión actual"""
+ con la posisión actual."""
pagina = self.notebook.get_current_page()
b_estado = self.barras_de_abajo[pagina].get_statusbar()
@@ -336,26 +360,28 @@ class CristianEdit(Gtk.Plug):
buffer = self.buffers[pagina]
iter = buffer.get_iter_at_mark(buffer.get_insert())
- row = iter.get_line()
- col = iter.get_line_offset()
+ linea = iter.get_line() + 1
+ columna = iter.get_line_offset() + 1
- mensage = 'Línea:%d, Columna:%d' % (row, col)
+ mensage = 'Línea:%d, Columna:%d' % (linea, columna)
b_estado.push(0, mensage)
def pagina_nueva(self, *args):
"""Crea algunos Widgets y llama a la función
- 'agregar' de la objetos.Notebook()"""
+ 'agregar' de la Notebook()"""
- barra_inferior = objetos.BarraInferior()
+ barra_inferior = BarraInferior()
combo = barra_inferior.get_combo()
- buffer = objetos.Buffer()
- view = objetos.View(buffer)
+ buffer = Buffer()
+ view = View(buffer)
label = Gtk.Label('Sin título')
combo.connect('changed', self.combo_changed)
buffer.connect('mark-set', self.actualizar_b_estado)
buffer.connect('modified-changed', self.changed_modificado)
+ view.connect('cambio-de-busqueda', self.color_changed)
+
label.modify_font(Pango.FontDescription('Arial'))
self.notebook.agregar(view, label, barra_inferior)
@@ -406,6 +432,12 @@ class CristianEdit(Gtk.Plug):
else:
label.modify_font(Pango.FontDescription('Arial'))
+ def color_changed(self, widget, color):
+ """Cambia el color de la entrada de busqueda,
+ según si lo introducido se encuentre o no"""
+
+ print color
+
def agregar_a_recientes(self, direccion):
"""Agrega una dirección a archivos recientes"""
@@ -422,6 +454,8 @@ class CristianEdit(Gtk.Plug):
def ejecutar(self, widget):
"""Ejecuta el archivo actual"""
+ pass
+ """
buffer = self.get_buffer()
lugar = self.get_direccion()
inicio, fin = buffer.get_bounds()
@@ -429,6 +463,7 @@ class CristianEdit(Gtk.Plug):
thread.start_new_thread(Run.ejecutar, (lugar,))
time.sleep(0.1)
buffer.select_range(inicio, fin)
+ """
def deshacer(self, widget):
"""Deshacer cambios"""
@@ -457,7 +492,9 @@ class CristianEdit(Gtk.Plug):
def seleccionar_fuente(self, widget):
"""Selecciona la fuente de texto"""
- selector = objetos.SelectordeFuente(self.fuente)
+ fuente = self.configuraciones['fuente']
+ selector = SelectordeFuente(fuente)
+
selector.connect('font-changed', self.set_fuente)
def set_fuente(self, widget, fuente):
@@ -465,20 +502,21 @@ class CristianEdit(Gtk.Plug):
'self.fuente' y establece la fuene de texto
de todos los views"""
- self.fuente = fuente
+ self.configuraciones['fuente'] = fuente
+
for view in self.views:
- view.modify_font(Pango.FontDescription(self.fuente))
+ view.modify_font(Pango.FontDescription(fuente))
def mostrar_dialogo_configuraciones(self, widget):
"""Abre un díalogo con configuraciones"""
- configurador = objetos.Configuraciones(self, self.configuraciones)
+ dialog = Configuraciones(self, self.configuraciones)
- configurador.set_modal(True)
-
- configurador.connect('configuration-changed', self.configuration_changed)
+ dialog.set_modal(True)
+
+ dialog.connect('configuration-changed', self.configuration_changed)
- configurador.show_all()
+ dialog.show_all()
def configuration_changed(self, widget, dict):
@@ -514,32 +552,16 @@ class CristianEdit(Gtk.Plug):
def get_fuente(self):
- return self.fuente
+ return self.configuraciones['fuente']
def get_sirve(self, direccion):
"""Devuelve si el GtkSourceView() actual
sirve para abrir un archivo o si se necesita
crear una página nueva en el cuaderno de fichas"""
- pagina = self.notebook.get_current_page()
-
- if direccion == 'Sin dirección':
- sirve1 = True
-
- else:
- sirve1 = False
-
- if not self.buffers[pagina].get_modified():
- sirve2 = True
-
- else:
- sirve2 = False
-
- if self.buffers[pagina].get_char_count() == 0:
- sirve3 = True
-
- else:
- sirve3 = False
+ sirve1 = direccion == 'Sin dirección'
+ sirve2 = not self.get_buffer().get_modified()
+ sirve3 = self.get_buffer().get_char_count() == 0
return sirve1, sirve2, sirve3
@@ -548,9 +570,9 @@ class CristianEdit(Gtk.Plug):
pestaña actual del cuaderno de fichas"""
pagina = self.notebook.get_current_page()
- start, end = self.buffers[pagina].get_bounds()
+ start, end = self.get_buffer().get_bounds()
- return self.buffers[pagina].get_text(start, end, False)
+ return self.buffers[pagina].get_text(start, end, 0)
def set_configuracion(self, diccionario):
"""Establece la configuración según datos de una lista"""
@@ -563,10 +585,6 @@ class CristianEdit(Gtk.Plug):
self.guardar_configuracion()
def get_if_exit(self):
- """Obtiene el estado de modificación de cada
- buffer de la lista de buffers, sí están modificados
- para consultar al usuario se desea guardar antes
- de cerrarlos o no"""
return self.buffers, self.lugares, self.views
@@ -574,12 +592,14 @@ class CristianEdit(Gtk.Plug):
"""Busca texto en el buffer actual por
cada cambio que se haga en la entrada de texto"""
+ view = self.get_view()
view.buscar_texto(texto)
def buscar_enter(self, widget, texto):
"""Busca texto en el buffer actual y
selecciona la siguiente coincidecia"""
+ view = self.get_view()
view.buscar_texto(texto, enter=True)
def guardar_configuracion(self, *args):
@@ -612,16 +632,30 @@ class CristianEdit(Gtk.Plug):
cfg.read([G.configuracion])
try:
- self.configuraciones['enumeracion'] = bool(cfg.get('datos', 'enumeracion'))
+ self.configuraciones['enumeracion'] = bool(cfg.get('datos',
+ 'enumeracion'))
+
self.configuraciones['fuente'] = cfg.get('datos', 'fuente')
- self.configuraciones['margen'] = int(float(cfg.get('datos', 'margen')))
- self.configuraciones['is_margen'] = bool(cfg.get('datos', 'is_margen'))
+ self.configuraciones['margen'] = int(float(cfg.get('datos',
+ 'margen')))
+
+ self.configuraciones['is_margen'] = bool(cfg.get('datos',
+ 'is_margen'))
+
self.configuraciones['ajuste'] = bool(cfg.get('datos', 'ajuste'))
- self.configuraciones['ajuste_palabras'] = bool(cfg.get('datos', 'ajuste_palabras'))
- self.configuraciones['tabulador'] = int(float(cfg.get('datos', 'tabulador')))
- self.configuraciones['insertar_espacios'] = bool(cfg.get('datos', 'insertar_espacios'))
+ self.configuraciones['ajuste_palabras'] = bool(cfg.get('datos',
+ 'ajuste_palabras'))
+
+ self.configuraciones['tabulador'] = int(float(cfg.get('datos',
+ 'tabulador')))
+
+ self.configuraciones['insertar_espacios'] = bool(cfg.get('datos',
+ 'insertar_espacios'))
+
self.configuraciones['sangria'] = bool(cfg.get('datos', 'sangria'))
- self.configuraciones['recientes'] = str(cfg.get('datos', 'recientes'))
+ self.configuraciones['recientes'] = str(cfg.get('datos',
+ 'recientes'))
+
self.configuraciones['tema'] = str(cfg.get('datos', 'tema'))
except ConfigParser.NoOptionError:
@@ -641,3 +675,4 @@ class CristianEdit(Gtk.Plug):
'recientes': ''}
self.guardar_configuracion()
+
diff --git a/CristianEdit/objetos.py b/CristianEdit/objetos.py
index 4ff92ff..c7a7f19 100644
--- a/CristianEdit/objetos.py
+++ b/CristianEdit/objetos.py
@@ -242,6 +242,8 @@ class Buffer(GtkSource.Buffer):
self.lenguaje_manager = G.lenguaje_manager
self.lenguajes = G.lenguajes
+ self.connect('changed', self.algo)
+
def buscar_lenguaje(self, filename, combo):
"""Busca el lenguaje de programación en un archivo
al guardarlo o abrirlo, sí es que tiene uno"""
@@ -271,10 +273,17 @@ class Buffer(GtkSource.Buffer):
return self.lenguaje
+ def algo(self, widget):
+
+ lineas = self.get_line_count()
+
class View(GtkSource.View):
"""Visor de Texto"""
+ __gsignals__ = {'cambio-de-busqueda': (GObject.SIGNAL_RUN_FIRST,
+ None, (str,))}
+
def __init__(self, buffer=None):
GtkSource.View.__init__(self)
@@ -333,16 +342,32 @@ class View(GtkSource.View):
self.modify_font(fuente)
def buscar_texto(self, texto, enter=None):
- """Buscar Texto"""
+ """Buscar texto. En lugar que no se encuentre,
+ saca la selección, de método manual, ya que de
+ la automática demoraba mucho y se colgaba."""
buffer = self.get_buffer()
+ inicio, fin = buffer.get_bounds()
+ texto_actual = buffer.get_text(inicio, fin, 0)
+ posicion = buffer.get_iter_at_mark(buffer.get_insert())
- cursor_mark = buffer.get_insert()
- start = buffer.get_iter_at_mark(cursor_mark)
- if start.get_offset() == buffer.get_char_count():
- start = buffer.get_start_iter()
+ if texto:
+ if texto in texto_actual:
+ cursor_mark = buffer.get_insert()
+ start = buffer.get_iter_at_mark(cursor_mark)
+
+ if start.get_offset() == buffer.get_char_count():
+ start = buffer.get_start_iter()
- self.seleccionar_texto(texto, start, enter)
+ self.seleccionar_texto(texto, start, enter)
+
+ else:
+ buffer.select_range(posicion, posicion)
+
+ self.emit('cambio-de-busqueda', '#FF0000')
+
+ else:
+ self.emit('cambio-de-busqueda', '#FFFFFF')
def seleccionar_texto(self, text, start, enter):
"""Selecciona el texto solicitado,
@@ -536,14 +561,11 @@ class Barra(Gtk.Toolbar):
self.emit(senial)
- def emitir_buscar(self, widget, *args):
+ def emitir_buscar(self, widget, senial):
"""Emite la señal que corresponde al argumento
'senial', con el texto como parámetro."""
- texto = ''
- for x in args:
- if str(type(x)) == 'str':
- texto = x
+ texto = widget.get_text()
self.emit(senial, texto)
@@ -1408,3 +1430,4 @@ class TerminalNotebook(Gtk.Notebook):
"""Emite la señal 'boton-cerrar-clicked'"""
self.emit('boton-cerrar-clicked', objeto)
+
diff --git a/CristianEdit/objetos.pyc b/CristianEdit/objetos.pyc
index 1bb1284..53b3361 100644
--- a/CristianEdit/objetos.pyc
+++ b/CristianEdit/objetos.pyc
Binary files differ
diff --git a/CristianEdit/objetos.py~ b/CristianEdit/objetos.py~
index 69884de..637ebcd 100644
--- a/CristianEdit/objetos.py~
+++ b/CristianEdit/objetos.py~
@@ -30,34 +30,7 @@ from gi.repository import Vte
from gi.repository import GLib
from Creditos import Creditos
-
-lenguaje_manager = GtkSource.LanguageManager()
-lenguajes = lenguaje_manager.get_language_ids()
-
-lenguajes.sort()
-lenguajes.remove(lenguajes[0])
-lenguajes.insert(0, 'Texto Plano')
-
-estilo_manager = GtkSource.StyleSchemeManager()
-estilos = estilo_manager.get_scheme_ids()
-
-BIENVENIDA = '''\n\nTerminal creada en python,
-por Cristian García <cristian99garcia@gmail.com>'''
-
-
-def get_clasico():
- """Devuelve la posisión de classic en el combo"""
-
- cuenta = 0
- clasico = 0
-
- for estilo in estilos:
- if estilo == 'classic':
- clasico = cuenta
-
- cuenta += 1
-
- return clasico
+import Globales as G
def dialogo_cerrar(direccion, buffer, cristianedit, accion):
@@ -112,7 +85,7 @@ class Menu(Gtk.MenuBar):
def __init__(self, padre):
- Gtk.Menu.__init__(self)
+ Gtk.MenuBar.__init__(self)
items = []
self.padre = padre
@@ -246,9 +219,6 @@ class Menu(Gtk.MenuBar):
self.recientes.append(archivo)
numero += 1
- else:
- self.menu_recientes.get_parent().get_parent().set_sensitive(False)
-
self.show_all()
def borrar_recientes(self):
@@ -264,40 +234,36 @@ class Menu(Gtk.MenuBar):
class Buffer(GtkSource.Buffer):
"""Buffer de Texto"""
- def __init__(self, combo):
+ def __init__(self):
GtkSource.Buffer.__init__(self)
- self.combo = combo
self.lenguaje = None
+ self.lenguaje_manager = G.lenguaje_manager
+ self.lenguajes = G.lenguajes
- def buscar_lenguaje(self, lugar, combo):
+ def buscar_lenguaje(self, filename, combo):
"""Busca el lenguaje de programación en un archivo
al guardarlo o abrirlo, sí es que tiene uno"""
- tipo = list(mimetypes.guess_type(lugar))[0]
- encontrado = False
-
- for id in lenguajes:
- lenguaje = lenguaje_manager.get_language(id)
-
- if lenguaje and len(lenguaje.get_mime_types()):
- mime = lenguaje.get_mime_types()[0]
-
- if tipo == mime:
- self.set_highlight_syntax(True)
- self.set_language(lenguaje)
+ lenguaje = self.lenguaje_manager.guess_language(filename, None)
- list_num = lenguajes.index(id) + 1
- self.lenguaje = lenguaje
- encontrado = True
-
- combo.set_active(list_num)
+ if lenguaje:
+ self.set_highlight_syntax(True)
+ self.set_language(lenguaje)
+
+ try:
+ nombre = lenguaje.get_name()
+ numero = self.lenguajes.index(nombre.lower())
+
+ combo.set_active(numero + 1)
+
+ except:
+ pass
- if not encontrado:
+ else:
self.set_highlight_syntax(False)
-
- self.lenguaje = None
+
combo.set_active(0)
def get_lenguaje(self):
@@ -315,6 +281,11 @@ class View(GtkSource.View):
self.set_buffer(buffer)
self.set_size_request(400, 500)
+
+ self.lenguaje_manager = G.lenguaje_manager
+ self.lenguajes = G.lenguajes
+ self.estilo_manager = G.estilo_manager
+ self.estilos = G.estilos
def deshacer(self):
"""Deshace cambios"""
@@ -328,24 +299,26 @@ class View(GtkSource.View):
if self.get_buffer().can_redo():
self.get_buffer().redo()
- def configurar(self, enumeracion,
- fuente, margen,
- is_margen, ajuste,
- ajuste_palabras,
- tabulador, insertar_espacios,
- sangria, tema):
-
+ def configurar(self, configuraciones):
"""Establecer configuración
- según los argumentos"""
+ según los argumentos."""
+
+ buffer = self.get_buffer()
+
+ enumeracion = configuraciones['enumeracion']
+ margen = configuraciones['margen']
+ is_margen = configuraciones['is_margen']
+ ajuste = configuraciones['ajuste']
+ ajuste_palabras = configuraciones['ajuste_palabras']
+ tabulador = configuraciones['tabulador']
+ insertar_espacios = configuraciones['insertar_espacios']
+ sangria = configuraciones['sangria']
+ tema = configuraciones['tema']
+ fuente = Pango.font_description_from_string(configuraciones['fuente'])
self.set_property('show-line-numbers', enumeracion)
- self.modify_font(Pango.font_description_from_string(fuente))
self.set_property('right-margin-position', margen)
self.set_property('show-right-margin', is_margen)
- self.set_property('insert-spaces-instead-of-tabs', insertar_espacios)
- self.set_tab_width(tabulador)
- self.set_property('auto-indent', sangria)
- self.get_buffer().set_style_scheme(estilo_manager.get_scheme(tema))
if ajuste:
self.set_wrap_mode(Gtk.WrapMode(1))
@@ -353,6 +326,12 @@ class View(GtkSource.View):
if ajuste and ajuste_palabras:
self.set_wrap_mode(Gtk.WrapMode(2))
+ self.set_tab_width(tabulador)
+ self.set_property('insert-spaces-instead-of-tabs', insertar_espacios)
+ self.set_property('auto-indent', sangria)
+ buffer.set_style_scheme(self.estilo_manager.get_scheme(tema))
+ self.modify_font(fuente)
+
def buscar_texto(self, texto, enter=None):
"""Buscar Texto"""
@@ -398,7 +377,7 @@ class Notebook(Gtk.Notebook):
__gsignals__ = {
'boton-cerrar-clicked': (GObject.SIGNAL_RUN_FIRST,
- GObject.TYPE_NONE, (GObject.TYPE_OBJECT,))
+ None, (object,))
}
def __init__(self, padre=None):
@@ -473,49 +452,63 @@ class Notebook(Gtk.Notebook):
self.emit('boton-cerrar-clicked', objeto)
-class Barra(Gtk.HBox):
- """GtkHBox() que simula una GtkToolBar()"""
+class Barra(Gtk.Toolbar):
+ """Barra de herramientas."""
- def __init__(self, funciones, abrir):
-
- Gtk.HBox.__init__(self)
-
- self.funciones = funciones
+ __gsignals__ = {
+ 'abrir': (GObject.SIGNAL_RUN_FIRST,
+ None, []),
+ 'guardar': (GObject.SIGNAL_RUN_FIRST,
+ None, []),
+ 'nuevo': (GObject.SIGNAL_RUN_FIRST,
+ None, []),
+ 'deshacer': (GObject.SIGNAL_RUN_FIRST,
+ None, []),
+ 'rehacer': (GObject.SIGNAL_RUN_FIRST,
+ None, []),
+ 'ejecutar': (GObject.SIGNAL_RUN_FIRST,
+ None, []),
+ 'tipografia': (GObject.SIGNAL_RUN_FIRST,
+ None, []),
+ 'preferencias': (GObject.SIGNAL_RUN_FIRST,
+ None, []),
+ 'buscar_changed': (GObject.SIGNAL_RUN_FIRST,
+ None, (str,)),
+ 'buscar_activate': (GObject.SIGNAL_RUN_FIRST,
+ None, (str,)),
+ }
- self.pack_start(abrir, False, False, 4)
+ def __init__(self):
- guardar = self.funciones[0]
- nuevo = self.funciones[1]
- deshacer = self.funciones[2]
- rehacer = self.funciones[3]
- ejecutar = self.funciones[4]
- seleccionar_fuente = self.funciones[5]
- preferencias = self.funciones[6]
- buscar = self.funciones[7]
- buscar_enter = self.funciones[8]
+ Gtk.Toolbar.__init__(self)
- self.toolbutton(Gtk.STOCK_SAVE, guardar, 'Guardar archivo')
+ self.toolbutton(Gtk.STOCK_OPEN, 'abrir', 'Abrir archivo.')
+ self.toolbutton(Gtk.STOCK_SAVE, 'guardar', 'Guardar archivo.')
self.separador()
- self.toolbutton(Gtk.STOCK_NEW, nuevo, 'Nuevo archivo')
+ self.toolbutton(Gtk.STOCK_NEW, 'nuevo', 'Nuevo archivo.')
self.separador()
- self.toolbutton(Gtk.STOCK_UNDO, deshacer, 'Deshacer cambios')
- self.toolbutton(Gtk.STOCK_REDO, rehacer, 'Rehacer cambios')
- self.toolbutton(Gtk.STOCK_EXECUTE, ejecutar, 'Ejecutar archivo')
+ self.toolbutton(Gtk.STOCK_UNDO, 'deshacer', 'Deshacer cambios.')
+ self.toolbutton(Gtk.STOCK_REDO, 'rehacer', 'Rehacer cambios.')
+ #self.toolbutton(Gtk.STOCK_EXECUTE, 'ejecutar', 'Ejecutar archivo.')
self.separador()
- self.toolbutton(Gtk.STOCK_SELECT_FONT, seleccionar_fuente,
- 'Seleccionar fuente de texto')
- self.toolbutton(Gtk.STOCK_PREFERENCES, preferencias)
+ self.toolbutton(Gtk.STOCK_SELECT_FONT, 'tipografia',
+ 'Seleccionar fuente de texto.')
+ self.toolbutton(Gtk.STOCK_PREFERENCES, 'preferencias', 'Preferencias.')
self.separador()
+
+ item = Gtk.ToolItem()
+ self.add(item)
+
entry = Gtk.Entry()
entry.props.secondary_icon_stock = 'gtk-find'
- entry.connect('changed', buscar)
- entry.connect('activate', buscar_enter)
- entry.connect('icon-release', buscar_enter)
- self.pack_start(entry, False, False, 4)
+ entry.connect('changed', self.emitir_buscar, 'buscar_changed')
+ entry.connect('activate', self.emitir_buscar, 'buscar_activate')
+ entry.connect('icon-release', self.emitir_buscar, 'buscar_activate')
+ item.add(entry)
self.show_all()
@@ -524,17 +517,33 @@ class Barra(Gtk.HBox):
separador = Gtk.SeparatorToolItem()
separador.set_size_request(10, 10)
- self.pack_start(separador, False, False, 0)
+ self.add(separador)
- def toolbutton(self, stock, callback, tooltip=None):
+ def toolbutton(self, stock, senial, tooltip=None):
"""Crea un boton para el Widget clase"""
toolbutton = Gtk.ToolButton(stock)
- toolbutton.connect('clicked', callback)
- self.pack_start(toolbutton, False, False, 0)
- if tooltip != None:
+ toolbutton.connect('clicked', self.emitir, senial)
+
+ if tooltip:
toolbutton.set_tooltip_text(tooltip)
+ self.add(toolbutton)
+
+ def emitir(self, widget, senial):
+ """Emite la señal que corresponde
+ al argumento 'senial'."""
+
+ self.emit(senial)
+
+ def emitir_buscar(self, widget, senial):
+ """Emite la señal que corresponde al argumento
+ 'senial', con el texto como parámetro."""
+
+ texto = widget.get_text()
+
+ self.emit(senial, texto)
+
class Navegador(Gtk.FileChooserDialog):
"""Navegador de archivos"""
@@ -571,7 +580,7 @@ class Navegador(Gtk.FileChooserDialog):
self.destroy()
-class Barra_Inferior(Gtk.HBox):
+class BarraInferior(Gtk.HBox):
"""Un GtkHBox() que contiene los
Widgets de la parte inferior de la ventana"""
@@ -579,7 +588,7 @@ class Barra_Inferior(Gtk.HBox):
Gtk.HBox.__init__(self)
- self.combo = Combo_Lenguajes()
+ self.combo = ComboLenguajes()
self.b_estado = Gtk.Statusbar()
self.b_estado.push(0, 'Línea:0, Columna:0')
@@ -599,7 +608,7 @@ class Barra_Inferior(Gtk.HBox):
return self.b_estado
-class Combo_Estilos(Gtk.ComboBoxText):
+class ComboEstilos(Gtk.ComboBoxText):
"""Un GtkComboBoxText para mostrar y utilizar
los temas instalados en el sistema"""
@@ -607,13 +616,13 @@ class Combo_Estilos(Gtk.ComboBoxText):
Gtk.ComboBoxText.__init__(self)
- for estilo in estilos:
+ for estilo in G.estilos:
self.append_text(estilo)
- self.set_active(estilo_principal)
+ self.set_active(G.estilos.index(estilo_principal))
-class Combo_Lenguajes(Gtk.ComboBoxText):
+class ComboLenguajes(Gtk.ComboBoxText):
"""Un GtkComboBoxText para mostrar los
lenguajes de programación instalados en el sistema"""
@@ -621,9 +630,10 @@ class Combo_Lenguajes(Gtk.ComboBoxText):
Gtk.ComboBoxText.__init__(self)
- self.primera_vez = True
+ self.lenguaje_manager = G.lenguaje_manager
+ self.lenguajes = G.lenguajes
- for lenguaje in lenguajes:
+ for lenguaje in self.lenguajes:
self.append_text(lenguaje)
self.set_active(0)
@@ -639,47 +649,17 @@ class Combo_Lenguajes(Gtk.ComboBoxText):
else:
tipo = 'text/plain'
- if not self.primera_vez:
- self.buscar_lenguaje(tipo, buffer)
-
- else:
- self.primera_vez = False
-
- def buscar_lenguaje(self, filename, buffer):
- """Busca un lenguaje especifico,
- y lo activa en el Widget clase"""
-
- manager = lenguaje_manager
- extension = filename.split('.')[-1]
-
- if extension != filename and extension in lenguajes:
- lenguaje = manager.get_language()
- numero = self.index(extension)
-
- self.set_active(numero)
- buffer.set_language(lenguaje)
-
- else:
- language = manager.guess_language(filename, 'algo')
-
- if language:
- buffer.set_highlight_syntax(True)
- buffer.set_language(language)
-
- else:
- buffer.set_highlight_syntax(False)
-
- buffer.buscar_lenguaje(filename)
+ self.buscar_lenguaje(tipo, buffer)
def get_lenguajes(self):
- """Devuelve la lista con lenguajes ya ordenados por orden alfabetico"""
+ """Devuelve la lista con los lenguajes."""
- return lenguajes
+ return self.lenguajes
def get_lenguaje_manager(self):
- """Devuelve la variable 'lenguaje_manager'"""
+ """Devuelve la variable 'lenguaje_manager'."""
- return lenguaje_manager
+ return self.lenguaje_manager
class DialogoCerrar(Gtk.MessageDialog):
@@ -753,21 +733,23 @@ class DialogoEstado(Gtk.Dialog):
self.label_lineas = Gtk.Label()
self.label_modificado = Gtk.Label()
self.label_fuente = Gtk.Label()
- self.label_lugar = Gtk.Label()
+ self.entry_lugar = Gtk.Entry()
self.label_pestania = Gtk.Label()
+ self.entry_lugar.set_editable(False)
+
self.actualizar_estado()
self.tabla = Gtk.Table(7, 2, False)
label_caracteres = Gtk.Label('Cantidad de caractéres:')
label_lineas = Gtk.Label('Cantidad de líneas:')
- label_lugar = Gtk.Label('Ubicación de archivo:')
+ entry_lugar = Gtk.Label('Ubicación de archivo:')
label_modificado = Gtk.Label('Estado de modificación:')
label_fuente = Gtk.Label('Fuente de Texto:')
label_pestania = Gtk.Label('Pestaña actual:')
- lista = [self.label_caracteres, self.label_lineas, self.label_lugar,
+ lista = [self.label_caracteres, self.label_lineas, self.entry_lugar,
self.label_modificado, self.label_pestania]
for label in lista:
@@ -780,14 +762,14 @@ class DialogoEstado(Gtk.Dialog):
self.tabla.attach(label_caracteres, 0, 1, 0, 1)
self.tabla.attach(label_lineas, 0, 1, 1, 2)
- self.tabla.attach(label_lugar, 0, 1, 2, 3)
+ self.tabla.attach(entry_lugar, 0, 1, 2, 3)
self.tabla.attach(label_modificado, 0, 1, 3, 4)
self.tabla.attach(label_fuente, 0, 1, 4, 5)
self.tabla.attach(label_pestania, 0, 1, 5, 6)
self.tabla.attach(self.label_caracteres, 1, 2, 0, 1)
self.tabla.attach(self.label_lineas, 1, 2, 1, 2)
- self.tabla.attach(self.label_lugar, 1, 2, 2, 3)
+ self.tabla.attach(self.entry_lugar, 1, 2, 2, 3)
self.tabla.attach(self.label_modificado, 1, 2, 3, 4)
self.tabla.attach(self.label_fuente, 1, 2, 4, 5)
self.tabla.attach(self.label_pestania, 1, 2, 5, 6)
@@ -816,7 +798,7 @@ class DialogoEstado(Gtk.Dialog):
self.label_caracteres.set_text(str(buffer.get_char_count()))
self.label_lineas.set_text(str(buffer.get_line_count()))
self.label_fuente.set_text(fuente)
- self.label_lugar.set_text(direccion)
+ self.entry_lugar.set_text(direccion)
self.label_pestania.set_text(str(pagina) + '/' + str(paginas))
if buffer.get_modified():
@@ -831,11 +813,11 @@ class DialogoEstado(Gtk.Dialog):
self.destroy()
-class Selector_de_Fuente(Gtk.FontSelectionDialog):
+class SelectordeFuente(Gtk.FontSelectionDialog):
__gsignals__ = {
'font-changed': (GObject.SIGNAL_RUN_FIRST,
- GObject.TYPE_NONE, (GObject.TYPE_STRING,))
+ None, (str,))
}
def __init__(self, fuente):
@@ -873,33 +855,17 @@ class Selector_de_Fuente(Gtk.FontSelectionDialog):
class Configuraciones(Gtk.Dialog):
- def __init__(self, padre,
- enumeracion,
- margen, is_margen,
- ajuste, ajuste_palabras,
- tabulador, insertar_espacios,
- sangria, tema):
+ __gsignals__ = {
+ 'configuration-changed': (GObject.SIGNAL_RUN_FIRST,
+ None, (GObject.TYPE_PYOBJECT,))
+ }
- ventana = padre.get_parent().get_parent()
+ def __init__(self, padre, configuraciones):
- Gtk.Dialog.__init__(self, 'Configurar CristianEdit 2', ventana)
+ Gtk.Dialog.__init__(self, 'Configurar CristianEdit')
self.padre = padre
- self.enumeracion = enumeracion
- self.margen = margen
- self.is_margen = is_margen
- self.ajuste = ajuste
- self.ajuste_palabras = ajuste_palabras
- self.tabulador = tabulador
- self.insertar_espacios = insertar_espacios
- self.sangria = sangria
- self.tema = tema
- self.lista = [self.enumeracion,
- self.margen, self.is_margen,
- self.ajuste, self.ajuste_palabras,
- self.tabulador,
- self.insertar_espacios,
- self.sangria, self.tema]
+ self.configuraciones = configuraciones
self.set_resizable(False)
@@ -919,8 +885,8 @@ class Configuraciones(Gtk.Dialog):
'Insertar espacios en lugar de tabulaciones')
boton_sangria = Gtk.CheckButton('Sangría automatica')
- ajuste1 = Gtk.Adjustment(self.margen, 1, 1000, 1, 10)
- ajuste2 = Gtk.Adjustment(self.tabulador, 1, 30, 1, 10)
+ ajuste1 = Gtk.Adjustment(self.configuraciones['margen'], 1, 1000, 1, 10)
+ ajuste2 = Gtk.Adjustment(self.configuraciones['tabulador'], 1, 30, 1, 10)
spin1 = Gtk.SpinButton()
spin2 = Gtk.SpinButton()
@@ -930,17 +896,18 @@ class Configuraciones(Gtk.Dialog):
label4 = Gtk.Label('Tema de colores')
l = [label1, label2, label3, label4]
+
for x in l:
x.modify_font(Pango.FontDescription('bold'))
-
- boton_margen.set_active(self.is_margen)
- boton_enumeracion.set_active(self.enumeracion)
+
+ boton_margen.set_active(self.configuraciones['is_margen'])
+ boton_enumeracion.set_active(self.configuraciones['enumeracion'])
spin1.set_adjustment(ajuste1)
spin2.set_adjustment(ajuste2)
- boton_ajuste1.set_active(self.ajuste)
- boton_ajuste2.set_active(self.ajuste_palabras)
- boton_insertar.set_active(self.insertar_espacios)
- boton_sangria.set_active(self.sangria)
+ boton_ajuste1.set_active(self.configuraciones['ajuste'])
+ boton_ajuste2.set_active(self.configuraciones['ajuste_palabras'])
+ boton_insertar.set_active(self.configuraciones['insertar_espacios'])
+ boton_sangria.set_active(self.configuraciones['sangria'])
spin1.set_sensitive(boton_margen.get_active())
boton_ajuste2.set_sensitive(boton_ajuste1.get_active())
@@ -969,8 +936,9 @@ class Configuraciones(Gtk.Dialog):
vbox1.pack_start(boton_ajuste1, False, False, 0)
vbox1.pack_start(boton_ajuste2, False, False, 0)
- combo_estilos = Combo_Estilos(estilos.index(self.tema))
+ combo_estilos = ComboEstilos(self.configuraciones['tema'])
+ print "\n\n\n\n\n", self.configuraciones['tema'], "\n\n\n\n\n"
combo_estilos.connect('changed', self.estilo_changed)
vbox2.pack_start(label4, False, False, 10)
@@ -985,104 +953,69 @@ class Configuraciones(Gtk.Dialog):
def estilo_changed(self, widget):
"""Establece en tema de colores"""
-
- self.tema = estilos[widget.get_active()]
- self.lista[8] = self.tema
- self.padre.set_configuracion(self.lista)
+
+ self.configuraciones['tema'] = G.estilos[widget.get_active()]
+ self.emit('configuration-changed', self.configuraciones)
def sangria_changed(self, widget):
"""Establece o desabilita la sangría automatica"""
- self.sangria = widget.get_active()
- self.lista[7] = self.sangria
-
- self.padre.set_configuracion(self.lista)
+ self.configuraciones['sangria'] = widget.get_active()
+ self.emit('configuration-changed', self.configuraciones)
def insertar_espacios_changed(self, widget):
"""Establece sí resaltar la línea actual o no"""
- self.insertar_espacios = widget.get_active()
- self.lista[6] = self.insertar_espacios
-
- self.padre.set_configuracion(self.lista)
+ self.configuraciones['insertar_espacios'] = widget.get_active()
+ self.emit('configuration-changed', self.configuraciones)
def tabulador_changed(self, widget):
"""Establece el ancho del tabulador"""
- view = self.padre.get_view()
- self.tabulador = widget.get_value()
-
- self.lista[5] = self.tabulador
- self.padre.set_configuracion(self.lista)
+ self.configuraciones['tabulador'] = widget.get_value()
+ self.emit('configuration-changed', self.configuraciones)
def change_ajuste(self, widget, boton):
"""Activa/Desactiva ajuste de texto"""
- view = self.padre.get_view()
- estado = widget.get_active()
-
- boton.set_sensitive(estado)
-
- if estado:
- view.set_wrap_mode(Gtk.WrapMode(1))
- self.ajuste_palabras = False
+ self.configuraciones['ajuste'] = widget.get_active()
- else:
- view.set_wrap_mode(Gtk.WrapMode(0))
+ boton.set_sensitive(self.configuraciones['ajuste'])
- if estado and boton.get_active() and boton.get_sensitive:
- view.set_wrap_mode(Gtk.WrapMode(2))
- self.ajuste_palabras = True
+ if self.configuraciones['ajuste']:
+ self.configuraciones['ajuste_palabras'] = False
- self.ajuste = estado
- self.lista[3] = self.ajuste
- self.lista[4] = self.ajuste_palabras
+ if boton.get_active() and boton.get_sensitive():
+ self.configuraciones['ajuste_palabras'] = True
- self.padre.set_configuracion(self.lista)
+ self.emit('configuration-changed', self.configuraciones)
def change_ajuste_palabras(self, widget):
"""Ajuste por palabras, no divide las palabras en dos líneas"""
- view = self.padre.get_view()
-
- if widget.get_active():
- view.set_wrap_mode(Gtk.WrapMode(2))
-
- else:
- view.set_wrap_mode(Gtk.WrapMode(1))
-
- self.ajuste_palabras = widget.get_active()
-
- self.lista[3] = self.ajuste
- self.lista[4] = self.ajuste_palabras
- self.padre.set_configuracion(self.lista)
+ self.configuraciones['ajuste_palabras'] = widget.get_active()
+ self.emit('configuration-changed', self.configuraciones)
def change_enumeracion(self, widget):
"""Hace que la enumeración sea igual al
estado de activación del botón"""
- self.enumeracion = widget.get_active()
- self.lista[0] = self.enumeracion
-
- self.padre.set_configuracion(self.lista)
+ self.configuraciones['enumeracion'] = widget.get_active()
+ self.emit('configuration-changed', self.configuraciones)
def margen_changed(self, widget):
"""Establece en la columna en la
que se muestra el margen derecho"""
- self.margen = widget.get_value()
- self.lista[1] = self.margen
-
- self.padre.set_configuracion(self.lista)
+ self.configuraciones['margen'] = widget.get_value()
+ self.emit('configuration-changed', self.configuraciones)
def is_margen_changed(self, widget, spin):
"""Establece sí el usuario quiere o no margen derecho"""
- self.is_margen = widget.get_active()
- spin.set_sensitive(self.is_margen)
-
- self.lista[2] = self.is_margen
- self.padre.set_configuracion(self.lista)
+ self.configuraciones['is_margen'] = widget.get_active()
+ spin.set_sensitive(self.configuraciones['is_margen'])
+ self.emit('configuration-changed', self.configuraciones)
def cerrar(self, widget):
"""Destruir al Widget clase"""
@@ -1325,7 +1258,7 @@ class Teclado(Gtk.Dialog):
buffer.set_text(string1 + string2)
-class Terminal_Toolbar(Gtk.Toolbar):
+class TerminalToolbar(Gtk.Toolbar):
def __init__(self, padre):
@@ -1405,7 +1338,7 @@ class Terminal(Vte.Terminal):
"""Imprime un texto cuando
recién se crea el Widget clase"""
- print BIENVENIDA
+ print G.BIENVENIDA
def tecla(self, widget, event):
"""Obtiene el evento de teclado y
@@ -1420,11 +1353,11 @@ class Terminal(Vte.Terminal):
pass
-class Terminal_Notebook(Gtk.Notebook):
+class TerminalNotebook(Gtk.Notebook):
__gsignals__ = {
'boton-cerrar-clicked': (GObject.SIGNAL_RUN_FIRST,
- GObject.TYPE_NONE, (GObject.TYPE_OBJECT,))
+ None, (object,))
}
def __init__(self):