Skip to content

Commit

Permalink
picviewer: mosaic gets highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
rmackay9 committed Sep 15, 2024
1 parent e2cb344 commit 1f141cd
Showing 1 changed file with 56 additions and 7 deletions.
63 changes: 56 additions & 7 deletions MAVProxy/tools/mavpicviewer/mosaic_window2.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ def __init__(self, filelist, image_select_cb):
self.menu_bar = wx.MenuBar()
self.menu_bar.Append(self.menu, "Menu")
self.frame.SetMenuBar(self.menu_bar)

# add bindings for arrow keys
self.frame.Bind(wx.EVT_CHAR_HOOK, self.on_key)

#self.frame.Bind(wx.EVT_MENU, self.menu_set_api_key_show, id=1)

# add settings input window
Expand All @@ -83,12 +87,24 @@ def __init__(self, filelist, image_select_cb):

# add images
for i in range(len(self.filelist)):
# create a panel for each image (this allows us to set a background colour)
panel = wx.Panel(self.scrolled_panel, -1, size=(104, 104))

# create an image for each panel
img_path = self.filelist[i]
wx_image = wx.Image(img_path, wx.BITMAP_TYPE_ANY).Scale(100, 100)
image = wx.StaticBitmap(self.scrolled_panel, i, wx.Bitmap(wx_image))
image.SetForegroundColour(wx.GREEN)
image = wx.StaticBitmap(panel, i, wx.Bitmap(wx_image))

# bind event for left mouse button click
image.Bind(wx.EVT_LEFT_DOWN, self.on_image_click)
self.scrolled_panel_sizer.Add(image, proportion=0, flag=wx.ALL, border=2, userData=i)

# create a box sizer to center the image within the panel
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(image, 0, wx.ALIGN_CENTER | wx.ALL, 2)
panel.SetSizer(sizer)

# add panel to mosaic
self.scrolled_panel_sizer.Add(panel, proportion=0, flag=wx.ALL, border=2, userData=i)

self.scrolled_panel.SetSizer(self.scrolled_panel_sizer)
self.scrolled_panel.SetupScrolling(scroll_x=True, scroll_y=True)
Expand Down Expand Up @@ -137,11 +153,46 @@ def set_status_text(self, status_text):
"""set status text"""
self.text_status.SetValue(status_text)

# process key events
def on_key(self, event):
"""process key events"""
keycode = event.GetKeyCode()
if keycode == wx.WXK_LEFT:
if self.filenumber > 0:
self.set_filenunmber(self.filenumber-1)
elif keycode == wx.WXK_RIGHT:
self.set_filenunmber(self.filenumber+1)
elif keycode == wx.WXK_UP:
if self.filenumber >= 5:
self.set_filenunmber(self.filenumber-5)
elif keycode == wx.WXK_DOWN:
self.set_filenunmber(self.filenumber+5)

# process window events
def on_image_click(self, event):
"""process image click event"""
# update filenumber and title
self.filenumber = event.GetId()
self.set_filenunmber(event.GetId())

# set filenumber and update display
def set_filenunmber(self, filenumber):
"""set filenumber"""
num_files = len(self.filelist)
if filenumber < 0 or filenumber >= len(self.filelist)-1:
print("picviewer: ignoring invalid filenumber %d (>%d)" % (filenumber, num_files-1))
return

# set current filenumber panel's background color to white
panel = self.scrolled_panel_sizer.GetItem(self.filenumber).GetWindow()
panel.SetBackgroundColour(wx.WHITE)

# set new filenumber
self.filenumber = filenumber

# set panel background color to red
panel = self.scrolled_panel_sizer.GetItem(self.filenumber).GetWindow()
panel.SetBackgroundColour(wx.RED)

# update title
self.update_title()

# callback to parent to select image
Expand Down Expand Up @@ -191,15 +242,13 @@ def cmd_nextimage(self):
print("picviewer: already at last image %d" % self.filenumber)
return
self.filenumber = self.filenumber+1
self.update_image()

# update current image to previous image
def cmd_previmage(self):
if self.filenumber <= 0:
print("picviewer: already at first image")
return
self.filenumber = self.filenumber - 1
self.update_image()

# update the mosaic of images
# should be called if filenumber is changed
Expand Down

0 comments on commit 1f141cd

Please sign in to comment.