本文整理汇总了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)
示例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)
示例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()
示例4: quit_app
# 需要导入模块: from AppKit import NSApplication [as 别名]
# 或者: from AppKit.NSApplication import sharedApplication [as 别名]
def quit_app():
NSApplication.sharedApplication().terminate_(None)
示例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 = []
示例6: quit
# 需要导入模块: from AppKit import NSApplication [as 别名]
# 或者: from AppKit.NSApplication import sharedApplication [as 别名]
def quit(self):
NSApplication.sharedApplication().terminate_(None)
示例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)
示例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()
示例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 = []