Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to reload mesh/scene and return file open shortcut #35

Merged
merged 2 commits into from
Apr 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions ogre_mesh_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def __init__(self, app):
self.show_metrics = False
self.show_render_settings = False
self.side_panel_visible = True
self.is_filedialog_open = False

self.app = app

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

def load_file(self):
# Avoid recursive calling, which might block the window manager
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how could we arrive here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The recursive calling?

I put that there (the lock) because you said that you managed to both the entire window manager by opening the file dialog twice if I remember correctly.

if self.is_filedialog_open:
return
self.is_filedialog_open = True
app.infile = askopenfilename(app.filedir)
self.is_filedialog_open = False
app.reload()

def preRenderTargetUpdate(self, evt):
if not self.app.cam.getViewport().getOverlaysEnabled():
return
Expand All @@ -215,11 +225,10 @@ def preRenderTargetUpdate(self, evt):
if ImGui.BeginMainMenuBar():

if ImGui.BeginMenu("File"):
if ImGui.MenuItem("Open File"):
app.infile = askopenfilename(app.filedir)
if app.infile:
app.restart = True
app.getRoot().queueEndRendering()
if ImGui.MenuItem("Open File", "F1"):
self.load_file()
if ImGui.MenuItem("Reload File", "F5"):
app.reload()
if ImGui.MenuItem("Save Screenshot", "P"):
self.app._save_screenshot()
ImGui.Separator()
Expand Down Expand Up @@ -456,6 +465,10 @@ def keyPressed(self, evt):
self._save_screenshot()
elif evt.keysym.sym == ord("w"):
self._toggle_wireframe_mode()
elif evt.keysym.sym == OgreBites.SDLK_F1:
self.gui.load_file()
elif evt.keysym.sym == OgreBites.SDLK_F5:
self.reload()

return True

Expand Down Expand Up @@ -511,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