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
18 class tableParser(HTMLParser.HTMLParser):
20 HTMLParser.HTMLParser.__init__(self)
21 self.table_horaires3 = False
22 self.code_de_mission = False
23 self.a_code_de_mission = False
24 self.heure_de_passage = False
26 self.liste_horaire = []
28 def handle_starttag(self, tag, attrs):
29 if (tag == 'table' and (dict(attrs)['class'] == 'horaires3')):
30 self.table_horaires3 = True
32 elif self.table_horaires3 and tag == 'td':
34 self.code_de_mission = (
35 dict(attrs)['headers'] == 'Code_de_mission')
36 self.heure_de_passage = (
37 dict(attrs)['headers'] == 'Heure_de_passage')
39 if dict(attrs).has_key('headers'):
44 self.a_code_de_mission = (tag == 'a' and self.code_de_mission)
46 def handle_data(self, data):
47 if self.a_code_de_mission:
48 self.liste_train.append(data.strip())
49 if self.heure_de_passage:
50 self.liste_horaire.append(data.strip())
52 def handle_endtag(self,tag):
53 self.a_code_de_mission ^= (self.a_code_de_mission and tag == 'a')
54 self.heure_de_passage ^= (self.heure_de_passage and tag == 'td')
57 def __init__(self, gare_source, gare_dest):
58 self.gare_source = gare_source
59 self.gare_dest = gare_dest
61 def get_liste_train(self):
62 return self.p.liste_train
63 def get_liste_horaire(self):
64 return self.p.liste_horaire
66 self.p = tableParser()
68 print 'http://www.transilien.com/web/ITProchainsTrainsAvecDest.do?codeTr3aDepart='+self.gare_source.shortname+'&codeTr3aDest='+self.gare_dest.shortname+'&urlModule=/site/pid/184&gareAcc=true'
69 self.p.feed(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').read())
71 class ConfFile(object):
72 def __init__(self, fichier):
73 self.c = ConfigParser.ConfigParser()
75 def get_short_name(self, longname):
76 return self.c.get('ListeDesGares', longname)
77 def get_liste_des_gares(self):
78 return self.c.items('ListeDesGares')
80 class LongNameGare(object):
81 def __init__(self, longname):
82 self.longname = longname
83 def get_gare(self, conffile):
84 short_name = conffile.get_short_name(self.longname)
85 return Gare(short_name)
88 def __init__(self, shortname):
89 self.shortname = shortname
96 mainWindow = hildon.Window()
97 mainWindow.set_title("Horaires des Prochains Trains")
98 mainWindow.connect("destroy", self.on_mainWindow_destroy)
100 rotation_object = FremantleRotation(app_name, mainWindow, app_version, initial_mode)
101 refreshButton = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT,
102 hildon.BUTTON_ARRANGEMENT_HORIZONTAL, "Actualiser")
103 refreshButton.connect("clicked", self.on_refreshButton_clicked)
105 self.treestore = gtk.TreeStore(str, str)
106 self.treeview = gtk.TreeView(self.treestore)
108 self.tvcolumn_train = gtk.TreeViewColumn('Train', gtk.CellRendererText(), text=0)
109 self.treeview.append_column(self.tvcolumn_train)
111 self.tvcolumn_horaire = gtk.TreeViewColumn('Horaire', gtk.CellRendererText(), text=1)
112 self.treeview.append_column(self.tvcolumn_horaire)
115 picker_button_source = hildon.PickerButton(gtk.HILDON_SIZE_AUTO, hildon.BUTTON_ARRANGEMENT_VERTICAL)
116 picker_button_source.set_title("Gare de Depart")
117 self.combo_source = hildon.TouchSelectorEntry(text=True)
118 self.combo_dest = hildon.TouchSelectorEntry(text=True)
120 for i in ConfFile('example.cfg').get_liste_des_gares():
121 self.combo_source.append_text(i[0])
122 self.combo_dest.append_text(i[0])
123 picker_button_source.set_selector(self.combo_source)
126 picker_button_dest = hildon.PickerButton(gtk.HILDON_SIZE_AUTO, hildon.BUTTON_ARRANGEMENT_VERTICAL)
127 picker_button_dest.set_title("Gare d'arrivee")
128 picker_button_dest.set_selector(self.combo_dest)
132 vBox.pack_start(hBox)
133 hBox.pack_start(picker_button_source)
134 hBox.pack_start(picker_button_dest)
135 vBox.pack_start(self.treeview)
136 vBox.pack_start(refreshButton)
140 mainWindow.show_all()
142 def on_mainWindow_destroy(self, widget):
145 def on_refreshButton_clicked(self, widget):
146 self.treestore.clear()
147 gare_source = LongNameGare(self.combo_source.get_current_text()).get_gare(ConfFile('example.cfg'))
148 gare_dest = LongNameGare(self.combo_dest.get_current_text()).get_gare(ConfFile('example.cfg'))
149 trajet = Trajet(gare_source, gare_dest)
151 print trajet.get_liste_train()
153 for i in trajet.get_liste_train():
154 liste_horaire = trajet.get_liste_horaire()
155 print liste_horaire[z]
156 self.treestore.append(None, [i, liste_horaire[z]])
161 if __name__ == "__main__":