moses-palmer / pystray

GNU General Public License v3.0
482 stars 59 forks source link

default call #88

Closed majiq3233 closed 3 years ago

majiq3233 commented 3 years ago

python 3.9, Windows 10

When clicking the left button on the icon, an error appears: TypeError: 'tuple' object is not callable

replace to fix: _base.py

old

    def __call__(self):
        if self._menu is not None:
            self._menu(self)
            self.update_menu()

new

    def __call__(self):
        if self._menu is not None:
            for idx, item in enumerate(self._menu):
                if item.default:
                    self._menu[idx](self)
                    continue
            self.update_menu()
moses-palmer commented 3 years ago

Thank you for your report.

How did you create the menu? Please note that, as noted in the documentation, the menu argument passed to the constructor must be an instance of pystray.Menu. Using a tuple or a list will seemingly work, but crash for the default menu action.

majiq3233 commented 3 years ago

tried two mini variants:

        pystray.Icon('name', image, menu=(
                item('Show', self.show_window, default=True),
                item('Quit', self.close_app),
            )
        ).run()
        menu = (
            item('Show', self.show_window, default=True),
            item('Quit', self.close_app),
        )

        icon = pystray.Icon("name", image, "title", menu)
        icon.run()

this code actually works:

        image = Image.open("icon.ico")

        menu = pystray.Menu(
            item('Show', self.show_window, default=True),
            item('Quit', self.quit_window),
        )

        icon = pystray.Icon("name", image, "title", menu)
        icon.run()

menu = pystray.Menu(