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()