def _event_handler(self): try: self.event_handler() except: print( traceback.format_exc()) # catch errors and print useful error NSApp.terminate_(None)
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 disable_focus_workaround(): global dialog global glib_id app_window.show() NSApp().setActivationPolicy_(NSApplicationActivationPolicyRegular) NSApp().activateIgnoringOtherApps_(True) GLib.idle_remove_by_data(glib_id)
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 showTaskCreationDialog_(self, sender): # Set default values for the title, start date and priority # Cocoa bindings will clear out the related fields in the sheet self._.calItemTitle = None self._.calItemStartDate = NSDate.date() NSApp.beginSheet_modalForWindow_modalDelegate_didEndSelector_contextInfo_( self.taskCreationDialog, self.mainWindow, self, 'didEndSheet:returnCode:contextInfo:', None)
def showEventCreationDialog_(self, sender): # Set default values for the title and start/end date # Cocoa bindings will clear out the related fields in the sheet self._.calItemTitle = None self._.calItemStartDate = NSDate.date() self._.calItemEndDate = NSDate.dateWithTimeIntervalSinceNow_(3600) NSApp.beginSheet_modalForWindow_modalDelegate_didEndSelector_contextInfo_( self.eventCreationDialog, self.mainWindow, self, 'didEndSheet:returnCode:contextInfo:', None)
def toggle(self): NSApp.activateIgnoringOtherApps_(True) window = self.window() if window.isMainWindow(): self.unpop() else: self.showWindow_(self) self.set_input('')
def osx_bring_to_front(self): NSApp.setActivationPolicy_(NSApplicationActivationPolicyRegular) # NSApp.activateIgnoringOtherApps_(True) # NSApp.activateWithOptions_(NSApplicationActivateIgnoringOtherApps | NSApplicationActivateAllWindows) macapp = self.get_application() #gtkosx_application.Application() self.set_keep_above(True) self.set_keep_above(False) macapp.attention_request( gtkosx_application.ApplicationAttentionType.NFO_REQUEST)
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 main(): app = NSApplication.sharedApplication() delegate = AppDelegate.alloc().init() NSApp().setDelegate_(delegate) win = NSWindow.alloc() frame = ((200.0, 300.0), (250.0, 100.0)) win.initWithContentRect_styleMask_backing_defer_(frame, 15, 2, 0) win.setTitle_("HelloWorld") app.run()
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 on_window_state_event(self, window, event): # FIXME: We don't receive notification on fullscreen on OSX # We'll have to figure this out some other way.. window = NSApp().mainWindow() if window is not None: window.disableSnapshotRestoration() if not self.app_ready: self.osx_menu_setup() NSApp().setActivationPolicy_(NSApplicationActivationPolicyRegular) NSApp().activateIgnoringOtherApps_(True) #force_focus(self) self.app_ready = True
def main(): app = NSApplication.sharedApplication() # we must keep a reference to the delegate object ourselves, # NSApp.setDelegate_() doesn't retain it. A local variable is # enough here. delegate = AppDelegate.alloc().init() NSApp().setDelegate_(delegate) win = NSWindow.alloc() frame = ((200.0, 300.0), (250.0, 100.0)) win.initWithContentRect_styleMask_backing_defer_(frame, 15, 2, 0) win.setTitle_("HelloWorld") win.setLevel_(3) # floating window hel = NSButton.alloc().initWithFrame_(((10.0, 10.0), (80.0, 80.0))) win.contentView().addSubview_(hel) hel.setBezelStyle_(4) hel.setTitle_("Hello!") hel.setTarget_(app.delegate()) hel.setAction_("sayHello:") beep = NSSound.alloc() beep.initWithContentsOfFile_byReference_( "/System/Library/Sounds/Tink.Aiff", 1) hel.setSound_(beep) bye = NSButton.alloc().initWithFrame_(((100.0, 10.0), (80.0, 80.0))) win.contentView().addSubview_(bye) bye.setBezelStyle_(4) bye.setTarget_(app) bye.setAction_("stop:") bye.setEnabled_(1) bye.setTitle_("Goodbye!") adios = NSSound.alloc() adios.initWithContentsOfFile_byReference_( "/System/Library/Sounds/Basso.aiff", 1) bye.setSound_(adios) win.display() win.orderFrontRegardless() # but this one does AppHelper.runEventLoop()
def isolateSheet(): window = NSApp.keyWindow() if not window: return if window.isSheet(): window = window.sheetParent() sheet = window.attachedSheet() if not sheet: return window.endSheet_(sheet) blankWindow = NSWindow.new() blankWindow.setStyleMask_(NSWindowStyleMaskFullSizeContentView | NSWindowStyleMaskBorderless) blankWindow.setFrame_display_(NSZeroRect, True) blankWindow.makeKeyAndOrderFront_(None) blankWindow.center() blankWindow.beginSheet_completionHandler_(sheet, None)
def enable_focus_workaround(window): global dialog global app_window app_window.hide() NSApp().activateIgnoringOtherApps_(False) NSApp().setActivationPolicy_(NSApplicationActivationPolicyAccessory)
def dismissDialog_(self, sender): NSApp.endSheet_(sender.window())
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()
__MenuTitle__ = { "de": "Fenster transparent machen", "en": "Make Window Transparent", } __MenuDescription__ = { "de": "Setzt den Alpha-Wert des vordersten Fensters auf 0. Hilfreich, falls Bildschirmfotos von Popover-Fenstern gemacht werden sollen (welche nicht von diesem Skript beeinflusst werden).", "en": "Sets the alpha value of the frontmost window to 0. Helpful for screenshotting popovers (which are not affected by this script).", } from Cocoa import NSApp NSApp.keyWindow().setAlphaValue_(0)
def main(): app = NSApplication.sharedApplication() delegate = AppDelegate.alloc().init() NSApp().setDelegate_(delegate) print 'loading' 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 windowWillClose_(self, sender): if sender is self.mainWindow: NSApp().terminate()
def invalidate_state(): NSApp().invalidateRestorableState()
def disable_focus_workaround(): NSApp.activateIgnoringOtherApps_(False)
def enable_focus_workaround(): NSApp.activateIgnoringOtherApps_(True)
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()