diff options
author | Rogelio Mita <rogeliomita@activitycentral.com> | 2013-06-25 19:51:03 (GMT) |
---|---|---|
committer | Rogelio Mita <rogeliomita@activitycentral.com> | 2013-06-25 19:51:03 (GMT) |
commit | f477e69bcb6d87116a150b259de97e5a72e6339e (patch) | |
tree | 75b12025e6f971c2dbc728b2954a1e2f0e2e5bc0 | |
parent | 0febdb8535ca6f7cefc2b2904adb8f2871de29bd (diff) |
Page buttons new behaviour
-rw-r--r-- | CeibalEncuesta/gtk2/CeibalEncuesta/Widgets.py | 106 |
1 files changed, 93 insertions, 13 deletions
diff --git a/CeibalEncuesta/gtk2/CeibalEncuesta/Widgets.py b/CeibalEncuesta/gtk2/CeibalEncuesta/Widgets.py index 50ec6b2..b6d451c 100644 --- a/CeibalEncuesta/gtk2/CeibalEncuesta/Widgets.py +++ b/CeibalEncuesta/gtk2/CeibalEncuesta/Widgets.py @@ -34,6 +34,7 @@ WORKPATH = os.path.join(HOME, "CeibalEncuesta") PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__)) ICON = PROJECT_ROOT + '/Iconos/ceibal.png' NEXT_PAGE_ACTIVE = PROJECT_ROOT + "/Iconos/next-page-active.png" +NEXT_PAGE_INACTIVE = PROJECT_ROOT + "/Iconos/next-page-inactive.png" NEXT_PAGE_OVER = PROJECT_ROOT + "/Iconos/next-page-over.png" NEXT_PAGE_DOWN = PROJECT_ROOT + "/Iconos/next-page-down.png" PREV_PAGE_ACTIVE = PROJECT_ROOT + "/Iconos/prev-page-active.png" @@ -172,16 +173,55 @@ class Panel(gtk.Paned): break if index_visible == 0: - self.toolbar_encuesta.anterior.set_sensitive(False) + self.toolbar_encuesta.anterior.hide() else: - self.toolbar_encuesta.anterior.set_sensitive(True) + self.toolbar_encuesta.anterior.show_now() if index_visible == grupos.index(grupos[-1]): - self.toolbar_encuesta.siguiente.set_sensitive(False) - + self.toolbar_encuesta.siguiente.hide() else: - self.toolbar_encuesta.siguiente.set_sensitive(True) + self.toolbar_encuesta.siguiente.show_now() + + self.toolbar_encuesta.siguiente.emit("update_status", self) + + def current_group(self): + grupos = self.box_encuesta.get_children() + + for child in grupos: + if child.get_visible(): + index_visible = grupos.index(child) + break + + return grupos[index_visible] + + def visible_questions(self): + + visible_questions = [] + + current_group = self.current_group() + + for question in current_group.box_preguntas: + if question.get_visible(): + visible_questions.append(question) + + return visible_questions + + def incomplete_questions(self): + without_answer = [] + + for question in self.visible_questions(): + active_options = question.widget_obtions.get_active_options() + # TODO: Revisar get_active_options para que funcione con cualquier + # tipo de widget y no diferenciar cuando es TextInput + if not len(active_options): + if question.pregunta.get("widget_type", None) == "TextInput": + if not question.widget_obtions.get_text().strip(): + without_answer.append(question) + else: + without_answer.append(question) + + return without_answer def __accion_encuesta(self, widget, accion): """ @@ -189,8 +229,6 @@ class Panel(gtk.Paned): a otro según valor de accion. """ - self._window.get_vadjustment().set_value(0) - index_visible = 0 grupos = self.box_encuesta.get_children() @@ -205,12 +243,14 @@ class Panel(gtk.Paned): map(self.__hide_groups, grupos) map(self.__show_groups, [grupos[index_visible - 1]]) self.box_encuesta.queue_draw() + self._window.get_vadjustment().set_value(0) - elif accion == "Siguiente": + elif accion == "Siguiente" and self.toolbar_encuesta.siguiente.active: if index_visible < len(grupos)-1: map(self.__hide_groups, grupos) map(self.__show_groups, [grupos[index_visible + 1]]) self.box_encuesta.queue_draw() + self._window.get_vadjustment().set_value(0) self.__check_sensibility_butons() @@ -855,12 +895,18 @@ class Grupo(gtk.Frame): self.show_all() + def __emit_update_button(self): + panel = self.get_toplevel().panel + siguiente = panel.toolbar_encuesta.siguiente + siguiente.emit("update_status", panel) + def __emit_text_and_change(self, pregunta, id_opcion, text, activan): """ Cuando el usuario ingresa algún valor en una entrada de texto, se manda guardar los datos y chequear las dependencias. """ + self.__emit_update_button() self.emit("text_and_change", pregunta, id_opcion, text, activan) def __change(self, widget, activan): @@ -869,6 +915,7 @@ class Grupo(gtk.Frame): dependencias y se guardan los datos. """ + self.__emit_update_button() self.emit("new", widget, activan) def update(self, dict): @@ -879,6 +926,7 @@ class Grupo(gtk.Frame): esos valores. """ + self.__emit_update_button() for child in self.box_preguntas.get_children(): # Si se respondió esta pregunta @@ -911,6 +959,9 @@ class Pregunta(gtk.VBox): gobject.TYPE_NONE,(gobject.TYPE_STRING, gobject.TYPE_STRING,gobject.TYPE_PYOBJECT))} + def __str__(self): + return "pos: %s, pregunta: %s" % (self.indice, self.pregunta["name"]) + def __init__(self, indice_pregunta, pregunta): gtk.VBox.__init__(self) @@ -1649,14 +1700,20 @@ class ToolbarEncuesta(gtk.HBox): class PageButton(gtk.Button): __gsignals__ = { - "enter-notify-event" : "override" + "enter-notify-event" : "override", + "update_status":( + gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, ) + ) } def __init__(self, label, img, imgs, *args, **kwargs): gtk.Button.__init__(self, None, *args, **kwargs) + self.label = None self.accion = label + self.active = True self.imgs = { "normal": img, @@ -1671,10 +1728,10 @@ class PageButton(gtk.Button): box = gtk.HBox() if label: - label = gtk.Label(label) - label.set_padding(10, 0) - label.modify_fg(0, gdk.color_parse("#B40404")) - box.pack_start(label) + self.label = gtk.Label(label) + self.label.set_padding(10, 0) + self.label.modify_fg(0, gdk.color_parse("#B40404")) + box.pack_start(self.label) box.pack_start(self.img_normal) self.add(box) @@ -1685,6 +1742,27 @@ class PageButton(gtk.Button): self.connect("activate", self.__button_event, "down") self.connect("enter", self.__button_event, "enter") self.connect("leave", self.__button_event, "leave") + self.connect("update_status", self.__update_status) + + def __update_status(self, widget, panel): + + new_img = NEXT_PAGE_ACTIVE + incomplete_questions = panel.incomplete_questions() + color = "#B40404" + + if len(incomplete_questions): + new_img = NEXT_PAGE_INACTIVE + color = "#7EAD45" + self.active = False + else: + self.active = True + + img = gtk.Image() + img_pixbuf = gdk.pixbuf_new_from_file(new_img) + img_scaled = img_pixbuf.scale_simple( + 45, 45, gdk.INTERP_BILINEAR) + self.img_normal.set_from_pixbuf(img_scaled) + if self.label: self.label.modify_fg(0, gdk.color_parse(color)) def do_enter_notify_event(self, widget): @@ -1692,6 +1770,8 @@ class PageButton(gtk.Button): def __button_event(self, widget, img_file=None): + if not self.active: return + if img_file is None: return img = gtk.Image() |