Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/CeibalEncuesta/CeibalEncuesta.py
blob: dd2cbb0f35dbce19c89207a07e67102bfb05ab6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/usr/bin/env python
# -*- coding: utf-8 -*-

#   CeibalEncuesta.py por:
#   Flavio Danesse <fdanesse@activitycentral.com>

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

import os
import sys

import gi
from gi.repository import Gtk

from Widgets import Panel
from Widgets import My_FileChooser

import Globales as G

PATH = os.path.dirname(__file__)

class CeibalEncuesta(Gtk.Window):
    
    def __init__(self):
        
        Gtk.Window.__init__(self)
        
        self.set_title("Ceibal Encuesta")
        
        self.set_icon_from_file(
            os.path.join(PATH,
            "Iconos", "ceibal.png"))
            
        self.set_resizable(True)
        self.set_size_request(640, 480)
        self.set_border_width(2)
        
        self.set_position(Gtk.WindowPosition.CENTER)
        
        box = Gtk.VBox()
        
        self.panel = Panel()
        
        box.pack_start(self.get_menu(), False, False, 0)
        box.pack_start(self.panel, True, True, 0)
        
        self.add(box)
        
        self.show_all()
        
        self.panel.connect("new", self.__change)
        self.panel.connect("new-selection", self.__new_selection)
        self.connect("destroy", self.__salir)
        
        self.out_dict = None
        
        # Carga Automática solo para probar
        #self.__load_alumnos(None,
        #    os.path.join(PATH,
        #    'Archivo de entrada_1903.csv'))
        
    def __change(self, widget, new_dict):
        """Recibe los cambios en la encuesta."""
        
        if self.out_dict == None:
            self.out_dict = {}
            
        self.out_dict[new_dict.keys()[0]] = new_dict[new_dict.keys()[0]]
        
        #print self.out_dict
        
    def __new_selection(self, widget, data):
        """Cuando el usuario cambia de Encuestado."""
        
        # leer out_dict
        # actualizar interfaz
        
        if self.out_dict != None:
            if data in self.out_dict.keys():
                print data
                print self.out_dict[data]
            
        else:
            # No ha llenado nada en la encuesta.
            #self.panel.reset()
            pass
        
    def get_menu(self):
        """Crea y devuelve el menú de la aplicación."""
        
        menu_bar = Gtk.MenuBar()
        menu_bar.show()
        
        file_menu = Gtk.Menu()
        
        alumnos = Gtk.MenuItem("Cargar Encuestados")
        encuesta = Gtk.MenuItem("Cargar Encuesta")
        #guardar = Gtk.MenuItem("Guardar")
        salir = Gtk.MenuItem("Salir")

        file_menu.append(alumnos)
        file_menu.append(encuesta)
        #file_menu.append(guardar)
        file_menu.append(salir)
        
        alumnos.connect_object ("activate", self.__cargar_alumnos, '')
        #encuesta.connect_object ("activate", self.__cargar_encuesta, '')
        #guardar.connect_object ("activate", self.__guardar, '')
        salir.connect_object ("activate", self.__salir, '')
        
        alumnos.show()
        #guardar.show()
        salir.show()
        
        file_item = Gtk.MenuItem("Archivo")
        file_item.show()

        file_item.set_submenu(file_menu)
        menu_bar.append(file_item)
        
        return menu_bar
        
    def __cargar_alumnos(self, widget = None, senial = None):
        """Abre Filechooser para cargar el archivo con la
        lista de alumnos a encuestar."""
        
        filechooser = My_FileChooser(
            parent_window = self,
            action_type = Gtk.FileChooserAction.OPEN,
            filter_type = 'text/csv')
    
        filechooser.connect('load', self.__load_alumnos)

    def __load_alumnos(self, widget, archivo):
        """Recibe archivo csv con la lista de alumnos a encuestar y
        la manda cargar en la aplicación."""
        
        self.out_dict = None
        
        alumnos = G.cargar_alumnos(os.path.join(archivo))
        self.panel._load_alumnos(alumnos)
        
    def __cargar_encuesta(self, widget = None, senial = None):
        """Abre Filechooser para cargar el
        archivo con la encuesta."""
        
        filechooser = My_FileChooser(
            parent_window = self,
            action_type = Gtk.FileChooserAction.OPEN,
            filter_type = 'text/csv')
    
        #filechooser.connect('load', self.__load_encuesta)

    def load_encuesta(self, encuesta):
        
        self.out_dict = None
        self.panel.load_encuesta(encuesta)
        
    def __guardar(self, widget = None, senial = None):
        """Abre Filechooser para guardar la encuesta."""
        
        filechooser = My_FileChooser(
            parent_window = self,
            action_type = Gtk.FileChooserAction.OPEN,
            filter_type = 'text/csv')
    
        #filechooser.connect('load', self.__load_alumnos)
    
    def __salir(self, widget = None, senial = None):
        
        sys.exit(0)
        
    
if __name__ == "__main__":
    
    encuesta = G.Encuesta
    
    ceibalencuesta = CeibalEncuesta()
    ceibalencuesta.load_encuesta( encuesta )
    
    Gtk.main()