當前位置: 首頁>>代碼示例>>Python>>正文


Python NSApplication.sharedApplication方法代碼示例

本文整理匯總了Python中AppKit.NSApplication.sharedApplication方法的典型用法代碼示例。如果您正苦於以下問題:Python NSApplication.sharedApplication方法的具體用法?Python NSApplication.sharedApplication怎麽用?Python NSApplication.sharedApplication使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在AppKit.NSApplication的用法示例。


在下文中一共展示了NSApplication.sharedApplication方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: register

# 需要導入模塊: from AppKit import NSApplication [as 別名]
# 或者: from AppKit.NSApplication import sharedApplication [as 別名]
def register(self, root, keycode, modifiers):
            self.root = root
            self.keycode = keycode
            self.modifiers = modifiers
            self.activated = False

            if keycode:
                if not self.observer:
                    self.root.after_idle(self._observe)
                self.root.after(HotkeyMgr.POLL, self._poll)

            # Monkey-patch tk (tkMacOSXKeyEvent.c)
            if not self.tkProcessKeyEvent_old:
                sel = 'tkProcessKeyEvent:'
                cls = NSApplication.sharedApplication().class__()
                self.tkProcessKeyEvent_old = NSApplication.sharedApplication().methodForSelector_(sel)
                newmethod = objc.selector(self.tkProcessKeyEvent, selector = self.tkProcessKeyEvent_old.selector, signature = self.tkProcessKeyEvent_old.signature)
                objc.classAddMethod(cls, sel, newmethod)

        # Monkey-patch tk (tkMacOSXKeyEvent.c) to:
        # - workaround crash on OSX 10.9 & 10.10 on seeing a composing character
        # - notice when modifier key state changes
        # - keep a copy of NSEvent.charactersIgnoringModifiers, which is what we need for the hotkey
        # (Would like to use a decorator but need to ensure the application is created before this is installed) 
開發者ID:EDCD,項目名稱:EDMarketConnector,代碼行數:26,代碼來源:hotkey.py

示例2: run

# 需要導入模塊: from AppKit import NSApplication [as 別名]
# 或者: from AppKit.NSApplication import sharedApplication [as 別名]
def run(self):
        """
        Perform various setup tasks then start application run loop.
        """
        nsapplication = NSApplication.sharedApplication()
        nsapplication.activateIgnoringOtherApps_(True)  # NSAlerts in front

        self._nsapp = NSApp.alloc().init()
        self._nsapp._app = self.__dict__  # allow for dynamic modification based on this App instance
        self._nsapp.initializeStatusBar()
        nsapplication.setDelegate_(self._nsapp)
        #NSUserNotificationCenter.defaultUserNotificationCenter().setDelegate_(self._nsapp)

        setattr(App, '*app_instance', self)  # class level ref to running instance (for passing self to App subclasses)
        t = b = None
        for t in getattr(timer, '*timers', []):
            t.start()
        for b in getattr(clicked, '*buttons', []):
            b(self)  # we waited on registering clicks so we could pass self to access _menu attribute
        del t, b

        AppHelper.runEventLoop()
        #sys.exit(0) 
開發者ID:beville,項目名稱:ComicStreamer,代碼行數:25,代碼來源:rumps.py

示例3: main

# 需要導入模塊: from AppKit import NSApplication [as 別名]
# 或者: from AppKit.NSApplication import sharedApplication [as 別名]
def main():
  app = NSApplication.sharedApplication()
  delegate = AppDelegate.alloc().init()
  NSApp().setDelegate_(delegate)
  AppHelper.callLater(_BUCKET_SIZE_SECONDS, record)
  AppHelper.runEventLoop() 
開發者ID:numenta,項目名稱:nupic.rogue,代碼行數:8,代碼來源:keys.py

示例4: quit_app

# 需要導入模塊: from AppKit import NSApplication [as 別名]
# 或者: from AppKit.NSApplication import sharedApplication [as 別名]
def quit_app():
    NSApplication.sharedApplication().terminate_(None) 
開發者ID:macadmins,項目名稱:nudge,代碼行數:4,代碼來源:nibbler.py

示例5: __init__

# 需要導入模塊: from AppKit import NSApplication [as 別名]
# 或者: from AppKit.NSApplication import sharedApplication [as 別名]
def __init__(self, path):
        bundle = NSBundle.mainBundle()
        info = bundle.localizedInfoDictionary() or bundle.infoDictionary()
        # Did you know you can override parts of infoDictionary (Info.plist,
        # after loading) even though Apple says it's read-only?
        info['LSUIElement'] = '1'
        # Initialize our shared application instance
        NSApplication.sharedApplication()
        # Two possibilities here
        # Either the path is a directory and we really want the file inside it
        # or the path is just a real .nib file
        if os.path.isdir(path):
            # Ok, so they just saved it from Xcode, not their fault
            # let's fix the path
            path = os.path.join(path, 'keyedobjects.nib')
        with open(path, 'rb') as f:
            # get nib bytes
            buffer = memoryview
            d = buffer(f.read())
        n_obj = NSNib.alloc().initWithNibData_bundle_(d, None)
        placeholder_obj = NSObject.alloc().init()
        result, n = n_obj.instantiateWithOwner_topLevelObjects_(
            placeholder_obj, None)
        self.hidden = True
        self.nib_contents = n
        self.win = [
            x for x in self.nib_contents if x.className() == 'NSWindow'][0]
        self.views = views_dict(self.nib_contents)
        self._attached = [] 
開發者ID:macadmins,項目名稱:nudge,代碼行數:31,代碼來源:nibbler.py

示例6: quit

# 需要導入模塊: from AppKit import NSApplication [as 別名]
# 或者: from AppKit.NSApplication import sharedApplication [as 別名]
def quit(self):
        NSApplication.sharedApplication().terminate_(None) 
開發者ID:macadmins,項目名稱:nudge,代碼行數:4,代碼來源:nibbler.py

示例7: quit_application

# 需要導入模塊: from AppKit import NSApplication [as 別名]
# 或者: from AppKit.NSApplication import sharedApplication [as 別名]
def quit_application(sender=None):
    """Quit the application. Some menu item should call this function so that the application can exit gracefully."""
    nsapplication = NSApplication.sharedApplication()
    _log('closing application')
    nsapplication.terminate_(sender) 
開發者ID:Tautulli,項目名稱:Tautulli,代碼行數:7,代碼來源:rumps.py

示例8: run

# 需要導入模塊: from AppKit import NSApplication [as 別名]
# 或者: from AppKit.NSApplication import sharedApplication [as 別名]
def run(self, **options):
        """Performs various setup tasks including creating the underlying Objective-C application, starting the timers,
        and registering callback functions for click events. Then starts the application run loop.

        .. versionchanged:: 0.2.1
            Accepts `debug` keyword argument.

        :param debug: determines if application should log information useful for debugging. Same effect as calling
                      :func:`rumps.debug_mode`.

        """
        dont_change = object()
        debug = options.get('debug', dont_change)
        if debug is not dont_change:
            debug_mode(debug)

        nsapplication = NSApplication.sharedApplication()
        nsapplication.activateIgnoringOtherApps_(True)  # NSAlerts in front
        self._nsapp = NSApp.alloc().init()
        self._nsapp._app = self.__dict__  # allow for dynamic modification based on this App instance
        nsapplication.setDelegate_(self._nsapp)
        if _NOTIFICATIONS:
            try:
                notification_center = _default_user_notification_center()
            except RuntimeError:
                pass
            else:
                notification_center.setDelegate_(self._nsapp)

        setattr(App, '*app_instance', self)  # class level ref to running instance (for passing self to App subclasses)
        t = b = None
        for t in getattr(timer, '*timers', []):
            t.start()
        for b in getattr(clicked, '*buttons', []):
            b(self)  # we waited on registering clicks so we could pass self to access _menu attribute
        del t, b

        self._nsapp.initializeStatusBar()

        AppHelper.runEventLoop() 
開發者ID:Tautulli,項目名稱:Tautulli,代碼行數:42,代碼來源:rumps.py

示例9: __init__

# 需要導入模塊: from AppKit import NSApplication [as 別名]
# 或者: from AppKit.NSApplication import sharedApplication [as 別名]
def __init__(self, path):
        bundle = NSBundle.mainBundle()
        info = bundle.localizedInfoDictionary() or bundle.infoDictionary()
        # Did you know you can override parts of infoDictionary (Info.plist, after loading) even though Apple says it's read-only?
        info['LSUIElement'] = '1'
        info['NSRequiresAquaSystemAppearance'] = False
        # Initialize our shared application instance
        NSApplication.sharedApplication()
        # Two possibilities here
        # Either the path is a directory and we really want the file inside it
        # or the path is just a real .nib file
        if os.path.isdir(path):
            # Ok, so they just saved it from Xcode, not their fault
            # let's fix the path
            path = os.path.join(path, 'keyedobjects.nib')
        with open(path, 'rb') as f:
            # get nib bytes
            # try py2 method first
            try:
                d = buffer(f.read())
            # fail to py3
            except NameError:
                d = memoryview(f.read())
        n_obj = NSNib.alloc().initWithNibData_bundle_(d, None)
        placeholder_obj = NSObject.alloc().init()
        result, n = n_obj.instantiateWithOwner_topLevelObjects_(placeholder_obj, None)
        self.hidden = True
        self.nib_contents = n
        self.win = [x for x in self.nib_contents if x.className() == 'NSWindow'][0]
        self.views = views_dict(self.nib_contents)
        self._attached = [] 
開發者ID:macadmins,項目名稱:nibbler,代碼行數:33,代碼來源:nibbler.py


注:本文中的AppKit.NSApplication.sharedApplication方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。