masstransit works on home computer without conic or hildon (closes #562)

This commit is contained in:
Juke 2011-03-16 04:20:59 +01:00
commit d2323b1467

View file

@ -18,22 +18,42 @@
from weboob.capabilities.travel import ICapTravel from weboob.capabilities.travel import ICapTravel
from weboob.tools.application.base import BaseApplication from weboob.tools.application.base import BaseApplication
from logging import warning
import conic
import gtk import gtk
import hildon
class FakeConic(object):
STATUS_CONNECTED = None
STATUS_DISCONNECTED = None
CONNECT_FLAG_NONE = None
def Connection(self):
raise NotImplementedError()
try:
import hildon
except ImportError:
toolkit = gtk
else:
toolkit = hildon
try :
import conic
except ImportError:
warning("conic is not found")
conic = FakeConic()
from logging import debug from logging import debug
__all__ = ['Masstransit'] __all__ = ['Masstransit']
class MasstransitHildon(): class MasstransitHildon():
"hildon interface" "hildon interface"
def connect_event(self, connection, event=None, c=None, d=None): def connect_event(self, connection, event=None, c=None, d=None):
debug("DBUS-DEBUG a: %s, b:%s, c:%s,d: %s" % (connection, event, c, d)) debug("DBUS-DEBUG a: %s, b:%s, c:%s,d: %s" % (connection, event, c, d))
status = event.get_status() status = event.get_status()
if conic != ImportError:
if status == conic.STATUS_CONNECTED: if status == conic.STATUS_CONNECTED:
self.connected = True self.connected = True
if self.touch_selector_entry_filled == False: if self.touch_selector_entry_filled == False:
@ -49,29 +69,60 @@ class MasstransitHildon():
self.refresh_in_progress = False self.refresh_in_progress = False
self.connected = False self.connected = False
self.weboob = weboob self.weboob = weboob
try :
self.connection = conic.Connection() self.connection = conic.Connection()
self.connection.connect("connection-event", self.connect_event)
self.connection.set_property("automatic-connection-events", True) self.connection.set_property("automatic-connection-events", True)
self.connection.request_connection(conic.CONNECT_FLAG_NONE) self.connection.request_connection(conic.CONNECT_FLAG_NONE)
except NotImplementedError:
pass
main_window = hildon.Window() horizontal_box = gtk.HBox()
main_window.set_title("Horaires des Prochains Trains") main_window = toolkit.Window()
main_window.connect("destroy", self.on_main_window_destroy) try :
self.refresh_button = toolkit.Button(
self.refresh_button = hildon.Button(
gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT,
hildon.BUTTON_ARRANGEMENT_HORIZONTAL, hildon.BUTTON_ARRANGEMENT_HORIZONTAL,
"Actualiser" "Actualiser"
) )
self.refresh_button.set_sensitive(False)
self.refresh_button.connect("clicked", self.on_refresh_button_clicked)
self.retour_button = hildon.Button( self.retour_button = hildon.Button(
gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT,
hildon.BUTTON_ARRANGEMENT_HORIZONTAL, hildon.BUTTON_ARRANGEMENT_HORIZONTAL,
"Retour" "Retour"
) )
self.combo_source = hildon.TouchSelectorEntry(text=True)
self.combo_dest = hildon.TouchSelectorEntry(text=True)
self.picker_button_source = hildon.PickerButton(
gtk.HILDON_SIZE_AUTO,
hildon.BUTTON_ARRANGEMENT_VERTICAL)
self.picker_button_dest = hildon.PickerButton(
gtk.HILDON_SIZE_AUTO,
hildon.BUTTON_ARRANGEMENT_VERTICAL
)
self.picker_button_source.set_sensitive(False)
self.picker_button_dest.set_sensitive(False)
self.picker_button_source.set_title("Gare de Depart")
self.picker_button_dest.set_title("Gare d'arrivee")
self.picker_button_source.set_selector(self.combo_source)
self.picker_button_dest.set_selector(self.combo_dest)
horizontal_box.pack_start(self.picker_button_source)
horizontal_box.pack_start(self.picker_button_dest)
except AttributeError:
self.refresh_button = gtk.Button("Actualiser")
self.retour_button = gtk.Button("Retour")
self.combo_source = gtk.combo_box_entry_new_text()
help(self.combo_source)
self.combo_dest = gtk.combo_box_entry_new_text()
horizontal_box.pack_start(self.combo_source)
horizontal_box.pack_start(self.combo_dest)
main_window.set_title("Horaires des Prochains Trains")
main_window.connect("destroy", self.on_main_window_destroy)
self.refresh_button.connect("clicked", self.on_refresh_button_clicked)
self.retour_button.set_sensitive(False) self.retour_button.set_sensitive(False)
self.retour_button.connect("clicked", self.on_retour_button_clicked) self.retour_button.connect("clicked", self.on_retour_button_clicked)
@ -106,7 +157,6 @@ class MasstransitHildon():
gtk.CellRendererText(), gtk.CellRendererText(),
text=3 text=3
)) ))
treeview.append_column( treeview.append_column(
gtk.TreeViewColumn( gtk.TreeViewColumn(
'Information', 'Information',
@ -115,39 +165,18 @@ class MasstransitHildon():
)) ))
self.combo_source = hildon.TouchSelectorEntry(text=True)
self.combo_dest = hildon.TouchSelectorEntry(text=True)
self.picker_button_source = hildon.PickerButton(
gtk.HILDON_SIZE_AUTO,
hildon.BUTTON_ARRANGEMENT_VERTICAL)
self.picker_button_dest = hildon.PickerButton(
gtk.HILDON_SIZE_AUTO,
hildon.BUTTON_ARRANGEMENT_VERTICAL
)
self.picker_button_source.set_sensitive(False)
self.picker_button_dest.set_sensitive(False)
self.picker_button_source.set_title("Gare de Depart")
self.picker_button_dest.set_title("Gare d'arrivee")
self.picker_button_source.set_selector(self.combo_source)
self.picker_button_dest.set_selector(self.combo_dest)
vertical_box = gtk.VBox() vertical_box = gtk.VBox()
horizontal_box = gtk.HBox()
vertical_box.pack_start(horizontal_box) vertical_box.pack_start(horizontal_box)
horizontal_box.pack_start(self.picker_button_source)
horizontal_box.pack_start(self.picker_button_dest)
horizontal_box.pack_start(self.retour_button) horizontal_box.pack_start(self.retour_button)
vertical_box.pack_start(treeview) vertical_box.pack_start(treeview)
vertical_box.pack_start(self.refresh_button) vertical_box.pack_start(self.refresh_button)
main_window.add(vertical_box) main_window.add(vertical_box)
main_window.show_all() main_window.show_all()
self.fill_touch_selector_entry()
if toolkit != gtk:
self.picker_button_source.connect("value-changed", self.picker_button_source.connect("value-changed",
self.check_station_input, self.check_station_input,
self.picker_button_source) self.picker_button_source)
@ -169,6 +198,7 @@ class MasstransitHildon():
self.combo_dest.append_text(station) self.combo_dest.append_text(station)
self.touch_selector_entry_filled = True self.touch_selector_entry_filled = True
if toolkit != gtk:
self.picker_button_source.set_sensitive(True) self.picker_button_source.set_sensitive(True)
def on_main_window_destroy(self, widget): def on_main_window_destroy(self, widget):
@ -190,7 +220,13 @@ class MasstransitHildon():
def on_refresh_button_clicked(self, widget): def on_refresh_button_clicked(self, widget):
"the refresh button is clicked" "the refresh button is clicked"
self.refresh_in_progress = True self.refresh_in_progress = True
try :
self.connection.request_connection(conic.CONNECT_FLAG_NONE) self.connection.request_connection(conic.CONNECT_FLAG_NONE)
except AttributeError:
if isinstance(conic, FakeConic):
self.refresh()
else:
raise
def check_station_input(self, widget, user_data): def check_station_input(self, widget, user_data):
if self.combo_source.get_current_text() is None : if self.combo_source.get_current_text() is None :
@ -209,11 +245,16 @@ class MasstransitHildon():
def refresh(self): def refresh(self):
"update departures" "update departures"
self.treestore.clear() self.treestore.clear()
try :
source_text = self.combo_source.get_current_text()
dest_text = self.combo_dest.get_current_text()
except AttributeError:
source_text = self.combo_source.child.get_text()
dest_text = self.combo_dest.child.get_text()
for backend in self.weboob.iter_backends(): for backend in self.weboob.iter_backends():
for station in \ for station in backend.iter_station_search(source_text):
backend.iter_station_search(self.combo_source.get_current_text()):
for arrival in \ for arrival in \
backend.iter_station_search(self.combo_dest.get_current_text()): backend.iter_station_search(dest_text):
for departure in \ for departure in \
backend.iter_station_departures(station.id, arrival.id): backend.iter_station_departures(station.id, arrival.id):
self.treestore.append(None, self.treestore.append(None,