Skip to content

Commit

Permalink
gui: estimate the fictrac framerate and show in the GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
nzjrs committed Feb 15, 2021
1 parent 403ccde commit bf4718a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions flyvr/gui.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import time

from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QPushButton, QGridLayout
from PyQt5.QtCore import QTimer

Expand All @@ -21,8 +23,13 @@ def __init__(self, app, quit_app_on_stop):

self._entries = {}

self._tick = 0
self._fn0 = self._t0 = 0

self._lbl_backends = None
self._lbl_started = None
self._lbl_fps = None

self._init_ui()

self.flyvr_shared_state = SharedState(options=None,
Expand All @@ -42,6 +49,16 @@ def _update_state(self):
self._lbl_backends.setText(', '.join(self.flyvr_shared_state.backends_ready))
self._lbl_started.setText(str(self.flyvr_shared_state.is_started()))

# every second-ish
if (self._tick % self.FPS) == 0:
fictrac_fps = (self.flyvr_shared_state.FICTRAC_FRAME_NUM - self._fn0) / (time.time() - self._t0)
self._lbl_fps.setText('%.1f' % fictrac_fps)

self._fn0 = self.flyvr_shared_state.FICTRAC_FRAME_NUM
self._t0 = time.time()

self._tick += 1

if self._quit_app_on_stop:
if self.flyvr_shared_state.is_stopped():
self._app.quit()
Expand Down Expand Up @@ -79,6 +96,9 @@ def _build_label(_name, _row):
self._entries[s] = _build_label(s, row)
row += 1

self._lbl_fps = _build_label('FicTrac Framerate', row)
row += 1

self._lbl_backends = _build_label('Backends Ready', row)
row += 1

Expand Down

0 comments on commit bf4718a

Please sign in to comment.