예제 #1
0
    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
    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)
예제 #3
0
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)
예제 #4
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