Exemple #1
0
def submit(*value):
    print('_____________________________________________________________')

    model = TableModel()
    # load data
    data = load_data(name, value)
    # import data to tablemodel
    model.importDict(data)

    # Create table for records preview
    table = TableCanvas(recordsFrame,
                        name="tablica",
                        model=model,
                        width=420,
                        height=600,
                        cols=0,
                        rows=0,
                        cellwidth=50,
                        editable=False,
                        showkeynamesinheader=True,
                        reverseorder=0)
    table.grid(row=0, sticky=W + N + S)
    table.createTableFrame()
    table.redrawTable()
Exemple #2
0
def openfile():
    global table, time, x_angle, y_angle, day, month, year, root, embedFrame, recordsFrame, play

    name = tkFileDialog.askopenfilename(initialdir=".",
                                        title="Select file",
                                        filetypes=(("Text File", "*.txt"),
                                                   ("All Files", "*.*")))

    if name == "":
        # if file openning was cancelled then return
        return
    else:
        try:
            path = name.split('/')
            # get date from file name
            filename = path[len(path) - 1]
            day = filename[6:8]
            month = filename[4:6]
            year = filename[2:4]

            # create data
            model = TableModel()
            # load data
            data = load_data(name)
            # import data ti tablemodel
            model.importDict(data)
        except:
            tkMessageBox.showerror("Error", "File reading failed!")
            return

    # If another file is open already then close it
    if table != None:
        closefile()

    # Change App title to include currently open file
    root.title('Smart Egg 3D Visualisation ver.1.1 - ' + filename)

    # Create embed frame for pygame window
    embedFrame = tk.Frame(root, width=700, height=600)
    embedFrame.grid(row=0, column=0)
    # Create embed frame for table
    recordsFrame = tk.Frame(root, width=450, height=600)
    recordsFrame.grid(row=0, column=1)
    recordsFrame.pack_propagate(0)
    # Create table for records preview
    table = TableCanvas(recordsFrame,
                        name="tablica",
                        model=model,
                        width=420,
                        height=600,
                        cols=0,
                        rows=0,
                        cellwidth=50,
                        editable=False,
                        showkeynamesinheader=True,
                        reverseorder=0)
    table.grid(row=0, sticky=W + N + S)
    table.createTableFrame()
    # arrange columns width and order
    model.moveColumn(model.getColumnIndex('time'), 1)
    model.moveColumn(model.getColumnIndex('x'), 2)
    model.moveColumn(model.getColumnIndex('y'), 3)
    model.moveColumn(model.getColumnIndex('z'), 4)
    model.moveColumn(model.getColumnIndex('roll'), 5)
    model.moveColumn(model.getColumnIndex('pitch'), 6)
    model.columnwidths['time'] = 150

    table.redrawTable()

    # Initiate and embed pygame
    os.environ['SDL_WINDOWID'] = str(embedFrame.winfo_id())
    #os.environ['SDL_VIDEODRIVER'] = 'windib'
    screen = pygame.display.set_mode(SCREEN_SIZE,
                                     HWSURFACE | OPENGL | DOUBLEBUF)
    resize(*SCREEN_SIZE)
    pygame.init()
    pygame.display.init()

    #Bind keys and buttons events
    root.bind('<ButtonRelease-1>', handle_click)  #click release event
    root.bind_all("<Up>", handle_arrow_keys)  #press Up key event
    root.bind_all("<Down>", handle_arrow_keys)  #press Down key event
    root.bind_all("<Left>", handle_arrow_keys)  #press Left key event
    root.bind_all("<Right>", handle_arrow_keys)  #press Right key event

    # Initiate OpenGL
    init_opengl()

    # Create OpenGL object
    egg = Egg((0.7, 0.0, 0.0), (1, .95, .8))

    # Load first element
    values = get_record(0)
    if values != None:
        time = values[0] + ' ' + values[1]
        x_angle = values[2]
        y_angle = values[3]

    root.update()

    # loop control variable
    play = True

    while play:
        drawXYZCoordinate()
        # Draw XYZ axis labels
        drawText3D(-1.2, -1.0, -2.4, 'x')
        drawText3D(-2.2, -0.6, -2.4, 'y')
        drawText3D(-2.2, -1.0, -2.0, 'z')

        for event in pygame.event.get():
            if event.type == KEYUP:
                handle_arrow_keys(event.key)

        glPushMatrix()
        # rotate object
        glRotate(float(x_angle), 0, 0, 1)
        glRotate(float(y_angle), 1, 0, 0)
        # render object and text
        egg.render(pygame)
        glPopMatrix()
        drawText(0, 2, time)
        # refresh screen
        pygame.display.flip()
        root.update()
Exemple #3
0
def run():
    global reader, time, x_angle, y_angle, day, month, year, table, model, index
    
    # tk init
    root = tk.Tk()
    root.title('Smart Egg 3D Visualisation')
    root.geometry("1100x650")    #Set the size of the app to be 800x600
    #root.resizable(0, 0)        #Don't allow resizing in the x or y direction

    # Initializa Menubar
    menubar = Menu(root)
    filemenu = Menu(menubar, tearoff=0)
    filemenu.add_command(label="Open file", command=openfile)
    filemenu.add_command(label="Close file", command=closefile)
    filemenu.add_separator()
    filemenu.add_command(label="Exit", command=root.quit)
    menubar.add_cascade(label="File", menu=filemenu)
    root.config(menu=menubar)

    # TODO create rest only when file selected
    
    # Create embed frame for pygame window
    embed = tk.Frame(root, width=700, height=600) 
    embed.grid(row=0,column=0)
    # Create embed frame for records preview console
    records = tk.Frame(root, width=300, height=600)
    records.grid(row=0,column=1)
    records.pack_propagate(0)
    # Create Table for records preview
    model = TableModel()
    table = TableCanvas(records,name="tablica",model=model, width=300, height=600, cols=0, rows=0,  cellwidth=50, editable=False, showkeynamesinheader=True, reverseorder=0)
    table.grid(row=0,sticky=W+N+S)
    table.createTableFrame()

    root.bind('<ButtonRelease-1>', clicked)   #Bind the click release event
    
    #data = {"age":25}#dict((k,2) for k in a)
    #data = {'rec1': {'time': '12:04:44', 'x': 99.88, 'y': 108.79, 'z': 108.79},
    #        'rec2': {'time': '12:04:45','x': 99.88, 'y': 108.79, 'z': 108.79}}
    #model = table.model
    #model.importDict(data) #can import from a dictionary to populate model
    #model.moveColumn(model.getColumnIndex('time'),0)
    #model.moveColumn(model.getColumnIndex('x'),1)
    #model.moveColumn(model.getColumnIndex('y'),2)
    #model.moveColumn(model.getColumnIndex('z'),3)
    #table.autoResizeColumns()
    #table.redrawTable()
    #button1 = Button(records,text = 'Draw',  command=donothing)
    #button1.pack(side=LEFT)

    #child_env = dict(os.environ)
    #child_env['SDL_WINDOWID'] = str(embed.winfo_id())#the_window_id
    #child_env['SDL_VIDEO_WINDOW_POS'] = '{},{}'.format(left, top)
    #p = subprocess.Popen(['lib/'],env=child_env)
    root.update()
    

    os.environ['SDL_WINDOWID'] = str(embed.winfo_id())
   # os.environ['SDL_VIDEODRIVER'] = 'windib'
    #HWSURFACE |
    # TODO 1: load pygame and table only when file loaded
    screen = pygame.display.set_mode(SCREEN_SIZE, OPENGL | DOUBLEBUF)
    resize(*SCREEN_SIZE)
    pygame.init()
    pygame.display.init()
    #pygame.display.update()

    root.update()  

    init()
    clock = pygame.time.Clock()
    
    egg = Egg((0.7, 0.0, 0.0), (1, .95, .8))
    #cube = Cube((0.0, 0.0, 0.0), (1, .95, .8))
    
    # turn off autoplay
    play = False
    if file_pointer != -1:
        # read first element
        values = read_next_values()
        if values != None:
            time = values[0]
            x_angle = values[1]
            y_angle = values[2]
    
    while True:
        drawXYZCoordinate()

        #then = pygame.time.get_ticks()
        

        # TODO 1: Key control
        # TODO 2: Mark Temperature sensors are reference
        for event in pygame.event.get():
            if event.type == QUIT:
                return
            if event.type == KEYUP:
                if event.key == K_UP:
                    if table.getSelectedRow() > 0: 
                        table.gotoprevRow()
                    #play = True
                if event.key == K_DOWN:
                    if table.getSelectedRow() < table.model.getRowCount()-1:
                        table.gotonextRow()
                    #play = False
                if play or event.key == K_RIGHT:
                    values = get_record(index)
                    #values = read_next_values()
                    print(values)
                    if values == None:
                        print("Koniec Pliku")
                    else:
                        time = values[0]
                        x_angle = values[1]
                        y_angle = values[2]
                if event.key == K_LEFT:
                    values = get_record(index)
                    print(values)
                    #values = read_previous_values()
                    if values == None:
                        print("Poczatek pliku!")
                    else:
                        time = values[0]
                        x_angle = values[1]
                        y_angle = values[2]
                if event.key == K_ESCAPE:
                    return

        # autoplay mode
        if play:
            values = read_next_values()
            if values == None:
                print("Koniec Pliku!")
            else:
                    time = values[0]
                    x_angle = values[1]
                    y_angle = values[2]

        if file_pointer != -1:
            glPushMatrix()
            # Correct
            glRotate(float(x_angle), 0, 0, 1)
            glRotate(float(y_angle), 1, 0, 0)
            egg.render()
            glPopMatrix()

            drawText(0, 2, time)
            
        pygame.display.flip()
        root.update() 
Exemple #4
0
def run():
    global reader, time, x_angle, y_angle, day, month, year, table, model
    
    # tk init
    root = tk.Tk()
    root.title('Smart Egg 3D Visualisation')
    root.geometry("1100x650")    #Set the size of the app to be 800x600
    #root.resizable(0, 0)        #Don't allow resizing in the x or y direction

    # Initializa Menubar
    menubar = Menu(root)
    filemenu = Menu(menubar, tearoff=0)
    filemenu.add_command(label="Open file", command=openfile)
    filemenu.add_command(label="Close file", command=closefile)
    #filemenu.add_separator()
    #filemenu.add_command(label="Exit", command=root.quit)
    menubar.add_cascade(label="File", menu=filemenu)
    root.config(menu=menubar)
    
    # Create embed frame for pygame window
    embed = tk.Frame(root, width=700, height=600) 
    embed.grid(row=0,column=0)
    # Create embed frame for records preview console
    records = tk.Frame(root, width=300, height=600)
    records.grid(row=0,column=1)
    records.pack_propagate(0)
    # Create Table for records preview
    model = TableModel()
    table = TableCanvas(records,name="tablica",model=model, width=300, height=600, cols=0, rows=0,  cellwidth=50, editable=False, showkeynamesinheader=True, reverseorder=0)
    table.grid(row=0,sticky=W+N+S)
    table.createTableFrame()

    root.bind('<ButtonRelease-1>', clicked)   #Bind the click release event
    
    #data = {"age":25}#dict((k,2) for k in a)
    #data = {'rec1': {'time': '12:04:44', 'x': 99.88, 'y': 108.79, 'z': 108.79},
    #        'rec2': {'time': '12:04:45','x': 99.88, 'y': 108.79, 'z': 108.79}}
    #model = table.model
    #model.importDict(data) #can import from a dictionary to populate model
    #model.moveColumn(model.getColumnIndex('time'),0)
    #model.moveColumn(model.getColumnIndex('x'),1)
    #model.moveColumn(model.getColumnIndex('y'),2)
    #model.moveColumn(model.getColumnIndex('z'),3)
    #table.autoResizeColumns()
    #table.redrawTable()
    #button1 = Button(records,text = 'Draw',  command=donothing)
    #button1.pack(side=LEFT)
    #os.environ['SDL_WINDOWID'] = str(embed.winfo_id())
    #os.environ['SDL_VIDEODRIVER'] = 'windib'

    #os.environ["SDL_VIDEODRIVER"] = "dummy"
    
    screen = pygame.display.set_mode(SCREEN_SIZE, HWSURFACE | OPENGL | DOUBLEBUF)
    resize(*SCREEN_SIZE)
    #screen.fill(pygame.Color(255,255,255))
    pygame.init()
    pygame.display.init()
    #pygame.display.update()

    root.update()  

    init()
    clock = pygame.time.Clock()
    egg = Egg2((0.0, 0.0, 0.0), (1, .95, .8))
    #cube = Cube((0.0, 0.0, 0.0), (1, .95, .8))
    angle = 0
    
    # turn off autoplay
    play = False
    if file_pointer != -1:
        # read first element
        values = read_next_values()
        if values != None:
            time = values[0]
            x_angle = values[1]
            y_angle = values[2]
    
    while True:
        then = pygame.time.get_ticks()

        # TODO 1: Key control
        # TODO 2: Mark Temperature sensors are reference
        # TODO 3: Shading
        for event in pygame.event.get():
            if event.type == QUIT:
                return
            if event.type == KEYUP:
                if event.key == K_UP:
                    print(pygame.colored('Odtwarzanie automatyczne','green'))
                    play = True
                if event.key == K_DOWN:
                    print(pygame.colored('Pauza','red'))
                    play = False
                if play or event.key == K_RIGHT:
                    values = read_next_values()
                    if values == None:
                        print(pygame.colored('Koniec Pliku!','red'))
                    else:
                        time = values[0]
                        x_angle = values[1]
                        y_angle = values[2]
                if event.key == K_LEFT:
                    values = read_previous_values()
                    if values == None:
                        print(pygame.colored('Poczatek pliku!','green'))
                    else:
                        time = values[0]
                        x_angle = values[1]
                        y_angle = values[2]
                if event.key == K_ESCAPE:
                    return

        # autoplay mode
        if play:
            values = read_next_values()
            if values == None:
                print(pygame.colored('Koniec Pliku!','red'))
            else:
                    time = values[0]
                    x_angle = values[1]
                    y_angle = values[2]
                   

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        glColor((1.,1.,1.))
        glLineWidth(1)
        glBegin(GL_LINES)

        # uklad wspolrzedny (x, y, z)
        for x in range(-20, 22, 2):
            glVertex3f(x/10.,-1,-2)
            glVertex3f(x/10.,-1,2)
    
        '''for x in range(-20, 22, 2):
            glVertex3f(x/10.,-1, 1)
            glVertex3f(x/10., 1, 1)
        '''
        for z in range(-20, 22, 2):
            glVertex3f(-2, -1, z/10.)
            glVertex3f( 2, -1, z/10.)
        
        '''for z in range(-10, 12, 2):
            glVertex3f(-2, -1, z/10.)
            glVertex3f(-2,  1, z/10.)
        
        for z in range(-10, 12, 2):
            glVertex3f( 2, -1, z/10.)
            glVertex3f( 2,  1, z/10.)
        
        for y in range(-10, 12, 2):
            glVertex3f(-2, y/10., 1)
            glVertex3f( 2, y/10., 1)
        
        for y in range(-10, 12, 2):
            glVertex3f(-2, y/10., 1)
            glVertex3f(-2, y/10., -1)
        
        for y in range(-10, 12, 2):
            glVertex3f(2, y/10., 1)
            glVertex3f(2, y/10., -1)
        '''
        glEnd()

        # draw xyz axis
        glLineWidth(2)
        glBegin(GL_LINES)
        # draw line for x axis
        glColor3f(1.0, 0.0, 0.0)

        glVertex3f(-2.2, -1.0, -2.4);
        glVertex3f(-1.2, -1.0, -2.4);
        glVertex3f(-1.2, -1.0, -2.4);
        glVertex3f(-1.3, -0.98, -2.4);
        glVertex3f(-1.3, -0.98, -2.4);
        glVertex3f(-1.3, -1.02, -2.4);
        glVertex3f(-1.3, -1.02, -2.4);
        glVertex3f(-1.2, -1.0, -2.4);

        # draw line for y axis
        glColor3f(0.0, 1.0, 0.0)

        glVertex3f(-2.2, -1.0, -2.4);
        glVertex3f(-2.2, -0.6, -2.4);
        glVertex3f(-2.2, -0.6, -2.4);
        glVertex3f(-2.22, -0.7, -2.4);
        glVertex3f(-2.22, -0.7, -2.4);
        glVertex3f(-2.18, -0.7, -2.4);
        glVertex3f(-2.18, -0.7, -2.4);
        glVertex3f(-2.2, -0.6, -2.4);

        # draw line for z axis
        glColor3f(0.0, 0.0, 1.0)

        glVertex3f(-2.2, -1.0, -2.4);
        glVertex3f(-2.2, -1.0, -2.0);
        glVertex3f(-2.2, -1.0, -2.0);
        glVertex3f(-2.18, -1.0, -2.1);
        glVertex3f(-2.18, -1.0, -2.1);
        glVertex3f(-2.22, -1.0, -2.1);
        glVertex3f(-2.22, -1.0, -2.1);
        glVertex3f(-2.2, -1.0, -2.0);
        
        glEnd()
        
        if file_pointer != -1:
            glPushMatrix()
            # Correct
            glRotate(float(x_angle), 0, 0, 1)
            glRotate(float(y_angle), 1, 0, 0)
            #glRotate(float(x_angle), 1, 0, 0)
            #glRotate(-float(y_angle), 0, 0, 1)
            #cube.render()
            egg.render()
            glPopMatrix()

            drawText(0, 2, time)
            
        pygame.display.flip()
        root.update() 
Exemple #5
0
class ActivityPage(Tk):
    def __init__(self):
        super(ActivityPage, self).__init__()
        global path
        global path2
        global path3
        global video
        global current
        global directory
        global isDec
        global fps
        global threshold
        global loadedAfflictTable
        global loadedConsoleTable
        if not debug:
            video = startingPage.entryVideo.get()
            print("Video Path: " + str(video))
            current = startingPage.entryCurrent.get()
            print("Current Path: " + str(current))
            directory = startingPage.entryDirectory.get()
            print("Directory Path: " + str(directory))
            # print(video)
            startingPage.destroy()
        self.title("MEDA")

        isDec = False  # variable to check if video has been decompiled
        # try:  # removing directory 1 - clearing it of all past data
        #     sh.rmtree(path)
        # except OSError:
        #     print("No tmp folder found. Will create now.\n")
        # else:
        #     print("Removed tmp folder previously.\n")
        # try:  # removing directory 2 - clearing it of all past frames
        #     sh.rmtree(path2)
        # except OSError:
        #     print("No stmp folder found. Will create now.\n")
        # else:
        #     print("Removed stmp folder previously.\n")
        # try:  # removing directory 2 - clearing it of all past frames
        #     sh.rmtree(path3)
        # except OSError:
        #     print("No btmp folder found. Will create now.\n")
        # else:
        #     print("Removed btmp folder previously.\n")
        # try:  # making new directory 1, checking to make sure it doesn't already exist
        #     path = os.path.join(directory, "DecompiledFrames").replace("\\", "/")
        #     os.mkdir(path)
        # except OSError:
        #     warning = tk.messagebox.showerror(title="file",
        #                                       message="The 'DecompiledFrames' folder already exists in the selected project folder. Please delete or choose a different folder")
            # print("Directory exists\n")
            # return 1
        # else:
        #     print("Temp made\n")
        # try:  # making new directory 2, checking to make sure it doesnt already exist
        #     path2 = os.path.join(directory, "SubtractedFrames").replace("\\", "/")
        #     os.mkdir(path2)
        # except OSError:
        #     warning = tk.messagebox.showerror(title="file",
        #                                       message="The 'SubtractedFrames' folder already exists in the selected project folder. Please delete or choose a different folder")
        #     # print("Directory exists\n")
        #     return 1
        # else:
        #     print("Stemp made\n")
        # try:  # making new directory 2, checking to make sure it doesnt already exist
        #     path3 = os.path.join(directory, "BinarizedFrames").replace("\\", "/")
        #     os.mkdir(path3)
        # except OSError:
        #     warning = tk.messagebox.showerror(title="file",
        #                                       message="The 'BinarizedFrames' folder already exists in the selected project folder. Please delete or choose a different folder")
        #     # print("Directory exists\n")
        #     return 1
        # # else:
        # #     print("Btemp made\n")

        self.LFMeda = LabelFrame(self, text="MEDA")
        self.LFMeda.grid(row=0, column=1, rowspan=1, sticky="NSEW")
        self.grid_columnconfigure(1, weight=1)
        self.grid_rowconfigure(0, weight=1)


        self.FVideoEditor = ttk.Frame(self.LFMeda)
        self.FVideoEditor.grid(column=2, row=0, padx=10, pady=10)
        self.FMenu = ttk.Frame(self)
        self.FMenu.grid(column=0, row=0, sticky="N", ipady=75)

        backButton = Button(self.FMenu, text="Exit Project", command=self.goBack)
        backButton.grid(row=0, column=0, ipadx=10, pady=5, sticky='NW')

        self.fpsEntryLabel = Label(self.FMenu, text="FPS:")
        self.fpsEntryLabel.grid(row=4, column=0, sticky="NW")
        self.fpsEntry = ttk.Entry(self.FMenu, width=6)
        self.fpsEntry.grid(row=4, column=1, sticky="NW")
        self.fpsEntry.delete(0, END)
        self.fpsEntry.insert(0, fps)

        self.thresholdEntryLabel = Label(self.FMenu, text="Threshold:")
        self.thresholdEntryLabel.grid(row=5, column=0, sticky="NW")
        self.thresholdEntry = ttk.Entry(self.FMenu, width=6)
        self.thresholdEntry.grid(row=5, column=1, sticky="NW")
        self.thresholdEntry.delete(0, END)
        self.thresholdEntry.insert(0, threshold)

        self.processButton = Button(self.FMenu, text="Perform Test", command=self.percentChange, width=19)
        self.processButton.grid(row=6, column=0, columnspan=2, sticky="NW")
        self.graphButton = Button(self.FMenu, text=" Show Graph", command=self.showOrHideGraph, state="disabled", width=19)
        self.graphButton.grid(row=7, column=0, columnspan=2, sticky="NW")
        self.tableButtonOnMenu = Button(self.FMenu, text=" Show Tables", state="disabled", width=19)
        self.tableButtonOnMenu.grid(row=8, column=0, columnspan=2, sticky="NW")
        self.subVidButton = Button(self.FMenu, text="Subtracted Video", command=self.createSubVideo, state="disabled", width=19)
        self.subVidButton.grid(row=9, column=0, columnspan=2, sticky="NW")
        self.binVidButton = Button(self.FMenu, text=" Binarized Video ", command=self.createBinVideo, state="disabled", width=19)
        self.binVidButton.grid(row=10, column=0, columnspan=2, sticky="NW")

        self.allStatusFalse()

        self.applyButton = Button(self.FVideoEditor, text="Apply & Save", command=self.printTest)
        self.applyButton.grid(row=1, column=0)

        self.FGraph = ttk.Frame(self.LFMeda)
        if debug or True:
            self.FGraph.grid(row=0, column=1)

        self.FTables = ttk.Frame(self.LFMeda)
        if debug:
            self.FTables.grid(row=0, column=0, sticky="NS", rowspan=2)

        self.FAfflictTable = ttk.Frame(self.FTables)
        self.FAfflictTable.grid(column=0, row=1, padx=10, pady=10, sticky="NW")

        self.FConsoleTable = ttk.Frame(self.FTables)
        self.FConsoleTable.grid(column=0, row=1, padx=10, pady=10, sticky="NW")

        self.FshowTablesButtons = ttk.Frame(self.FTables)
        self.FshowTablesButtons.grid(row=0, column=0, sticky="S", padx=10)
        self.showConsoleDataTableButton = Button(self.FshowTablesButtons, text="Show Console Data",
                                                 command=self.loadConsoleTable, width=19)
        self.showConsoleDataTableButton.grid(row="0", column="0", sticky="S")
        self.showAfflictTableButton = Button(self.FshowTablesButtons, text="Show Affliction Data",
                                             command=self.showAfflictTable, width=19)
        self.showAfflictTableButton.grid(row="0", column="1", sticky="S")

        self.tableButtonOnMenu.configure(command=self.showOrHideAllTables)

        if debug or (isDec and isSub and isBin):
            self.loadAfllictTable()
            # self.loadConsoleTable()
            # self.consoleTableDec.configure(state="disabled")

    def printTest(self):
        print("This Works in Between")

    def cancelPerformTest(self):
        global testCancelled
        global runningTest
        self.processButton.configure(text="Perform Test")
        # self.showOrHideAllTables()
        print("set to false and true")
        runningTest = False
        testCancelled = True

    def allStatusFalse(self):
        global isDec
        global isSub
        global isBin
        self.subVidButton.configure(state="disabled")
        self.binVidButton.configure(state="disabled")

        isDec = False
        self.labelD = Label(self.FMenu, text="Decompiled: ")
        self.labelD.grid(row=1, column=0, sticky="NW")
        self.labelDstatus = Label(self.FMenu, text=" False   ", fg="red", width=6)
        self.labelDstatus.grid(row=1, column=1, sticky="NW")
        # self.labelDStatus.configure(text="False", fg="red")
        self.update_idletasks()
        self.update()

        isSub = False
        self.labelS = Label(self.FMenu, text="Subtracted:  ")
        self.labelS.grid(row=2, column=0, sticky="NW")
        self.labelSstatus = Label(self.FMenu, text=" False   ", fg="red", width=6)
        self.labelSstatus.grid(row=2, column=1, sticky="NW")
        # self.labelSstatus.configure(text="False", fg="red")
        self.update_idletasks()
        self.update()

        isBin = False
        self.labelB = Label(self.FMenu, text="Binarized:  ")
        self.labelB.grid(row=3, column=0, sticky="NW")
        self.labelBstatus = Label(self.FMenu, text=" False   ", fg="red", width=6)
        self.labelBstatus.grid(row=3, column=1, sticky="NW")
        # self.labelBstatus.configure(text="False", fg="red")
        self.update_idletasks()
        self.update()

    def loadAfllictTable(self):
        global showingTables
        afflicDataTableModel = TableModel()
        if debug:
            afflicDataTableModel.importCSV("D:\\TAMS Stuff\\TAMS Research\\Dr. Chyan Lab\\TAMS Summer Research 2020\\MEDA\\FPS Testing\\Sample 1 TI Device\\S1 Reg B\\Results\\15FPM\\0.25FPS AfflictData.csv", sep=",")
        else:
            print(directory + "/" + str(fps) + "FPS AfflictData.csv")
            afflicDataTableModel.importCSV(directory + "/" + str(fps) + "FPS AfflictData.csv")
        self.afflictTable = TableCanvas(self.FAfflictTable, model=afflicDataTableModel, rowheaderwidth=0, read_only=True, cols=3, height=865, width=384)
        self.afflictTable.cellwidth=121
        self.afflictTable.maxcellwidth=121
        self.afflictTable.grid(column=0, row=0, sticky="NSW")
        self.afflictTable.show()
        self.afflictTable.resizeColumn(0, 82)
        self.afflictTable.resizeColumn(1, 123)
        self.afflictTable.resizeColumn(2, 178)
        self.showAfflictTable()

    def loadConsoleTable(self):
        global decText
        global subText
        global binText
        global vidFramesCount
        global fps
        global video

        if not (isDec or isSub or isBin):
            self.programLoadingBar = ttk.Progressbar(self.FConsoleTable, orient="horizontal", length=415, mode="determinate")
            if not debug:
                vidFramesCount = fps * mp.VideoFileClip(video).duration
                vidFramesCount = int(vidFramesCount)
                print(vidFramesCount)
                self.programLoadingBar['maximum'] = vidFramesCount * 3 - 2
            self.programLoadingBar.grid(column=0, row=0, pady=10, sticky="W")


        self.consoleTableDecLabel = tk.Label(self.FConsoleTable, text="Decompilation Console Data")
        self.consoleTableDecLabel.grid(column=0, row=1, sticky="W")
        self.consoleTableDec = scrolledtext.ScrolledText(self.FConsoleTable, width=50, height=15, wrap=WORD)
        self.consoleTableDec.grid(column=0, row=2, pady=10)
        for i in range(len(decText)):
            self.consoleTableDec.insert(tk.INSERT, decText[i])

        self.consoleTableSubLabel = tk.Label(self.FConsoleTable, text="Subtraction Console Data")
        self.consoleTableSubLabel.grid(column=0, row=3, sticky="W")
        self.consoleTableSub = scrolledtext.ScrolledText(self.FConsoleTable, width=50, height=15, wrap=WORD)
        self.consoleTableSub.grid(column=0, row=4, pady=10)
        for i in range(len(subText)):
            self.consoleTableSub.insert(tk.INSERT, subText[i])

        self.consoleTableBinLabel = tk.Label(self.FConsoleTable, text="Binarization Console Data")
        self.consoleTableBinLabel.grid(column=0, row=5, sticky="W")
        self.consoleTableBin = scrolledtext.ScrolledText(self.FConsoleTable, width=50, height=15, wrap=WORD)
        self.consoleTableBin.grid(column=0, row=6, pady=10)
        for i in range(len(binText)):
            self.consoleTableBin.insert(tk.INSERT, binText[i])

        self.showConsoleTable()


    def showConsoleTable(self):
        try:
            self.FAfflictTable.grid_remove()
            if (isDec and isSub and isBin):
                self.showAfflictTableButton.configure(state="normal")
            else:
                self.showAfflictTableButton.configure(state="disabled")
        except:
            "hello"

        self.FConsoleTable.grid(row=1, column=0)
        self.consoleTableDec.configure(state="disabled")
        self.consoleTableSub.configure(state="disabled")
        self.consoleTableBin.configure(state="disabled")
        # self.consoleTableSub.insert(tk.INSERT, "This works")
        # self.consoleTableSub.configure(state="normal")
        # self.consoleTableSub.insert(tk.INSERT, "This works though")
        # self.consoleTableSub.configure(state="disabled")


        self.showConsoleDataTableButton.configure(state="disabled")



    def showAfflictTable(self):
        try:
            self.FConsoleTable.grid_remove()
        except:
            "hello"
        self.FAfflictTable.grid(row=1, column=0)
        self.showAfflictTableButton.configure(state="disabled")
        self.showConsoleDataTableButton.configure(state="normal")

    def showOrHideGraph(self):
        global showingGraph
        if showingGraph:
            self.FGraph.grid_remove()
            self.graphButton.configure(text="Show Graph")
            showingGraph = False
        else:
            self.FGraph.grid(row=0, column=1, sticky="EW")
            self.LFMeda.grid_columnconfigure(1, weight=5, minsize=480)
            self.LFMeda.grid_rowconfigure(0, weight=1, minsize=320)
            self.graphButton.configure(text="Hide Graph")
            showingGraph = True

    def showOrHideAllTables(self):
        global showingTables
        if showingTables:
            if debug:
                print("Got here")
            self.FTables.grid_remove()
            self.tableButtonOnMenu.configure(text="Show Tables")
            showingTables = False
        else:
            if debug:
                print("Got here2")
            self.FTables.grid(row=0, column=0, sticky="NS", rowspan=2)
            # self.LFMeda.grid_columnconfigure(0, weight=1)
            self.tableButtonOnMenu.configure(text="Hide Tables")
            showingTables = True

    def buildUp(self, bounding, pathing, directory):
        ##    initFrame = input("Intial frame of dendrite formation?")#getting initial frame from user input
        # img_array = []  # array to stoer image files
        ##    iFrame = int(initFrame)#casting input of user to an int
        bound = len(bounding) - 1  # returns length of the bounding
        iFrame = 0
        text = ""
        saveText = ""
        if "SubtractedFrames" in pathing:
            # print("Going here")
            text = "/isframe"
            saveText = "FPS SubtractedFramesVideo.mp4"
            bound += 1
        else:
            text = "/binarizedim"
            saveText = "FPS BinarizedFramesVideo.mp4"
        img = cv2.imread(pathing + text + str(iFrame) + ".jpg")
        # height, width, layers = img.shape
        height = img.shape[0]
        width = img.shape[1]
        size = (width, height)
        out = cv2.VideoWriter(directory + "/" + str(fps) + saveText, cv2.VideoWriter_fourcc(*'MP4V'), fps, size)  # need to change##############################
        for i in range(iFrame+1, bound):  # for all the frames
            img = cv2.imread(pathing + text + str(i) + ".jpg")
            out.write(img)
        out.release()

    def createSubVideo(self):
        print(path2 + "/*.jpg")
        bound = glob.glob(path2 + "/*.jpg")  # creating an array of all the new frames' names
        self.buildUp(bound, path2, directory)  # building up a new video using the frames' names array and file path

    def createBinVideo(self):
        print(path3 + "/*.jpg")
        bound = glob.glob(path3 + "/*.jpg")  # creating an array of all the new frames' names
        self.buildUp(bound, path3, directory)  # building up a new video using the frames' names array and file path

    def breakDown(self, video, pathing, sec, num):  # function to check if video file still has frames
        global decText
        video.set(cv2.CAP_PROP_POS_MSEC, sec * 1000)  # set the video to the position in milliseconds (sec*1000)
        hasFrames, image = video.read()  # set hasFrames and image to get if video has frames, and then reading in image
        if hasFrames:  # if the video has a frame, then write it to a file named "frame#" where # is the frame number
            cv2.imwrite(pathing + "/frame%d.jpg" % num, image)
            decText.append('Read frame ' + str(num+1) + ': ' + str(hasFrames) + "\n")  # printing if frame has been read
            self.consoleTableDec.configure(state="normal")
            self.consoleTableDec.insert(tk.INSERT, decText[num])
            self.consoleTableDec.see(tk.END)
            self.consoleTableDec.configure(state="disabled")
            self.programLoadingBar['value'] += 1
            self.programLoadingBar.update()
            self.update_idletasks()
            self.update()
        return hasFrames  # return if there is actually a frame

    def decomp(self, video, pathing, framerate):  # function called to break a video down into individual frames to count them up
        global fps
        global testCancelled
        fps = framerate
        count = 0  # frame counting variable
        # userInp = input("Full video file path: ")  # Getting file name and path for video to be analyzed
        # print("Video from decomp function: " + str(video))
        if video == "cancel":  # leaving program if userinput is to cancel
            return -1
        vidFile = cv2.VideoCapture(video)  # reading in video file
        sec = 0  # time elapsed
        # fps = 1  # 10 frame -> 1 sec, means 1 frame -> 0.1 sec#####################################
        frameRate = 1.0 / fps
        success = self.breakDown(vidFile, pathing, sec, count)  # getting success bool from breakdown function (for first frame)
        while success:  # looping while video has more frames to break down into
            if testCancelled:
                return -1
            count += 1  # incrementing frame count
            sec = sec + frameRate  # incrementing seconds counter by frameRate
            sec = round(sec, 2)  # rounds the seconds to the nearest 2nd decimal (why do we need this?)
            success = self.breakDown(vidFile, pathing, sec, count)  # calling breakDown function again (for next frame)
        return count - 1  # returning total frames in video

    def changeLineOnGraph(self, xpos):
        self.currentLocationLine.set_data([xpos, xpos], [min(self.data2y), max(self.data2y)])
        self.canvas.draw()
        self.update_idletasks()
        self.update()

    def on_click(self, event):
        if event.inaxes is not None and event.xdata >= 0 and event.xdata <= max(self.data2x):
            self.changeLineOnGraph(event.xdata)
            # plt.axvline(x=event.xdata, color='green')
            # print(plt.vlines)
            # print(plt.axes)
            # print(event.xdata, event.ydata)
        # else:
        #     # print('Clicked ouside axes bounds but inside plot window')

    def loadGraph(self):
        "hello"

    def plotTest(self, directory, currentfile, bounding, subpathing, binpathing, framerate):
        global fps
        global threshold
        global binText
        fps = framerate
        x = []
        y = []
        afflictFile = open(directory + "/" + str(fps) + "FPS AfflictData.csv", "w+")
        afflictFile.write("Time(M),%Change, Af-Area(mm^2)\n")
        imi = str(subpathing) + "/isframe0.jpg"
        imiread = cv2.imread(imi)
        imireadGrayscale = cv2.cvtColor(imiread, cv2.COLOR_BGR2GRAY)
        retval, binarizedimi = cv2.threshold(imireadGrayscale, 75, 255, cv2.THRESH_BINARY)  # +cv2.THRESH_OTSU)
        cv2.imwrite(str(binpathing) + "/binarizedimi0.jpg", binarizedimi)
        binarizedimipath = str(binpathing) + "/binarizedimi0.jpg"
        w = 0
        for i in range(bounding):
            if testCancelled:
                return -1
            im = str(subpathing) + "/isframe" + str(i) + ".jpg"
            # print("Frame difference with initial " + str(i + 1))
            imread = cv2.imread(im)
            imreadGrayscale = cv2.cvtColor(imread, cv2.COLOR_BGR2GRAY)
            retval, binarizedim = cv2.threshold(imreadGrayscale, 75, 255, cv2.THRESH_BINARY)  # +cv2.THRESH_OTSU)
            cv2.imwrite(str(binpathing) + "/binarizedim" + str(i) + ".jpg", binarizedim)
            binarizedimpath = str(binpathing) + "/binarizedim" + str(i) + ".jpg"
            percent = imgcmp.image_diff_percent(binarizedimpath, binarizedimipath)
            # print("Percent of afflicted pixels in subtract: " + str(percent))
            x.append((i / (fps)) / 60)  # points on xaxis##########################################
            afflictFile.write(str((i / (fps)) / 60) + ",")  #########################################
            if percent >= threshold:
                y.append(percent)
                afflictFile.write(str(percent) + "," + str(percent / 100.0 * 0.485) + "\n")
                binText.append("%Affliction between Initial and Frame " + str(i + 1) + ":\n  - " + str(percent) + " - Appended Percent\n\n")  # printing if frame has been read
                self.consoleTableBin.configure(state="normal")
                self.consoleTableBin.insert(tk.INSERT, binText[i])
                self.consoleTableBin.see(tk.END)
                self.consoleTableBin.configure(state="disabled")
                self.programLoadingBar['value'] += 1
                self.programLoadingBar.update()
                self.update_idletasks()
                self.update()
                # print("Appended percent.")
                if w == 0:
                    w = percent
                x[i] -= w
            else:
                y.append(0)
                afflictFile.write("0,0\n")
                binText.append("%Affliction between Initial and Frame " + str(i + 1) + ":\n  - " + str(percent) + " - Appended Zero\n\n")
                self.consoleTableBin.configure(state="normal")
                self.consoleTableBin.insert(tk.INSERT, binText[i])
                self.consoleTableBin.see(tk.END)
                self.consoleTableBin.configure(state="disabled")
                self.update_idletasks()
                self.update()
        afflictFile.close()
        #    plt.plot(x, y)
        #    plt.xlabel('Time (secs)')#.1,.2,.3,etc.
        #    plt.ylabel('% area covered')
        #    plt.axis([0, bounding/10, 0, 0.5])
        #    plt.show()

        current = currentfile

        self.data1x = x
        self.data1y = y

        # root = tkinter.Tk()
        # root.wm_title("Embedding in Tk")

        # This is oneeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
        # self.fig = Figure(figsize=(7, 6), dpi=100)
        # self.fig.add_subplot(111).plot(data1x, data1y)
        # axes = self.fig.get_axes()
        # ax1 = axes[0]

        self.fig, ax1 = plt.subplots()
        ax1.set_title("% Area Change vs Current vs Time", fontweight='bold')

        green = 'tab:green'
        ax1.set_xlabel('Time (Min)', fontweight='bold', labelpad=10)
        ax1.set_ylabel('% Area Covered', color=green, fontweight='bold', labelpad=10)
        ax1.plot(self.data1x, self.data1y, color=green)
        ax1.tick_params(axis='y', labelcolor=green, color=green)
        for tick in ax1.xaxis.get_major_ticks():
            tick.label1.set_fontweight('bold')
        for tick in ax1.yaxis.get_major_ticks():
            tick.label1.set_fontweight('bold')

        ax2 = ax1.twinx()

        self.data2x = []
        self.data2y = []
        with open(current) as f:
            reader = csv.reader(f, delimiter=',', quotechar='"')
            for row in reader:
                try:
                    self.data2x.append(float(row[0]))
                except:
                    pass
                try:
                    self.data2y.append(float(row[1]) * 1000000)
                except:
                    pass

        blue = 'tab:blue'
        ax2.set_ylabel('Current (μA)', color=blue, fontweight='bold',
                       labelpad=10)  # we already handled the x-label with ax1
        ax2.plot(self.data2x, self.data2y, color=blue)
        ax2.tick_params(axis='y', labelcolor=blue, color=blue)
        for tick in ax2.yaxis.get_major_ticks():
            tick.label2.set_fontweight('bold')
        for tick in ax2.xaxis.get_major_ticks():
            tick.label2.set_fontweight('bold')
        # ax2.set_aspect(1.5)
        self.fig.set_dpi(150)
        self.fig.tight_layout()
        tend1 = time.time()
        # plt.show()
        plt.savefig(directory + "/" + str(fps) + " Graph.jpg")
        # plt.grid()
        # plt.gcf().canvas.draw()
        # self.fig = plt.figure()
        # plt.axvline(x=20)
        self.canvas = FigureCanvasTkAgg(self.fig, master=self.FGraph)  # A tk.DrawingArea.
        self.canvas.draw()
        self.canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)

        # self.fig.canvas.callbacks.connect('button_press_event', self.on_click)
        self.fig.canvas.callbacks.connect('button_release_event', self.on_click)
        # self.fig.canvas.callbacks.connect('motion_notify_event', self.on_click)



        self.currentLocationLine, v = plt.plot(0, 0, min(self.data2y), max(self.data2y), color='red', linewidth=2)

        toolbar = NavigationToolbar2Tk(self.canvas, self.FGraph)
        toolbar.update()
        self.canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)
        if showingGraph:
            self.showOrHideGraph()
            self.showOrHideGraph()
        else:
            self.showOrHideGraph()
        return tend1

    def initmult(self, bounder, pathing1,
                 pathing2):  # subtracts initial image from each frame and makes that many subtracted ones, makes bound and returns the value
        global subText
        global testCancelled
        count = 0
        for i in range(bounder):
            if testCancelled:
                return -1
            im1 = cv2.imread(pathing1 + "/frame0.jpg")  # image 1
            im2 = cv2.imread(pathing1 + "/frame" + str(i) + ".jpg")  # image 2
            polaroid = cv2.subtract(im1, im2)  # subtracting each image
            cv2.imwrite(pathing2 + "/isframe%d.jpg" % count, polaroid)  # writing to new
            count += 1
            subText.append("Initial frame and frame " + str(i+1) + " subtracted.\n")
            self.consoleTableSub.configure(state="normal")
            self.consoleTableSub.insert(tk.INSERT, subText[i])
            self.consoleTableSub.see(tk.END)
            self.consoleTableSub.configure(state="disabled")
            self.programLoadingBar['value'] += 1
            self.programLoadingBar.update()
            self.update_idletasks()
            self.update()
        return count  # returns how many of the newly subtracted images there are (isframe, not sframe, each are different)

    def percentChange(self):
        global isDec
        global isSub
        global isBin
        global path
        global path2
        global path3
        global video
        global current
        global directory
        global fps
        global threshold
        global decText
        global subText
        global binText
        global testCancelled
        global runningTest

        if runningTest:
            self.cancelPerformTest()
            return

        runningTest = True
        self.processButton.configure(text="Cancel Test")
        self.tableButtonOnMenu.configure(state="disabled")
        self.graphButton.configure(state="disabled")
        decText = []
        subText = []
        binText = []
        fps = float(self.fpsEntry.get())
        threshold = float(self.thresholdEntry.get())
        self.allStatusFalse()
        self.loadConsoleTable()

        if testCancelled:
            runningTest = False
            testCancelled = False
            return

        if showingGraph:
            self.showOrHideGraph()
            self.FGraph.destroy()
            self.FGraph = ttk.Frame(self.LFMeda)
        if showingTables:
            self.showOrHideAllTables()
            self.showOrHideAllTables()
        else:
            self.showOrHideAllTables()
        try:  # removing directory 1 - clearing it of all past data
            sh.rmtree(path)
        except OSError:
            print("No tmp folder found. Will create now.\n")
        # else:
        #     print("Removed tmp folder previously.\n")
        try:  # removing directory 2 - clearing it of all past frames
            sh.rmtree(path2)
        except OSError:
            print("No stmp folder found. Will create now.\n")
        # else:
        #     print("Removed stmp folder previously.\n")
        try:  # removing directory 2 - clearing it of all past frames
            sh.rmtree(path3)
        except OSError:
            print("No btmp folder found. Will create now.\n")
        # else:
        #     print("Removed btmp folder previously.\n")
        try:  # making new directory 1, checking to make sure it doesn't already exist
            os.mkdir(path)
        except OSError:
            print("Directory exists\n")
            return 1
        # else:
        #     print("Temp made\n")
        try:  # making new directory 2, checking to make sure it doesnt already exist
            os.mkdir(path2)
        except OSError:
            # print("Directory exists\n")
            return 1
        # else:
        #     print("Stemp made\n")
        try:  # making new directory 2, checking to make sure it doesnt already exist
            os.mkdir(path3)
        except OSError:
            print("Directory exists\n")
            return 1
        # else:
        #     print("Btemp made\n")
        self.consoleTableDecLabel.configure(fg='green')
        if testCancelled:
            runningTest = False
            testCancelled = False
            return
        bound = self.decomp(video, path, fps)  # decompiling video and getting the bound from it
        if testCancelled:
            runningTest = False
            testCancelled = False
            return
        self.consoleTableDecLabel.configure(fg='black')
        if bound > 0:
            isDec = True
            # labelD = Label(self.FMenu, text="Decompiled: ")
            # labelD.grid(row=0, column=0)
            labelDstatus = Label(self.FMenu, text=" Success", fg="green", width=6)
            labelDstatus.grid(row=1, column=1)
            self.update_idletasks()
            self.update()
        self.consoleTableSubLabel.configure(fg='green')
        if testCancelled:
            runningTest = False
            testCancelled = False
            return
        bounding = self.initmult(bound, path, path2)
        if testCancelled:
            runningTest = False
            testCancelled = False
            return
        self.consoleTableSubLabel.configure(fg='black')
        # labelS = Label(self.FMenu, text="Subtracted:  ")
        # labelS.grid(row=1, column=0)
        isSub = True
        labelSstatus = Label(self.FMenu, text=" Success", fg="green", width=6)
        labelSstatus.grid(row=2, column=1)
        self.update_idletasks()
        self.update()
        self.consoleTableBinLabel.configure(fg='green')
        if testCancelled:
            runningTest = False
            testCancelled = False
            return
        tend1 = self.plotTest(directory, current, bounding, path2, path3, fps)
        if testCancelled:
            runningTest = False
            testCancelled = False
            return
        self.consoleTableBinLabel.configure(fg='black')
        # labelB = Label(self.FMenu, text="Binarized:  ")
        # labelB.grid(row=2, column=0)
        isBin = True
        labelBstatus = Label(self.FMenu, text=" Success", fg="green", width=6)
        labelBstatus.grid(row=3, column=1)
        self.update_idletasks()
        self.update()

        self.graphButton.configure(state="normal")
        self.tableButtonOnMenu.configure(state="normal")
        self.subVidButton.configure(state="normal")
        self.binVidButton.configure(state="normal")
        self.processButton.configure(text="Perform Test")
        if testCancelled:
            runningTest = False
            testCancelled = False
            return
        runningTest = False
        testCancelled = False
        self.loadAfllictTable()
        # self.showOrHideAllTables()

    def goBack(self):
        global goingBack
        global startingPage
        if messagebox.askokcancel("Exit Project", "Are you sure you want to exit the project? If you exit, you have to start a new project to continue experimentation."):
            goingBack = True
            startingPage = StartingPage()
            startingPage.mainloop()
        else:
            return