elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Security Series.XSS. [Cross Site Scripting]


+  Foro de elhacker.net
|-+  Programación
| |-+  Scripting
| | |-+  Variables en OpenDialog.py no se importan en JottyWindow (python)
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Variables en OpenDialog.py no se importan en JottyWindow (python)  (Leído 2,065 veces)
adgellida


Desconectado Desconectado

Mensajes: 532


Hardware & Software Developer


Ver Perfil WWW
Variables en OpenDialog.py no se importan en JottyWindow (python)
« en: 28 Agosto 2012, 01:06 am »

Ir al final del tema, se descubrió el problema pero no se sabe solucionar.

Soy un principiante en python, he instalado quickly , escribí "quickly tutorial" en el terminal e hice todos los pasos antes de:

"However, the application is not complete. There are a few things left for you to do:"

Todos los pasos siguientes no están hechos porque cuando uso el OpenDialog y selecciono uno de los archivos guardados, el contenido del archivo no se muestra en "textview1" ¿Por qué? Sólo se elimina el contenido escrito. Antes, si se utilizaba sin OpenDialog funcionaba muy bien.

SaveDialog.py funciona correctamente.

-def on_mnu_new_activate(self, widget, data=None) no funciona tampoco.

-Si uso las líneas negritas por las otras no funcionan.

def open_file(self, widget, data=None):
def on_mnu_open_activate(self, widget, data=None):

def save_file(self, widget, data=None):
def on_mnu_save_activate(self, widget, data=None):

-Para ver el código, vayan al siguiente enlace, descomprimir el archivo, instalar "quickly" si no lo tienen, dentro del directorio Jotty, a continuación, poner "quickly run", "quickly edit", "quickly design ", dependiendo de qué es lo que quieran hacer.

jotty - Código problemático con OpenDialog implementado

jotty-part1 - funciona bien, pero sin OpenDialog

Acceso a los mismos aquí  http://www.mediafire.com/?rb2svaudqgxxqq1

Necesito principalmente que la función OpenDialog funcione correctamente

Muchas gracias a todos.

Me puse en contacto con el desarrollador del tutorial (aplicación) y publiqué el tema en los foros de ask ubuntu sin respuesta alguna durante varias horas largas. Espero encontrar a alguien que me ayude con python


Código:
JottyWindow.py

# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
### BEGIN LICENSE
# This file is in the public domain
### END LICENSE

import gettext
from gettext import gettext as _
gettext.textdomain('jotty')

import os
from gi.repository import GLib # pylint: disable=E0611
from gi.repository import Gtk # pylint: disable=E0611
import logging
logger = logging.getLogger('jotty')

from jotty_lib import Window
from jotty.AboutJottyDialog import AboutJottyDialog
from jotty.PreferencesJottyDialog import PreferencesJottyDialog
from jotty.SaveDialog import SaveDialog
from jotty.OpenDialog import OpenDialog

# See jotty_lib.Window.py for more details about how this class works
class JottyWindow(Window):
    __gtype_name__ = "JottyWindow"
    
    def finish_initializing(self, builder): # pylint: disable=E1002
        """Set up the main window"""
        super(JottyWindow, self).finish_initializing(builder)

        self.AboutDialog = AboutJottyDialog
        self.PreferencesDialog = PreferencesJottyDialog

        # Code for other initialization actions should be added here.

    def on_mnu_save_activate(self, widget, data=None):
    #def save_file(self, widget, data=None):
        print "save"
        #get the title from the user
        saber = SaveDialog()
        result = saber.run()
        title = saber.title_text

        saber.destroy()
        if result != Gtk.ResponseType.OK:
            return

        #get the string
        buff = self.ui.textview1.get_buffer()
        start_iter = buff.get_start_iter()
        end_iter = buff.get_end_iter()
        text = buff.get_text(start_iter, end_iter, True)

        #create the filename
        data_dir = GLib.get_user_data_dir()
        jotty_dir = os.path.join(data_dir, "jotty")
        filename = os.path.join(jotty_dir, title)

        #write the data
        GLib.mkdir_with_parents(jotty_dir, 0o700)
        GLib.file_set_contents(filename, text)

    #def open_file(self, widget, data=None):
    def on_mnu_open_activate(self, widget, data=None):
        #get the name of the document to open
        opener = OpenDialog()
        result = opener.run()
        filename = opener.selected_file

        #close the dialog, and check whether to proceed
        opener.destroy()
        if result != Gtk.ResponseType.OK:
            return

        #try to get the data from the file if it exists
        try:
            success, text = GLib.file_get_contents(filename)
        except Exception:
            text = ""

        #set the UI to display the string
        buff = self.ui.textview1.get_buffer()
        buff.set_text(text)

    def on_mnu_new_activate(self, widget, data=None):
        self.ui.entry1.set_text("Note Title")
        buff = self.ui.textview1.get_buffer()
        buff.set_text("")


Código:
OpenDialog.py

# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
### BEGIN LICENSE
# This file is in the public domain
### END LICENSE

from gi.repository import Gtk # pylint: disable=E0611

from jotty_lib.helpers import get_builder

import gettext
from gettext import gettext as _
gettext.textdomain('jotty')

import os
from quickly.widgets.dictionary_grid import DictionaryGrid
from gi.repository import GLib # pylint: disable=E0611

class OpenDialog(Gtk.Dialog):
    __gtype_name__ = "OpenDialog"

    def __new__(cls):
        """Special static method that's automatically called by Python when
        constructing a new instance of this class.
        
        Returns a fully instantiated OpenDialog object.
        """
        builder = get_builder('OpenDialog')
        new_object = builder.get_object('open_dialog')
        new_object.finish_initializing(builder)
        return new_object

    def finish_initializing(self, builder):
        """Called when we're finished initializing.

        finish_initalizing should be called after parsing the ui definition
        and creating a OpenDialog object with it in order to
        finish initializing the start of the new OpenDialog
        instance.
        """
        # Get a reference to the builder and set up the signals.
        self.builder = builder
        self.ui = builder.get_ui(self)
        
        #get the jotty document names
        data_dir = GLib.get_user_data_dir()
        jotty_dir = os.path.join(data_dir, "jotty")
        filenames = os.listdir(jotty_dir)
        
        #put them into a grid
        dicts = [{'Name': x, 'File': os.path.join(jotty_dir, x)} for x in filenames]
        self.grid = DictionaryGrid(dictionaries=dicts, keys=['Name'])
        
        #add grid to dialog
        self.grid.show()
        self.ui.box1.pack_end(self.grid, True, True, 0)

    def on_btn_ok_clicked(self, widget, data=None):
        """The user has elected to save the changes.

        Called before the dialog returns Gtk.ResponseType.OK from run().
        """
        pass

    def on_btn_cancel_clicked(self, widget, data=None):
        """The user has elected cancel changes.

        Called before the dialog returns Gtk.ResponseType.CANCEL for run()
        """
        pass
        
    @property
    def selected_file(self):
        rows = self.grid.selected_rows
        if len(rows) < 1:
            return None
        else:
            return rows[0]['Name']


if __name__ == "__main__":
    dialog = OpenDialog()
    dialog.show()
    Gtk.main()



« Última modificación: 16 Septiembre 2012, 13:31 pm por urban fury » En línea

adgellida


Desconectado Desconectado

Mensajes: 532


Hardware & Software Developer


Ver Perfil WWW
Re: Por qué OpenDialog.py no me funciona en el tutorial de quickly (python)
« Respuesta #1 en: 3 Septiembre 2012, 16:55 pm »

Descubrí el problema! No funciona el "from" correctamente.

Lo solucioné agregando después de todos los "from" en JottyWindow:

Código:
data_dir = GLib.get_user_data_dir()
jotty_dir = os.path.join(data_dir, "jotty")
os.chdir(jotty_dir)

Código que está en OpenDialog

A alguien se le ocurre como importar correctamente el OpenDialog para no tener que repetir código?

Así lo hago yo, está bien?

Código:
from jotty.OpenDialog import OpenDialog


« Última modificación: 3 Septiembre 2012, 17:23 pm por urban fury » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Insertar variables en SQLITE3 Python
Scripting
CaronteGold 4 5,811 Último mensaje 13 Septiembre 2010, 01:32 am
por CaronteGold
[Python] - Generador de variables
Scripting
ChicoMaravilla 3 5,090 Último mensaje 21 Enero 2011, 16:00 pm
por Karcrack
[Python]Crear variables.....
Scripting
Jirp96 3 7,198 Último mensaje 27 Mayo 2011, 01:29 am
por Novlucker
Por qué OpenDialog.py no me funciona en el tutorial de quickly (python)
Programación General
adgellida 2 1,762 Último mensaje 28 Agosto 2012, 01:03 am
por adgellida
¿Quieres vender tu móvil? Importan el dónde y el cómo
Noticias
wolfbcn 0 1,293 Último mensaje 13 Septiembre 2013, 02:23 am
por wolfbcn
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines