Bar menus
See original GitHub issueDescription
Although this question is not strictly about pywebview if I can get some help I could write a guide with the code or even work with a PR in the future if there is interest.
I have seen that a menu bar is quite required for my app (ex. File > Open, File > Save, Edit > …). Although I plan to release it in the three platforms, I am starting with Mac, which let me try to hijack the Cocoa’s BrowserView._add_view_menu to add simple menu items that would ultimately just call a custom python function.
I have never touched PyObjC. Just mimicking the existing code I can create new menus
myMenu.addItemWithTitle_action_keyEquivalent_("full", "foobar:", "o")
but I don’t know how to do it to execute my python function (I understand I need to add a foobar_() function somewhere…). PyObjC guides / example code have not helped me, as there are differences between the ones I have seen and your implementation. Could I get some help?
I understand in Linux / Windows this task will less cryptic?
Thank you!
Btw, amazing tool you have here 😃
Practicalities
- YES I am willing to work on this issue myself.
- NO I am prepared to support this issue financially.
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (3 by maintainers)
Top GitHub Comments
I have been able to create a working menu 😃
Now the problem is that I don’t know how to relate the menu to the active window. For now, the menu is global. So if I click “save” and I have several windows I don’t know which window to save. Ideally the
my_action()
should receive awindow
argument to know which window executed it. Any idea how to get it?Objective C is confusing af and can be intimidating. PyObjC adds its own quirks, but the good news is that it mostly works, once you get the syntax. As for the menu, somebody else has implemented it, so myself I have only a vague idea how it should be done.
addItemWithTitle_action_keyEquivalent_
seems to be the right method and action is attached via a selector. Here is an example of how to use a selector in Python. https://lethain.com/how-to-use-selectors-in-pyobjc/The menubar has been requested several times and in my opinion it can be incorporated into
pywebview
. If you would like to extend your work into a generic solution, that would be most welcomed. The scaffold for the API would be something like this