示例#1
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()