Beispiel #1
0
class TrailBlazerGUI:
    ''' Defines the graphical user interface, which displays and allows users to interact with various modules. '''

    def __init__(self, master):
        ''' Initializes the GUI. '''
        self.master = master
        self.bg = "#90EE90"
        self.fg = "#654321"
        self.e_page = "empty"
        master.title("Trail Blazer")
        master.geometry("1920x1080")
        master.configure(bg=self.bg)
        master.bind("<Escape>", self.close)

        self.start = Frame(master, height=1080, width=1920, bg=self.bg)
        self.start.pack()
        self.start.focus_set()
        self.start.bind("<Return>", self.login_page)
        self.greet = Label(self.start, text="Welcome to our Route Suggestion GUI!", font=("sans serif", 50),
                           fg=self.fg, bg=self.bg, pady=10)
        self.greet.pack()
        self.intro = Message(self.start, text="We are writing software to help generate and visualize new routes for runners, walkers, and bikers. \nWe are creating this for our Software Design final project.",
                             font=("sans serif", 20), width=1900, justify=CENTER, fg=self.fg, bg=self.bg, pady=10)
        self.intro.pack()


        self.buttons1 = Frame(self.start, width=500, bg=self.bg)
        self.buttons1.pack()
        self.proceed = Button(self.buttons1, text="Proceed", bg="#64e764", fg="#654321", pady=5,
                              activebackground="#bcf5bc", activeforeground="#8b5d2e", command=self.login_page)
        self.proceed.grid(row=0, column=0)
        self.cancel = Button(self.buttons1, text="Cancel", bg="#64e764", fg="#654321", pady=5,
                             activebackground="#bcf5bc", activeforeground="#8b5d2e", command=master.quit)
        self.cancel.grid(row=0, column=1)

        self.logo = PhotoImage(file="images/trail_blazer_logo.gif")
        self.logo_disp = Label(self.start, image=self.logo, fg=self.fg, bg=self.bg)
        self.logo_disp.pack(side=BOTTOM)

    def login_page(self, event=None):
        ''' Displays a page where the user can login to find a route. '''
        if self.e_page != "empty":
            self.e_page.pack_forget()
            self.e_page.destroy()
        else:
            self.start.pack_forget()
            self.start.destroy()
        self.l_page = Frame(self.master, height=1080, width=1920, bg=self.bg)
        self.l_page.pack()
        self.l_page.focus_set()
        self.l_page.bind("<Return>", self.valid_login)
        self.l_page.bind("<Escape>", self.close)


        self.request = Label(self.l_page, text="Please log in to continue.", font=("sans serif", 20),
                             fg=self.fg, bg=self.bg, pady=20)
        self.request.pack()


        self.login = Frame(self.l_page, width=1000, bg=self.bg)
        self.login.pack()
        self.login.bind("<Return>", self.valid_login)
        self.first = Label(self.login, text="First Name = ", font=("sans serif", 15), anchor=W, bg=self.bg,
                           fg=self.fg, pady=10)
        self.first.grid(row=0, sticky=E)
        self.first_in = Entry(self.login, font=("sans serif", 15), exportselection=0, cursor="xterm")
        self.first_in.bind("<Return>", self.valid_login)
        self.first_in.grid(row=0, column=1, columnspan=3)
        self.last = Label(self.login, text="Last Name = ", font=("sans serif", 15), anchor=W, bg=self.bg,
                          fg=self.fg, pady=10)
        self.last.grid(row=1, sticky=E)
        self.last_in = Entry(self.login, font=("sans serif", 15), exportselection=0, cursor="xterm")
        self.last_in.bind("<Return>", self.valid_login)
        self.last_in.grid(row=1, column=1, columnspan=3)
        self.user = Label(self.login, text="Username = "******"sans serif", 15), anchor=W, bg=self.bg,
                          fg=self.fg, pady=10)
        self.user.grid(row=2, sticky=E)
        self.user_in = Entry(self.login, font=("sans serif", 15), exportselection=0, cursor="xterm")
        self.user_in.bind("<Return>", self.valid_login)
        self.user_in.grid(row=2, column=1, columnspan=3)
        self.pss = Label(self.login, text="Password = "******"sans serif", 15), anchor=W, bg=self.bg,
                         fg=self.fg, pady=10)
        self.pss.grid(row=3, sticky=E)
        self.pss_in = Entry(self.login, font=("sans serif", 15), exportselection=0, cursor="xterm", show="*")
        self.pss_in.bind("<Return>", self.valid_login)
        self.pss_in.grid(row=3, column=1, columnspan=3)


        self.buttons2 = Frame(self.l_page, width=500, bg=self.bg)
        self.buttons2.pack()
        self.submit = Button(self.buttons2, text="Submit", bg="#64e764", fg="#654321", pady=5,
                             activebackground="#bcf5bc", activeforeground="#8b5d2e", command=self.valid_login)
        self.submit.bind("<Return>", self.valid_login)
        self.submit.grid(row=0, column=0)
        self.cancel = Button(self.buttons2, text="Cancel", bg="#64e764", fg="#654321", pady=5,
                             activebackground="#bcf5bc", activeforeground="#8b5d2e", command=self.master.quit)
        self.cancel.bind("<Return>", self.valid_login)
        self.cancel.grid(row=0, column=1)

    def home_page(self, event=None):
        ''' Displays the GUI home page, where user can find the weather of a given location and request a route. '''
        first_name = self.first_in.get()
        last_name = self.last_in.get()
        self.l_page.pack_forget()
        self.l_page.destroy()
        self.h_page = Frame(self.master, height=1080, width=1920, bg=self.bg)
        self.h_page.pack()
        self.h_page.focus_set()
        self.h_page.bind("<Return>", self.find_route)
        self.h_page.bind("<Escape>", self.close)


        self.hello = Label(self.h_page, text="Hello! Welcome to your profile page!", font=("sans serif", 50),
                           bg=self.bg, fg=self.fg, pady=20)
        self.hello.pack()


        self.weather_init = Frame(self.h_page, width=1000, bg=self.bg)
        self.weather_init.pack()
        self.weather_init.bind("<Return>", self.get_forecast)
        self.location = Label(self.weather_init, text="Current Location = ", font=("sans serif", 15), anchor=W, bg=self.bg,
                              fg=self.fg, pady=10)
        self.location.grid(row=0, sticky=E)
        self.location_in = Entry(self.weather_init, font=("sans serif", 15), exportselection=0, cursor="xterm")
        self.location_in.bind("<Return>", self.get_forecast)
        self.location_in.grid(row=0, column=1)


        self.buttons5 = Frame(self.h_page, width=500, bg=self.bg)
        self.buttons5.pack()
        self.buttons5.bind("<Return>", self.get_forecast)
        self.weatherby = Button(self.buttons5, text="Find Weather", bg="#64e764", fg="#654321",
                                activebackground="#bcf5bc", activeforeground="#8b5d2e", pady=5, command=self.get_forecast)
        self.weatherby.grid(row=0, column=0)


        self.name_is = Label(self.h_page, text="Where would you like to go, %s %s?" % (first_name, last_name),
                             font=("sans serif", 15), fg=self.fg, bg=self.bg, pady=10)
        self.name_is.pack()


        self.profile = Frame(self.h_page, width=1000, bg=self.bg)
        self.profile.pack()
        self.profile.bind("<Return>", self.find_route)
        self.loc = Label(self.profile, text="Starting Location:", font=("sans serif", 15), anchor=W, bg=self.bg,
                         fg=self.fg, pady=10)
        self.loc.grid(row=0, sticky=E)
        self.lat = Label(self.profile, text="Latitiude = ", font=("sans serif", 15), anchor=W, bg=self.bg,
                         fg=self.fg, pady=10)
        self.lat.grid(row=1, column=0)
        self.lat_in = Entry(self.profile, font=("sans serif", 15), exportselection=0, cursor="xterm")
        self.lat_in.bind("<Return>", self.find_route)
        self.lat_in.insert(0, "42.292922")
        if self.profile.focus_get() == self.lat_in:
            self.lat_in.delete()
        self.lat_in.grid(row=1, column=1)
        self.lng = Label(self.profile, text="Longitude = ", font=("sans serif", 15), anchor=W, bg=self.bg,
                         fg=self.fg, pady=10)
        self.lng.grid(row=1, column=2)
        self.lng_in = Entry(self.profile, font=("sans serif", 15), exportselection=0, cursor="xterm")
        self.lng_in.bind("<Return>", self.find_route)
        self.lng_in.insert(0, "-71.263073")
        if self.profile.focus_get() == self.lat_in:
            self.lat_in.delete()
        self.lng_in.grid(row=1, column=3)
        self.dist = Label(self.profile, text="Distance(km) = ", font=("sans serif", 15), anchor=W, bg=self.bg,
                          fg=self.fg, pady=10)
        self.dist.grid(row=2, sticky=E)
        self.dist_in = Entry(self.profile, font=("sans serif", 15), exportselection=0, cursor="xterm")
        self.dist_in.bind("<Return>", self.find_route)
        self.dist_in.grid(row=2, column=1)
        self.dist_max = Label(self.profile, text="Maximum distance = 2", font=("sans serif", 10), anchor=W, bg=self.bg,
                              fg=self.fg, pady=10, padx=10)
        self.dist_max.grid(row=2, column=2, sticky=E)


        self.buttons3 = Frame(self.h_page, width=500, bg=self.bg)
        self.buttons3.pack()
        self.enter = Button(self.buttons3, text="Find Route", bg="#64e764", fg="#654321",
                            activebackground="#bcf5bc", activeforeground="#8b5d2e", pady=5, command=self.find_route)
        self.enter.bind("<Return>", self.find_route)
        self.enter.grid(row=0, column=0)
        self.elev = Button(self.buttons3, text="View Elevation", bg="#64e764", fg="#654321",
                           activebackground="#bcf5bc", activeforeground="#8b5d2e", pady=5, command=self.find_elevation)
        self.elev.bind("<Return>", self.find_elevation)
        self.elev.grid(row=0, column=1)
        self.cancel = Button(self.buttons3, text="Cancel", bg="#64e764", fg="#654321",
                             activebackground="#bcf5bc", activeforeground="#8b5d2e", pady=5, command=self.master.quit)
        self.cancel.grid(row=0, column=2)

    def error(self, event=None):
        ''' Displays an error page if a user did not provide all of the required information. '''
        self.l_page.pack_forget()
        self.l_page.destroy()
        self.e_page = Frame(self.master, height=1080, width=1920, bg=self.bg)
        self.e_page.pack()
        self.e_page.focus_set()
        self.e_page.bind("<Return>", self.login_page)
        self.e_page.bind("<Escape>", self.close)


        self.err_title = Label(self.e_page, text="Error: Missing Information", font=("sans serif", 50),
                               bg=self.bg, fg=self.fg, pady=10)
        self.err_title.pack()
        self.err_mss = Message(self.e_page, text="Your submission was missing some data. All fields are rquired.\nPlease return to fill out all fields.",
                               font=("sans serif", 20), width=1900, justify=CENTER, fg=self.fg, bg=self.bg, pady=10)
        self.err_mss.pack()


        self.buttons4 = Frame(self.e_page, width=500, bg=self.bg)
        self.buttons4.pack()
        self.ret = Button(self.buttons4, text="Return", bg="#64e764", fg="#654321", pady=5,
                          activebackground="#bcf5bc", activeforeground="#8b5d2e", command=self.login_page)
        self.ret.grid(row=0, column=0)
        self.cancel = Button(self.buttons4, text="Cancel", bg="#64e764", fg="#654321", pady=5,
                             activebackground="#bcf5bc", activeforeground="#8b5d2e", command=self.master.quit)
        self.cancel.grid(row=0, column=1)

    def valid_login(self, event=None):
        ''' Checks if a user provided all of the necessary information to login. '''
        firstname = self.first_in.get()
        lastname = self.last_in.get()
        username = self.user_in.get()
        password = self.pss_in.get()
        if not firstname and not lastname and not username and not password:
            return self.error()
        else:
            return self.home_page()

    def get_forecast(self, event=None):
        ''' Gets and displays a weather forecast for a given location. '''
        from weather import Weather, Unit
        self.weather = Weather(unit=Unit.FAHRENHEIT)
        self.local = self.weather.lookup_by_location(self.location_in.get())
        self.condition = self.local.condition
        self.forecasts = self.local.forecast
        self.forecast = self.forecasts[1]


        self.location.destroy()
        self.location_in.destroy()
        self.buttons5.destroy()


        self.weather_1 = Label(self.weather_init, text="Today's weather will be %s and %s F" % (self.condition.text, self.condition.temp),
                               font=("sans serif", 17), justify=CENTER, fg=self.fg, bg=self.bg)
        self.weather_1.pack()
        self.weather_2 = Label(self.weather_init, text="with a high of %s F and a low of %s F." % (self.forecast.high, self.forecast.low),
                               font=("sans serif", 15), justify=CENTER, fg=self.fg, bg=self.bg)
        self.weather_2.pack()
        self.weather_3 = Label(self.weather_init, text="According to Yahoo weather on %s." % (self.condition.date), font=("sans serif", 10),
                               justify=CENTER, fg=self.fg, bg=self.bg, pady=5)
        self.weather_3.pack()

    def find_route(self, event=None):
        ''' Finds and plots a route. '''
        api = overpy.Overpass()
        lat = float(self.lat_in.get())
        lng = float(self.lng_in.get())
        radius = 0.01
        distance = float(self.dist_in.get())
        self.route = intersections.graph_it(api, lat, lng, radius, distance)
        intersections.plot_graph(self.route)

    def find_elevation(self, event=None):
        ''' Finds and graphs the elevations of points along a route. '''
        distance = float(self.dist_in.get())
        route_coords = intersections.find_route_coords(self.route)
        unzipped = list(zip(*route_coords))
        get_elevations.plot_elevation(get_elevations.get_elevation_list(unzipped[0], unzipped[1]), distance)

    def close(self, event=None):
        self.master.quit()
Beispiel #2
0
class Verfahren():
    def __init__(self, tkobj):
        #Label - Verfahren
        self.lblVerf = Label(tkobj, text='Verfahren \n', font=('Arial', 15))
        self.lblVerf.grid(column=0, row=0, pady=5, padx=5, sticky=(NW))

        #Buttons für Verf Entries und Textfeld
        #Ausgabe der Entries als Liste
        self.all_Verf = []
        self.addVerfahren = Button(tkobj,
                                   text='+',
                                   fg='Red',
                                   command=self.__addVerf)
        self.addVerfahren.grid(column=0, row=1, pady=5, padx=5, sticky=(NW))

        self.remVerfahren = Button(tkobj,
                                   text='-',
                                   fg='Dark Blue',
                                   command=self.__remVerf)
        self.remVerfahren.grid(column=1, row=1, pady=5, padx=5, sticky=(NW))

        self.EntryVerf = Frame(tkobj)
        self.EntryVerf.grid(column=0, row=2, pady=5, padx=5, sticky=(NW))

        #Frame Checkbutton + Latex-Befehle
        self.boxframe = Frame(tkobj)
        self.boxframe.grid(column=1, row=2, pady=10, padx=10, sticky=NW)

        #Hinzufügen eines Checkbuttons
        self.c = BooleanVar()
        self.c.set(False)
        self.latexctn = Checkbutton(self.boxframe,
                                    text='LaTeX-Befehl aktivieren',
                                    var=self.c,
                                    command=self.LaFrhide)
        self.latexctn.grid(column=0, row=0, pady=5, padx=5, sticky=NW)

        #Frame - LaTeX-Befehle aktivieren
        self.LaFr = Frame(self.boxframe)
        self.LaFr.grid(column=2, row=0, pady=10, padx=10, sticky=N)

        #Button für LaTeX-Befehle
        self.btnit = Button(self.LaFr,
                            text='kursiv',
                            font=('Arial', 10, 'italic'),
                            command=self.LaTeXitalic)
        self.btnit.grid(column=0, row=0, pady=5, sticky=(NW))

        self.btnbd = Button(self.LaFr,
                            text='fett',
                            font=('Arial', 10, 'bold'),
                            command=self.LaTeXbold)
        self.btnbd.grid(column=0, row=1, pady=5, sticky=(NW))

        self.btnun = Button(self.LaFr,
                            text='unterstrichen',
                            font=('Arial', 10, 'underline'),
                            command=self.LaTeXundl)
        self.btnun.grid(column=0, row=2, pady=5, sticky=(NW))

        self.btntl = Button(self.LaFr,
                            text='~',
                            font=('Arial', 10, 'bold'),
                            command=self.LaTeXTilde)
        self.btntl.grid(column=0, row=3, pady=5, sticky=(NW))

        self.btntg = Button(self.LaFr,
                            text='<',
                            font=('Arial', 10, 'bold'),
                            command=self.LaTeXless)
        self.btntg.grid(column=1, row=3, pady=5, sticky=(NW))

        self.btntd = Button(self.LaFr,
                            text='>',
                            font=('Arial', 10, 'bold'),
                            command=self.LaTeXgreater)
        self.btntd.grid(column=2, row=3, pady=5, sticky=(NW))

        self.btnLi = Button(self.LaFr,
                            text='Aufzählung',
                            font=('Arial', 10),
                            command=self.LaTeXBullet)
        self.btnLi.grid(column=0, row=4, pady=5, sticky=(NW))

        self.btnim = Button(self.LaFr,
                            text='Item',
                            font=('Arial', 10),
                            command=self.LaTeXItem)
        self.btnim.grid(column=1, row=4, pady=5, sticky=(NW))

        self.btnNum = Button(self.LaFr,
                             text='Nummerierung',
                             font=('Arial', 10),
                             command=self.LaTeXNum)
        self.btnNum.grid(column=0, row=5, pady=5, sticky=(NW))

        self.LaFr.grid_forget()

    def __addVerf(self):
        self.frameVerf = Frame(self.EntryVerf)  #Erstellung eines Frames
        self.frameVerf.pack()

        self.frameVeAb = Frame(self.frameVerf)
        self.frameVeAb.grid(row=1, column=0, sticky=(NW))
        self.frameVeTe = Frame(self.frameVerf)
        self.frameVeTe.grid(row=2, column=0, sticky=(NW))

        Label(self.frameVeAb, text='Abschnitt', font=12,
              justify=LEFT).grid(row=0, column=0, padx=5, pady=5,
                                 sticky=(NW))  #Bezeichnung des Entries

        self.entVerf = Entry(self.frameVeAb, width=60,
                             background='white')  #Entry-Feld
        self.entVerf.grid(column=1, row=0, padx=36, pady=5, sticky=(EW))

        Label(self.frameVeTe, text='Beschreibung',
              font=12).grid(column=0, row=2, padx=5, pady=5,
                            sticky=(NW))  #Bezeichnung der Textbox

        self.txtVerf = scrolledtext.ScrolledText(self.frameVeTe,
                                                 relief='sunken',
                                                 width=60,
                                                 height=5,
                                                 background='white')  #Textbox
        self.txtVerf.insert(INSERT,
                            'Bitte geben sie Text ein! ')  #Vorgegebener Text
        self.txtVerf.grid(column=1, row=2, padx=5, pady=5, sticky=(EW))

        self.all_Verf.append(
            (self.entVerf, self.txtVerf, self.frameVerf
             ))  # Plus-Button hängt o.g. Objekte an die Bestehenden an.

    def __remVerf(self):
        if len(self.all_Verf) > 0:  #wenn elemente in all_Verf vorhanden sind
            self.all_Verf[-1][2].forget(
            )  #vergessen des übergeordneten Frames (frameVerf) des graphischen Objektes (pack/grid)
            self.all_Verf[-1][2].destroy(
            )  #zerstören des Frameobjektes (Unterobjekte werden mitzerstört)
            self.all_Verf.pop(
                -1)  #letztes Element der Liste wird aus dem Speicher entfernt
        else:
            pass

    def get(self):
        temp = []
        for e in self.all_Verf:  #Element dieser Liste = Liste mit zwei Elementen ['', '']
            nlist = [e[0].get(), e[1].get(1.0, END)
                     ]  #Erstellung einer Hilfslist aus den Sublisten
            temp.append(nlist)  #Liste von Daten wird an Liste angehängt
        return temp

    def set(self, arg):
        while len(self.all_Verf) > 0:
            self.__remVerf()  #entfernt alle Entryfelder
        for index, elem in enumerate(
                arg):  #iterieren durch die übergebenen Elemente
            self.__addVerf()  #hinzufügen der Entries
            self.all_Verf[index][0].insert(
                0,
                elem[0])  #einfügen des str aus der Liste Position 0 von TVerf
            self.all_Verf[index][1].delete(1.0,
                                           END)  #löschen des initialen Inhalts
            self.all_Verf[index][1].insert(
                1.0,
                elem[1])  #einfügen des str aus der Liste Position 1 von TVerf

    def insert(self, *args):
        self.txtVerf.insert(*args)

    def delete(self, *args):
        self.txtVerf.delete(*args)

    def getflag(self):
        return self.c.get()

    def setflag(self, flag):
        self.c.set(flag)
        self.LaFrhide()

    def LaFrhide(self):
        if self.c.get() == False:
            self.LaFr.grid_forget()
        else:
            self.LaFr.grid(column=0, row=1, pady=10, padx=10, sticky=(N))

    #------------------------------------
    def LaTeXitalic(self):
        try:
            self.EntryVerf.focus_get().insert(INSERT, '\\textit{}')
        except:
            pass

    #------------------------------------

    def LaTeXbold(self):
        try:
            self.EntryVerf.focus_get().insert(INSERT, '\\textbf{}')
        except:
            pass

    #------------------------------------

    def LaTeXundl(self):
        try:
            self.EntryVerf.focus_get().insert(INSERT, '\\underline{}')
        except:
            pass

    #------------------------------------

    def LaTeXTilde(self):
        try:
            self.EntryVerf.focus_get().insert(INSERT, r'$\sim$')
        except:
            pass

    #------------------------------------

    def LaTeXless(self):
        try:
            self.EntryVerf.focus_get().insert(INSERT, '\\textless{}')
        except:
            pass

    #------------------------------------

    def LaTeXgreater(self):
        try:
            self.EntryVerf.focus_get().insert(INSERT, '\\textgreater{}')
        except:
            pass

    #------------------------------------

    def LaTeXBullet(self):
        try:
            self.EntryVerf.focus_get().insert(
                INSERT, '\\begin{itemize}\n\\item lorem ipsum\n\\end{itemize}')
        except:
            pass

    #------------------------------------
    def LaTeXNum(self):
        try:
            self.EntryVerf.focus_get().insert(
                INSERT,
                '\\begin{enumerate}\n\\item lorem ipsum\n\\end{enumerate}')
        except:
            pass

    #------------------------------------
    #def LaTeXGrafic(self):
    #try:
    #self.EntryVerf.focus_get().insert(INSERT, '\\begin{figure}[h]\n\\centering\n\\includegraphics[width=4cm]{Dateiname}\n\\caption{Bildunterschrift}\n\\end{figure}')
    #except:
    #pass

    #------------------------------------

    def LaTeXItem(self):
        try:
            self.EntryVerf.focus_get().insert(INSERT, '\\item ')
        except:
            pass