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 tableParser(HTMLParser.HTMLParser):
19 HTMLParser.HTMLParser.__init__(self)
20 self.table_horaires3 = False
21 self.code_de_mission = False
22 self.a_code_de_mission = False
23 self.heure_de_passage = False
25 self.liste_horaire = []
27 def handle_starttag(self, tag, attrs):
28 if (tag == 'table' and (dict(attrs)['class'] == 'horaires3')):
29 self.table_horaires3 = True
31 elif self.table_horaires3 and tag == 'td':
33 self.code_de_mission = (
34 dict(attrs)['headers'] == 'Code_de_mission')
35 self.heure_de_passage = (
36 dict(attrs)['headers'] == 'Heure_de_passage')
38 if dict(attrs).has_key('headers'):
43 self.a_code_de_mission = (tag == 'a' and self.code_de_mission)
45 def handle_data(self, data):
46 if self.a_code_de_mission:
47 self.liste_train.append(data.strip())
48 if self.heure_de_passage:
49 self.liste_horaire.append(data.strip())
51 def handle_endtag(self,tag):
52 self.a_code_de_mission ^= (self.a_code_de_mission and tag == 'a')
53 self.heure_de_passage ^= (self.heure_de_passage and tag == 'td')
57 mainWindow = hildon.Window()
58 mainWindow.set_title("Horaires des Prochains Trains")
59 mainWindow.connect("destroy", self.on_mainWindow_destroy)
61 rotation_object = FremantleRotation(app_name, mainWindow, app_version, initial_mode)
62 refreshButton = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT,
63 hildon.BUTTON_ARRANGEMENT_HORIZONTAL, "Actualiser")
64 refreshButton.connect("clicked", self.on_refreshButton_clicked)
66 self.treestore = gtk.TreeStore(str, str)
67 self.treeview = gtk.TreeView(self.treestore)
69 self.tvcolumn_train = gtk.TreeViewColumn('Train', gtk.CellRendererText(), text=0)
70 self.treeview.append_column(self.tvcolumn_train)
72 self.tvcolumn_horaire = gtk.TreeViewColumn('Horaire', gtk.CellRendererText(), text=1)
73 self.treeview.append_column(self.tvcolumn_horaire)
76 picker_button_source = hildon.PickerButton(gtk.HILDON_SIZE_AUTO, hildon.BUTTON_ARRANGEMENT_VERTICAL)
77 picker_button_source.set_title("Gare de Depart")
78 self.combo_source = hildon.TouchSelectorEntry(text=True)
79 self.combo_dest = hildon.TouchSelectorEntry(text=True)
81 self.c = ConfigParser.ConfigParser()
82 self.c.read('example.cfg')
83 for i in self.c.items('ListeDesGares'):
84 self.combo_source.append_text(i[0])
85 self.combo_dest.append_text(i[0])
86 picker_button_source.set_selector(self.combo_source)
89 picker_button_dest = hildon.PickerButton(gtk.HILDON_SIZE_AUTO, hildon.BUTTON_ARRANGEMENT_VERTICAL)
90 picker_button_dest.set_title("Gare d'arrivee")
91 picker_button_dest.set_selector(self.combo_dest)
97 hBox.pack_start(picker_button_source)
98 hBox.pack_start(picker_button_dest)
99 vBox.pack_start(self.treeview)
100 vBox.pack_start(refreshButton)
104 mainWindow.show_all()
106 def on_mainWindow_destroy(self, widget):
109 def on_refreshButton_clicked(self, widget):
110 self.treestore.clear()
112 print self.c.get('ListeDesGares', self.combo_source.get_current_text())
113 print self.c.get('ListeDesGares', self.combo_dest.get_current_text())
114 p.feed(urllib2.urlopen('http://www.transilien.com/web/ITProchainsTrainsAvecDest.do?codeTr3aDepart='+self.c.get('ListeDesGares', self.combo_source.get_current_text())+'&codeTr3aDest='+self.c.get('ListeDesGares', self.combo_dest.get_current_text())+'&urlModule=/site/pid/184&gareAcc=true').read())
116 for i in p.liste_train:
117 print p.liste_horaire[z]
118 self.treestore.append(None, [i, p.liste_horaire[z]])
121 if __name__ == "__main__":