microscope-cockpit / cockpit

Cockpit is a microscope graphical user interface. It is a flexible and easy to extend platform aimed at life scientists using bespoke microscopes.
https://microscope-cockpit.org
GNU General Public License v3.0
37 stars 26 forks source link

getNumberDialogs are never destroyed #666

Closed juliomateoslangerak closed 1 month ago

juliomateoslangerak commented 4 years ago

Every time one sets the diffraction angle or generates a new sequence on the SLM a new menu item is added to the Windows menu.

carandraug commented 4 years ago

The list of windows on the windows menu is updated each time the windows menu is opened (this is because when the menu is created the other windows don't exist yet). If a new menu item is being added each time, that suggests that the SLM is somewhere creating a window and then doesn't destroy. If you run this on cockpit's Python shell:

import wx.lib.inspection
wx.lib.inspection.InspectionTool().Show()

Can you see where those extra windows are?

juliomateoslangerak commented 4 years ago

Yes, they are top-level windows. I don't know if that is what you mean. This is what I see after setting twice diffraction angle and creating twice a sequence image

carandraug commented 4 years ago

That confirms it. The dialogs from cockpit.gui.dialogs.getNumberDialog are not destroyed after being used but they should. This can be tested without the boulder SLM, like so:

from cockpit.gui.dialogs import getNumberDialog
val = getNumberDialog.getNumberFromUser(None, 'Title', 'prompt', 77)
# Note that after been closed, there is a GetNumberDialog still around (it should not)
for w in wx.GetTopLevelWindows(): print(w)

# in comparison, if one uses the real wx GetX dialog, the dialog disappears after been used
import wx
val = wx.GetNumberFromUser('message', 'prompt', 'caption', 77)
for w in wx.GetTopLevelWindows(): print(w)

I guess one can fix the getNumberDialog but an alternative is to use one of the wx.Get*FromUser. There isn't one in wx to get a floating point value though.

carandraug commented 1 month ago

Now fixed by calling Destroy after being done with the dialog. Closing as fixed.