Skip to content

Commit

Permalink
Apply suggestions by @paroj
Browse files Browse the repository at this point in the history
  • Loading branch information
sercero committed Apr 17, 2024
1 parent 8bea37e commit 234e5ef
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions ogre_mesh_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def __init__(self, app):
self.show_metrics = False
self.show_render_settings = False
self.side_panel_visible = True
self.load_file_lock = False
self.is_filedialog_open = False

self.app = app

Expand Down Expand Up @@ -201,20 +201,14 @@ def draw_loading(self):
ImGui.Text("Loading.. ")
ImGui.End()

def reload(self):
if app.infile:
app.restart = True
app.getRoot().queueEndRendering()

def load_file(self):
# Avoid recursive calling, which might block the window manager
if self.load_file_lock:
if self.is_filedialog_open:
return
else:
self.load_file_lock = True
self.is_filedialog_open = True
app.infile = askopenfilename(app.filedir)
self.load_file_lock = False
self.reload()
self.is_filedialog_open = False
app.reload()

def preRenderTargetUpdate(self, evt):
if not self.app.cam.getViewport().getOverlaysEnabled():
Expand All @@ -233,8 +227,8 @@ def preRenderTargetUpdate(self, evt):
if ImGui.BeginMenu("File"):
if ImGui.MenuItem("Open File", "F1"):
self.load_file()
if ImGui.MenuItem("ReLoad File", "F5"):
self.reload()
if ImGui.MenuItem("Reload File", "F5"):
app.reload()
if ImGui.MenuItem("Save Screenshot", "P"):
self.app._save_screenshot()
ImGui.Separator()
Expand Down Expand Up @@ -474,7 +468,7 @@ def keyPressed(self, evt):
elif evt.keysym.sym == OgreBites.SDLK_F1:
self.gui.load_file()
elif evt.keysym.sym == OgreBites.SDLK_F5:
self.gui.reload()
self.reload()

return True

Expand Down Expand Up @@ -530,6 +524,11 @@ def _save_screenshot(self):
self.getRenderWindow().writeContentsToTimestampedFile(outpath, ".png")
self.cam.getViewport().setOverlaysEnabled(True)

def reload(self):
if app.infile:
app.restart = True
app.getRoot().queueEndRendering()

def locateResources(self):
self.filename = os.path.basename(self.infile)
self.filedir = os.path.dirname(self.infile)
Expand Down

0 comments on commit 234e5ef

Please sign in to comment.