Note that there are some explanatory texts on larger screens.

plurals
  1. PONSWindow launched from statusItem menuItem does not appear as active window
    primarykey
    data
    text
    <p>I have a statusItem application written in PyObjC. The statusItem has a menuItem which is supposed to launch a new window when it is clicked:</p> <pre><code># Create statusItem statusItem = NSStatusBar.systemStatusBar().statusItemWithLength_(NSVariableStatusItemLength) statusItem.setHighlightMode_(TRUE) statusItem.setEnabled_(TRUE) statusItem.retain() # Create menuItem menu = NSMenu.alloc().init() menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Preferences', 'launchPreferences:', '') menu.addItem_(menuitem) statusItem.setMenu_(menu) </code></pre> <p>The launchPreferences: method is:</p> <pre><code>def launchPreferences_(self, notification): preferences = Preferences.alloc().initWithWindowNibName_('Preferences') preferences.showWindow_(self) </code></pre> <p>Preferences is an NSWindowController class:</p> <pre><code>class Preferences(NSWindowController): </code></pre> <p>When I run the application in XCode (Build &amp; Go), this works fine. However, when I run the built .app file externally from XCode, the statusItem and menuItem appear as expected but when I click on the Preferences menuItem the window does not appear. I have verified that the launchPreferences code is running by checking console output. </p> <p>Further, if I then double click the .app file again, the window appears but if I change the active window away by clicking, for example, on a Finder window, the preferences window disappears. This seems to me to be something to do with the active window. </p> <p><strong>Update 1</strong> I have tried <a href="https://stackoverflow.com/questions/152344/nswindow-launched-from-statusitem-menuitem-does-not-appear-as-active-window#152399">these</a> <a href="https://stackoverflow.com/questions/152344/nswindow-launched-from-statusitem-menuitem-does-not-appear-as-active-window#152409">two</a> answers but neither work. If I add in to the launchPreferences method:</p> <pre><code>preferences.makeKeyAndOrderFront_() </code></pre> <p>or</p> <pre><code>preferences.setLevel_(NSNormalWindowLevel) </code></pre> <p>then I just get an error:</p> <blockquote> <p>'Preferences' object has no attribute</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload