コード例 #1
0
ファイル: GTGui.py プロジェクト: CodeforBirmingham/subte
    def __init__(self):
        Gtk.Window.__init__(self, title = 'Subte GTFS Builder', type = Gtk.WindowType.TOPLEVEL)
        self.set_icon_name('subte')

        GTGui.instance = weakref.ref(self)

        self.connect('delete-event', self.on_quit)

        # load up our database
        self.db = libsubte.Database()

        # setup a controller
        self.controller = Controller(self)

        vbox = Gtk.VBox(False)

        # a tool bar

        toolbar = self._build_tool_bar()
        vbox.pack_start(toolbar, False, True, 0)

        # a horizontal pane
        self.main_pane = Gtk.Paned.new(Gtk.Orientation.HORIZONTAL)
        self.info_frame = Gtk.Frame()
        self.map_frame = Gtk.Frame()

        self.main_pane.pack1(self.info_frame)
        self.main_pane.pack2(self.map_frame)

        # info frame
        box = Gtk.VBox(False)
        notebook = Gtk.Notebook()
        box.pack_start(notebook, True, True, 5)

        self.stop_list_widget = StopListGui()
        notebook.append_page(self.stop_list_widget.get_widget(), Gtk.Label('Stops'))
        self.trip_list_widget = TripRouteListGui()
        notebook.append_page(self.trip_list_widget.get_widget(), Gtk.Label('Trips'))
        self.path_list_widget = PathListGui()
        notebook.append_page(self.path_list_widget.get_widget(), Gtk.Label('Paths'))

        self.info_frame.add(box)

        # map frame
        box = Gtk.VBox(False)
        self.map_widget = GTMap()        
        box.pack_start(self.map_widget, True, True, 5)
        self.map_frame.add(box)

        vbox.pack_start(self.main_pane, True, True, 15)

        self.add(vbox)

        # initialize the controller
        self.controller.initialize()
        
        # some signals
        self.map_widget.view.connect('button-release-event', self.controller.on_map_click, self.map_widget)
        self.stop_list_widget.treeview.connect('cursor-changed', self.controller.on_stop_list_selected)
        self.trip_list_widget.treeview.connect('cursor-changed', self.controller.on_route_trip_list_selected)
コード例 #2
0
ファイル: TripRouteDialog.py プロジェクト: line72/subte
    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()
コード例 #3
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
コード例 #4
0
ファイル: AddRoute.py プロジェクト: CodeforBirmingham/subte
    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)
コード例 #5
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)
コード例 #6
0
    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: ')
        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, 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: ')
        size_group.add_widget(headsign_lbl)       
        hbox.pack_start(headsign_lbl, False, False, 0)
        self.headsign_txt = Gtk.Entry()
        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: ')
        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: ')
        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: ')
        size_group.add_widget(stops_lbl)
        hbox.pack_start(stops_lbl, False, False, 0)
        self.stops = StopListGui()
        hbox.pack_start(self.stops.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)

        #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()
コード例 #7
0
ファイル: GTGui.py プロジェクト: line72/subte
class GTGui(Gtk.Window):
    instance = None
    def __init__(self):
        Gtk.Window.__init__(self, title = 'Subte GTFS Builder', type = Gtk.WindowType.TOPLEVEL)
        self.set_icon_name('subte')

        GTGui.instance = weakref.ref(self)

        self.connect('delete-event', self.on_quit)

        # load up our database
        self.db = libsubte.Database()

        # setup a controller
        self.controller = Controller(self)

        vbox = Gtk.VBox(False)

        # a tool bar

        toolbar = self._build_tool_bar()
        vbox.pack_start(toolbar, False, True, 0)

        # a horizontal pane
        self.main_pane = Gtk.Paned.new(Gtk.Orientation.HORIZONTAL)
        self.info_frame = Gtk.Frame()
        self.map_frame = Gtk.Frame()

        self.main_pane.pack1(self.info_frame)
        self.main_pane.pack2(self.map_frame)

        # info frame
        box = Gtk.VBox(False)
        notebook = Gtk.Notebook()
        box.pack_start(notebook, True, True, 5)

        self.stop_list_widget = StopListGui()
        notebook.append_page(self.stop_list_widget.get_widget(), Gtk.Label(_('Stops')))
        self.trip_list_widget = TripRouteListGui()
        notebook.append_page(self.trip_list_widget.get_widget(), Gtk.Label(_('Trips')))
        self.path_list_widget = PathListGui()
        notebook.append_page(self.path_list_widget.get_widget(), Gtk.Label(_('Paths')))

        self.info_frame.add(box)

        # map frame
        box = Gtk.VBox(False)
        self.map_widget = GTMap()        
        box.pack_start(self.map_widget, True, True, 5)
        self.map_frame.add(box)

        vbox.pack_start(self.main_pane, True, True, 15)

        self.add(vbox)

        # initialize the controller
        self.controller.initialize()
        
        # some signals
        #!lukstafi -- changed button-release to button-press
        self.map_widget.view.connect('button-press-event', self.controller.on_map_click, self.map_widget)
        #!lukstafi -- for some reason AddTripRoute dialogs behave as modal
        # although they should be modeless, and these or similar signals
        # are not sent when AddTripRoute dialogs are open
        self.stop_list_widget.treeview.connect('cursor-changed', self.controller.on_stop_list_selected)
        self.trip_list_widget.treeview.connect('cursor-changed', self.controller.on_route_trip_list_selected)

    def on_quit(self, widget, evt, data = None):
        # try to save
        if self.controller.clear_project(True) == False: # they cancelled, stay in
            return True

        GTGui.instance = None
        Gtk.main_quit()

        return True
        
    def _build_tool_bar(self):
        toolbar = Gtk.Toolbar()
        toolbar.set_icon_size(Gtk.IconSize.LARGE_TOOLBAR)
        #toolbar.set_style(Gtk.ToolbarStyle.BOTH_HORIZ)

        ## LOAD/SAVE/CLOSE DB
        load_db = Gtk.ToolButton.new_from_stock(Gtk.STOCK_OPEN)
        load_db.set_tooltip_text(_('Load a project'))
        load_db.connect('clicked', self.controller.on_load_project_clicked)
        toolbar.add(load_db)
        
        save_db = Gtk.ToolButton.new_from_stock(Gtk.STOCK_SAVE)
        save_db.set_tooltip_text(_('Save a project'))
        save_db.connect('clicked', self.controller.on_save_project_clicked)
        toolbar.add(save_db)
        
        close_db = Gtk.ToolButton.new_from_stock(Gtk.STOCK_CLOSE)
        close_db.set_tooltip_text(_('Close a project'))
        close_db.connect('clicked', self.controller.on_close_project_clicked)
        toolbar.add(close_db)

        toolbar.add(Gtk.SeparatorToolItem())

        ## STOPS
        #!mwd - how do I add a frakin' label?
        #stop_lbl = Gtk.ToolButton()
        #stop_lbl.set_label('Stops:')
        #stop_lbl.set_label_widget(Gtk.Label('Stops:'))
        #toolbar.add(stop_lbl)

        add_stop = Gtk.ToolButton.new_from_stock(Gtk.STOCK_ADD)
        add_stop.set_tooltip_text(_('Add a new stop'))
        add_stop.connect('clicked', self.controller.on_add_stop_clicked)
        toolbar.add(add_stop)

        edit_stop = Gtk.ToolButton.new_from_stock(Gtk.STOCK_EDIT)
        edit_stop.set_tooltip_text(_('Edit a new stop'))
        edit_stop.connect('clicked', self.controller.on_edit_stop_clicked)
        toolbar.add(edit_stop)

        remove_stop = Gtk.ToolButton.new_from_stock(Gtk.STOCK_REMOVE)
        remove_stop.set_tooltip_text(_('Remove a stop'))
        remove_stop.connect('clicked', self.controller.on_remove_stop_clicked)
        toolbar.add(remove_stop)

        merge_stop = Gtk.ToolButton()
        merge_stop.set_icon_name('gtk-copy')
        merge_stop.set_tooltip_text(_('Merge two stops'))
        merge_stop.connect('clicked', self.controller.on_merge_stops_clicked)
        toolbar.add(merge_stop)

        toolbar.add(Gtk.SeparatorToolItem())

        ## TRIPS
        add_trip = Gtk.ToolButton.new_from_stock(Gtk.STOCK_ADD)
        add_trip.set_tooltip_text(_('Add a new trip'))
        add_trip.connect('clicked', self.controller.on_add_trip_clicked)
        toolbar.add(add_trip)

        edit_trip = Gtk.ToolButton.new_from_stock(Gtk.STOCK_EDIT)
        edit_trip.set_tooltip_text(_('Edit a trip'))
        edit_trip.connect('clicked', self.controller.on_edit_trip_clicked)
        toolbar.add(edit_trip)

        remove_trip = Gtk.ToolButton.new_from_stock(Gtk.STOCK_REMOVE)
        remove_trip.set_tooltip_text(_('Remove a trip'))
        remove_trip.connect('clicked', self.controller.on_remove_trip_clicked)
        toolbar.add(remove_trip)

        copy_trip = Gtk.ToolButton()
        copy_trip.set_icon_name('gtk-copy')
        copy_trip.set_tooltip_text(_('Copy a trip'))
        copy_trip.connect('clicked', self.controller.on_copy_trip_clicked)
        toolbar.add(copy_trip)

        toolbar.add(Gtk.SeparatorToolItem())

        ## PICTURES
        add_picture = Gtk.ToolButton.new_from_stock(Gtk.STOCK_ADD)
        add_picture.set_tooltip_text(_('Add a new picture'))
        add_picture.connect('clicked', self.controller.on_add_picture_clicked)
        toolbar.add(add_picture)
        
        # remove_picture = Gtk.ToolButton.new_from_stock(Gtk.STOCK_REMOVE)
        # remove_picture.set_tooltip_text('Remove a picture')
        # remove_picture.connect('clicked', self.controller.on_remove_picture_clicked)
        # toolbar.add(remove_picture)
        
        toolbar.add(Gtk.SeparatorToolItem())


        ## PATHS
        add_path = Gtk.ToolButton.new_from_stock(Gtk.STOCK_ADD)
        add_path.set_tooltip_text(_('Add a new path from a .kml (or .kmz) file'))
        add_path.connect('clicked', self.controller.on_add_path_clicked)
        toolbar.add(add_path)

        remove_path = Gtk.ToolButton.new_from_stock(Gtk.STOCK_REMOVE)
        remove_path.set_tooltip_text(_('Remove a path'))
        remove_path.connect('clicked', self.controller.on_remove_path_clicked)
        toolbar.add(remove_path)

        toolbar.add(Gtk.SeparatorToolItem())

        ## Import
        import_gtfs = Gtk.ToolButton('Import')
        import_gtfs.set_icon_name('document-import')
        import_gtfs.set_tooltip_text(_('Import GTFS'))
        import_gtfs.connect('clicked', self.controller.on_import_gtfs)
        toolbar.add(import_gtfs)

        ## EXPORT
        export = Gtk.ToolButton('Export')
        export.set_icon_name('document-send')
        export.set_tooltip_text(_('Export to GTFS'))
        export.connect('clicked', self.controller.on_export_gtfs)
        toolbar.add(export)

        export = Gtk.ToolButton('Export')
        export.set_icon_name('document-send')
        export.set_tooltip_text(_('Export to KML/JS/HTML'))
        export.connect('clicked', self.controller.on_export_kml)
        toolbar.add(export)

        toolbar.add(Gtk.SeparatorToolItem())

        return toolbar