1 # -*- coding: UTF-8 -*-
10 from timetable import StanTimetable
12 class StanGUI(hildon.Program):
15 hildon.Program.__init__(self)
17 self.window = hildon.Window()
18 self.window.set_title('pySTAN')
19 self.window.connect("destroy", gtk.main_quit)
20 self.add_window(self.window)
22 self.tabs = self.main_tabs()
23 self.window.add(self.tabs)
25 self.last_station = False
29 tabs.set_tab_pos(gtk.POS_TOP)
30 tabs.append_page(self.tab_lines(), gtk.Label('Par lignes'))
31 #tabs.append_page(self.tab_stations(), gtk.Label('Par arrets'))
32 #tabs.append_page(self.tab_search(), gtk.Label('Recherche'))
36 tab_search = gtk.Frame(None) #'Recherche de trajet')
38 from_location = gtk.Entry()
39 from_location_label = gtk.Label(u"Départ")
40 from_city = gtk.Entry()
41 from_city_label = gtk.Label(u"à")
43 to_location = gtk.Entry()
44 to_location_label = gtk.Label(u"Arrivée")
46 to_city_label = gtk.Label(u"à")
48 datetime_select = gtk.Calendar()
49 datetime_select.display_options(gtk.CALENDAR_SHOW_DAY_NAMES | gtk.CALENDAR_WEEK_START_MONDAY)
51 restriction = gtk.Combo()
52 restriction.set_popdown_strings([u"partir après", u"arriver avant"])
55 vbox.add(from_location_label)
56 vbox.add(from_location)
58 vbox.add(to_location_label)
62 vbox.add(datetime_select)
69 # special callback for drawing line numbers in combo box
70 def line_number_cell_cb(self, treeviewcolumn, cellrenderer, modele, iter):
71 for line in self.stan.lines():
72 cell_line_name = modele.get_value(iter, 1)
73 cell_line_id = modele.get_value(iter, 2)
75 if line['id'] == cell_line_id:
76 text = '-'.join(line['numbers'])
77 cellrenderer.set_property('text', text)
80 cellrenderer.set_property('scale', 0.8)
82 cellrenderer.set_property('scale', 0.6)
84 if not line.has_key('fg-color'):
85 #print "ERROR:\tline %s do not have foreground color" % line['id']
88 cellrenderer.set_property('foreground-gdk', gtk.gdk.color_parse(line['fg-color']))
90 if not line.has_key('bg-color'):
91 #print "ERROR:\tline %s do not have background color" % line['id']
94 cellrenderer.set_property('background-gdk', gtk.gdk.color_parse(line['bg-color']))
97 def set_previous_button_cb(self, callback):
98 self._previous_button_cb = callback
100 def _previous_button_cb(self, data):
103 def set_active_lineid(self, lineid):
107 tab_lines = gtk.Frame(None) #'Recherche par lignes')
109 #lines_navigation = gtk.Table(rows=2, columns=2)
110 lines_navigation = gtk.HBox()
112 #previous_button = gtk.Button(u"<")
113 #previous_button.connect('clicked', self._previous_button_cb)
114 #alignment_previous_button = gtk.Alignment(xalign=0, xscale=0.02)
115 #alignment_previous_button.add(previous_button)
116 #lines_navigation.attach(previous_button, 0, 1, 0, 1, xoptions=gtk.SHRINK, yoptions=gtk.SHRINK, xpadding=1, ypadding=0)
117 #lines_navigation.pack_start(previous_button)
119 lines_list = gtk.ComboBox()
120 lines_model = gtk.ListStore(str, str, int)
121 lines_item_number = gtk.CellRendererText()
122 lines_item_number.set_property('scale', 0.8)
123 lines_item_name = gtk.CellRendererText()
124 lines_item_name.set_property('scale', 0.8)
126 lines_list.pack_start(lines_item_number, True)
127 lines_list.pack_start(lines_item_name, True)
129 lines_list.add_attribute(lines_item_number, 'text', 0)
130 lines_list.add_attribute(lines_item_name, 'text', 1)
132 lines_list.set_cell_data_func(lines_item_number, self.line_number_cell_cb)
134 for line in self.stan.lines():
135 lines_model.append([ '' , line['name'], line['id'] ])
137 lines_list.connect('changed', self.show_line_timetable)
138 lines_list.set_model(lines_model)
140 alignment_lines_list = gtk.Alignment(yscale=0.1)
141 alignment_lines_list.add(lines_list)
142 lines_navigation.pack_end(alignment_lines_list)
143 #lines_navigation.attach(lines_list, 1, 2, 0, 1, xoptions=gtk.SHRINK, yoptions=gtk.FILL)
147 alignment_lines_navigation = gtk.Alignment(xscale=1.0, yscale=0.1)
148 alignment_lines_navigation.add(lines_navigation)
150 vbox.pack_start(alignment_lines_navigation, False)
152 self.timetable = StanTimetable()
153 self.timetable.create()
154 self.timetable.set_activated_callback(self.timetable_row_clicked)
156 #alignment_tt = gtk.Alignment(yscale=0.9)
157 #alignment_tt.add(self.timetable)
158 vbox.pack_start(self.timetable, True, True)
160 #lines_navigation.attach(self.timetable, 0, 2, 1, 2, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND, xpadding=1, ypadding=0)
161 #lines_navigation.pack_start(self.timetable)
166 def show_line_timetable(self, selection):
167 self.timetable.load( self.stan.lines()[selection.get_active()], time.strftime("%d/%m/%Y"), time.strftime("%H"), 0 )
169 def timetable_row_clicked(self, station):
170 if self.last_station != station['name']:
171 if self.last_station != False:
172 self.tabs.remove(self.tab_map)
173 self.last_station = station['name']
174 self.tab_map = self.tab_geomap(station)
175 self.tabs.append_page(self.tab_map, gtk.Label(station['name']))
177 self.tabs.set_current_page(1)
179 def tab_stations(self):
180 tab_stations = gtk.Frame(None) #'Recherche par arrets')
182 list_stations = gtk.Combo()
183 list_stations.set_popdown_strings([])
185 tab_stations.add(list_stations)
189 def tab_geomap(self, station):
190 tab_map = gtk.Frame(None)
191 map_button = gtk.Button()
192 #map_label = gtk.Label(u"Link to map")
193 map_button.connect('clicked', self.open_map, station['href'])
195 tab_map.add(map_button)
198 def open_map(self, data, url):
202 self.window.show_all()