def setup_mac_integration(self, menubar): from Cocoa import NSApp self.set_use_quartz_accelerators(True) self.set_menu_bar(menubar) item = Gtk.MenuItem.new_with_label(_("About")) item.connect("activate", self.about_callback, None) menubar.add(item) self.insert_app_menu_item(item, 0) self.set_about_item(item) separator = Gtk.SeparatorMenuItem() menubar.add(separator) self.insert_app_menu_item(separator, 1) item = Gtk.MenuItem.new_with_label(_("Preferences")) item.connect("activate", self.preferences_callback, None) menubar.add(item) self.insert_app_menu_item(item, 2) item = Gtk.MenuItem.new_with_label(_("Shell Integration")) item.connect("activate", self.mac_shell_integration_callback, None) menubar.add(item) self.insert_app_menu_item(item, 3) separator = Gtk.SeparatorMenuItem() menubar.add(separator) self.insert_app_menu_item(separator, 4) self.sync_menubar() self.ready() NSApp.activateIgnoringOtherApps_(True) self.attention_request(GtkosxApplication.ApplicationAttentionType.NFO_REQUEST)
def osx_menu_setup(self, widget, event, callback_data=None): if self.osx_ready == False: import gi gi.require_version('GtkosxApplication', '1.0') from gi.repository import GtkosxApplication as gtkosx_application self.macapp = gtkosx_application.Application() prefs_item = self.menubar.get_children()[1].get_submenu( ).get_children()[1] about_item = self.menubar.get_children()[1].get_submenu( ).get_children()[3] #self.menubar.get_children()[1].get_submenu().get_children()[2] #help quit_item = self.menubar.get_children()[1].get_submenu( ).get_children()[4] self.menubar.show() self.menubar.remove(self.menubar.get_children()[1]) self.macapp.set_menu_bar(self.menubar) self.menubar.hide() self.menubar.get_children()[1].hide() self.macapp.insert_app_menu_item(about_item, 0) self.macapp.insert_app_menu_item(Gtk.SeparatorMenuItem(), 1) self.macapp.insert_app_menu_item(prefs_item, 2) self.macapp.insert_app_menu_item(Gtk.SeparatorMenuItem(), 3) #self.macapp.ready() NSApp.activateIgnoringOtherApps_(True) self.osx_ready = True
def toggle(self): NSApp.activateIgnoringOtherApps_(True) window = self.window() if window.isMainWindow(): self.unpop() else: self.showWindow_(self) self.set_input('')
def toggle(self): NSApp.activateIgnoringOtherApps_(True) window = self.window() if window.isMainWindow(): self.unpop() else: self.showWindow_(self) self.set_input('')
def show_popover(self): self.on_show_callback() bounds = self.button.bounds() print 'BOUNDS ', bounds print 'show popover' #NSWindow *window = [[[NSApplication sharedApplication] currentEvent] window]; window = NSApplication.sharedApplication().currentEvent().window() x = NSApplication.sharedApplication().currentEvent().window().frame().origin.x y = NSApplication.sharedApplication().currentEvent().window().frame().origin.y x = x - 300 if x < 0: x = 0 y = y - 20 point = NSPoint(x, y) #point.setX_(x) #point.setY_(y) self.window.setFrameOrigin_(point) from Cocoa import NSApp as CocoaNSApp CocoaNSApp.activateIgnoringOtherApps_(True) #NSApp.activateIgnoringOtherApps_(True) self.window.makeKeyAndOrderFront_(self.window) #NSApplication.sharedApplication().activateIgnoringOtherApps(True) self._shown = True #self.popover.showRelativeToRect_ofView_preferredEdge_( # self.button.bounds(), # self.button, # NSMinYEdge #) def global_click(evt): print 'Global click!' self.close_popover() self.monitor = NSEvent.addGlobalMonitorForEventsMatchingMask_handler_( NSLeftMouseDownMask | NSRightMouseDownMask, global_click )
def osx_menu_setup(self, widget, event, callback_data=None): if self.quartz_ready == False: import gi from Cocoa import NSApp gi.require_version('GtkosxApplication', '1.0') from gi.repository import GtkosxApplication as gtkosx_application macapp = gtkosx_application.Application() macapp.set_use_quartz_accelerators(True) prefs_item = self.menubar.get_children()[1].get_submenu( ).get_children()[1] about_item = self.menubar.get_children()[1].get_submenu( ).get_children()[3] quit_item = self.menubar.get_children()[1].get_submenu( ).get_children()[4] help_item = self.menubar.get_children()[1].get_submenu( ).get_children()[2] mac_shell_item = self.menubar.get_children()[1].get_submenu( ).get_children()[5] self.menubar.show() #self.menubar.remove(help_menu) macapp.set_menu_bar(self.menubar) self.menubar.hide() self.menubar.get_children()[1].hide() macapp.set_about_item(about_item) macapp.insert_app_menu_item(prefs_item, 2) macapp.insert_app_menu_item(Gtk.SeparatorMenuItem(), 3) macapp.insert_app_menu_item( mac_shell_item, 3) # Disabled till we fix the symlink to be an alias macapp.insert_app_menu_item(help_item, 4) macapp.ready() NSApp.activateIgnoringOtherApps_(True) macapp.attention_request( gtkosx_application.ApplicationAttentionType.NFO_REQUEST) self.quartz_ready = True
def syncop_(self, sender): self.appendText_('Sync text') @objc.IBAction def asyncop_(self, sender): asyncio.create_task(self.asynctask()) @objc.IBAction def clear_(self, sender): self.textview.setString_('') def appendText_(self, text): old = self.textview.string() self.textview.setString_(old + text + '\n') self.textview.scrollToEndOfDocument_(None) if __name__ == "__main__": app = NSApplication.sharedApplication() viewController = GuiDemo.alloc().initWithWindowNibName_("guidemo") viewController.showWindow_(viewController) NSApp.activateIgnoringOtherApps_(True) # Configure asyncio to use CoreFoundationEventLoop loop = CoreFoundationEventLoop() asyncio.set_event_loop(loop) try: loop.run_forever() finally: loop.close()
def enable_focus_workaround(): NSApp.activateIgnoringOtherApps_(True)
def disable_focus_workaround(): NSApp.activateIgnoringOtherApps_(False)
def awakeFromNib(self): NSLog('awakeFromNib') def windowDidLoad(self): NSWindowController.windowDidLoad(self) NSLog('windowDidLoad') def windowShouldClose_(self, sender): NSLog('windowShouldClose') return True def windowWillClose_(self, notification): NSLog('windowWillClose') AppHelper.stopEventLoop() def applicationShouldTerminateAfterLastWindowClosed_(self, sender): NSLog('applicationShouldTerminateAfterLastWindowClosed') return True if __name__ == '__main__': app = NSApplication.sharedApplication() viewController = Media.alloc().initWithWindowNibName_('Media') viewController.showWindow_(viewController) NSApp.activateIgnoringOtherApps_(True) AppHelper.runEventLoop()
def applicationDidFinishLaunching_(self, notification): window = MainWindowController() window.showWindow_(window) NSApp.activateIgnoringOtherApps_(True)
def _bring_app_to_the_top(): try: from Cocoa import NSApp except ImportError: raise NSApp.activateIgnoringOtherApps_(True)
def applicationDidFinishLaunching_(self, notification): window = MainWindowController() window.showWindow_(window) NSApp.activateIgnoringOtherApps_(True)