Esempio n. 1
0
    def printLeg(self, root, trip): 
        frame = tk.Frame(root, bd=2, relief=tk.GROOVE)
        frame.grid(column=0, columnspan=2, sticky=NESW)

        # If more than one leg (1+ changes)
        if type(trip) == list: 

            triptime, tH, tM = misc.tripTime(trip)

            tk.Label(frame, text= f'Resa {trip[0].get("Origin").get("time")}-{trip[-1].get("Destination").get("time")} - Restid {str(tH)} h {str(tM)} min', pady=5).grid(row=0, column=0, columnspan=2, sticky=NESW)
                                                                                          
            tk.Button(frame, text="Karta", command= lambda: mapmaker.geometryBackEnd(trip)).grid(row=1, column=0, columnspan=2, sticky=NESW)

            # Go through all legs and print them
            for i, leg in enumerate(trip):
                depTime = leg.get("Origin").get("time")
                arrTime = leg.get("Destination").get("time")
                depDelay = misc.getDelay(leg.get("Origin"))
                arrDelay = misc.getDelay(leg.get("Destination"))

                if leg.get("type") == "WALK":
                    #Exclude walks inside the same stop.
                    if not leg.get("Origin").get("name") == leg.get("Destination").get("name"): 
                        tk.Label(frame,text=leg.get("name") + " till " + leg.get("Destination").get("name")).grid(row=i + 2, column=0, sticky=NESW)
                        tk.Label(frame, text=f'{depTime} - {arrTime}').grid(row=i + 2, column=1, sticky=NESW)


                else:
                    # Print line, destination and times
                    tk.Button(frame, text=leg.get("name") + " till " + leg.get("Destination").get("name"),
                           bg=leg.get("fgColor"), fg=leg.get("bgColor"),
                           command=lambda leg=leg: self.displayRoute(leg.get("JourneyDetailRef").get("ref")),
                           relief=tk.FLAT).grid(row=i + 2, column=0, sticky=NESW)
                    tk.Label(frame, text=f'{depTime}{depDelay} - {arrTime}{arrDelay}').grid(row=i + 2, column=1, sticky=NESW)

        # If only one leg. (No changes)
        elif type(trip) == dict: 
            triptime, tH, tM = misc.tripTime(trip)

            depTime = trip.get("Origin").get("time")
            arrTime = trip.get("Destination").get("time")
            depDelay = misc.getDelay(trip.get("Origin"))
            arrDelay = misc.getDelay(trip.get("Destination"))

            tk.Label(frame, text=f'Resa {depTime}-{arrTime} - Restid {tH!s} h {tM!s} min', pady=5).pack(side=tk.TOP, fill=tk.X)
            tk.Button(frame, text="Karta", command= lambda: mapmaker.geometryBackEnd(trip.get("GeometryRef").get("ref"), trip.get("fgColor"))).pack(fill=tk.X)

            tk.Button(frame, text=trip.get("name") + " till " + trip.get("Destination").get("name"),
                   bg=trip.get("fgColor"), fg=trip.get("bgColor"),
                   command=lambda: self.displayRoute(trip.get("JourneyDetailRef").get("ref")),
                   relief=tk.FLAT).pack(side=tk.LEFT, fill=tk.X)
            tk.Label(frame, text=f'{depTime}{depDelay} - {arrTime}{arrDelay}').pack(side=tk.LEFT)
Esempio n. 2
0
    def printDepartures(self, departures, stopname, date, time_):
        self.clearFrame()
        BackButton(self).grid(row=0, column=0, columnspan=3, sticky=NESW)

        # Print stopname and time.
        headline = tk.Label(self.frame, text=f'Avgångar från {stopname} {time_} {date}', pady=5, padx=10)
        headline.grid(row=1, column=0, columnspan=3, sticky=tk.E + tk.W)

        # Go through all departures and add buttons to printJourney.
        for i, departure in enumerate(departures):
            tk.Label(self.frame, text=departure.get("sname"), bg=departure.get("fgColor"),
                  fg=departure.get("bgColor")).grid(row=i + 2, column=0, sticky=NESW)
            tk.Button(self.frame, text=departure.get("direction"),
                   command=lambda departure=departure: self.displayRoute(departure.get("JourneyDetailRef").get("ref"))).grid(
                row=i + 2, column=1, sticky=tk.E + tk.W)

            if not departure.get("rtTime"):
                tk.Label(self.frame, text="ca " + departure.get("time")).grid(row=i + 2, column=2, sticky=NESW)
            else:

                delay = misc.getDelay(departure)

                tk.Label(self.frame, text=f'{departure.get("time")} {delay}').grid(row=i + 2, column=2, sticky=NESW)
Esempio n. 3
0
    def displayRoute(self,
                     url):  # Display line, stops and times for one departure.
        route = self.api.getRoute(url)

        routeRoot = tk.Toplevel()

        # Get name of route ("Buss 50")
        try:
            name = route.get("JourneyName")[0].get("name")
        except KeyError:
            name = route.get("JourneyName").get("name")

        # Make names presentable
        name = name.replace("Bus", "Buss")
        name = name.replace("Sp\u00e5", "Sp\u00e5rvagn")
        name = name.replace("Reg T\u00c5G", "T\u00e5g")
        name = name.replace("V\u00e4s T\u00c5G", "V\u00e4stt\u00e5g")
        name = name.replace("Fär", "Färja")

        # Get destination ("Centralstationen")
        try:
            destination = route.get("Direction")[0].get("$")
            multipleDestionations = True
        except KeyError:
            destination = route.get("Direction").get("$")
            multipleDestionations = False

        # Store colour-dict in variable
        colour = route.get("Color")

        # Print out line and destination
        label = tk.Label(routeRoot,
                         text=f'{name} mot {destination}',
                         bg=colour.get("fgColor"),
                         fg=colour.get("bgColor"))

        # Get labels if the line changes number/destination
        extras = []
        if multipleDestionations:
            direction = route.get("Direction")
            journeyName = route.get("JourneyName")
            stop = route.get("Stop")

            # Go through every change
            i = 1
            while i < len(direction):
                # Get the stop where it changes
                stopID = int(direction[i].get("routeIdxFrom"))
                fromStop = stop[stopID].get("name")

                # Get new line name and make them presentable
                name = journeyName[i].get("name")
                name = name.replace("Bus", "Buss")
                name = name.replace("Sp\u00e5", "Sp\u00e5rvagn")
                name = name.replace("Reg T\u00c5G", "T\u00e5g")
                name = name.replace("V\u00e4s T\u00c5G", "V\u00e4stt\u00e5g")
                name = name.replace("Fär", "Färja")

                # Create the label and add it to a list
                labelText = f'Blir {name} mot {direction[i].get("$")} vid {fromStop}'
                extras.append(
                    tk.Label(routeRoot,
                             text=labelText,
                             bg=colour.get("fgColor"),
                             fg=colour.get("bgColor")))
                i += 1

        # Determines how many columns are necessary
        if len(route.get("Stop")) > 60:
            columns = 6
        elif len(route.get("Stop")) > 30:
            columns = 4
        else:
            columns = 2

        # Grid the journey info
        label.grid(sticky=NESW, row=0, column=0, columnspan=columns)

        if multipleDestionations:
            for i, value in enumerate(extras):
                value.grid(sticky=NESW,
                           row=i + 1,
                           column=0,
                           columnspan=columns)

        # Print route and times
        for i, stops in enumerate(route.get("Stop")):
            column = 0
            row = i + len(extras)
            # Changes what column stuff is being put into.
            if len(route.get("Stop")) > 60:
                if i >= 2 * len(route.get("Stop")) // 3:
                    column = 4
                    row -= (2 * len(route.get("Stop")) // 3)
                elif i >= len(route.get("Stop")) // 3:
                    column = 2
                    row -= (len(route.get("Stop")) // 3)

            elif len(route.get("Stop")) > 30:
                if i >= len(route.get("Stop")) // 2:
                    column = 2
                    row -= (len(route.get("Stop")) // 2)

            # Prints name of stop
            tk.Label(routeRoot, text=stops.get("name")).grid(sticky=NESW,
                                                             row=row + 1,
                                                             column=column)

            # Tries to get times. RT Dep -> TT Dep -> RT Arr -> TT Arr -> Error
            if not stops.get("rtDepTime"):
                if not stops.get("depTime"):
                    if not stops.get("rtArrTime"):
                        if not stops.get("arrTime"):
                            tk.Label(routeRoot,
                                     text="Error").grid(sticky=NESW,
                                                        row=row + 1,
                                                        column=column + 1)
                        else:
                            tk.Label(routeRoot,
                                     text="a(" + stops.get("arrTime") +
                                     ")").grid(sticky=NESW,
                                               row=row + 1,
                                               column=column + 1)
                    else:
                        delay = misc.getDelay(stops)
                        tk.Label(routeRoot,
                                 text=f'a{stops.get("arrTime")} {delay}').grid(
                                     sticky=NESW,
                                     row=row + 1,
                                     column=column + 1)
                else:
                    tk.Label(routeRoot, text="(" + stops.get("depTime") +
                             ")").grid(sticky=NESW,
                                       row=row + 1,
                                       column=column + 1)
            else:
                delay = misc.getDelay(stops)
                tk.Label(routeRoot,
                         text=f'{stops.get("depTime")} {delay}').grid(
                             sticky=NESW, row=row + 1, column=column + 1)

        tk.Button(routeRoot,
                  text="Karta",
                  command=lambda: mapmaker.geometryBackEnd(
                      route.get("GeometryRef").get("ref"), colour.get(
                          "fgColor"))).grid(column=0,
                                            columnspan=columns,
                                            sticky=NESW)

        tk.Button(routeRoot, text="Stäng",
                  command=routeRoot.destroy).grid(column=0,
                                                  columnspan=columns,
                                                  sticky=NESW)
Esempio n. 4
0
    def displayRoute(self, url): # Display line, stops and times for one departure.
        route = self.api.getRoute(url)

        routeRoot = tk.Toplevel()

        # Get name of route ("Buss 50")
        try:
            name = route.get("JourneyName")[0].get("name")
        except KeyError:
            name = route.get("JourneyName").get("name")

        # Make names presentable
        name = name.replace("Bus", "Buss")
        name = name.replace("Sp\u00e5", "Sp\u00e5rvagn")
        name = name.replace("Reg T\u00c5G", "T\u00e5g")
        name = name.replace("Fär", "Färja")

        # Get destination ("Centralstationen")
        try:
            destination = route.get("Direction")[0].get("$")
        except KeyError:
            destination = route.get("Direction").get("$")

        # Store colour-dict in variable
        colour = route.get("Color")

        # Print out line and destination
        label = tk.Label(routeRoot, text= f'{name} mot {destination}', bg=colour.get("fgColor"), fg=colour.get("bgColor"))

        # Determines how many columns are necessary
        if len(route.get("Stop")) > 60:
            label.grid(sticky=NESW, row=0, column=0, columnspan=6)
            columns = 6
        elif len(route.get("Stop")) > 30:
            label.grid(sticky=NESW, row=0, column=0, columnspan=4)
            columns = 4
        else:
            label.grid(sticky=NESW, row=0, column=0, columnspan=2)
            columns = 2

        # Print route and times
        for i, stops in enumerate(route.get("Stop")):
            column = 0
            row = i
            # Changes what column stuff is being put into.
            if len(route.get("Stop")) > 60:
                if i >= 2 * len(route.get("Stop")) // 3:
                    column = 4
                    row = i - (2 * len(route.get("Stop")) // 3)
                elif i >= len(route.get("Stop")) // 3:
                    column = 2
                    row = i - (len(route.get("Stop")) // 3)
                
            elif len(route.get("Stop")) > 30:
                if i >= len(route.get("Stop")) // 2:
                    column = 2
                    row = i - (len(route.get("Stop")) // 2)
            
            # Prints name of stop 
            tk.Label(routeRoot, text=stops.get("name")).grid(sticky=NESW, row=row + 1, column=column)

            # Tries to get times. RT Dep -> TT Dep -> RT Arr -> TT Arr -> Error
            if not stops.get("rtDepTime"):
                if not stops.get("depTime"):
                    if not stops.get("rtArrTime"):
                        if not stops.get("arrTime"):
                            tk.Label(routeRoot, text="Error").grid(sticky=NESW, row=row + 1, column=column + 1)
                        else:
                            tk.Label(routeRoot, text="a(" + stops.get("arrTime") + ")").grid(sticky=NESW, row=row + 1, column=column + 1)
                    else:
                        delay = misc.getDelay(stops)
                        tk.Label(routeRoot, text=f'a{stops.get("arrTime")} {delay}').grid(sticky=NESW, row=row + 1, column=column + 1)
                else:
                    tk.Label(routeRoot, text="(" + stops.get("depTime") + ")").grid(sticky=NESW, row=row + 1, column=column + 1)
            else:
                delay = misc.getDelay(stops)
                tk.Label(routeRoot, text=f'{stops.get("depTime")} {delay}').grid(sticky=NESW, row=row + 1, column=column + 1)

        tk.Button(routeRoot, text="Karta", command= lambda: mapmaker.geometryBackEnd(route.get("GeometryRef").get("ref"), colour.get("fgColor"))).grid(column=0, columnspan=columns, sticky=NESW)

        tk.Button(routeRoot, text="Stäng", command=routeRoot.destroy).grid(column=0, columnspan=columns, sticky=NESW)