Exemplo n.º 1
0
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)

        f = Flight()

        # ----Home/Current Flight/Sign Out----
        home_button = ttk.Button(
            self,
            text="Home",
            command=lambda: controller.show_frame(CustomerPortal))
        home_button.grid(row=0, column=0, pady=5, columnspan=2)
        flight_string = "Flight #" + str(f.number)
        flight_label = ttk.Label(self, text=flight_string)
        flight_label.grid(row=0, column=2, pady=5, columnspan=3)
        sign_out_button = ttk.Button(
            self,
            text="Sign Out",
            command=lambda: controller.show_frame(HomePage))
        sign_out_button.grid(row=0, column=5, pady=5, columnspan=2)

        # ----Logo and Titles----
        load = Image.open("logo.png")
        load = load.resize((150, 85), Image.ANTIALIAS)
        render = ImageTk.PhotoImage(load)
        img = tk.Label(self, image=render)
        img.image = render
        img.grid(row=1, column=0, padx=100, columnspan=7)
        title1 = ttk.Label(self, text="Sunset Chaser Airlines")
        title1.grid(row=2, column=0, padx=20, pady=2, columnspan=7)
        title2 = ttk.Label(self, text="Customer Portal")
        title2.grid(row=3, column=0, padx=20, pady=5, columnspan=7)

        def display_business(pos):
            r = 4
            c = 0
            for i in range(len(seats)):
                if i == options[pos]:
                    color = 'green'
                elif seats[i] != 'None':
                    color = 'red'
                else:
                    color = 'black'

                s = ttk.Label(self,
                              text=f.get_seat_number(i),
                              foreground=color)
                s.grid(row=r, column=c, padx=1, pady=1)

                c += 1
                if c == 6:
                    c = 0
                    r += 1

        def display_group(pos):
            r = 4
            c = 0
            for i in range(len(seats)):
                for j in options[pos]:
                    if i == j:
                        color = 'green'
                        break

                if seats[i] != 'None':
                    color = 'red'
                elif seats[i] == 'None':
                    if i not in options[pos]:
                        color = 'black'

                s = ttk.Label(self,
                              text=f.get_seat_number(i),
                              foreground=color)
                s.grid(row=r, column=c, padx=1, pady=1)

                c += 1
                if c == 6:
                    c = 0
                    r += 1

        # ----Show Seat Options & New/Confirm Button----
        global index
        index = 0

        if controller.USER != '' and controller.USERTYPE == "customer":
            seats = f.get_seats()
            user = Customer(controller.USER)
            if user.type != "None":
                options = []

                if user.type == "BT-BS":
                    options = f.add_business(True)
                    # display seats
                    display_business(index)
                elif user.type == "BT-N":
                    options = f.add_business(False)
                    display_business(index)

                elif user.type == "TT":
                    options = f.add_tourist()
                    display_group(index)

                elif user.type == "FT-1":
                    options = f.add_family(1)
                    display_group(index)

                elif user.type == "FT-2":
                    options = f.add_family(2)
                    display_group(index)

                elif user.type == "FT-3":
                    options = f.add_family(3)
                    display_group(index)

            def confirm():
                if user.type == "BT-BS" or user.type == "BT-N":
                    f.confirm([options[index]], controller.USER)
                else:
                    f.confirm(options[index], controller.USER)

                controller.refresh_user(controller.USER, "customer")
                controller.show_frame(TicketGenerated)

            def next():
                global index
                index += 1
                if index == len(options):
                    index = 0
                # display seats
                if user.type == "BT-BS" or user.type == "BT-N":
                    display_business(index)
                else:
                    display_group(index)

            new_button = ttk.Button(self, text="New", command=lambda: next())
            new_button.grid(row=4, column=6, padx=2, rowspan=4)
            confirm_button = ttk.Button(self,
                                        text="Confirm",
                                        command=lambda: confirm())
            confirm_button.grid(row=8, column=6, padx=2, rowspan=4)
Exemplo n.º 2
0
 def test_addTourist(self):
     flight = Flight()
     options = flight.add_tourist()
     flight.confirm(options[0], "user6")