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-17 16:11:48 (GMT)
committer Rogelio Mita <rogeliomita@activitycentral.com>2013-06-18 18:18:04 (GMT)
commitc5534c77ec913e8780197523e9975bb437838f58 (patch)
treeb720b9004ab3cbc6164c52b0066f7d9d79022e39
parent9e8f3452b1183e917b1aca5fa49d3651840a0470 (diff)
First impression of new style
-rw-r--r--CeibalEncuesta/gtk2/CeibalEncuesta/CeibalEncuesta.py12
-rw-r--r--CeibalEncuesta/gtk2/CeibalEncuesta/Widgets.py257
2 files changed, 180 insertions, 89 deletions
diff --git a/CeibalEncuesta/gtk2/CeibalEncuesta/CeibalEncuesta.py b/CeibalEncuesta/gtk2/CeibalEncuesta/CeibalEncuesta.py
index eea931e..9af09de 100644
--- a/CeibalEncuesta/gtk2/CeibalEncuesta/CeibalEncuesta.py
+++ b/CeibalEncuesta/gtk2/CeibalEncuesta/CeibalEncuesta.py
@@ -58,6 +58,7 @@ archivo.close()
gobject.threads_init()
gdk.threads_init()
+
class CeibalEncuesta(gtk.Window):
__gsignals__ = {
@@ -76,7 +77,6 @@ class CeibalEncuesta(gtk.Window):
self.set_resizable(True)
self.set_size_request(640, 480)
- self.set_border_width(5)
self.set_position(gtk.WIN_POS_CENTER)
@@ -96,7 +96,7 @@ class CeibalEncuesta(gtk.Window):
box.pack_start(self.__get_menu(), False, False, 5)
box.pack_start(self.infowidget, False, False, 5)
- box.pack_start(self.panel, True, True, 0)
+ box.pack_end(self.panel, True, True, 0)
self.add(box)
@@ -121,7 +121,8 @@ class CeibalEncuesta(gtk.Window):
if not os.path.exists(BACKUP_PATH):
self.__save_json(path=BACKUP_PATH)
- self.fullscreen()
+ self.connect("destroy", gtk.main_quit)
+ self.show_all()
def __init(self, widget = None):
"""
@@ -160,6 +161,9 @@ class CeibalEncuesta(gtk.Window):
if reset: self.__init()
+ self.fullscreen()
+ self.panel.box_encuesta.queue_draw()
+
def do_window_state_event(self, event, *args, **kwargs):
is_fullscreen = False
@@ -198,6 +202,7 @@ class CeibalEncuesta(gtk.Window):
self.panel.show_lista()
self.menu_bar.show_all()
self.infowidget.show_all()
+ self.panel.box_encuesta.queue_draw()
def __do_draw(self, widget, event):
"""
@@ -716,7 +721,6 @@ class CeibalEncuesta(gtk.Window):
os.remove(TEMPPATH)
def __salir(self, widget = None, senial = None):
-
sys.exit(0)
if __name__ == "__main__":
diff --git a/CeibalEncuesta/gtk2/CeibalEncuesta/Widgets.py b/CeibalEncuesta/gtk2/CeibalEncuesta/Widgets.py
index 1b975a6..7b32abc 100644
--- a/CeibalEncuesta/gtk2/CeibalEncuesta/Widgets.py
+++ b/CeibalEncuesta/gtk2/CeibalEncuesta/Widgets.py
@@ -20,16 +20,30 @@
import os
import base64
+from math import pi
import gtk
from gtk import gdk
import gobject
import pango
+import cairo
import Globales as G
HOME = os.environ["HOME"]
WORKPATH = os.path.join(HOME, "CeibalEncuesta")
+ICON = 'Iconos/ceibal.png'
+
+
+def draw_rounded(cr, area, radius):
+ """ draws rectangles with rounded (circular arc) corners """
+ a,b,c,d = area
+ cr.arc(a + radius, c + radius, radius, 2*(pi/2), 3*(pi/2))
+ cr.arc(b - radius, c + radius, radius, 3*(pi/2), 4*(pi/2))
+ cr.arc(b - radius, d - radius, radius, 0*(pi/2), 1*(pi/2))
+ cr.arc(a + radius, d - radius, radius, 1*(pi/2), 2*(pi/2))
+ cr.close_path()
+
class Panel(gtk.Paned):
@@ -49,6 +63,8 @@ class Panel(gtk.Paned):
gtk.Paned.__init__(self)
+ self.cr = None
+
self.modify_bg(0, gdk.color_parse("#d8eeb1"))
self.encuestados = None # mantiene csv para guardarlo como tal
@@ -71,30 +87,59 @@ class Panel(gtk.Paned):
self.pack1(box, resize = False, shrink = True)
# Derecha
- base_box = gtk.VBox()
+ window = gtk.ScrolledWindow(vadjustment=gtk.Adjustment())
+ window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
+ window.set_shadow_type(gtk.SHADOW_NONE)
+
+ # Make scrolleable main box questions container, one group
+ container = gtk.VBox()
self.box_encuesta = gtk.VBox()
- scroll = gtk.ScrolledWindow()
- scroll.set_policy(
- gtk.POLICY_AUTOMATIC,
- gtk.POLICY_AUTOMATIC)
+ container.pack_start(self.box_encuesta, True, True)
+ self.toolbar_encuesta = ToolbarEncuesta()
+ container.pack_end(self.toolbar_encuesta, False, False, 30)
+ window.add_with_viewport(container)
- scroll.add_with_viewport(self.box_encuesta)
+ self.pack2(window, resize = True, shrink = False)
- self.toolbar_encuesta = ToolbarEncuesta()
+ self.show_all()
- base_box.pack_start(scroll, True, True, 0)
- base_box.pack_start(self.toolbar_encuesta, False, False, 0)
+ self.toolbar_encuesta.connect("accion", self.__accion_encuesta)
+ container.connect("expose-event", self.expose)
- self.pack2(base_box, resize = True, shrink = True)
+ def expose(self, widget, event):
- self.show_all()
+ x,y,w,h = widget.get_toplevel().get_allocation()
- self.scroll_list.hide()
- self.box_encuesta.hide()
+ cr = widget.window.cairo_create()
- self.toolbar_encuesta.connect("accion", self.__accion_encuesta)
+ w_, h = widget.get_parent().size_request()
+
+ none, none, none, top_level_height = widget.get_toplevel().get_allocation()
+ if h < top_level_height:
+ h = top_level_height
+
+ cr.set_source_color(gdk.color_parse("#1C1C1C"))
+ cr.rectangle(x, y, w, h)
+ cr.fill_preserve()
+
+ scrollbar_w, scrollbar_h = widget.get_parent().get_parent(
+ ).get_vscrollbar().size_request()
+
+ draw_rounded(cr, (0, w - scrollbar_w - 8, 0, h - 8 -25), 35)
+ cr.stroke()
+
+ cr.set_source_color(gdk.color_parse("#38610B"))
+ draw_rounded(cr, (8, w - scrollbar_w - 16 - 25, 0, h - 8 - 25), 20)
+ cr.fill_preserve()
+ cr.stroke()
+
+ cr.set_source_color(gdk.color_parse("#E3F6CE"))
+ draw_rounded(cr, (50, w - scrollbar_w - 16, 16, h - 8), 20)
+ cr.fill_preserve()
+
+ return False
def __check_sensibility_butons(self):
"""
@@ -138,15 +183,18 @@ class Panel(gtk.Paned):
index_visible = grupos.index(child)
break
+ event = gdk.Event(gdk.EXPOSE)
if accion == "Pag. Anterior":
if index_visible > 0:
map(self.__hide_groups, grupos)
map(self.__show_groups, [grupos[index_visible - 1]])
+ self.box_encuesta.queue_draw()
elif accion == "Pag. Siguiente":
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.__check_sensibility_butons()
@@ -770,12 +818,11 @@ class Grupo(gtk.Frame):
gtk.Frame.__init__(self)
- self.modify_bg(0, gdk.color_parse("#d8eeb1"))
-
self.indice = indice_grupo # indice del grupo en la encuesta
self.grupo = grupo.copy() # Diccionario del grupo en la encuesta
- self.set_label(self.grupo["name"])
+ #self.set_label(self.grupo["name"])
+ self.set_shadow_type(gtk.SHADOW_NONE)
self.box_preguntas = gtk.VBox()
self.add(self.box_preguntas)
@@ -787,7 +834,7 @@ class Grupo(gtk.Frame):
for indice in keys:
pregunta = Pregunta(indice, preguntas[indice])
- self.box_preguntas.pack_start(pregunta, False, True, 3)
+ self.box_preguntas.pack_start(pregunta, True, False, 3)
pregunta.connect("new", self.__change)
pregunta.connect("text_and_change", self.__emit_text_and_change)
@@ -823,7 +870,7 @@ class Grupo(gtk.Frame):
if dict["fields"].get(child.indice, False):
child.update(dict["fields"][child.indice])
-class Pregunta(gtk.HBox):
+class Pregunta(gtk.VBox):
"""
Box con Pregunta.
@@ -851,11 +898,15 @@ class Pregunta(gtk.HBox):
def __init__(self, indice_pregunta, pregunta):
- gtk.HBox.__init__(self)
+ gtk.VBox.__init__(self)
self.indice = indice_pregunta
self.pregunta = pregunta.copy()
+ # CEIBAL ICON PIXBUF
+ # TODO: def question_icon(self, scaled_size)
+ self.question_icon = gdk.pixbuf_new_from_file(ICON)
+
self.widget_obtions = None
widget = self.pregunta["widget_type"]
@@ -879,14 +930,37 @@ class Pregunta(gtk.HBox):
print "Widget no Considerado", widget
label = gtk.Label(self.pregunta["name"])
-
- pangoFont = pango.FontDescription("10")
-
+ pangoFont = pango.FontDescription("30")
label.modify_font(pangoFont)
- label.modify_fg(0, gdk.Color(0, 0, 65000))
-
- self.pack_start(label, False, True, 5)
- self.pack_end(self.widget_obtions, True, True, 0)
+ label.set_line_wrap(True)
+
+ # --- QUESTION TITLE INDENT: horizontal alignment
+ halign = gtk.Alignment(0, 0, 1, 0)
+ halign.set_padding(50, 0, 50, 0)
+
+ # CEIBAL ICON | Question title
+ question_hbox = gtk.HBox()
+ question_icon = gtk.Image()
+ scaled_qicon = self.question_icon.scale_simple(
+ 60, 60, gdk.INTERP_BILINEAR)
+ question_icon.set_from_pixbuf(scaled_qicon)
+ question_hbox.pack_start(question_icon, False, False, 10)
+ title = label
+ question_hbox.pack_start(title, False, False, 25)
+
+ halign.add(question_hbox)
+ self.pack_start(halign, False, False)
+ # --- END QUESTION TITLE INDENT
+
+ # --- OPTIONS INDENT: horizontal alignment for question's options
+ halign = gtk.Alignment(0.2, 0, 0, 0)
+
+ # Vertical list of question's options
+ vbbox = gtk.VButtonBox()
+ vbbox.add(self.widget_obtions)
+ halign.add(vbbox)
+ self.pack_end(halign)
+ # -- END OPTIONS INDENT
self.show_all()
@@ -1069,6 +1143,10 @@ class Widget_TextInput(gtk.Entry):
gtk.Entry.__init__(self)
+ font_description = pango.FontDescription("24")
+ self.modify_font(font_description)
+ self.set_size_request(24*20, -1)
+
self.nombre = "TextInput"
self.options = options.copy()
@@ -1172,7 +1250,7 @@ class Widget_TextInput(gtk.Entry):
self.emit("text_and_change", key, text, activan)
-class Widget_RadioButon(gtk.ButtonBox):
+class Widget_RadioButon(gtk.VButtonBox):
"""
Contenedor de opciones para respuestas posibles en una pregunta.
@@ -1190,7 +1268,7 @@ class Widget_RadioButon(gtk.ButtonBox):
def __init__(self, options):
- gtk.ButtonBox.__init__(self)
+ gtk.VButtonBox.__init__(self)
self.nombre = "RadioButton"
@@ -1209,11 +1287,9 @@ class Widget_RadioButon(gtk.ButtonBox):
radio = MyRadioButton(key)
- text = self.options[key].get("text", "")
+ text = self.options[key].get("text", None)
imagen = self.options[key].get("img", "")
- if text: radio.set_label(text)
-
if imagen:
loader = gdk.PixbufLoader()
image_string = base64.b64decode(imagen)
@@ -1227,7 +1303,8 @@ class Widget_RadioButon(gtk.ButtonBox):
radio.set_group(self.null_button)
- self.pack_start(radio, False, False, 3)
+ r = MyContainer(radio, text)
+ self.pack_start(r, False, False, 3)
self.null_button.set_active(True)
@@ -1245,7 +1322,7 @@ class Widget_RadioButon(gtk.ButtonBox):
options = self.get_children()
for child in options:
-
+ child = child.get_button()
if child.get_active():
activas.append(child.indice)
@@ -1264,7 +1341,7 @@ class Widget_RadioButon(gtk.ButtonBox):
activan = []
for child in options:
-
+ child = child.get_button()
if child.get_active():
activan.append(child.indice)
@@ -1281,6 +1358,7 @@ class Widget_RadioButon(gtk.ButtonBox):
options = self.get_children()
for child in options:
+ child = child.get_button()
if child.indice in dict.get("default", []):
child.set_active(True)
@@ -1299,6 +1377,7 @@ class Widget_RadioButon(gtk.ButtonBox):
activan = []
for child in options:
+ child = child.get_button()
child.set_active(False)
self.null_button.set_active(True)
@@ -1306,7 +1385,7 @@ class Widget_RadioButon(gtk.ButtonBox):
### Porque se debe avisar que esta pregunta se ha desactivado.
self.emit("new", activan)
-class Widget_MultipleCheckBox(gtk.Table):
+class Widget_MultipleCheckBox(gtk.VButtonBox):
"""
Contenedor de opciones para respuestas posibles en una pregunta.
@@ -1326,17 +1405,7 @@ class Widget_MultipleCheckBox(gtk.Table):
self.nombre = "MultipleCheckBox"
- columns = 2
-
- rows = int(len(options)/columns)
-
- while rows*columns < int(len(options)):
- rows += 1
-
- gtk.Table.__init__(
- self, rows = rows,
- columns = columns,
- homogeneous = True)
+ gtk.VButtonBox.__init__(self)
self.options = options.copy()
self.updating = False
@@ -1344,18 +1413,13 @@ class Widget_MultipleCheckBox(gtk.Table):
keys = self.options.keys()
keys.sort()
- col = 0
- row = 0
-
for key in keys:
check = MyCheckButton(key)
- text = self.options[key].get("text", "")
+ text = self.options[key].get("text", None)
imagen = self.options[key].get("img", "")
- if text: check.set_label(text)
-
if imagen:
loader = gdk.PixbufLoader()
image_string = base64.b64decode(imagen)
@@ -1367,15 +1431,8 @@ class Widget_MultipleCheckBox(gtk.Table):
check.set_image(gtk.image_new_from_pixbuf(pixbuf))
- self.attach_defaults(check,
- col, col+1,
- row, row+1)
-
- col += 1
-
- if col == columns:
- col = 0
- row += 1
+ c = MyContainer(check, text)
+ self.pack_start(c, False, False, 3)
check.connect("toggled", self.__change)
@@ -1391,7 +1448,7 @@ class Widget_MultipleCheckBox(gtk.Table):
options = self.get_children()
for child in options:
-
+ child = child.get_button()
if child.get_active():
activas.append(child.indice)
@@ -1410,7 +1467,7 @@ class Widget_MultipleCheckBox(gtk.Table):
activan = []
for child in options:
-
+ child = child.get_button()
if child.get_active():
activan.append(child.indice)
@@ -1427,6 +1484,7 @@ class Widget_MultipleCheckBox(gtk.Table):
options = self.get_children()
for child in options:
+ child = child.get_button()
if child.indice in dict.get("default", []):
child.set_active(True)
@@ -1445,11 +1503,47 @@ class Widget_MultipleCheckBox(gtk.Table):
activan = []
for child in options:
+ child = child.get_button()
child.set_active(False)
### Porque se debe avisar que esta pregunta se ha desactivado.
self.emit("new", activan)
+
+class MyContainer(gtk.HBox):
+
+ __gsignals__ = {
+ "accion":(gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE, (gobject.TYPE_STRING,))}
+
+ def __init__(self, button, label):
+
+ gtk.HBox.__init__(self)
+
+ self.button = button
+ self.text_label = label
+ self.label = None
+
+ if self.text_label:
+ self.label = gtk.Label(label)
+ self.label.modify_font(pango.FontDescription("24"))
+
+ align = gtk.Alignment(0, 0, 0, 0)
+ align.set_padding(10, 0, 50, 0)
+ align.add(self.button)
+ self.pack_start(align, False, False)
+ if self.label:
+ align = gtk.Alignment(0, 0, 0, 0)
+ align.set_padding(0, 0, 25, 0)
+ align.add(self.label)
+ self.pack_start(align, False, False)
+
+ self.show_all()
+
+ def get_button(self):
+ return self.button
+
+
class MyCheckButton(gtk.CheckButton):
def __init__(self, indice):
@@ -1493,7 +1587,7 @@ class My_Alert_Dialog(gtk.Dialog):
self.vbox.pack_start(label, True, True, 0)
-class ToolbarEncuesta(gtk.Toolbar):
+class ToolbarEncuesta(gtk.HBox):
__gsignals__ = {
"accion":(gobject.SIGNAL_RUN_FIRST,
@@ -1501,34 +1595,27 @@ class ToolbarEncuesta(gtk.Toolbar):
def __init__(self):
- gtk.Toolbar.__init__(self)
-
- self.modify_bg(0, gdk.color_parse("#d8eeb1"))
-
- separador = gtk.SeparatorToolItem()
- separador.props.draw = False
- separador.set_size_request(0, -1)
- separador.set_expand(True)
-
- self.insert(separador, -1)
+ gtk.HBox.__init__(self)
- item = gtk.ToolItem()
- item.set_expand(False)
self.anterior = gtk.Button("Pag. Anterior")
self.anterior.set_tooltip_text("Ir a la Página de Preguntas Anterior")
self.anterior.connect("clicked", self.__button_clicked)
- self.anterior.show()
- item.add(self.anterior)
- self.insert(item, -1)
- item = gtk.ToolItem()
- item.set_expand(False)
self.siguiente = gtk.Button("Pag. Siguiente")
self.siguiente.set_tooltip_text("Ir a la Siguiente Página de Preguntas")
self.siguiente.connect("clicked", self.__button_clicked)
- self.siguiente.show()
- item.add(self.siguiente)
- self.insert(item, -1)
+
+ # DOWN BUTTONS: < prev next >
+ # TODO: self.__draw_pagination_buttons(self, parent_widget=vbox)
+ halign_prev = gtk.Alignment(0.03, 0, 0, 0)
+ halign_prev.add(self.anterior)
+ halign_next = gtk.Alignment(0.85, 0, 0, 0)
+ halign_next.add(self.siguiente)
+
+ self.pack_start(halign_prev, True, True)
+ self.pack_end(halign_next, True, True)
+ #vbox.pack_start(hbox, False, False, 10)
+ # -- END DOWN BUTTONS
self.show_all()