Skip to content

Commit

Permalink
Inside view: adding box (to Quality tab) for showing fps label. Hidin…
Browse files Browse the repository at this point in the history
…g fps label by default. This "fixes" the issue that the inside view briefly freezes when we update the fps label.
  • Loading branch information
unhyperbolic committed Nov 20, 2024
1 parent 35282b1 commit 5cadc3d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
16 changes: 14 additions & 2 deletions python/raytracing/gui_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,17 @@ def __init__(self, label):
self.num_iterations = 0
self.total_time = 0.0
self.last_time = time.time()
self._visible = False
self._text = '-fps (-ms)'

def set_visible(self, visible):
if self._visible == visible:
return
self._visible = visible
if visible:
self.label.configure(text = self._text)
else:
self.label.configure(text = '')

def __call__(self, t):
self.num_iterations += 1
Expand All @@ -206,8 +217,9 @@ def __call__(self, t):
current_time = time.time()
fps = self.num_iterations / (current_time - self.last_time)
time_ms = 1000 * self.total_time / self.num_iterations

self.label.configure(text='%.1ffps (%dms)' % (fps, time_ms))
self._text = '%.1ffps (%dms)' % (fps, time_ms)
if self._visible:
self.label.configure(text=self._text)
self.last_time = current_time
self.num_iterations = 0
self.total_time = 0.0
Expand Down
20 changes: 19 additions & 1 deletion python/raytracing/inside_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ def __init__(self, container, manifold,
self.view_scale_value_label,
update_function=self.widget.draw)

self.widget.report_time_callback = FpsLabelUpdater(
self.widget.fps_label_updater = FpsLabelUpdater(
self.fps_label)
self.widget.report_time_callback = self.widget.fps_label_updater

self.update_volume_label()

Expand Down Expand Up @@ -543,6 +544,19 @@ def create_quality_frame(self, parent):
left_end=1.0,
right_end=4.25,
update_function=self.widget.draw)
row += 1

misc_frame = ttk.Frame(frame)
misc_frame.grid(row=row, column=1, columnspan=3)

self.fps_box_var = tkinter.BooleanVar()
self.fps_box_var.set(False)
fps_box = ttk.Checkbutton(misc_frame, takefocus=0)
fps_box.grid(row=0, column=0)
fps_box.configure(
variable = self.fps_box_var,
text='Show fps',
command=self.show_fps)

return frame

Expand Down Expand Up @@ -830,6 +844,10 @@ def pick_cohomology_class(self, i):
def build_menus(self):
pass

def show_fps(self):
self.widget.fps_label_updater.set_visible(
self.fps_box_var.get())

def test(self):
X = 100
self.widget.event_generate('<Button-1>', x=X, y=300, warp=True)
Expand Down

0 comments on commit 5cadc3d

Please sign in to comment.