10 from portrait import FremantleRotation
12 #main_window = mainWindow # your main hildon.StackableWindow
13 app_name = 'NameOfYourApp' # the name of your app
14 app_version = '1.0' # the version number of your app
15 initial_mode = FremantleRotation.AUTOMATIC
17 class LigneHoraire(object):
18 def __init__(self, code_mission, heure_de_passage):
19 self.code_mission = code_mission
20 self.heure_de_passage = heure_de_passage
22 def add_to_treestore(self, treestore):
24 treestore.append(None, [self.code_mission, self.heure_de_passage])
28 class tableParser(HTMLParser.HTMLParser):
30 HTMLParser.HTMLParser.__init__(self)
31 self.table_horaires3 = False
32 self.code_de_mission = False
33 self.a_code_de_mission = False
34 self.heure_de_passage = False
36 self.liste_horaire = []
37 self.list_ligne_horaire = []
39 def handle_starttag(self, tag, attrs):
40 if (tag == 'table' and (dict(attrs)['class'] == 'horaires3')):
41 self.table_horaires3 = True
43 elif self.table_horaires3 and tag == 'td':
45 self.code_de_mission = (
46 dict(attrs)['headers'] == 'Code_de_mission')
47 self.heure_de_passage = (
48 dict(attrs)['headers'] == 'Heure_de_passage')
50 if dict(attrs).has_key('headers'):
55 self.a_code_de_mission = (tag == 'a' and self.code_de_mission)
57 def handle_data(self, data):
58 if self.a_code_de_mission:
59 self.liste_train.append(data.strip())
60 if self.heure_de_passage:
61 self.liste_horaire.append(data.strip())
63 def handle_endtag(self,tag):
64 self.a_code_de_mission ^= (self.a_code_de_mission and tag == 'a')
65 self.heure_de_passage ^= (self.heure_de_passage and tag == 'td')
67 def get_list_ligne_horaire(self):
68 print 'get_list_ligne_horaire'
70 print self.liste_train
71 for i in self.liste_train:
72 self.list_ligne_horaire.append(LigneHoraire(code_mission=i, heure_de_passage=self.liste_horaire[z]))
74 return self.list_ligne_horaire
79 def __init__(self, gare_source, gare_dest):
80 self.gare_source = gare_source
81 self.gare_dest = gare_dest
83 def get_liste_train(self):
84 return self.p.liste_train
85 def get_liste_horaire(self):
86 return self.p.liste_horaire
88 self.p = tableParser()
90 #print 'http://www.transilien.com/web/ITProchainsTrainsAvecDest.do?codeTr3aDepart='+self.gare_source.shortname+'&codeTr3aDest='+self.gare_dest.shortname+'&urlModule=/site/pid/184&gareAcc=true'
91 rsrc = urllib2.urlopen('http://www.transilien.com/web/ITProchainsTrainsAvecDest.do?codeTr3aDepart='+self.gare_source.shortname+'&codeTr3aDest='+self.gare_dest.shortname+'&urlModule=/site/pid/184&gareAcc=true')
92 self.p.feed(rsrc.read())
95 def refresh_treestore(self, treestore):
100 liste_ligne_horaire = self.p.get_list_ligne_horaire()
101 print liste_ligne_horaire
102 for i in liste_ligne_horaire:
104 i.add_to_treestore(treestore)
106 class ConfFile(object):
107 def __init__(self, fichier):
108 self.c = ConfigParser.ConfigParser()
110 def get_short_name(self, longname):
111 return self.c.get('ListeDesGares', longname)
112 def get_liste_des_gares(self):
113 return self.c.items('ListeDesGares')
115 class LongNameGare(object):
116 def __init__(self, longname):
117 self.longname = longname
118 def get_gare(self, conffile):
119 short_name = conffile.get_short_name(self.longname)
120 return Gare(short_name)
123 def __init__(self, shortname):
124 self.shortname = shortname
131 mainWindow = hildon.Window()
132 mainWindow.set_title("Horaires des Prochains Trains")
133 mainWindow.connect("destroy", self.on_mainWindow_destroy)
135 rotation_object = FremantleRotation(app_name, mainWindow, app_version, initial_mode)
136 refreshButton = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT,
137 hildon.BUTTON_ARRANGEMENT_HORIZONTAL, "Actualiser")
138 refreshButton.connect("clicked", self.on_refreshButton_clicked)
140 self.treestore = gtk.TreeStore(str, str)
141 self.treeview = gtk.TreeView(self.treestore)
143 self.tvcolumn_train = gtk.TreeViewColumn('Train', gtk.CellRendererText(), text=0)
144 self.treeview.append_column(self.tvcolumn_train)
146 self.tvcolumn_horaire = gtk.TreeViewColumn('Horaire', gtk.CellRendererText(), text=1)
147 self.treeview.append_column(self.tvcolumn_horaire)
150 picker_button_source = hildon.PickerButton(gtk.HILDON_SIZE_AUTO, hildon.BUTTON_ARRANGEMENT_VERTICAL)
151 picker_button_source.set_title("Gare de Depart")
152 self.combo_source = hildon.TouchSelectorEntry(text=True)
153 self.combo_dest = hildon.TouchSelectorEntry(text=True)
155 for i in ConfFile('example.cfg').get_liste_des_gares():
156 self.combo_source.append_text(i[0])
157 self.combo_dest.append_text(i[0])
158 picker_button_source.set_selector(self.combo_source)
161 picker_button_dest = hildon.PickerButton(gtk.HILDON_SIZE_AUTO, hildon.BUTTON_ARRANGEMENT_VERTICAL)
162 picker_button_dest.set_title("Gare d'arrivee")
163 picker_button_dest.set_selector(self.combo_dest)
167 vBox.pack_start(hBox)
168 hBox.pack_start(picker_button_source)
169 hBox.pack_start(picker_button_dest)
170 vBox.pack_start(self.treeview)
171 vBox.pack_start(refreshButton)
175 mainWindow.show_all()
177 def on_mainWindow_destroy(self, widget):
180 def on_refreshButton_clicked(self, widget):
181 gare_source = LongNameGare(self.combo_source.get_current_text()).get_gare(ConfFile('example.cfg'))
182 gare_dest = LongNameGare(self.combo_dest.get_current_text()).get_gare(ConfFile('example.cfg'))
183 trajet = Trajet(gare_source , gare_dest)
186 trajet.refresh_treestore(self.treestore)
189 if __name__ == "__main__":