wavefrontshaping / slmPy

A simple Python module based on wxPython to interact with spatial light modulators handled as secondary monitors.
Other
63 stars 26 forks source link

Fix for Displaying Image on Specified Monitor #14

Open Shui96 opened 8 months ago

Shui96 commented 8 months ago

Hi Sebastien, I have recently been using your code to control SLM. After I switched to a different computer monitor (as main monitor), there were some problems with the code which was allowing well. I would like to give you feedback on these problems and the corresponding solutions. Maybe it will help different users.

Issue Description

In Windows, my SLM (monitor) number is displayed as 2 and the main monitor number is 1. When using wxPython, the SLM number is displayed as 1 and the main monitor number is 2. In this context, I have a problem loading images into SLM using this code. When attempting to display an image on a specified monitor, the image consistently appears on Main Monitor regardless of the specified monitor number.

Steps to Reproduce

  1. Create an instance of SLMdisplay with any monitor number (including negative numbers and numbers exceeding the actual monitor count).
  2. Call the updateArray method to attempt displaying an image on the specified monitor.
  3. Notice that the image window is displayed on the primary monitor instead of the specified one.

Expected Behavior

The image should appear on the monitor specified in the monitor parameter of the SLMdisplay class, or an error should be thrown if the monitor number is invalid.

Actual Behavior

The image window consistently defaults to the primary monitor, irrespective of the specified monitor number.

Proposed Fix

I've identified that the monitor parameter, though passed to the SLMdisplay class, is not being utilized correctly in the videoThread class. Here's a summary of the changes I made to address this issue:

  1. In the SLMdisplay class, ensure that the monitor parameter is stored as a class attribute:

    
    class SLMdisplay:
       def __init__(self, monitor=1, isImageLock=False):
           self.monitor = monitor  # Store the monitor parameter
           ...
  2. **In the videoThread class, modify the run method to pass the monitor attribute to the SLMframe instance:

    
    def run(self):
       app = wx.App()
       monitor = self.parent.monitor  # Retrieve the monitor parameter

With these changes, the code now correctly displays images on the monitor specified by the user.

Best, Yuyang