Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
POMXARK opened this issue May 25, 2024 · 3 comments

Comments

@POMXARK
Copy link

POMXARK commented May 25, 2024

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
Copy link
Author

POMXARK commented May 25, 2024

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
Copy link
Author

POMXARK commented May 25, 2024

or best

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

@marcelstoer
Copy link

marcelstoer commented Jul 14, 2024

This is an issue on Windows as well, see marcelstoer/nodemcu-pyflasher#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants