本文整理汇总了Python中AppKit.NSBundle.mainBundle方法的典型用法代码示例。如果您正苦于以下问题:Python NSBundle.mainBundle方法的具体用法?Python NSBundle.mainBundle怎么用?Python NSBundle.mainBundle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppKit.NSBundle
的用法示例。
在下文中一共展示了NSBundle.mainBundle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: keyboard_tap_callback
# 需要导入模块: from AppKit import NSBundle [as 别名]
# 或者: from AppKit.NSBundle import mainBundle [as 别名]
def keyboard_tap_callback(proxy, type_, event, refcon):
from AppKit import NSKeyUp, NSEvent, NSBundle
NSBundle.mainBundle().infoDictionary()['NSAppTransportSecurity'] =\
dict(NSAllowsArbitraryLoads=True)
if type_ < 0 or type_ > 0x7fffffff:
LOG.error('Unkown mac event')
run_event_loop()
LOG.error('restart mac key board event loop')
return event
try:
key_event = NSEvent.eventWithCGEvent_(event)
except:
LOG.info("mac event cast error")
return event
if key_event.subtype() == 8:
key_code = (key_event.data1() & 0xFFFF0000) >> 16
key_state = (key_event.data1() & 0xFF00) >> 8
if key_code in (16, 19, 20):
# 16 for play-pause, 19 for next, 20 for previous
if key_state == NSKeyUp:
if key_code is 19:
ControllerApi.player.play_next()
elif key_code is 20:
ControllerApi.player.play_last()
elif key_code is 16:
ControllerApi.player.play_or_pause()
return None
return event
示例2: keyboard_tap_callback
# 需要导入模块: from AppKit import NSBundle [as 别名]
# 或者: from AppKit.NSBundle import mainBundle [as 别名]
def keyboard_tap_callback(proxy, type_, event, refcon):
from AppKit import NSKeyUp, NSEvent, NSBundle
NSBundle.mainBundle().infoDictionary()['NSAppTransportSecurity'] =\
dict(NSAllowsArbitraryLoads=True)
if type_ < 0 or type_ > 0x7fffffff:
logger.error('Unkown mac event')
run_event_loop()
logger.error('restart mac key board event loop')
return event
try:
key_event = NSEvent.eventWithCGEvent_(event)
except:
logger.info("mac event cast error")
return event
if key_event.subtype() == 8:
key_code = (key_event.data1() & 0xFFFF0000) >> 16
key_state = (key_event.data1() & 0xFF00) >> 8
if key_code in (16, 19, 20):
# 16 for play-pause, 19 for next, 20 for previous
if key_state == NSKeyUp:
if key_code is 19:
logger.info('mac hotkey: play next')
send_cmd('next')
elif key_code is 20:
logger.info('mac hotkey: play last')
send_cmd('previous')
elif key_code is 16:
os.system('echo "play_pause" | nc -4u -w0 localhost 8000')
send_cmd('toggle')
return None
return event
示例3: extract_tb
# 需要导入模块: from AppKit import NSBundle [as 别名]
# 或者: from AppKit.NSBundle import mainBundle [as 别名]
def extract_tb(tb, script=None, src=None):
"""Return a list of pre-processed entries from traceback."""
list = []
n = 0
while tb is not None:
f = tb.tb_frame
lineno = tb.tb_lineno
co = f.f_code
filename = co.co_filename
name = co.co_name
if filename==script:
line = src.split('\n')[lineno-1]
else:
linecache.checkcache(filename)
line = linecache.getline(filename, lineno, f.f_globals)
if line: line = line.strip()
else: line = None
list.append((filename, lineno, name, line))
tb = tb.tb_next
# omit the internal plotdevice stack frames in `dist` builds
from AppKit import NSBundle
debug = 'flux' in NSBundle.mainBundle().infoDictionary().get('CFBundleVersion','')
if not debug:
moduledir = abspath(dirname(dirname(__file__)))
return [frame for frame in list if moduledir not in frame[0]]
return list
示例4: resource_path
# 需要导入模块: from AppKit import NSBundle [as 别名]
# 或者: from AppKit.NSBundle import mainBundle [as 别名]
def resource_path(resource, resource_type):
path = NSBundle.mainBundle().pathForResource_ofType_(
resource, resource_type)
if NSFileManager.defaultManager().fileExistsAtPath_(path):
return path
else:
return None
示例5: migrateSupport
# 需要导入模块: from AppKit import NSBundle [as 别名]
# 或者: from AppKit.NSBundle import mainBundle [as 别名]
def migrateSupport(oldAppName, newAppName):
print('Checking Miro preferences and support migration...')
global migrated
migrated = False
from AppKit import NSBundle
prefsPath = os.path.expanduser('~/Library/Preferences').decode('utf-8')
newDomain = NSBundle.mainBundle().bundleIdentifier()
newPrefs = '%s.plist' % os.path.join(prefsPath, newDomain)
oldDomain = newDomain.replace(newAppName, oldAppName)
oldPrefs = '%s.plist' % os.path.join(prefsPath, oldDomain)
if os.path.exists(oldPrefs):
if os.path.exists(newPrefs):
print("Both %s and %s preference files exist." % (oldAppName, newAppName))
else:
os.rename(oldPrefs, newPrefs)
print("Migrated preferences to %s" % newPrefs)
supportFolderRoot = os.path.expanduser('~/Library/Application Support')
oldSupportFolder = os.path.join(supportFolderRoot, oldAppName)
newSupportFolder = os.path.join(supportFolderRoot, newAppName)
if os.path.exists(oldSupportFolder):
if os.path.exists(newSupportFolder):
print("Both %s and %s support folders exist." % (oldAppName, newAppName))
else:
os.rename(oldSupportFolder, newSupportFolder)
print("Migrated support folder to %s" % newSupportFolder)
migrated = True
示例6: _helpBookCallback
# 需要导入模块: from AppKit import NSBundle [as 别名]
# 或者: from AppKit.NSBundle import mainBundle [as 别名]
def _helpBookCallback(self, sender):
from Carbon import AH
bundle = NSBundle.mainBundle()
if bundle is None:
return
info = bundle.infoDictionary()
helpBookName = info.get("CFBundleHelpBookName")
if self._page is not None:
AH.AHGoToPage(helpBookName, self._page, self._anchor)
elif self._anchor is not None:
AH.AHLookupAnchor(helpBookName, self._anchor)
示例7: applicationDidFinishLaunching_
# 需要导入模块: from AppKit import NSBundle [as 别名]
# 或者: from AppKit.NSBundle import mainBundle [as 别名]
def applicationDidFinishLaunching_(self, notification):
u"""
Setting up globals.
"""
print '* Meta Application finished launching, initializing...'
self.model = Model()
self.path = os.path.join(os.path.dirname(__file__))
self.resourcePath = NSBundle.mainBundle().resourcePath()
self.documentFilesPath = self.resourcePath + '/en.lproj/'
path = '/Users/michiel/Projects/Meta/imftc/imftc.meta'
document = self.model.openDocument(path)
self.openStartWindow()
示例8: finishLaunching
# 需要导入模块: from AppKit import NSBundle [as 别名]
# 或者: from AppKit.NSBundle import mainBundle [as 别名]
def finishLaunching(self):
# Make statusbar item
statusbar = NSStatusBar.systemStatusBar()
self.statusitem = statusbar.statusItemWithLength_(
NSVariableStatusItemLength)
# Thanks Matthias Kretschmann
# at http://kremalicious.com/coffee-cup-icon/
icon_path = NSBundle.mainBundle()\
.pathForResource_ofType_(
ICON_BASE, ICON_EXT)
if not icon_path:
icon_path = ICON_FILE
self.icon = NSImage.alloc()\
.initByReferencingFile_(icon_path)
self.icon.setScalesWhenResized_(True)
self.icon.setSize_((20, 20))
self.statusitem.setImage_(self.icon)
# Make the menu
self.menubarMenu = NSMenu.alloc().init()
self.menuItem = NSMenuItem.alloc()\
.initWithTitle_action_keyEquivalent_(
'Connect', 'connectAndCloseCNA:', '')
self.menubarMenu.addItem_(self.menuItem)
self.quit = NSMenuItem.alloc()\
.initWithTitle_action_keyEquivalent_(
'Quit', 'terminate:', '')
self.menubarMenu.addItem_(self.quit)
# Add menu to statusitem
self.statusitem.setMenu_(self.menubarMenu)
self.statusitem.setToolTip_('Cartel')
self.statusitem.setHighlightMode_(True)
# Get the default notification center.
self.workspace = NSWorkspace.sharedWorkspace()
self.default_center = NSNotificationCenter.defaultCenter()
# Create the handler
self.rhandler = ReachabilityHandler.new()
self.rhandler.app = self
self.default_center.addObserver_selector_name_object_(
self.rhandler,
"handleChange:",
kReachabilityChangedNotification,
None)
# Create the reachability object and start notifactions.
self.reachability = Reachability()
self.reachability.startNotifier()
示例9: check_version
# 需要导入模块: from AppKit import NSBundle [as 别名]
# 或者: from AppKit.NSBundle import mainBundle [as 别名]
def check_version(self):
infodict = NSBundle.mainBundle().infoDictionary()
mailversion = infodict['CFBundleVersion']
lastknown = self.prefs.string["QuoteFixLastKnownBundleVersion"]
if lastknown and lastknown != mailversion:
NSRunAlertPanel(
'QuoteFix plug-in',
'''
The QuoteFix plug-in detected a different Mail.app version (perhaps you updated?).
If you run into any problems with regards to replying or forwarding mail, consider removing this plug-in (from ~/Library/Mail/Bundles/).
(This alert is only displayed once for each new version of Mail.app)''',
None,
None,
None
)
self.prefs.string["QuoteFixLastKnownBundleVersion"] = mailversion
示例10: show_backdrop
# 需要导入模块: from AppKit import NSBundle [as 别名]
# 或者: from AppKit.NSBundle import mainBundle [as 别名]
def show_backdrop(comm_queue, image_path):
from AppKit import NSWindow, NSWindowCollectionBehaviorCanJoinAllSpaces, NSWindowCollectionBehaviorStationary, \
NSWindowCollectionBehaviorIgnoresCycle, NSBorderlessWindowMask, NSBackingStoreBuffered, NSColor, \
NSApplication, NSScreen, NSView, NSImage, NSImageView, NSZeroRect, NSCompositeCopy, NSApp, \
NSTimer, NSObject, NSEvent, NSApplicationDefined, NSMakePoint, NSBundle
from Quartz import kCGDesktopWindowLevel
from ctypes import CDLL, Structure, POINTER, c_uint32, byref
from ctypes.util import find_library
class ProcessSerialNumber(Structure):
_fields_ = [('highLongOfPSN', c_uint32),
('lowLongOfPSN', c_uint32)]
kCurrentProcess = 2
kProcessTransformToUIElementAppication = 4
ApplicationServices = CDLL(find_library('ApplicationServices'))
TransformProcessType = ApplicationServices.TransformProcessType
TransformProcessType.argtypes = [POINTER(ProcessSerialNumber), c_uint32]
class MainController(NSObject):
timer = None
def kickRunLoop(self):
event = NSEvent.otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2_(NSApplicationDefined, \
NSMakePoint(0,0), 0, 0.0, 0, None, 0, 0, 0)
NSApp.postEvent_atStart_(event, True)
def checkProcess_(self, timer):
if not comm_queue.empty():
# We Get Signal, Take Off Every Zig - er, time to shut down this forked process
# Clear the queue
while not comm_queue.empty():
ignore = comm_queue.get_nowait()
NSApp.stop_(None)
# After you stop the runloop, the app has to receive another event to determine the runloop stopped ...
self.kickRunLoop()
def run(self):
# You could adjust the 1.0 here to how ever many seconds you wanted to wait between checks to terminate
self.timer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(1.0, self, self.checkProcess_, None, True)
NSApp.run()
class FullScreenWindow(NSWindow):
def canBecomeKeyWindow(self):
return False
def canBecomeMainWindow(self):
return False
class LockView(NSView):
def getTopOffset(self, height):
return (self.bounds().size.height / 2) - height / 2
def getLeftOffset(self, width):
return (self.bounds().size.width / 2) - width / 2
def drawRect_(self, rect):
image = NSImage.alloc().initWithContentsOfFile_(image_path)
rep = image.representations()[0]
bg_width = rep.pixelsWide()
bg_height = rep.pixelsHigh()
image.drawInRect_fromRect_operation_fraction_(((self.getLeftOffset(bg_width), self.getTopOffset(bg_height)), (bg_width, bg_height)), NSZeroRect, NSCompositeCopy, 1.0)
imageView = NSImageView.alloc().init()
imageView.setImage_(image)
self.addSubview_(imageView)
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?
# This is enough to make an app faceless / without a Dock icon
info['LSUIElement'] = '1'
# Initialize our shared application instance
app = NSApplication.sharedApplication()
# ... This isn't really necessary, but it's nice to ensure that the application truly is UIElement type
psn = ProcessSerialNumber(0, kCurrentProcess)
ApplicationServices.TransformProcessType(psn, kProcessTransformToUIElementAppication)
screen = NSScreen.mainScreen()
myWindow = FullScreenWindow.alloc().initWithContentRect_styleMask_backing_defer_(screen.frame(), NSBorderlessWindowMask, NSBackingStoreBuffered, True)
myView = LockView.alloc().initWithFrame_(screen.frame())
myWindow.setContentView_(myView)
myWindow.setLevel_(kCGDesktopWindowLevel)
myWindow.setCollectionBehavior_(NSWindowCollectionBehaviorCanJoinAllSpaces | NSWindowCollectionBehaviorStationary | NSWindowCollectionBehaviorIgnoresCycle)
myWindow.setBackgroundColor_(NSColor.blackColor())
myWindow.makeKeyAndOrderFront_(myWindow)
myWindow.display()
controller = MainController.alloc().init()
controller.run()
示例11: bundle_path
# 需要导入模块: from AppKit import NSBundle [as 别名]
# 或者: from AppKit.NSBundle import mainBundle [as 别名]
def bundle_path(name, typ):
if typ:
return NSBundle.mainBundle().pathForResource_ofType_(name, typ)
else:
return os.path.join(NSBundle.mainBundle().resourcePath(), name)
示例12: __import__
# 需要导入模块: from AppKit import NSBundle [as 别名]
# 或者: from AppKit.NSBundle import mainBundle [as 别名]
# FontLab
# alternative syntax to cheat on the FL import filtering in RF
__import__("FL")
application = "fontlab"
#applicationVersion = fl.version
except ImportError:
pass
if application is None:
try:
# RoboFont
import mojo
application = 'robofont'
try:
from AppKit import NSBundle
b = NSBundle.mainBundle()
applicationVersion = b.infoDictionary()["CFBundleVersion"]
except ImportError:
pass
except ImportError:
pass
if application is None:
try:
# Glyphs
import GlyphsApp
application = "glyphs"
except ImportError:
pass
if application is None:
示例13: _findrubyrenderer
# 需要导入模块: from AppKit import NSBundle [as 别名]
# 或者: from AppKit.NSBundle import mainBundle [as 别名]
def _findrubyrenderer():
from AppKit import NSBundle
return NSBundle.mainBundle().pathForResource_ofType_('rubyrenderer', 'rb')
示例14: __init__
# 需要导入模块: from AppKit import NSBundle [as 别名]
# 或者: from AppKit.NSBundle import mainBundle [as 别名]
def __init__(self):
self.mac = None
self.pc = None
self.platform = sys.platform
self.applicationName = None # name of the application we're running in
self.name = os.name
self.version = version # the robofab version
self.numberVersion = numberVersion
self.run = True
# get some platform information
if self.name == "mac" or self.name == "posix":
if self.platform == "darwin":
self.mac = "X"
else:
self.mac = "pre-X"
elif self.name == "nt":
# if you know more about PC & win stuff, add it here!
self.pc = True
else:
raise RoboFabError, "We're running on an unknown platform."
# collect versions
self.pyVersion = sys.version[:3]
self.inPython = False
self.inFontLab = False
self.flVersion = None
self.inGlyphs = False
self.glyphsVersion = None
self.inRoboFont = False
self.roboFontVersion = None
# are we in FontLab?
try:
from FL import fl
self.applicationName = fl.filename
self.inFontLab = True
self.flVersion = fl.version
except ImportError:
pass
# are we in Glyphs?
try:
import objectsGS
from AppKit import NSBundle
bundle = NSBundle.mainBundle()
self.applicationName = bundle.infoDictionary()["CFBundleName"]
self.inGlyphs = True
self.glyphsVersion = bundle.infoDictionary()["CFBundleVersion"]
except ImportError:
pass
# are we in RoboFont
try:
import mojo
from AppKit import NSBundle
bundle = NSBundle.mainBundle()
self.applicationName = bundle.infoDictionary()["CFBundleName"]
self.inRoboFont = True
self.roboFontVersion = bundle.infoDictionary()["CFBundleVersion"]
except ImportError:
pass
# we are in NoneLab
if not self.inFontLab:
self.inPython = True
# see if we have DialogKit
self.supportsDialogKit = False
示例15: globals
# 需要导入模块: from AppKit import NSBundle [as 别名]
# 或者: from AppKit.NSBundle import mainBundle [as 别名]
"control": NSControlKeyMask,
"ctrl": NSControlKeyMask,
"shift": NSShiftKeyMask
}
key_map = {
"left": 123,
"right": 124,
"down": 125,
"up": 126,
'help': 114, 'mute': 74, 'comma': 43, 'volumedown': 73, '1': 18, '0': 29, '4': 21, '8': 28, 'return': 36, 'enter': 36, 'slash': 44, 'downarrow': 125, 'd': 2, 'h': 4, 'l': 37, 'p': 35, 't': 17, 'x': 7, 'forwarddelete': 117, 'rightbracket': 30, 'right': 124, 'escape': 53, 'home': 115, '5': 23, 'space': 49, '3': 20, 'f20': 90, 'pagedown': 121, '7': 26, 'keypadequals': 81, 'keypadplus': 69, 'c': 8, 'f11': 103, 'keypadclear': 71, 'g': 5, 'k': 40, 'equal': 24, 'o': 31, 'minus': 27, 's': 1, 'w': 13, 'f15': 113, 'rightshift': 60, 'period': 47, 'down': 125, 'capslock': 57, 'f6': 97, '2': 19, 'keypadmultiply': 67, '6': 22, 'function': 63, 'option': 58, 'leftbracket': 33, 'f19': 80, 'b': 11, 'f': 3, 'j': 38, 'pageup': 116, 'up': 126, 'n': 45, 'f18': 79, 'r': 15, 'rightoption': 61, 'v': 9, 'f12': 111, 'f13': 105, 'f10': 109, 'z': 6, 'f16': 106, 'f17': 64, 'f14': 107, 'delete': 51, 'f1': 122, 'f2': 120, 'f3': 99, 'f4': 118, 'f5': 96, 'semicolon': 41, 'f7': 98, 'f8': 100, 'f9': 101, 'backslash': 42, 'keypaddivide': 75, 'tab': 48, 'rightarrow': 124, 'end': 119, 'leftarrow': 123, 'keypad7': 89, 'keypad6': 88, 'keypad5': 87, 'keypad4': 86, 'keypad3': 85, 'keypad2': 84, 'keypad1': 83, 'keypad0': 82, '9': 25, 'u': 32, 'keypad9': 92, 'keypad8': 91, 'quote': 39, 'volumeup': 72, 'grave': 50, '<': 50, '>':62, 'keypaddecimal': 65, 'e': 14, 'i': 34, 'keypadminus': 78, 'm': 46, 'uparrow': 126, 'q': 12, 'y': 16, 'keypadenter': 76, 'left': 123
}
# this module contains a wrapper around the SGHotKeysLib to make it usable from Python/PyObjC
base_path = os.path.join(
NSBundle.mainBundle().bundlePath(), "Contents", "Frameworks")
bundle_path = os.path.abspath(os.path.join(base_path, 'SGHotKey.framework'))
objc.loadBundle(
'SGHotKey', globals(), bundle_path=objc.pathForFramework(bundle_path))
SGHotKey = NSClassFromString("SGHotKey")
SGKeyCombo = NSClassFromString("SGKeyCombo")
SGHotKeyCenter = NSClassFromString("SGHotKeyCenter")
cmdKeyBit = 8
shiftKeyBit = 9
optionKeyBit = 11
controlKeyBit = 12
cmdKey = 1 << cmdKeyBit
shiftKey = 1 << shiftKeyBit