Esempio n. 1
0
class UI(Tk):

    def __init__(self):

        Tk.__init__(self)

        self.geometry('%dx%d+500+500' % (WIDTH,HEIGHT))
        self.title('GooMPy')

        self.canvas = Canvas(self, width=WIDTH, height=HEIGHT)

        self.canvas.pack()

        self.bind("<Key>", self.check_quit)
        self.bind('<B1-Motion>', self.drag)
        self.bind('<Button-1>', self.click)

        self.label = Label(self.canvas)

        self.radiogroup = Frame(self.canvas)
        self.radiovar = IntVar()
        self.maptypes = ['roadmap', 'terrain', 'satellite', 'hybrid']
        self.add_radio_button('Road Map',  0)
        self.add_radio_button('Terrain',   1)
        self.add_radio_button('Satellite', 2)
        self.add_radio_button('Hybrid',    3)

        self.zoom_in_button  = self.add_zoom_button('+', +1)
        self.zoom_out_button = self.add_zoom_button('-', -1)

        self.zoomlevel = ZOOM

        maptype_index = 0
        self.radiovar.set(maptype_index)

        self.goompy = GooMPy(WIDTH, HEIGHT, LATITUDE, LONGITUDE, ZOOM, MAPTYPE)

        self.restart()

    def add_zoom_button(self, text, sign):

        button = Button(self.canvas, text=text, width=1, command=lambda:self.zoom(sign))
        return button

    def reload(self):

        self.coords = None
        self.redraw()

        self['cursor']  = ''


    def restart(self):

        # A little trick to get a watch cursor along with loading
        self['cursor']  = 'watch'
        self.after(1, self.reload)

    def add_radio_button(self, text, index):

        maptype = self.maptypes[index]
        Radiobutton(self.radiogroup, text=maptype, variable=self.radiovar, value=index, 
                command=lambda:self.usemap(maptype)).grid(row=0, column=index)

    def click(self, event):

        self.coords = event.x, event.y

    def drag(self, event):

        self.goompy.move(self.coords[0]-event.x, self.coords[1]-event.y)
        self.image = self.goompy.getImage()
        self.redraw()
        self.coords = event.x, event.y

    def redraw(self):

        self.image = self.goompy.getImage()
        self.image_tk = ImageTk.PhotoImage(self.image)
        self.label['image'] = self.image_tk

        self.label.place(x=0, y=0, width=WIDTH, height=HEIGHT) 

        self.radiogroup.place(x=0,y=0)

        x = int(self.canvas['width']) - 50
        y = int(self.canvas['height']) - 80

        self.zoom_in_button.place(x= x, y=y)
        self.zoom_out_button.place(x= x, y=y+30)

    def usemap(self, maptype):

        self.goompy.useMaptype(maptype)
        self.restart()

    def zoom(self, sign):

        newlevel = self.zoomlevel + sign
        if newlevel > 0 and newlevel < 22:
            self.zoomlevel = newlevel
            self.goompy.useZoom(newlevel)
            self.restart()

    def check_quit(self, event):

        if ord(event.char) == 27: # ESC
            exit(0)
Esempio n. 2
0
class UI(Tk):
    def __init__(self):

        Tk.__init__(self)

        self.geometry('%dx%d+100+100' % (1200, 600))
        self.title('Crowdtour')
        self.audioCount = 0
        self.WAVE_OUTPUT_FILENAME = ''
        self.button_list = []
        self.current_places = []

        app = QApplication(sys.argv)

        self.canvas = Canvas(self, width=WIDTH, height=HEIGHT)

        self.canvas.pack()
        self.canvas.place(relx=0, rely=0)
        self.bind("<Key>", self.check_quit)
        self.bind('<B1-Motion>', self.drag)
        self.bind('<Button-1>', self.click)

        self.label = Label(self.canvas)

        self.radiogroup = Frame(self.canvas)
        self.radiovar = IntVar()
        self.maptypes = ['roadmap', 'terrain', 'satellite', 'hybrid']
        self.add_radio_button('Road Map', 0)
        self.add_radio_button('Terrain', 1)
        self.add_radio_button('Satellite', 2)
        self.add_radio_button('Hybrid', 3)

        #input
        self.entry = Entry(self, bd=3)
        self.button = Button(self, text="Location", command=self.geolocation)
        self.button.place(relx=.18, rely=.90, anchor="c")
        self.entry.place(relx=.05, rely=.80)

        #buttons
        self.recordButton = Button(self, text="Record", command=self.record)
        self.recordButton.place(relx=.30, rely=.75, anchor="c")

        self.uploadButton = Button(self, text="Upload", command=self.upload)
        self.uploadButton.place(relx=.30, rely=.80, anchor="c")

        self.playButton = Button(self, text="Play", command=self.play)
        self.playButton.place(relx=.30, rely=.85, anchor="c")

        self.deleteButton = Button(self, text="Delete", command=self.delete)
        self.deleteButton.place(relx=.30, rely=.90, anchor="c")
        ### adding part here ###
        self.sound = QSoundEffect()
        # This is where you set default sound source
        if not os.path.exists('sounds'):
            os.makedirs('sounds')

        defaultBytes = b'27\xe5\xb2\x81\xe5'
        waveTest = wave.open(os.path.join('sounds', 'DefaultSound.wav'), 'w')
        waveTest.setparams((2, 2, 44100, 440320, 'NONE', 'not compressed'))
        waveTest.writeframes(defaultBytes)

        self.sound.setSource(
            QUrl.fromLocalFile(os.path.join('sounds', 'DefaultSound.wav')))

        ### adding part here ###

        self.zoom_in_button = self.add_zoom_button('+', +1)
        self.zoom_out_button = self.add_zoom_button('-', -1)

        self.zoomlevel = ZOOM

        maptype_index = 0
        self.radiovar.set(maptype_index)
        MARKER = "markers=size:tiny|label:B|color:blue|" + str(
            LATITUDE) + "," + str(LONGITUDE)
        self.goompy = GooMPy(WIDTH, HEIGHT, LATITUDE, LONGITUDE, ZOOM, MAPTYPE,
                             MARKER)

        self.restart()

    def add_zoom_button(self, text, sign):

        button = Button(self.canvas,
                        text=text,
                        width=1,
                        command=lambda: self.zoom(sign))
        return button

    def reload(self):

        self.coords = None
        self.redraw()

        self['cursor'] = ''

    def restart(self):

        # A little trick to get a watch cursor along with loading
        self['cursor'] = 'watch'
        self.after(1, self.reload)

    def add_radio_button(self, text, index):

        maptype = self.maptypes[index]
        Radiobutton(self.radiogroup,
                    text=maptype,
                    variable=self.radiovar,
                    value=index,
                    command=lambda: self.usemap(maptype)).grid(row=0,
                                                               column=index)

    def click(self, event):

        self.coords = event.x, event.y

    def drag(self, event):

        self.goompy.move(self.coords[0] - event.x, self.coords[1] - event.y)
        self.image = self.goompy.getImage()
        self.redraw()
        self.coords = event.x, event.y

    def redraw(self):

        self.image = self.goompy.getImage()
        self.image_tk = ImageTk.PhotoImage(self.image)
        self.label['image'] = self.image_tk

        self.label.place(x=0, y=0, width=WIDTH, height=HEIGHT)

        self.radiogroup.place(x=0, y=0)

        x = int(self.canvas['width']) - 50
        y = int(self.canvas['height']) - 80

        self.zoom_in_button.place(x=x, y=y)
        self.zoom_out_button.place(x=x, y=y + 30)

    def usemap(self, maptype):

        self.goompy.useMaptype(maptype)
        self.restart()

    def zoom(self, sign):

        newlevel = self.zoomlevel + sign
        if newlevel > 0 and newlevel < 22:
            self.zoomlevel = newlevel
            self.goompy.useZoom(newlevel)
            self.restart()

    def check_quit(self, event):

        if ord(event.char) == 27:  # ESC
            exit(0)

    #input
    def geolocation(self):
        self.maplist = []
        self.buttonHeightCounter = .05
        API_KEY = 'AIzaSyBPGAbevdKkeXaZT0ZsR0qbO30Bpqqm0Mc'

        google_places = GooglePlaces(API_KEY)

        self.query_result = google_places.nearby_search(
            location=self.entry.get(),
            radius=700,
            types=[types.TYPE_RESTAURANT])
        self.current_places = self.query_result

        if self.query_result.has_attributions:
            print(self.query_result.html_attributions)

        for place in self.query_result.places:
            place.get_details()

            markers = "&markers=size:big|label:S|color:red|" + str(
                place.details['geometry']['location']['lat']) + "," + str(
                    place.details['geometry']['location']['lng']) + "|"
            self.maplist.append(markers)
            print(place.name)
            self.button_list.append(
                Button(self,
                       text=place.name,
                       command=lambda pname=place.name: self.on_click(pname),
                       width=25))
            self.button_list[-1].place(relx=.70,
                                       rely=self.buttonHeightCounter,
                                       anchor="c")
            self.buttonHeightCounter += .035
            print(place.formatted_address + "\n")

        google_maps = GoogleMaps(
            api_key='AIzaSyDlJqxwlOWWAPwf54ivrpAZw4R1Yb5j6Yk')

        location = google_maps.search(
            location=self.entry.get())  # sends search to Google Maps.

        my_location = location.first()  # returns only first location.

        #MARKER = '&markers=color:blue' + '%' + str(7) + 'Clabel:S%' + str(7) + 'C' + str(my_location.lat) + ',' + str(my_location.lng)
        #MARKER = "&markers=size:big|label:S|color:blue|" + str(my_location.lat) + "," + str(my_location.lng) + "|" + \

        MARKER = self.maplist[1] + self.maplist[2] + self.maplist[3]

        self.zoomlevel = ZOOM

        maptype_index = 0
        self.radiovar.set(maptype_index)

        self.goompy = GooMPy(WIDTH, HEIGHT, my_location.lat, my_location.lng,
                             ZOOM, MAPTYPE, MARKER)

        self.restart()
        print(self.query_result)
        print(str(my_location.lat))
        print(str(my_location.lng))
        #print(self.button_list)

    def record(self):
        print("Hello Anthony")
        #audioCount = 0
        CHUNK = 1024
        FORMAT = pyaudio.paInt16
        CHANNELS = 2
        RATE = 44100
        RECORD_SECONDS = 10
        self.WAVE_OUTPUT_FILENAME = "output" + str(self.audioCount) + ".wav"
        self.audioCount += 1

        p = pyaudio.PyAudio()

        stream = p.open(format=FORMAT,
                        channels=CHANNELS,
                        rate=RATE,
                        input=True,
                        frames_per_buffer=CHUNK)

        print("recording...")

        frames = []

        for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
            data = stream.read(CHUNK)
            frames.append(data)

        print("...done recording")

        stream.stop_stream()
        stream.close()
        p.terminate()

        wf = wave.open(os.path.join('sounds', self.WAVE_OUTPUT_FILENAME), 'wb')
        wf.setnchannels(CHANNELS)
        wf.setsampwidth(p.get_sample_size(FORMAT))
        wf.setframerate(RATE)
        wf.writeframes(b''.join(frames))
        wf.close()

        label = Label(self, text="recording is 10 seconds...done recording")
        #this creates a new label to the GUI
        label.place(relx=.35, rely=.80)

    def upload(self):
        #Convert .Wav into Binary
        self.w = wave.open(os.path.join('sounds', 'output0.wav'))

        #Parameters of the source file (keep this)
        #print(self.w.getparams())

        #Write the binary as a string...
        self.binary_data = self.w.readframes(self.w.getnframes())
        self.w.close()

        #Store binary into SQL
        cursorTest = connection.cursor()
        #TEST INSERT
        cursorTest.execute(
            "INSERT INTO `MARKERS` (`id`, `name`, `address`, `lat`, `lng`, `type`,`sound`) VALUES (%s, %s, %s, %s, %s, %s, %s)",
            ('9', 'Test Human', '999 Test Street, Rozelle, NSW', '-33.861034',
             '151.171936', 'restaurant', self.binary_data))
        #       cursorTest.execute("INSERT INTO `MARKERS` (`name`) VALUES (%s)", ('10'))
        #       cursorTest.execute("INSERT INTO `MARKERS` (`address`) VALUES (%s)", ('Insert Name Here'))
        #       cursorTest.execute("INSERT INTO `MARKERS` (`lat`) VALUES (%s)", ('0'))
        #       cursorTest.execute("INSERT INTO `MARKERS` (`lng`) VALUES (%s)", ('0'))
        #       cursorTest.execute("INSERT INTO `MARKERS` (`type`) VALUES (%s)", ('Insert Type Here'))
        #       cursorTest.execute("INSERT INTO `MARKERS` (`sound`) VALUES (%s)", ('Insert Sound Here'))

        #Read Binary from SQL
        cursors = connection.cursor(pymysql.cursors.DictCursor)
        cursors.execute("SELECT sound FROM MARKERS")
        result_set = cursors.fetchall()
        x = 0
        listSoundbytes = [None] * 1
        for row in result_set:
            listSoundbytes.insert(0, row["sound"])
            x += 1

        #Convert string to .wav file
        stringToByte = bytes(listSoundbytes[0])
        waveSave = wave.open(os.path.join('sounds', 'testFile.wav'), 'w')

        #Set parameters for writing
        waveSave.setparams((2, 2, 44100, 440320, 'NONE', 'not compressed'))
        waveSave.writeframes(stringToByte)
        connection.close()

        #Set sound source to soundbyte from SQL
        self.sound.setSource(
            QUrl.fromLocalFile(os.path.join('sounds', 'testFile.wav')))

        #The "All clear"
        print("Upload Successful")

        label1 = Label(self, text="Upload Successful!")
        #this creates a new label to the GUI
        label1.place(relx=.35, rely=.85)

    def play(self):
        pygame.init()
        pygame.mixer.init()
        sounda = pygame.mixer.Sound("./sounds/testFile.wav")
        sounda.play()

        #self.isPlaying = not self.isPlaying
        #self.isPlaying = True;
        #if self.isPlaying:
        #    self.sound.play()
        #    print('Play')
        #else:
        #    self.sound.stop()
        #    print('Stop')
        #print("play/stop")

    def delete(self):
        print("File Deleted from local device")
        try:
            os.remove('sounds/' + self.WAVE_OUTPUT_FILENAME)
            if self.audioCount < 0:
                self.audioCount -= 1
        except OSError as e:
            print("Error: %s - %s." % (e.filename, e.strerror))

    def on_click(self, pname):
        for place in self.query_result.places:
            if (place.name == pname):
                place.get_details()
                if (place.photos):
                    place.photos[0].get(200, 200)
                    place.photos[2].get(200, 200)
                    url = place.photos[0].url
                    url1 = place.photos[2].url
                    print(url)
                    resource = urllib.request.urlopen(url)
                    im = resource.read()
                    resource.close()
                    self.img = Image.open(BytesIO(im))
                    resource1 = urllib.request.urlopen(url1)
                    im1 = resource1.read()
                    resource1.close()
                    self.img1 = Image.open(BytesIO(im1))
                    canvas = Canvas(width=200, height=200, bg='black')
                    canvas1 = Canvas(width=200, height=200, bg='black')
                    canvas.pack()
                    canvas1.pack()
                    canvas.place(relx=.81, rely=.1)
                    canvas1.place(relx=.81, rely=.5)
                    img = self.img.resize((200, 200), Image.ANTIALIAS)
                    self.photo = ImageTk.PhotoImage(img)
                    img1 = self.img1.resize((200, 200), Image.ANTIALIAS)
                    self.photo1 = ImageTk.PhotoImage(img1)
                    canvas.create_image(105, 105, image=self.photo, anchor="c")
                    canvas1.create_image(105,
                                         105,
                                         image=self.photo1,
                                         anchor="c")

        self.restart()
Esempio n. 3
0
class UI(tk.Tk):

    def __init__(self):

        tk.Tk.__init__(self)

        self.geometry('%dx%d+500+500' % (WIDTH,HEIGHT))
        self.title('GooMPy')

        self.canvas = tk.Canvas(self, width=WIDTH, height=HEIGHT)

        self.canvas.pack()

        self.bind("<Key>", self.check_quit)
        self.bind('<B1-Motion>', self.drag)
        self.bind('<Button-1>', self.click)

        self.label = tk.Label(self.canvas)

        self.radiogroup = tk.Frame(self.canvas)
        self.radiovar = tk.IntVar()
        self.maptypes = ['roadmap', 'terrain', 'satellite', 'hybrid']
        self.add_radio_button('Road Map',  0)
        self.add_radio_button('Terrain',   1)
        self.add_radio_button('Satellite', 2)
        self.add_radio_button('Hybrid',    3)

        self.zoom_in_button  = self.add_zoom_button('+', +1)
        self.zoom_out_button = self.add_zoom_button('-', -1)

        self.zoomlevel = ZOOM

        maptype_index = 0
        self.radiovar.set(maptype_index)

        self.goompy = GooMPy(WIDTH, HEIGHT, LATITUDE, LONGITUDE, ZOOM, MAPTYPE)

        self.restart()

    def add_zoom_button(self, text, sign):

        button = tk.Button(self.canvas, text=text, width=1, command=lambda:self.zoom(sign))
        return button

    def reload(self):

        self.coords = None
        self.redraw()

        self['cursor']  = ''


    def restart(self):

        # A little trick to get a watch cursor along with loading
        self['cursor']  = 'watch'
        self.after(1, self.reload)

    def add_radio_button(self, text, index):

        maptype = self.maptypes[index]
        tk.Radiobutton(self.radiogroup, text=maptype, variable=self.radiovar, value=index, 
                command=lambda:self.usemap(maptype)).grid(row=0, column=index)

    def click(self, event):

        self.coords = event.x, event.y

    def drag(self, event):

        self.goompy.move(self.coords[0]-event.x, self.coords[1]-event.y)
        self.image = self.goompy.getImage()
        self.redraw()
        self.coords = event.x, event.y

    def redraw(self):

        self.image = self.goompy.getImage()
        self.image_tk = ImageTk.PhotoImage(self.image)
        self.label['image'] = self.image_tk

        self.label.place(x=0, y=0, width=WIDTH, height=HEIGHT) 

        self.radiogroup.place(x=0,y=0)

        x = int(self.canvas['width']) - 50
        y = int(self.canvas['height']) - 80

        self.zoom_in_button.place(x= x, y=y)
        self.zoom_out_button.place(x= x, y=y+30)

    def usemap(self, maptype):

        self.goompy.useMaptype(maptype)
        self.restart()

    def zoom(self, sign):

        newlevel = self.zoomlevel + sign
        if newlevel > 0 and newlevel < 22:
            self.zoomlevel = newlevel
            self.goompy.useZoom(newlevel)
            self.restart()

    def check_quit(self, event):

        if ord(event.char) == 27: # ESC
            exit(0)
Esempio n. 4
0
class Application(Frame):
    def __init__(self, parent):
        Frame.__init__(self, parent)
        self.parent = parent
        self.parent.protocol("WM_DELETE_WINDOW", self.onExit)
        self.parent.bind("<Destroy>", lambda e: self.onExit)

        self.init_settings()
        self.init_classes()
        self.init_variables()
        self.init_images()

        self.init_menubar()
        self.init_toolbar()
        self.init_tabs()
        self.init_statusbar()

        self.init_connections()

        self.pack()

    def init_settings(self):
        pass

    def init_classes(self):
        self.config_menus = configparser.ConfigParser()
        self.config_tools = configparser.ConfigParser()
        self.config_tabs = configparser.ConfigParser()
        self.config_map = configparser.ConfigParser()
        self._serial = serial.Serial()
        self._parser = parsenmea.ParseNmea()
        self._storage = StorageDB('gps.sqlite')
        self._settings = Settings()
        self._gpgga = nmea.GPGGA()
        self._gprmc = nmea.GPRMC()

        pass

    def init_variables(self):
        self.images_ui = {}
        self.toolbars = {}
        self.menus = {}

        self.lbl_status = StringVar()
        self.connection_status = StringVar()
        self.port_label = StringVar()
        self.port = StringVar()
        self.baud = StringVar()

        self.line_raw = IntVar()
        self.progress = IntVar()
        self.progress_maximum = IntVar()

        self.lastLat = 0.0
        self.lastLon = 0.0

        self.is_zoomIn = True

        # get current project root path
        self.dir_name = os.path.dirname(os.path.realpath(__file__))
        self.menu_file = os.path.join(self.dir_name, "configs/menus.ini")
        self.tool_file = os.path.join(self.dir_name, "configs/toolbars.ini")
        self.tabs_file = os.path.join(self.dir_name, "configs/tabs.ini")
        self.config_file = os.path.join(self.dir_name, "configs/global.ini")
        self.img_path = os.path.join(self.dir_name, "images")
        self.output_path = os.path.join(self.dir_name, "outputs")
        pass

    def init_images(self):
        for file in os.listdir(self.img_path):
            if file.endswith(".png"):
                self.images_ui[file.replace(".png", "")] = PhotoImage(
                    file=str(os.path.join(self.img_path, file)))
        pass

    def init_menubar(self):
        # Load the menus configuration file
        self.config_menus.read(self.menu_file)
        # Initialize menus from configuration file
        self.menubar = Menu(self.parent)
        for section in self.config_menus.sections():
            topMenu = Menu(self.menubar, tearoff=0)
            for option in self.config_menus.options(section):
                if option.strip() == "-":
                    topMenu.add_separator()
                else:
                    topMenu.add_command(
                        label=self.config_menus.get(section, option),
                        compound=LEFT,
                        image=self.images_ui[option],
                        command=lambda tag=option: self.doClickEvent(0, tag))
                    self.menus[option] = topMenu
            self.menubar.add_cascade(label=section, menu=topMenu)
        self.parent.config(menu=self.menubar)
        #for entry in self.menus:
        #self.menus[entry].config(fg= 'green', image= self.images_ui['connect'])
        pass

    def init_toolbar(self):
        # Load the toolbars configuration file
        self.config_tools.read(self.tool_file)
        # Initialize toolbars from configuration file

        self.toolbar = Frame(self.parent, bd=1, relief=RAISED)
        for section in self.config_tools.sections():
            for option in self.config_tools.options(section):
                self.btn_tool = Button(
                    self.toolbar,
                    image=self.images_ui[option],
                    text=option,
                    relief=FLAT,
                    justify=CENTER,
                    command=lambda tag=option: self.doClickEvent(0, tag))
                self.btn_tool.image = self.images_ui[option]
                self.btn_tool.pack(side=LEFT, padx=2, pady=2)
                self.toolbars[option] = self.btn_tool
        self.toolbar.pack(side=TOP, fill=X)

        #for entry in self.toolbars:
        #    self.toolbars[entry]['state'] = DISABLED
        pass

    def init_tabs(self):
        # Load the tabs configuration file
        self.config_tabs.read(self.tabs_file)
        # Initialize tabs from configuration file
        self.tabs = ttk.Notebook(self.parent)
        for section in self.config_tabs.sections():
            for tab in self.config_tabs.options(section):
                tabPage = ttk.Frame(
                    self.tabs
                )  # first page, which would get widgets gridded into it
                self.tabs.add(tabPage,
                              text=self.config_tabs.get(section, tab),
                              image=self.images_ui[tab],
                              compound=LEFT)
                self.create_tabPages(tab, tabPage)
                pass
        self.tabs.pack(expand=1, fill="both")  # Pack to make visible

    def init_statusbar(self):
        self.status_frame = Frame(self.parent, bd=1, relief=GROOVE)
        self.status_frame.pack(fill=X)

        label_Status = Label(self.status_frame,
                             textvariable=self.lbl_status,
                             anchor=W)
        label_Status.pack(side=LEFT)
        label_Dummy = Label(self.status_frame, text='|  GPS Device:', anchor=W)
        label_Dummy.pack(side=LEFT)
        lbl_Connection = Label(self.status_frame,
                               textvariable=self.connection_status,
                               anchor=E,
                               fg='blue')
        lbl_Connection.pack(side=LEFT)
        self.connection_status.set("Disconnected")
        label_lineDummy = Label(self.status_frame, text='|  Line:', anchor=W)
        label_lineDummy.pack(side=LEFT)
        lbl_lineRaw = Label(self.status_frame,
                            textvariable=self.line_raw,
                            anchor=E,
                            fg='green')
        lbl_lineRaw.pack(side=LEFT)
        self.line_raw.set(0)

    def create_tabPages(self, tag, tabPage):
        if tag == 'parse':
            self.tree_parseDate = ttk.Treeview(tabPage, selectmode='browse')
            verticalScroll = ttk.Scrollbar(tabPage,
                                           orient='vertical',
                                           command=self.tree_parseDate.yview)
            verticalScroll.pack(side='right', fill='y')
            horScroll = ttk.Scrollbar(tabPage,
                                      orient='horizontal',
                                      command=self.tree_parseDate.xview)
            horScroll.pack(side='bottom', fill='x')

            self.tree_parseDate.configure(yscrollcommand=verticalScroll.set)
            self.tree_parseDate.configure(xscrollcommand=horScroll.set)

            self.tree_parseDate['columns'] = ('latitude', 'longhitude',
                                              'altitude', 'distance',
                                              'satellites', 'quality', 'speed',
                                              'course', 'date')
            #self.tree_parseDate['show'] = 'headings'
            self.tree_parseDate.heading("#0", text='Timestamp', anchor='w')
            self.tree_parseDate.column("#0", anchor="w", width=40)
            self.tree_parseDate.heading('latitude', text='Latitude')
            self.tree_parseDate.column('latitude',
                                       stretch='yes',
                                       anchor='w',
                                       width=14)

            self.tree_parseDate.heading('longhitude', text='Longhitude')
            self.tree_parseDate.column('longhitude', anchor='w', width=20)

            self.tree_parseDate.heading('altitude', text='Altitude')
            self.tree_parseDate.column('altitude', anchor='w', width=20)

            self.tree_parseDate.heading('distance', text='Distance')
            self.tree_parseDate.column('distance', anchor='w', width=20)

            self.tree_parseDate.heading('satellites', text='Satellites')
            self.tree_parseDate.column('satellites', anchor='w', width=10)

            self.tree_parseDate.heading('quality', text='Quality')
            self.tree_parseDate.column('quality', anchor='w', width=20)

            self.tree_parseDate.heading('speed', text='Speed')
            self.tree_parseDate.column('speed', anchor='w', width=20)

            self.tree_parseDate.heading('course', text='Course')
            self.tree_parseDate.column('course', anchor='w', width=20)

            self.tree_parseDate.heading('date', text='Date')
            self.tree_parseDate.column('date', anchor='w', width=20)

            #self.init_workspaces()
            self.tree_parseDate.pack(expand=1, fill='both')
        elif tag == 'raw':
            self.txt_rawData = Text(tabPage)
            self.txt_rawData.pack(expand=1, fill='both')
            self.txt_rawData.insert(END, 'GPS Logger started...')
            pass
        elif tag == 'summary':
            pass
        else:
            self.canvas = Canvas(tabPage)
            self.canvas.pack(expand=1, fill='both')
            self.label = Label(self.canvas)
            self.label.bind('<B1-Motion>', self.goompy_drag)
            self.label.bind('<Button-1>', self.goompy_click)
            self.label.bind("<Double-1>", lambda e: self.goompy_zoom(+1))
            self.label.bind("<Double-3>", lambda e: self.goompy_zoom(-1))
            self.label.bind_all("<MouseWheel>", self.goompy_mousewheel)
            self.zoomlevel = ZOOM
            self.goompy = GooMPy(WIDTH, HEIGHT, LATITUDE, LONGITUDE, ZOOM,
                                 MAPTYPE)
            self.goompy_restart()
            pass
        pass

    def goompy_reload(self):
        self.coords = None
        self.goompy_redraw()
        self.parent['cursor'] = ''
        pass

    def goompy_restart(self):
        # A little trick to get a watch cursor along with loading
        self.parent['cursor'] = 'watch'
        self.after(1, self.goompy_reload)

    def goompy_redraw(self):
        self.image = self.goompy.getImage()
        self.image_tk = ImageTk.PhotoImage(self.image)
        self.label['image'] = self.image_tk
        self.label.pack(expand=1, fill='both')

    def goompy_zoom(self, sign):
        newlevel = self.zoomlevel + sign
        if newlevel > 0 and newlevel < 22:
            self.zoomlevel = newlevel
            self.goompy.useZoom(newlevel)
            self.goompy_restart()

    def goompy_mousewheel(self, event):
        if event.num == 5 or event.delta < 0:
            self.goompy_zoom(-1)
        else:
            self.goompy_zoom(+1)
        pass

    def goompy_drag(self, event):
        try:
            # Ignore NONE value
            self.goompy.move(self.coords[0] - event.x,
                             self.coords[1] - event.y)
        except:
            pass
        self.image = self.goompy.getImage()
        self.goompy_redraw()
        self.coords = event.x, event.y

    def goompy_click(self, event):
        self.coords = event.x, event.y

    def init_connections(self):
        self.port_label.set(self._settings.GetSetting('port_label'))
        self.port.set(self._settings.GetSetting('port'))
        self.baud.set(self._settings.GetSetting('baud'))
        self.lbl_status.set(
            ('%s | %s' % (self.port_label.get(), self.baud.get())))

        self.port_old = self._settings.GetSetting('port_old')
        if self.port.get() != self.port_old:
            if self._serial.is_open == True:
                self._serial.close()
                self.connection_status.set("Disconnected")
                self.toolbars['connect']['image'] = self.images_ui['connect']
                self.menus['connect'].entryconfig(
                    1, image=self.images_ui['connect'], label='Connect')

        self._serial.baudrate = self.baud.get()
        self._serial.port = self.port.get()

    def connect_device(self):
        if self._serial.is_open == False:
            try:
                self._serial.open()  # Open serial port
            except:
                pass
        else:
            self._serial.close()

        if self._serial.is_open == True:
            self.connection_status.set("Connected")
            self.toolbars['connect']['image'] = self.images_ui['disconnect']
            self.menus['connect'].entryconfig(
                1, image=self.images_ui['disconnect'], label='Disconnect')
            self.thread = Thread(target=self.read_serial,
                                 name=str(datetime.datetime.now()))
            self.thread.start()
        else:
            self.connection_status.set("Disconnected")
            self.toolbars['connect']['image'] = self.images_ui['connect']
            self.menus['connect'].entryconfig(1,
                                              image=self.images_ui['connect'],
                                              label='Connect')

    def read_serial(self):
        self.txt_rawData.insert(END, '\n')  # add first line as line space
        self.line_raw.set(0)
        i = 0
        while self._serial.is_open:
            reading = self._serial.read(self._serial.in_waiting)
            self.txt_rawData.insert(END, reading)
            self.txt_rawData.see("end")
            self.line_raw.set(i)
            self.parse_data(reading)
            i += 1

    def read_data(self, filename):
        if filename.strip() == '':
            return
        self._parser.ParseGpsNmeaFile(filename)
        # If the gpsData is length zero the file was not in the
        # GPGGA, GPRMC pair format. Try the just GPRMC format
        if len(self._parser.gpsData) == 0:
            self._parser.ParseGpsNmeaGprmcFile(filename)
            if len(self._parser.gpsData) == 0:
                print("Error parsing data. Fix input file?")
                exit
        output_file = ''.join(ch for ch in str(datetime.datetime.now())
                              if ch.isalnum())
        self._parser.SaveReducedGpsData(
            '%s.txt' % os.path.join(self.output_path, output_file))

        self.txt_rawData.delete('1.0', END)
        self.txt_rawData.insert(END, '\n')  # add first line as line space
        with open(filename) as fp:
            self.line_raw.set(0)
            i = 0
            for cnt, line in enumerate(fp):
                #print("Line {}: {}".format(cnt, line))
                if line.strip() is not '':
                    self.txt_rawData.insert(END, line)
                    self.txt_rawData.see("end")
                    self.line_raw.set(i)
                    self.parse_data(line)
                    i += 1

    def parse_data(self, line):
        # Skip any sentence other than GPGGA
        if line.startswith('$GPGGA'):
            self._gpgga.parse(line)
            #if self._parser.DoNotHaveFix(self._gpgga.latitude):
            #    continue
            [lat, lon] = self._parser.ConvertLatLonToDecimalDegrees(
                self._gpgga.latitude, self._gpgga.lat_direction,
                self._gpgga.longitude, self._gpgga.lon_direction)
            distance = self._parser.HaversineDistance(lat, self.lastLat, lon,
                                                      self.lastLon)
            self.lastLat = lat
            self.lastLon = lon
            self.tree_parseDate.insert(
                '',
                'end',
                self._gpgga.timestamp,
                values=(lat, lon, self._gpgga.antenna_altitude, distance,
                        self._gpgga.num_sats, self._gpgga.gps_qual))

    '''
    This region starts with control events
    '''

    def doClickEvent(self, index, tag):
        if tag == 'zoom_out':
            self.is_zoomIn = False
            self.goompy_zoom(-1)
        elif tag == 'zoom_in':
            self.is_zoomIn = True
            self.goompy_zoom(+1)
        elif tag == 'port':
            self._settings.SetSettings('port_old', self.port.get())
            cd = ConnectionDialog(self.parent)
            if cd.OK[0] == True:
                self.init_connections()
        elif tag == 'connect':
            self.connect_device()
            pass

        elif tag == 'open':
            self.file_name = filedialog.askopenfilename()
            self.lbl_status.set(self.file_name)
            self.read_data(self.file_name)
            #self.thread = Thread(target=self.read_data, name = str(datetime.datetime.now()))
            #self.thread.start()
        elif tag == 'exit':
            self.onExit()
            pass
        else:
            print((index, tag))
            pass
        pass

    def onExit(self):
        try:
            if messagebox.askokcancel('Quit', 'Do you want to quit?'):
                self.parent.destroy()
        except:
            pass