Initial commit
This commit is contained in:
commit
6ced48c47b
|
@ -0,0 +1 @@
|
|||
virtenv
|
|
@ -0,0 +1,72 @@
|
|||
import PySimpleGUI as sg
|
||||
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, FigureCanvasAgg
|
||||
from matplotlib.figure import Figure
|
||||
from matplotlib import pyplot as plt
|
||||
from datetime import datetime, timedelta
|
||||
from random import randint
|
||||
|
||||
|
||||
STATS_FONT = 'SourceCodePro 60'
|
||||
PLOT_W=1400
|
||||
PLOT_H=1000
|
||||
DPI=150
|
||||
|
||||
def draw_figure(canvas, figure, loc=(0, 0)):
|
||||
figure_canvas_agg = FigureCanvasTkAgg(figure, canvas)
|
||||
figure_canvas_agg.draw()
|
||||
figure_canvas_agg.get_tk_widget().pack(side='top', fill='both', expand=1)
|
||||
return figure_canvas_agg
|
||||
|
||||
|
||||
def main():
|
||||
sg.theme('Dark Gray 10') # Add a touch of color
|
||||
# All the stuff inside your window.
|
||||
|
||||
layout = [[
|
||||
sg.Column([
|
||||
[sg.Text('00:00:00', font=STATS_FONT)],
|
||||
[sg.Text('0 km', font=STATS_FONT)],
|
||||
[sg.Text('0 km/h', font=STATS_FONT)],
|
||||
[sg.Text('0 W', font=STATS_FONT)],
|
||||
[sg.Text('0 RPM', font=STATS_FONT)],
|
||||
[sg.Button('Start'), sg.Button('Stop')],
|
||||
]),
|
||||
sg.Canvas(size=(PLOT_W, PLOT_H), key='-CANVAS-'),
|
||||
]]
|
||||
|
||||
# Create the Window
|
||||
window = sg.Window('Misuro Logger', layout, finalize=True)
|
||||
|
||||
canvas_elem = window['-CANVAS-']
|
||||
canvas = canvas_elem.TKCanvas
|
||||
|
||||
plt.style.use('dark_background')
|
||||
fig = Figure(figsize=(PLOT_W/DPI,PLOT_H/DPI), dpi=DPI)
|
||||
ax = fig.add_subplot(111)
|
||||
ax.set_xlabel("X axis")
|
||||
ax.set_ylabel("Y axis")
|
||||
ax.grid()
|
||||
fig_agg = draw_figure(canvas, fig)
|
||||
|
||||
last_ts = datetime.now()
|
||||
data = []
|
||||
|
||||
# Event Loop to process "events" and get the "values" of the inputs
|
||||
while True:
|
||||
if datetime.now() - last_ts > timedelta(seconds = 1):
|
||||
data += [randint(0,400)]
|
||||
last_ts = datetime.now()
|
||||
ax.cla()
|
||||
ax.grid()
|
||||
ax.plot(data)
|
||||
fig_agg.draw()
|
||||
|
||||
event, values = window.read(timeout=100)
|
||||
if event == sg.WIN_CLOSED or event == 'Stop': # if user closes window or clicks cancel
|
||||
break
|
||||
|
||||
window.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in New Issue