Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRogelio Mita <rogeliomita@activitycentral.com>2013-06-13 21:32:39 (GMT)
committer Rogelio Mita <rogeliomita@activitycentral.com>2013-06-13 21:32:39 (GMT)
commit944c3892d2d113f55d4b7c6e00d0d695da257f77 (patch)
tree751f8024aef7b63ca782f55b93ecf7c21b6d0416
parent38f9ab4b9d5456f4ca1c48a1575995b8442e8710 (diff)
Select destination for results.
-rw-r--r--CeibalEncuesta/gtk2/CeibalEncuesta/CeibalEncuesta.py68
-rw-r--r--CeibalEncuesta/gtk2/CeibalEncuesta/Widgets.py8
-rwxr-xr-xCeibalEncuesta/gtk3/CeibalEncuesta/CeibalEncuesta.py68
-rwxr-xr-xCeibalEncuesta/gtk3/CeibalEncuesta/Widgets.py8
4 files changed, 116 insertions, 36 deletions
diff --git a/CeibalEncuesta/gtk2/CeibalEncuesta/CeibalEncuesta.py b/CeibalEncuesta/gtk2/CeibalEncuesta/CeibalEncuesta.py
index 2fa3027..eea931e 100644
--- a/CeibalEncuesta/gtk2/CeibalEncuesta/CeibalEncuesta.py
+++ b/CeibalEncuesta/gtk2/CeibalEncuesta/CeibalEncuesta.py
@@ -369,6 +369,19 @@ class CeibalEncuesta(gtk.Window):
def __exportar_encuesta(self, widget = None, senial = None):
"""
+ Abre Filechooser para elegir directorio donde se
+ guardará el archivo con los resultados
+ """
+
+ filechooser = My_FileChooser(
+ parent_window = self,
+ action_type = gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ title = "Exportar resultados de encuesta")
+
+ filechooser.connect("load", self.__save_results)
+
+ def __save_results(self, widget = None, chosen_path = WORKPATH):
+ """
Exporta los datos a un archivo con el formato
necesario para ser enviado a web app.
"""
@@ -457,31 +470,52 @@ class CeibalEncuesta(gtk.Window):
poll_id = enc.get("poll_id", "")
hash = int(time.time() * 1000)
- path = os.path.join(WORKPATH, "%s_%s.poll_result" % (poll_id, hash))
+ path = os.path.join(chosen_path, "%s_%s.poll_result" % (poll_id, hash))
import json
- archivo = open(path, "w")
- archivo.write(
- json.dumps(
- out_dict,
- indent=4,
- separators=(", ", ":"),
- sort_keys=True
+ try:
+ archivo = open(path, "w")
+ except IOError, ioe:
+ dialog = My_Alert_Dialog(
+ parent_window = self,
+ label = u"Ocurrió un error inesperado al exportar los resultados."
+ )
+
+ if "Permission denied" in str(ioe):
+ dialog = My_Alert_Dialog(
+ parent_window = self,
+ label = u"No tiene permisos para escribir en el directorio elegido."
+ )
+
+ response = dialog.run()
+ dialog.destroy()
+
+ if widget: widget.destroy()
+
+ self.exportar.emit("activate")
+
+ else:
+ archivo.write(
+ json.dumps(
+ out_dict,
+ indent=4,
+ separators=(", ", ":"),
+ sort_keys=True
+ )
)
- )
- archivo.close()
+ archivo.close()
- dialog = My_Alert_Dialog(
- parent_window = self,
- label = "Encuesta Exportada Correctamente.")
+ dialog = My_Alert_Dialog(
+ parent_window = self,
+ label = "Encuesta Exportada Correctamente.")
- response = dialog.run()
+ response = dialog.run()
- dialog.destroy()
+ dialog.destroy()
- if os.path.exists(BACKUP_PATH):
- os.remove(BACKUP_PATH)
+ if os.path.exists(BACKUP_PATH):
+ os.remove(BACKUP_PATH)
def __load_encuesta_respondida(self, widget, archivo):
"""
diff --git a/CeibalEncuesta/gtk2/CeibalEncuesta/Widgets.py b/CeibalEncuesta/gtk2/CeibalEncuesta/Widgets.py
index 4962f49..1b975a6 100644
--- a/CeibalEncuesta/gtk2/CeibalEncuesta/Widgets.py
+++ b/CeibalEncuesta/gtk2/CeibalEncuesta/Widgets.py
@@ -566,6 +566,9 @@ class My_FileChooser(gtk.FileChooserDialog):
elif action_type == gtk.FILE_CHOOSER_ACTION_SAVE:
texto = "Guardar"
+ elif action_type == gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER:
+ texto = "Elegir ubicacion"
+
abrir = gtk.Button(texto)
salir = gtk.Button("Salir")
@@ -581,7 +584,10 @@ class My_FileChooser(gtk.FileChooserDialog):
def __abrir(self, widget):
- self.emit("load", self.get_filename())
+ if self.get_action() == gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER:
+ self.emit("load", self.get_current_folder())
+ else:
+ self.emit("load", self.get_filename())
self.__salir(None)
def __salir(self, widget):
diff --git a/CeibalEncuesta/gtk3/CeibalEncuesta/CeibalEncuesta.py b/CeibalEncuesta/gtk3/CeibalEncuesta/CeibalEncuesta.py
index 0ee1760..ead8d23 100755
--- a/CeibalEncuesta/gtk3/CeibalEncuesta/CeibalEncuesta.py
+++ b/CeibalEncuesta/gtk3/CeibalEncuesta/CeibalEncuesta.py
@@ -366,6 +366,19 @@ class CeibalEncuesta(Gtk.Window):
def __exportar_encuesta(self, widget = None, senial = None):
"""
+ Abre Filechooser para elegir directorio donde se
+ guardará el archivo con los resultados
+ """
+
+ filechooser = My_FileChooser(
+ parent_window = self,
+ action_type = Gtk.FileChooserAction.SELECT_FOLDER,
+ title = "Exportar resultados de encuesta")
+
+ filechooser.connect("load", self.__save_results)
+
+ def __save_results(self, widget = None, chosen_path = WORKPATH):
+ """
Exporta los datos a un archivo con el formato
necesario para ser enviado a web app.
"""
@@ -454,31 +467,52 @@ class CeibalEncuesta(Gtk.Window):
poll_id = enc.get("poll_id", "")
hash = int(time.time() * 1000)
- path = os.path.join(WORKPATH, "%s_%s.poll_result" % (poll_id, hash))
+ path = os.path.join(chosen_path, "%s_%s.poll_result" % (poll_id, hash))
import json
- archivo = open(path, "w")
- archivo.write(
- json.dumps(
- out_dict,
- indent=4,
- separators=(", ", ":"),
- sort_keys=True
+ try:
+ archivo = open(path, "w")
+ except IOError, ioe:
+ dialog = My_Alert_Dialog(
+ parent_window = self,
+ label = u"Ocurrió un error inesperado al exportar los resultados."
+ )
+
+ if "Permission denied" in str(ioe):
+ dialog = My_Alert_Dialog(
+ parent_window = self,
+ label = u"No tiene permisos para escribir en el directorio elegido."
+ )
+
+ response = dialog.run()
+ dialog.destroy()
+
+ if widget: widget.destroy()
+
+ self.exportar.emit("activate")
+
+ else:
+ archivo.write(
+ json.dumps(
+ out_dict,
+ indent=4,
+ separators=(", ", ":"),
+ sort_keys=True
+ )
)
- )
- archivo.close()
+ archivo.close()
- dialog = My_Alert_Dialog(
- parent_window = self,
- label = "Encuesta Exportada Correctamente.")
+ dialog = My_Alert_Dialog(
+ parent_window = self,
+ label = "Encuesta Exportada Correctamente.")
- response = dialog.run()
+ response = dialog.run()
- dialog.destroy()
+ dialog.destroy()
- if os.path.exists(BACKUP_PATH):
- os.remove(BACKUP_PATH)
+ if os.path.exists(BACKUP_PATH):
+ os.remove(BACKUP_PATH)
def __load_encuesta_respondida(self, widget, archivo):
"""
diff --git a/CeibalEncuesta/gtk3/CeibalEncuesta/Widgets.py b/CeibalEncuesta/gtk3/CeibalEncuesta/Widgets.py
index 96bd190..200c306 100755
--- a/CeibalEncuesta/gtk3/CeibalEncuesta/Widgets.py
+++ b/CeibalEncuesta/gtk3/CeibalEncuesta/Widgets.py
@@ -565,6 +565,9 @@ class My_FileChooser(Gtk.FileChooserDialog):
elif action_type == Gtk.FileChooserAction.SAVE:
texto = "Guardar"
+ elif action_type == Gtk.FileChooserAction.SELECT_FOLDER:
+ texto = "Elegir ubicacion"
+
abrir = Gtk.Button(texto)
salir = Gtk.Button("Salir")
@@ -580,7 +583,10 @@ class My_FileChooser(Gtk.FileChooserDialog):
def __abrir(self, widget):
- self.emit("load", self.get_filename())
+ if self.get_action() == Gtk.FileChooserAction.SELECT_FOLDER:
+ self.emit("load", self.get_current_folder())
+ else:
+ self.emit("load", self.get_filename())
self.__salir(None)
def __salir(self, widget):