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 osx_dock_bounce(self): import gi gi.require_version('GtkosxApplication', '1.0') from gi.repository import GtkosxApplication as gtkosx_application macapp = gtkosx_application.Application() macapp.attention_request( gtkosx_application.ApplicationAttentionType.NFO_REQUEST)
def get_OSXApplication(): global macapp if macapp is None: import gi gi.require_version('GtkosxApplication', '1.0') from gi.repository import GtkosxApplication #@UnresolvedImport macapp = GtkosxApplication.Application() macapp.connect("NSApplicationWillTerminate", quit_handler) return macapp
def _setup_osx(self): ''' Copied from Quod Libet, GPL v2 or later ''' from AppKit import NSObject, NSApplication import objc try: import gi gi.require_version('GtkosxApplication', '1.0') from gi.repository import GtkosxApplication except (ValueError, ImportError): logger.warning( "importing GtkosxApplication failed, no native menus") else: osx_app = GtkosxApplication.Application() # self.main.setup_osx(osx_app) osx_app.ready() shared_app = NSApplication.sharedApplication() gtk_delegate = shared_app.delegate() other_self = self # TODO # Instead of quitting when the main window gets closed just hide it. # If the dock icon gets clicked we get # applicationShouldHandleReopen_hasVisibleWindows_ and show everything. class Delegate(NSObject): @objc.signature('B@:#B') def applicationShouldHandleReopen_hasVisibleWindows_( self, ns_app, flag): logger.debug("osx: handle reopen") # TODO # app.present() return True def applicationShouldTerminate_(self, sender): logger.debug("osx: block termination") other_self.main.quit() return False def applicationDockMenu_(self, sender): return gtk_delegate.applicationDockMenu_(sender) # def application_openFile_(self, sender, filename): # return app.window.open_file(filename.encode("utf-8")) delegate = Delegate.alloc().init() delegate.retain() shared_app.setDelegate_(delegate)
def _main_setup_osx(window): from AppKit import NSObject, NSApplication import objc try: import gi gi.require_version('GtkosxApplication', '1.0') from gi.repository import GtkosxApplication except (ValueError, ImportError): print_d("importing GtkosxApplication failed, no native menus") else: osx_app = GtkosxApplication.Application() window.set_as_osx_window(osx_app) osx_app.ready() shared_app = NSApplication.sharedApplication() gtk_delegate = shared_app.delegate() # Instead of quitting when the main window gets closed just hide it. # If the dock icon gets clicked we get # applicationShouldHandleReopen_hasVisibleWindows_ and show everything. class Delegate(NSObject): @objc.signature(b'B@:#B') def applicationShouldHandleReopen_hasVisibleWindows_( self, ns_app, flag): print_d("osx: handle reopen") app.present() return True def applicationShouldTerminate_(self, sender): print_d("osx: block termination") # FIXME: figure out why idle_add is needed here from gi.repository import GLib GLib.idle_add(app.quit) return False def applicationDockMenu_(self, sender): return gtk_delegate.applicationDockMenu_(sender) def application_openFile_(self, sender, filename): return app.window.open_file(filename.encode("utf-8")) delegate = Delegate.alloc().init() delegate.retain() shared_app.setDelegate_(delegate) # QL shouldn't exit on window close, EF should if window.get_is_persistent(): window.connect( "delete-event", lambda window, event: window.hide() or True)
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 Application(): return MockOSXAppObject() class MockOSXAppObject(object): def __getattr__(self, name): def method(*a): print(">>> OSX call:", name, a) return method if GtkosxApplication is None: GtkosxApplication = MockOSXAppModule if GtkosxApplication: # Global for all notebooks / windows, once per process _global_osx_application = GtkosxApplication.Application() _global_items_initialized = False else: _global_osx_application = None _global_items_initialized = False class OSXmenubarPlugin(PluginClass): # This object just provides some information for the plugin manager # no real logic happening here. plugin_info = { 'name': _('macOS Menubar'), # T: plugin name 'description': _('This plugin provides a macOS menubar for zim.' ), # T: plugin description 'author': 'Brecht Machiels, Jaap Karssenberg',
macapp.insert_app_menu_item(item, 0) item = Gtk.MenuItem.new_with_label("Check for updates...") item.connect("activate", self.activate_cb) item.show() macapp.insert_app_menu_item(Gtk.SeparatorMenuItem(), 1) macapp.insert_app_menu_item(item, 2) item = Gtk.MenuItem.new_with_label("Preferences") item.connect("activate", self.activate_cb) item.show() macapp.insert_app_menu_item(item, 3) # def dock_clicked_cb(self, dock): # print("Dock clicked") def activate_cb(self, widget): try: print(widget.get_child().get_text()) except: print(widget) if __name__ == '__main__': macapp = GtkosxApplication.Application() window = MainWindow(macapp) window.connect("destroy", Gtk.main_quit) macapp.ready() #Just to illustrate using the qtkosx_application_get... functions print(macapp.get_resource_path()) Gtk.main()