How to make StatusInteractivePopUpWindow active by default
anya last edited by gferreira
When I use
StatusInteractivePopUpWindowas a UI base for an extension, the vanilla List within is not active (in focus?) by default. So when I press its shortcut and the window opens, I need to click on the List for it to be active. It seems that there is no problem like this if I use vanilla’s Window, but the problem does still happen with FloatingWindow. I was wondering why that is? Is there a way to make a popup window that would be active? Can there be an argument in
StatusInteractivePopUpWindowto control this? I’m not sure with the documentation on the website — mentions Window in the sample code instead of
While I’m here, is there an option to bind “Escape” key to a close() command?
the different types of windows in macOS have different behaviours. this is documented in the macOS Human Interface Guidelines, see Window Anatomy > Types of Windows.
it’s possible to change some of these default behaviours by accessing the underlying AppKit objects directly. here’s an example showing how you can make the list inside
StatusInteractivePopUpWindowbecome the first responder, and how to use the Escape and Enter keys to cancel/confirm the dialog.
from mojo.UI import StatusInteractivePopUpWindow from vanilla import Button, List, HorizontalLine class StatusInteractivePopUpWindowDemo(object): def __init__(self): self.w = StatusInteractivePopUpWindow((200, 300)) self.w.myButton = Button((10, 10, -10, 20), "My Button") self.w.myList = List((10, 40, -10, -55), ['a', 'b', 'c']) self.w.line = HorizontalLine((10, -40, -10, 1)) self.w.cancelButton = Button((10, -30, 70, 20), "Cancel", callback=self.cancelCallback) self.w.okButton = Button((90, -30, 70, 20), "OK", callback=self.okCallback) # make `myList` the first responder self.w.getNSWindow().makeFirstResponder_(self.w.myList.getNSTableView()) # define the OK button as the default one (Enter key) self.w.setDefaultButton(self.w.okButton) # bind the Cancel button to the Escape key self.w.cancelButton.bind(chr(27), ) self.w.open() def cancelCallback(self, sender): print('cancelled') self.w.close() def okCallback(self, sender): # get all items in list items = self.w.myList.get() # get list selection selection = self.w.myList.getSelection() # get selected list items selectedItems = [item for i, item in enumerate(items) if i in selection] print(selectedItems) self.w.close() StatusInteractivePopUpWindowDemo()
hope this helps!
anya last edited by
Thank you so much, Gustavo!