Skip to content

Commit

Permalink
mavpicviewer: event handlers use wx.CallAfter
Browse files Browse the repository at this point in the history
  • Loading branch information
rmackay9 committed Oct 9, 2024
1 parent 208b19a commit 10a3169
Showing 1 changed file with 40 additions and 32 deletions.
72 changes: 40 additions & 32 deletions MAVProxy/tools/mavpicviewer/mavpicviewer_mosaic.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ def __init__(self, folderpath, comm_pipe=None):
self.menu.Append(1, "Open Folder", "Open a Folder of images")
self.frame.Bind(wx.EVT_MENU, self.menu_open_folder, id=1)
self.menu.Append(2, "Show All", "Show all images")
self.frame.Bind(wx.EVT_MENU, self.display_all_images, id=2)
self.frame.Bind(wx.EVT_MENU, self.menu_display_all_images, id=2)
self.menu.Append(3, "Show POI", "Show images with POI")
self.frame.Bind(wx.EVT_MENU, self.display_poi_images, id=3)
self.frame.Bind(wx.EVT_MENU, self.menu_display_poi_images, id=3)
self.menu.Append(4, "Settings", "Settings")
self.frame.Bind(wx.EVT_MENU, self.mavpicviewer_settings.show_settings_window, id=4)
self.menu.Append(5, "Quit", "Quit")
Expand Down Expand Up @@ -154,6 +154,37 @@ def update_panel_dict(self):
# add panel to dictionary
self.panel_dict[i] = panel

# process menu events
def menu_open_folder(self, event):
"""process menu events"""
dlg = wx.DirDialog(self.frame, "Choose a directory:", style=wx.DD_DEFAULT_STYLE)
folder_path = None
if dlg.ShowModal() == wx.ID_OK:
folder_path = dlg.GetPath()
dlg.Destroy()
if folder_path is not None:
wx.CallAfter(self.open_folder, folder_path)

# menuy event handler for display all images
def menu_display_all_images(self, event):
"""menu event handler for display all images"""
wx.CallAfter(self.display_all_images)

# display POI images only
def menu_display_poi_images(self, event):
"""display POI images only"""
wx.CallAfter(self.display_all_images, poi_only=True)

# process menu quit event
def menu_quit(self, event, notify_image_viewer=True):
"""process menu quit event"""
if notify_image_viewer:
# send Close command to image viewer
self.send_comm_object(mpv.Close())

# Close frame and exit main loop
self.app.ExitMainLoop()

# handle timer event. used to consume messages from the comm pipe
def handle_timer_event(self, event):
"""handle timer event"""
Expand Down Expand Up @@ -222,14 +253,6 @@ def update_status_text(self):
status_text = status_text + f"Temp: {tap.temp_max:.1f}C at ({tap.temp_pos_x}, {tap.temp_pos_y})"
self.text_status.SetValue(status_text)

# process menu events
def menu_open_folder(self, event):
"""process menu events"""
dlg = wx.DirDialog(self.frame, "Choose a directory:", style=wx.DD_DEFAULT_STYLE)
if dlg.ShowModal() == wx.ID_OK:
self.open_folder(dlg.GetPath())
dlg.Destroy()

# update filelist dictionary which holds the filepaths for all images
def update_file_list(self, folderpath):
filelist = mpv.get_file_list(folderpath, ['jpg', 'jpeg'])
Expand Down Expand Up @@ -261,16 +284,6 @@ def open_folder(self, folderpath):
# notify image viewer
self.send_comm_object(mpv.SetFilelist(self.filelist))

# process menu quit event
def menu_quit(self, event, notify_image_viewer=True):
"""process menu quit event"""
if notify_image_viewer:
# send Close command to image viewer
self.send_comm_object(mpv.Close())

# Close frame and exit main loop
self.app.ExitMainLoop()

# set image poi
def set_image_poi(self, filenumber, poi):
"""set image poi"""
Expand All @@ -291,22 +304,22 @@ def on_key(self, event):
"""process key events"""
keycode = event.GetKeyCode()
if keycode == wx.WXK_LEFT:
self.set_filenunmber(self.filenumber-1)
wx.CallAfter(self.set_filenunmber, self.filenumber-1)
elif keycode == wx.WXK_RIGHT:
self.set_filenunmber(self.filenumber+1)
wx.CallAfter(self.set_filenunmber, self.filenumber+1)
elif keycode == wx.WXK_UP:
self.set_filenunmber(self.filenumber-5)
wx.CallAfter(self.set_filenunmber, self.filenumber-5)
elif keycode == wx.WXK_DOWN:
self.set_filenunmber(self.filenumber+5)
wx.CallAfter(self.set_filenunmber, self.filenumber+5)
elif keycode == ord('p') or keycode == ord('P'):
self.add_poi(self.filenumber)
wx.CallAfter(self.add_poi, self.filenumber)
elif keycode == ord('c') or keycode == ord('C'):
self.clear_poi(self.filenumber)
wx.CallAfter(self.clear_poi, self.filenumber)

# process window events
def on_image_click(self, event):
"""process image click event"""
self.set_filenunmber(event.GetId())
wx.CallAfter(self.set_filenunmber, event.GetId())

# set filenumber and update display
def set_filenunmber(self, filenumber, notify_image_viewer=True):
Expand Down Expand Up @@ -415,11 +428,6 @@ def display_all_images(self, poi_only=False):
# update frame layout
self.frame.Layout()

# display POI images only
def display_poi_images(self, event):
"""display POI images only"""
self.display_all_images(poi_only=True)

# set filenumber and update display
def hide_image(self, filenumber):
# sanity check filenumber
Expand Down

0 comments on commit 10a3169

Please sign in to comment.