wxWidgets / Phoenix

wxPython's Project Phoenix. A new implementation of wxPython, better, stronger, faster than he was before.
http://wxpython.org/
2.34k stars 517 forks source link

wx.PopupTransientWindow. The window does not close when losing focus or clicking outside the area. #2554

Open POMXARK opened 6 months ago

POMXARK commented 6 months ago

I wanted to explore the project, but I encountered an error. The window does not close when losing focus or clicking outside the area.

wx.PopupTransientWindow it works incorrectly

glcontext==2.5.0 gsnodegraph==0.5.5 gswidgetkit==0.3.2 moderngl==5.6.4 numpy==1.22.0 opencolorio==2.3.2 opencv-python==4.9.0.80 pillow==10.3.0 six==1.16.0 wxPython==4.2.0

Python 3.10.12

NAME="Linux Mint" VERSION="21.2 (Victoria)" ID=linuxmint ID_LIKE="ubuntu debian" PRETTY_NAME="Linux Mint 21.2" VERSION_ID="21.2" HOME_URL="https://www.linuxmint.com/" SUPPORT_URL="https://forums.linuxmint.com/" BUG_REPORT_URL="http://linuxmint-troubleshooting-guide.readthedocs.io/en/latest/" PRIVACY_POLICY_URL="https://www.linuxmint.com/" VERSION_CODENAME=victoria UBUNTU_CODENAME=jammy

import wx

class AddNodeMenu(wx.PopupTransientWindow):
    def __init__(self, parent, style=wx.BORDER_NONE | wx.PU_CONTAINS_CONTROLS):
        wx.PopupTransientWindow.__init__(self, parent, style)

        self.parent = parent
        self._nodeRegistryMapping = {}
        self.InitAddNodeMenuUI()

    def InitAddNodeMenuUI(self):
        # Sizer
        main_sizer = wx.BoxSizer(wx.VERTICAL)

        # Label
        main_sizer.AddSpacer(5)
        header_lbl = wx.StaticText(self, wx.ID_ANY, "Add Node")
        header_lbl.SetForegroundColour(wx.Colour("#fff"))
        header_lbl.SetFont(self.GetFont().MakeBold())
        main_sizer.Add(header_lbl, flag=wx.EXPAND | wx.ALL, border=14)
        main_sizer.AddSpacer(5)
        main_sizer.AddSpacer(5)

class MyFrame(wx.Frame):
    def __init__(self, parent, title):
        super().__init__(parent, title=title, size=(600, 300))

        menubar = wx.MenuBar()
        file_menu = wx.Menu()

        item = file_menu.Append(wx.ID_EDIT, "Test\tCtrl+Q", "Open PopupTransientWindow")

        menubar.Append(file_menu, "&File")
        self.SetMenuBar(menubar)

        self.Bind(wx.EVT_MENU, self.OnAddNodeMenu, item)

    def PopupAddNodeMenu(self, pos):
        self.addnodemenu = AddNodeMenu(self)
        self.addnodemenu.Position(pos, (2, 2))
        self.addnodemenu.SetSize(250, 400)
        if self.addnodemenu.IsShown() is not True:
            self.addnodemenu.Show()

    def OnAddNodeMenu(self, event):
        pos = wx.GetMousePosition()
        pos = (pos[0] - 125, pos[1] - 100)
        self.PopupAddNodeMenu(pos)

    def OnAddNodeMenuButton(self, event):
        pos = wx.GetMousePosition()
        self.PopupAddNodeMenu(pos)

app = wx.App()

frame = MyFrame(None, 'wxPython')
frame.Show()

app.MainLoop()
POMXARK commented 6 months ago

had to add

        if platform.system() == "Linux":
            self.btn = wx.Button(self, label='Х', size=(70, 30))
            main_sizer.Add(self.btn, flag=wx.EXPAND | wx.ALL, border=14)
            self.Bind(wx.EVT_BUTTON, self._Dismiss, self.btn)

        main_sizer.Add(self.nodes_listbox, flag=wx.EXPAND | wx.ALL, border=5)

        self.SetSizer(main_sizer)

  def _Dismiss(self, event):
         self.Dismiss()
POMXARK commented 6 months ago

or best

        if platform.system() == "Linux":
            self.Bind(wx.EVT_KILL_FOCUS, self.ClickOut)

      def ClickOut(self, event):
        self.Dismiss()
marcelstoer commented 4 months ago

This is an issue on Windows as well, see https://github.com/marcelstoer/nodemcu-pyflasher/issues/80, all the way up to at least wxPython 4.2.0 (#2499 prevents the use of 4.2.1). Works on my Mac, though.