本文整理汇总了Python中AppKit.NSWorkspace.sharedWorkspace方法的典型用法代码示例。如果您正苦于以下问题:Python NSWorkspace.sharedWorkspace方法的具体用法?Python NSWorkspace.sharedWorkspace怎么用?Python NSWorkspace.sharedWorkspace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppKit.NSWorkspace
的用法示例。
在下文中一共展示了NSWorkspace.sharedWorkspace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: loadGlyphsInfo
# 需要导入模块: from AppKit import NSWorkspace [as 别名]
# 或者: from AppKit.NSWorkspace import sharedWorkspace [as 别名]
def loadGlyphsInfo():
try:
GlyphsPath = NSWorkspace.sharedWorkspace().URLForApplicationWithBundleIdentifier_("com.GeorgSeifert.Glyphs2")
if GlyphsPath is None:
GlyphsPath = NSWorkspace.sharedWorkspace().URLForApplicationWithBundleIdentifier_("com.GeorgSeifert.Glyphs")
if GlyphsPath is None:
GlyphsPath = NSWorkspace.sharedWorkspace().URLForApplicationWithBundleIdentifier_("com.schriftgestaltung.Glyphs")
if GlyphsPath is None:
GlyphsPath = NSWorkspace.sharedWorkspace().URLForApplicationWithBundleIdentifier_("com.schriftgestaltung.GlyphsMini")
GlyphsPath = GlyphsPath.path()
except:
return
if GlyphsPath is not None:
GlyphsInfoPath = GlyphsPath+"/Contents/Frameworks/GlyphsCore.framework/Versions/A/Resources/GlyphData.xml"
WeightCodesPath = GlyphsPath+"/Contents/Frameworks/GlyphsCore.framework/Versions/A/Resources/weights.plist"
parseGlyphDataFile(GlyphsInfoPath)
CustomGlyphsInfoPath = applicationSupportFolder()
if CustomGlyphsInfoPath:
CustomGlyphsInfoPath = CustomGlyphsInfoPath.stringByAppendingPathComponent_("/Info/GlyphData.xml")
if os.path.isfile(CustomGlyphsInfoPath):
parseGlyphDataFile(CustomGlyphsInfoPath)
global weightCodes
weightCodes = NSDictionary.alloc().initWithContentsOfFile_(WeightCodesPath)
示例2: loadGlyphsInfo
# 需要导入模块: from AppKit import NSWorkspace [as 别名]
# 或者: from AppKit.NSWorkspace import sharedWorkspace [as 别名]
def loadGlyphsInfo(GlyphsInfoPath=None):
if GlyphsInfoPath is None:
try:
from AppKit import NSWorkspace
except ImportError:
pass # on Windows, skip
else:
try:
GlyphsPath = NSWorkspace.sharedWorkspace().URLForApplicationWithBundleIdentifier_(
"com.GeorgSeifert.Glyphs2"
)
if GlyphsPath is None:
GlyphsPath = NSWorkspace.sharedWorkspace().URLForApplicationWithBundleIdentifier_(
"com.GeorgSeifert.Glyphs"
)
if GlyphsPath is None:
GlyphsPath = NSWorkspace.sharedWorkspace().URLForApplicationWithBundleIdentifier_(
"com.schriftgestaltung.Glyphs"
)
if GlyphsPath is None:
GlyphsPath = NSWorkspace.sharedWorkspace().URLForApplicationWithBundleIdentifier_(
"com.schriftgestaltung.GlyphsMini"
)
GlyphsPath = GlyphsPath.path()
except:
return
if GlyphsPath is not None:
bundledGlyphData = (
GlyphsPath + "/Contents/Frameworks/GlyphsCore.framework/Versions/A/Resources/GlyphData.xml"
)
if os.path.isfile(bundledGlyphData):
GlyphsInfoPath = bundledGlyphData
if GlyphsInfoPath is None:
# try to locate GlyphData.xml in FontLab's "Data" directory
flGlyphData = os.path.join(fl.path, "Data", "GlyphData.xml")
if os.path.isfile(flGlyphData):
GlyphsInfoPath = flGlyphData
if GlyphsInfoPath and os.path.isfile(GlyphsInfoPath):
parseGlyphDataFile(GlyphsInfoPath)
else:
print (
'Cannot find "GlyphData.xml".\n'
'Make sure Glyphs.app is installed correctly, or download "GlyphData.xml" from\n'
'https://github.com/schriftgestalt/GlyphsInfo, and place it inside "FontLab/Studio 5/Data".'
)
CustomGlyphsInfoPath = applicationSupportFolder()
if CustomGlyphsInfoPath:
CustomGlyphsInfoPath = CustomGlyphsInfoPath.stringByAppendingPathComponent_("/Info/GlyphData.xml")
if os.path.isfile(CustomGlyphsInfoPath):
parseGlyphDataFile(CustomGlyphsInfoPath)
示例3: dealloc
# 需要导入模块: from AppKit import NSWorkspace [as 别名]
# 或者: from AppKit.NSWorkspace import sharedWorkspace [as 别名]
def dealloc(self):
try:
NSDistributedNotificationCenter.defaultCenter().removeObserver_(self)
except Exception:
unhandled_exc_handler()
try:
NSWorkspace.sharedWorkspace().notificationCenter().removeObserver_(self)
except Exception:
unhandled_exc_handler()
super(CameraNotifier, self).dealloc()
示例4: webView_decidePolicyForNewWindowAction_request_newFrameName_decisionListener_
# 需要导入模块: from AppKit import NSWorkspace [as 别名]
# 或者: from AppKit.NSWorkspace import sharedWorkspace [as 别名]
def webView_decidePolicyForNewWindowAction_request_newFrameName_decisionListener_(self, webView, info, request, frame, listener):
try:
theURL = info[WebActionOriginalURLKey]
if self._account.server.settings_url is not None and theURL.host() == self._account.server.settings_url.hostname:
listener.use()
elif self._account.web_alert.alert_url is not None and theURL.host() == self._account.web_alert.alert_url.hostname:
listener.use()
else:
# use system wide web browser
NSWorkspace.sharedWorkspace().openURL_(theURL)
listener.ignore()
except KeyError:
pass
示例5: awakeFromNib
# 需要导入模块: from AppKit import NSWorkspace [as 别名]
# 或者: from AppKit.NSWorkspace import sharedWorkspace [as 别名]
def awakeFromNib(self):
# Initialise our session and selected state parameters
self.session = None
self.columns = [[]]
self.selectedResource = None
self.selectedDetails = None
self.selectedData = None
# Cache some useful icons
self.fileImage = NSWorkspace.sharedWorkspace().iconForFileType_(NSPlainFileType)
self.fileImage.setSize_(NSSize(16, 16))
self.directoryImage = NSWorkspace.sharedWorkspace().iconForFile_("/usr/")
self.directoryImage.setSize_(NSSize(16, 16))
# Initialise the toolbar
self._toolbarItems = {}
self._toolbarDefaultItemIdentifiers = []
self._toolbarAllowedItemIdentifiers = []
self.createToolbar()
# Set up browser view
container = self.mainSplitterView.subviews()[0]
container.addSubview_(self.columnView)
container.addSubview_(self.listView)
self.currentBrowserView = None
self.setBrowserView(self.BROWSERVIEW_COLUMNS)
self.browser.setMaxVisibleColumns_(7)
self.browser.setMinColumnWidth_(150)
# Set up data view
container = self.mainSplitterView.subviews()[1]
container.addSubview_(self.propertiesView)
container.addSubview_(self.dataView)
self.currentDataView = None
self.setDataView(self.DATAVIEW_PROPERTIES)
self.text.setString_("")
self.pathLabel.setStringValue_("No server specified")
# Get preferences
lastServer = NSUserDefaults.standardUserDefaults().stringForKey_("LastServer")
if lastServer and len(lastServer):
self.serverText.setStringValue_(lastServer)
lastPath = NSUserDefaults.standardUserDefaults().stringForKey_("LastPath")
if lastPath and len(lastPath):
self.pathText.setStringValue_(lastPath)
else:
self.pathText.setStringValue_("/")
lastUser = NSUserDefaults.standardUserDefaults().stringForKey_("LastUser")
if lastUser and len(lastUser):
self.userText.setStringValue_(lastUser)
示例6: webView_decidePolicyForNavigationAction_request_frame_decisionListener_
# 需要导入模块: from AppKit import NSWorkspace [as 别名]
# 或者: from AppKit.NSWorkspace import sharedWorkspace [as 别名]
def webView_decidePolicyForNavigationAction_request_frame_decisionListener_(self, webView, info, request, frame, listener):
# intercept when user clicks on links so that we process them in different ways
try:
theURL = info[WebActionOriginalURLKey]
if self._account.server.settings_url is not None and theURL.host() == self._account.server.settings_url.hostname:
listener.use()
elif self._account.web_alert.alert_url is not None and theURL.host() == self._account.web_alert.alert_url.hostname:
listener.use()
else:
# use system wide web browser
NSWorkspace.sharedWorkspace().openURL_(theURL)
listener.ignore()
except KeyError:
pass
示例7: set_desktop_background
# 需要导入模块: from AppKit import NSWorkspace [as 别名]
# 或者: from AppKit.NSWorkspace import sharedWorkspace [as 别名]
def set_desktop_background(desktop_picture_path):
file_url = NSURL.fileURLWithPath_(desktop_picture_path)
ws = NSWorkspace.sharedWorkspace()
screens = NSScreen.screens()
for screen in screens:
ws.setDesktopImageURL_forScreen_options_error_(file_url, screen, {}, None)
示例8: next_image
# 需要导入模块: from AppKit import NSWorkspace [as 别名]
# 或者: from AppKit.NSWorkspace import sharedWorkspace [as 别名]
def next_image(self, _):
if not os.path.exists(self.media_dir):
os.makedirs(self.media_dir)
url = 'https://unsplash.it/'
if self.gray_mood: url += 'g/'
url += '{w}/{h}/?random'
if self.blur: url += '&blur'
url = url.format(w=self.screen_width, h=self.screen_height)
file_name = self.media_dir + datetime.datetime.now().strftime("%H:%M:%S.%f") + '.jpg'
try:
self.icon = 'img/wait.png'
urllib.urlretrieve(url, file_name)
file_url = NSURL.fileURLWithPath_(file_name)
# Get shared workspace
ws = NSWorkspace.sharedWorkspace()
# Iterate over all screens
for screen in NSScreen.screens():
# Tell the workspace to set the desktop picture
(result, error) = ws.setDesktopImageURL_forScreen_options_error_(
file_url, screen, {}, None)
self.icon = 'img/icon.png'
except IOError:
print('Service unavailable, check your internet connection.')
rumps.alert(title='Connection Error', message='Service unavailable\n'
'Please, check your internet connection')
示例9: init
# 需要导入模块: from AppKit import NSWorkspace [as 别名]
# 或者: from AppKit.NSWorkspace import sharedWorkspace [as 别名]
def init(self):
self = super(CameraNotifier, self).init()
if self is None:
return
def register(events, center):
for event, selector in events.iteritems():
center.addObserver_selector_name_object_(self, selector, event, None)
self._screen_handler = Handler()
self.add_screen_handler = self._screen_handler.add_handler
self.remove_screen_handler = self._screen_handler.remove_handler
self._mount_handler = Handler()
self.add_mount_handler = self._mount_handler.add_handler
self.remove_mount_handler = self._mount_handler.remove_handler
notifications = {'com.apple.screensaver.didstart': self.onScreenSaverStarted_,
'com.apple.screensaver.didstop': self.onScreenSaverStopped_,
'com.apple.screenIsLocked': self.onScreenLocked_,
'com.apple.screenIsUnlocked': self.onScreenUnlocked_}
register(notifications, NSDistributedNotificationCenter.defaultCenter())
notifications = {'NSWorkspaceSessionDidBecomeActiveNotification': self.onFastUserSwitchEnd_,
'NSWorkspaceSessionDidResignActiveNotification': self.onFastUserSwitchStart_,
'NSWorkspaceWillUnmountNotification': self.onMountEvent_,
'NSWorkspaceDidUnmountNotification': self.onMountEvent_,
'NSWorkspaceDidMountNotification': self.onMountEvent_}
register(notifications, NSWorkspace.sharedWorkspace().notificationCenter())
self._fast_user_switching = False
self._screen_saver_running = False
self._screen_locked = False
self._screen_busy = False
return self
示例10: run_profiler
# 需要导入模块: from AppKit import NSWorkspace [as 别名]
# 或者: from AppKit.NSWorkspace import sharedWorkspace [as 别名]
def run_profiler():
samples = []
while True:
activeAppName = NSWorkspace.sharedWorkspace().activeApplication()['NSApplicationName']
samples.append([int(time.time()), activeAppName])
print_summary(samples)
time.sleep(sample_interval)
示例11: change_desktop_background
# 需要导入模块: from AppKit import NSWorkspace [as 别名]
# 或者: from AppKit.NSWorkspace import sharedWorkspace [as 别名]
def change_desktop_background(file, desk_id):
"""Function that applies the named file as wallaper for the specified
monitor (desk_id)"""
file_url = NSURL.fileURLWithPath_(file)
screen = NSScreen.screens()[desk_id]
ws = NSWorkspace.sharedWorkspace()
ws.setDesktopImageURL_forScreen_options_error_(file_url, screen, {}, None)
示例12: is_alias
# 需要导入模块: from AppKit import NSWorkspace [as 别名]
# 或者: from AppKit.NSWorkspace import sharedWorkspace [as 别名]
def is_alias (path):
uti, err = NSWorkspace.sharedWorkspace().typeOfFile_error_(
os.path.realpath(path), None)
if err:
raise Exception(unicode(err))
else:
return "com.apple.alias-file" == uti
示例13: observeValueForKeyPath_ofObject_change_context_
# 需要导入模块: from AppKit import NSWorkspace [as 别名]
# 或者: from AppKit.NSWorkspace import sharedWorkspace [as 别名]
def observeValueForKeyPath_ofObject_change_context_(self, path, obj, change, context):
if context == self.FinderTerminatedContext:
if path == self.FinderTerminationKey:
TRACE('Restarting finder %r', obj)
self.ret.set(NSWorkspace.sharedWorkspace().launchAppWithBundleIdentifier_options_additionalEventParamDescriptor_launchIdentifier_(self.FinderIdentifier, NSWorkspaceLaunchDefault, None, None))
else:
return super(FinderRestarterHelper, self).observeValueForKeyPath_ofObject_change_context_(path, obj, change, context)
示例14: set_background
# 需要导入模块: from AppKit import NSWorkspace [as 别名]
# 或者: from AppKit.NSWorkspace import sharedWorkspace [as 别名]
def set_background(image_file):
from AppKit import NSWorkspace, NSScreen
from Foundation import NSURL
file_url = NSURL.fileURLWithPath_(image_file)
ws = NSWorkspace.sharedWorkspace()
for screen in NSScreen.screens():
ws.setDesktopImageURL_forScreen_options_error_(file_url, screen, {}, None)
示例15: run
# 需要导入模块: from AppKit import NSWorkspace [as 别名]
# 或者: from AppKit.NSWorkspace import sharedWorkspace [as 别名]
def run(self):
NSApplication.sharedApplication()
self.delegate = AppDelegate.alloc().init()
self.delegate.event_sniffer = self
NSApp().setDelegate_(self.delegate)
self.workspace = NSWorkspace.sharedWorkspace()
nc = self.workspace.notificationCenter()
# This notification needs OS X v10.6 or later
nc.addObserver_selector_name_object_(
self.delegate,
'applicationActivated:',
'NSWorkspaceDidActivateApplicationNotification',
None)
nc.addObserver_selector_name_object_(
self.delegate,
'screenSleep:',
'NSWorkspaceScreensDidSleepNotification',
None)
# I don't think we need to track when the screen comes awake, but in case
# we do we can listen for NSWorkspaceScreensDidWakeNotification
NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(
self.options.active_window_time, self.delegate, 'writeActiveApp:',
None, True)
# Start the application. This doesn't return.
AppHelper.runEventLoop()