Exemple #1
0
    def do_open_connections(self):
        """Open the connections file and extract roads connecting cities."""

        # Get the filename.
        newfilename = tkfile.askopenfilename()
        # If they cancel, cancel.
        if not newfilename:
            return
        self.connection_file_name = newfilename

        # Try to open the file.
        try:
            connectionsfile = open(self.connection_file_name)
        # And complain if we can't.
        except IOError:
            tkmsg.showerror("Error", "Error loading connections file.")
            return

        # Get rid of any previous connections.
        for city in self.cities:
            city.neighbors = []

        # Load new connections from the file.
        self.cities = parse_connections_file(connectionsfile, self.cities)

        # Count the number of connections we just loaded and log it.
        roadcount = 0
        for city in self.cities:
            roadcount += len(city.neighbors)
        self.log_message("Loaded " + str(roadcount) + " roads.")

        # Draw the new connections onto the canvas.
        for city in self.cities:
            for road in city.neighbors:
                road.draw(self.canvas)

        # Let the user start a search.
        self.searchmenu.entryconfig(0, state=tk.NORMAL)
        self.searchmenu.entryconfig(1, state=tk.NORMAL)
Exemple #2
0
    print("Usage: python {} <locations> <connections> <origin> <destination> [<avoid>]".format(sys.argv[0]))
    exit(1)

try:
    locationsfile = open(sys.argv[1])
except IOError:
    print("Could not open file", sys.argv[1])
    exit(1)

try:
    connectionsfile = open(sys.argv[2])
except IOError:
    print("Could not open file", sys.argv[2])
    exit(1)

locations = parse_connections_file(connectionsfile, parse_locations_file(locationsfile))

try:
    startcity = [x for x in locations if x.name == sys.argv[3]][0]
except IndexError:
    print("Could not find origin city:", sys.argv[3])
    exit(1)

try:
    destcity = [x for x in locations if x.name == sys.argv[4]][0]
except IndexError:
    print("Could not find destination city:", sys.argv[4])
    exit(1)

avoidcities = [x for x in locations if x.name in sys.argv[5:]]