def DataGrid(xValues, yValues):
    ## setup window
    dataGrid = Tk()
    dataGrid.wm_title("Data")

    ## setup frame
    frame = Frame(dataGrid)
    frame.pack()

    label = Label(dataGrid, text=("Showing %.0f data points" % len(xValues)), font=("Verdana", 12))
    label.pack(pady=5, padx=10)

    dataDict = {}

    ## iterate through time
    for i in range(0, len(xValues)):
        xVal = "%.2f" % float(xValues[i])
        yVal = "%.2f" % float(yValues[i])
        dataDict[xVal] = {"Time (s)": xVal, "Height (m)": yVal}

    model = TableModel()
    model.importDict(dataDict)
    model.moveColumn(model.getColumnIndex("Time (s)"), 0)

    table = TableCanvas(frame, model=model, editable=False)
    table.createTableFrame()

    ## order by time
    table.sortTable(columnName="Time (s)")

    dataGrid.mainloop()
Esempio n. 2
0
def DataGrid(xValues, yValues):
    ## setup window
    dataGrid = Tk()
    dataGrid.wm_title("Data")

    ## setup frame
    frame = Frame(dataGrid)
    frame.pack()

    label = Label(dataGrid,
                  text=("Showing %.0f data points" % len(xValues)),
                  font=("Verdana", 12))
    label.pack(pady=5, padx=10)

    dataDict = {}

    ## iterate through time
    for i in range(0, len(xValues)):
        xVal = ("%.2f" % float(xValues[i]))
        yVal = ("%.2f" % float(yValues[i]))
        dataDict[xVal] = {"Time (s)": xVal, "Height (m)": yVal}

    model = TableModel()
    model.importDict(dataDict)
    model.moveColumn(model.getColumnIndex('Time (s)'), 0)

    table = TableCanvas(frame, model=model, editable=False)
    table.createTableFrame()

    ## order by time
    table.sortTable(columnName='Time (s)')

    dataGrid.mainloop()
Esempio n. 3
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()