コード例 #1
0
ファイル: TripRouteDialog.py プロジェクト: line72/subte
class AddTripRoute(Gtk.VBox):
    '''A vbox for adding a single trip along a route'''
    def __init__(self, trip_route):
        Gtk.VBox.__init__(self, False)

        self._trip_route = trip_route

        size_group = Gtk.SizeGroup(mode = Gtk.SizeGroupMode.HORIZONTAL)

        # name
        hbox = Gtk.HBox(False)
        name_lbl = Gtk.Label(_('Name: '))
        name_lbl.set_tooltip_text(_('A group of trips sharing a route and days of operation'))
        size_group.add_widget(name_lbl)       
        hbox.pack_start(name_lbl, False, False, 0)
        self.name_txt = Gtk.Entry()
        self.name_txt.set_tooltip_text(_('A group of trips sharing a route and days of operation'))
        hbox.pack_start(self.name_txt, True, True, 5)
        self.pack_start(hbox, True, True, 5)

        # route
        self.route_hbox = RouteChoice()
        size_group.add_widget(self.route_hbox.get_label())
        self.pack_start(self.route_hbox, True, False, 5)

        # calendar
        self.calendar_hbox = CalendarChoice()
        size_group.add_widget(self.calendar_hbox.get_label())
        self.pack_start(self.calendar_hbox, True, False, 5)

        # path
        self.path_hbox = PathChoice()
        size_group.add_widget(self.path_hbox.get_label())
        self.pack_start(self.path_hbox, True, False, 5)

        # headsign
        hbox = Gtk.HBox(False)
        headsign_lbl = Gtk.Label(_('Headsign: '))
        headsign_lbl.set_tooltip_text(_('A sign on the bus identifying the destination'))
        size_group.add_widget(headsign_lbl)       
        hbox.pack_start(headsign_lbl, False, False, 0)
        self.headsign_txt = Gtk.Entry()
        self.headsign_txt.set_tooltip_text(_('A sign on the bus identifying the destination'))
        hbox.pack_start(self.headsign_txt, True, True, 5)
        self.pack_start(hbox, True, True, 5)

        # direction
        hbox = Gtk.HBox(False)
        direction_lbl = Gtk.Label(_('Direction: '))
        direction_lbl.set_tooltip_text(_('Distinguish trips on routes that go both ways'))
        size_group.add_widget(direction_lbl)
        hbox.pack_start(direction_lbl, False, False, 0)
        self.direction = Gtk.ComboBoxText.new()
        hbox.pack_start(self.direction, True, True, 5)
        self.pack_start(hbox, True, True, 5)

        self.direction.append_text(_('Outbound'))
        self.direction.append_text(_('Inbound'))
        self.direction.set_active(0)

        # edit trips
        hbox = Gtk.HBox(False)
        edit_trips_lbl = Gtk.Label(_('Edit Trips: '))
        edit_trips_lbl.set_tooltip_text(_('Enter times at which trips leave stops'))
        size_group.add_widget(edit_trips_lbl)
        hbox.pack_start(edit_trips_lbl, False, False, 0)
        edit_trip_btn = Gtk.Button.new_from_stock(Gtk.STOCK_INFO)
        edit_trip_btn.connect('clicked', self.on_modify_trips)
        hbox.pack_start(edit_trip_btn, True, True, 5)
        self.pack_start(hbox, True, True, 5)

        # edit frequencies
        hbox = Gtk.HBox(False)
        edit_frequencies_lbl = Gtk.Label(_('Edit Frequencies: '))
        size_group.add_widget(edit_frequencies_lbl)
        hbox.pack_start(edit_frequencies_lbl, False, False, 0)
        edit_frequencies_btn = Gtk.Button.new_from_stock(Gtk.STOCK_INFO)
        edit_frequencies_btn.connect('clicked', self.on_modify_frequencies)
        hbox.pack_start(edit_frequencies_btn, True, True, 5)
        self.pack_start(hbox, True, True, 5)

        # and all our stops
        hbox = Gtk.HBox(False)
        stops_lbl = Gtk.Label(_('Stops: '))
        stops_lbl.set_tooltip_text(_('Click a stop on the map to add'))
        size_group.add_widget(stops_lbl)
        hbox.pack_start(stops_lbl, False, False, 0)
        self.stops = StopListGui()
        stops_list = self.stops.get_widget()
        stops_list.set_tooltip_text(_('Click a stop on the map to add'))
        hbox.pack_start(stops_list, True, True, 5)
        # actions
        vbox = Gtk.VBox(True)
        #add_btn = Gtk.Button.new_from_stock(Gtk.STOCK_ADD)
        rm_btn = Gtk.Button.new_from_stock(Gtk.STOCK_REMOVE)
        up_btn = Gtk.Button.new_from_stock(Gtk.STOCK_GO_UP)
        down_btn = Gtk.Button.new_from_stock(Gtk.STOCK_GO_DOWN)

        #add_btn.connect('clicked', self.on_move_stop_left)
        rm_btn.connect('clicked', self.on_remove_stop)
        up_btn.connect('clicked', self.on_raise_stop)
        down_btn.connect('clicked', self.on_lower_stop)

        #vbox.pack_start(add_btn, False, False, 5)
        vbox.pack_start(rm_btn, False, False, 5)
        vbox.pack_start(up_btn, False, False, 5)
        vbox.pack_start(down_btn, False, False, 5)
        hbox.pack_start(vbox, False, True, 0)

        self.pack_start(hbox, True, True, 5)
        
        self.fill()

    def fill(self):
        if self._trip_route is None:
            return

        self.name_txt.set_text(self._trip_route.name)
        self.route_hbox.set_selection(self._trip_route.route)
        self.calendar_hbox.set_selection(self._trip_route.calendar)
        self.path_hbox.set_selection(self._trip_route.path)
        self.headsign_txt.set_text(self._trip_route.headsign)
        self.direction.set_active(self._trip_route.direction)

        # stops
        for stop in self._trip_route.stops:
            self.stops.add_stop(stop)

    def get_name(self):
        return self.name_txt.get_text()

    def get_route(self):
        return self.route_hbox.get_selection()

    def get_calendar(self):
        return self.calendar_hbox.get_selection()

    def get_headsign(self):
        return self.headsign_txt.get_text()

    def get_direction(self):
        selection = self.direction.get_active_text()
        if selection == _('Outbound'):
            return 0
        return 1 # inbound

    def get_path(self):
        return self.path_hbox.get_selection()

    def get_stops(self):
        return self.stops.get_stops()

    def on_stop_selected(self, stop):
        print 'on_stop_selected TripRoute',stop
        self.stops.add_stop(stop)
        self._trip_route.add_stop(stop)

        return True

    def on_remove_stop(self, btn):
        index = self.stops.get_selected_index()
        self.stops.remove_selection()
        self._trip_route.remove_stop_at(index)

        return True

    def on_raise_stop(self, btn):
        index = self.stops.get_selected_index()
        self.stops.raise_selection()
        self._trip_route.increment_stop_at(index)

        return True

    def on_lower_stop(self, btn):
        index = self.stops.get_selected_index()
        self.stops.lower_selection()
        self._trip_route.decrement_stop_at(index)

        return True
    
    def on_modify_trips(self, btn):
        print 'on-modify-trips'
        if self._trip_route:
            if not self._trip_route.route:
                print 'on-modify-trips: hack - set route',self.get_route()
                self._trip_route.route = self.get_route()
            if not self._trip_route.calendar:
                print 'on-modify-trips: hack - set calendar',self.get_calendar()
                self._trip_route.calendar = self.get_calendar()

            dlg = TripListDialog(None, self._trip_route)
            dlg.show_all()

            dlg.run()

            dlg.destroy()

        return True
    
    def on_modify_frequencies(self, btn):
        if self._trip_route:
            dlg = FrequencyListDialog(None, self._trip_route)
            dlg.show_all()

            dlg.run()

            dlg.destroy()

        return True
コード例 #2
0
ファイル: AddRoute.py プロジェクト: CodeforBirmingham/subte
class AddRoute(Gtk.VBox):
    '''A dialog that creates a new route'''
    def __init__(self, controller, route = None):
        Gtk.VBox.__init__(self, False)

        if route:
            self._route = weakref.ref(route)
        else:
            self._route = None

        self._controller = weakref.ref(controller)

        size_group = Gtk.SizeGroup(mode = Gtk.SizeGroupMode.HORIZONTAL)

        # name
        hbox = Gtk.HBox(False)
        name_lbl = Gtk.Label('Short Name: ')
        size_group.add_widget(name_lbl)       
        hbox.pack_start(name_lbl, False, False, 0)
        self.name_txt = Gtk.Entry()
        hbox.pack_start(self.name_txt, True, True, 5)

        self.pack_start(hbox, True, False, 5)

        # name
        hbox = Gtk.HBox(False)
        name_lbl = Gtk.Label('Long Name: ')
        size_group.add_widget(name_lbl)       
        hbox.pack_start(name_lbl, False, False, 0)
        self.long_name_txt = Gtk.Entry()
        hbox.pack_start(self.long_name_txt, True, True, 5)

        self.pack_start(hbox, True, False, 5)


        # description
        hbox = Gtk.HBox(False)
        description_lbl = Gtk.Label('Description: ')
        size_group.add_widget(description_lbl)       
        hbox.pack_start(description_lbl, False, False, 0)
        self.description_txt = Gtk.TextView()
        hbox.pack_start(self.description_txt, True, True, 5)

        self.pack_start(hbox, True, True, 5)

        # agency
        self.agency_hbox = AgencyChoice()
        size_group.add_widget(self.agency_hbox.get_label())
        self.pack_start(self.agency_hbox, True, False, 5)

        # path
        self.path_hbox = PathChoice()
        size_group.add_widget(self.path_hbox.get_label())
        self.pack_start(self.path_hbox, True, False, 5)

        # stop list
        hbox = Gtk.HBox(False)
        stop_lbl = Gtk.Label('Stops: ')
        size_group.add_widget(stop_lbl)
        hbox.pack_start(stop_lbl, False, False, 0)
        self.stop_list = StopListGui()
        hbox.pack_start(self.stop_list.get_widget(), True, True, 5)
        # actions
        vbox = Gtk.VBox(True)
        add_btn = Gtk.Button.new_from_stock(Gtk.STOCK_ADD)
        rm_btn = Gtk.Button.new_from_stock(Gtk.STOCK_REMOVE)
        up_btn = Gtk.Button.new_from_stock(Gtk.STOCK_GO_UP)
        down_btn = Gtk.Button.new_from_stock(Gtk.STOCK_GO_DOWN)

        rm_btn.connect('clicked', self.on_remove_stop)
        up_btn.connect('clicked', self.on_raise_stop)
        down_btn.connect('clicked', self.on_lower_stop)

        vbox.pack_start(add_btn, False, False, 5)
        vbox.pack_start(rm_btn, False, False, 5)
        vbox.pack_start(up_btn, False, False, 5)
        vbox.pack_start(down_btn, False, False, 5)
        hbox.pack_start(vbox, False, False, 0)

        self.pack_start(hbox, True, True, 5)

        # trip route list
        hbox = Gtk.HBox(False)
        trip_route_lbl = Gtk.Label('Trips: ')
        size_group.add_widget(trip_route_lbl)
        hbox.pack_start(trip_route_lbl, False, False, 0)
        self.trip_list = TripRouteListGui()
        hbox.pack_start(self.trip_list.get_widget(), True, True, 5)
        # actions
        vbox = Gtk.VBox(True)
        add_btn = Gtk.Button.new_from_stock(Gtk.STOCK_ADD)
        rm_btn = Gtk.Button.new_from_stock(Gtk.STOCK_REMOVE)
        edit_btn = Gtk.Button.new_from_stock(Gtk.STOCK_EDIT)
        modify_btn = Gtk.Button('Modify Trips')

        add_btn.connect('clicked', self.on_add_trip)
        rm_btn.connect('clicked', self.on_remove_trip)
        edit_btn.connect('clicked', self.on_edit_trip)
        modify_btn.connect('clicked', self.on_modify_trips)

        vbox.pack_start(add_btn, False, False, 5)
        vbox.pack_start(rm_btn, False, False, 5)
        vbox.pack_start(edit_btn, False, False, 5)
        vbox.pack_start(modify_btn, False, False, 5)
        hbox.pack_start(vbox, False, False, 0)

        self.pack_start(hbox, True, True, 5)


        self._fill(route)

    def get_name(self):
        return self.name_txt.get_text()

    def get_long_name(self):
        return self.long_name_txt.get_text()

    def get_description(self):
        b = self.description_txt.get_buffer()
        return b.get_text(b.get_start_iter(), b.get_end_iter(), False)

    def set_description(self, desc):
        b = Gtk.TextBuffer()
        b.set_text(desc)
        self.description_txt.set_buffer(b)

    def get_agency(self):
        return self.agency_hbox.get_selection()

    def get_path(self):
        return self.path_hbox.get_selection()

    def get_stops(self):
        return self.stop_list.get_stops()

    def get_trip_routes(self):
        return self.trip_list.get_trip_routes()

    def on_stop_selected(self, stop):
        print 'on_stop_selected', stop
        # !mwd - are duplicate stops ok?
        #  We may use the same stops just in
        #  a different direction.
        # !mwd - I really don't think we
        #  should allow duplicates, it 
        #  breaks things. We should have
        #  two stops, one going each direction
        self.stop_list.add_stop(stop)

        return True

    def on_remove_stop(self, btn, user_data = None):
        self.stop_list.remove_selection()

        return True

    def on_raise_stop(self, btn, user_data = None):
        self.stop_list.raise_selection()

        return True

    def on_lower_stop(self, btn, user_data = None):
        self.stop_list.lower_selection()

        return True

    def on_add_trip(self, btn):
        dlg = AddTripRouteDialog(None)
        dlg.content.set_route(self._route())
        dlg.show_all()

        resp = dlg.run()
        if resp == Gtk.ResponseType.ACCEPT:
            # create a new trip route
            tr = libsubte.TripRoute(dlg.content.get_name(),
                                    self._route(),
                                    dlg.content.get_calendar(),
                                    dlg.content.get_headsign(),
                                    dlg.content.get_direction(),
                                    dlg.content.get_path())
            for s in dlg.content.get_stops():
                tr.add_stop(s)
            
            self.trip_list.add_trip_route(tr)
            

        dlg.destroy()

        return True

    def on_edit_trip(self, btn):
        tr = self.trip_list.get_selected()
        if tr is None:
            return True

        dlg = AddTripRouteDialog(None)
        dlg.content.set_route(self._route())
        dlg.content.fill(tr)
        dlg.show_all()

        resp = dlg.run()
        if resp == Gtk.ResponseType.ACCEPT:
            # edit a trip route
            tr.name = dlg.content.get_name()
            tr.calendar = dlg.content.get_calendar()
            tr.headsign = dlg.content.get_headsign()
            tr.direction = dlg.content.get_direction()
            tr.path = dlg.content.get_path()

            tr._stops = []
            for s in dlg.content.get_stops():
                tr.add_stop(s)

            self.trip_list.update_trip_route(tr)

        dlg.destroy()

        return True

    def on_remove_trip(self, btn):
        tr = self.trip_list.get_selected()

        self.trip_list.remove_selection()

        # die baby, die
        if tr:
            tr.destroy()

        return True

    def on_modify_trips(self, btn):
        trip_route = self.trip_list.get_selected()
        if trip_route:
            dlg = TripListDialog(None, trip_route)
            dlg.show_all()

            dlg.run()

            dlg.destroy()

        return True

    def _fill(self, route):
        if route is None:
            return

        self.name_txt.set_text(route.short_name)
        self.long_name_txt.set_text(route.long_name)
        self.set_description(route.description)
        if route.agency:
            self.agency_hbox.set_selection(route.agency.name)
        if route.path:
            self.path_hbox.set_selection(route.path)

        # fill the stops
        for s in route.stops:
            self.stop_list.add_stop(s)

        # fill the trips
        for tr in route.trip_routes:
            self.trip_list.add_trip_route(tr)