本文整理汇总了Python中AppKit.NSScreen.screens方法的典型用法代码示例。如果您正苦于以下问题:Python NSScreen.screens方法的具体用法?Python NSScreen.screens怎么用?Python NSScreen.screens使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppKit.NSScreen
的用法示例。
在下文中一共展示了NSScreen.screens方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: next_image
# 需要导入模块: from AppKit import NSScreen [as 别名]
# 或者: from AppKit.NSScreen import screens [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')
示例2: change_desktop_background
# 需要导入模块: from AppKit import NSScreen [as 别名]
# 或者: from AppKit.NSScreen import screens [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)
示例3: set_background
# 需要导入模块: from AppKit import NSScreen [as 别名]
# 或者: from AppKit.NSScreen import screens [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)
示例4: set_desktop_background
# 需要导入模块: from AppKit import NSScreen [as 别名]
# 或者: from AppKit.NSScreen import screens [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)
示例5: get_workareas
# 需要导入模块: from AppKit import NSScreen [as 别名]
# 或者: from AppKit.NSScreen import screens [as 别名]
def get_workareas():
try:
from AppKit import NSScreen #@UnresolvedImport
except ImportError as e:
log("cannot get workarea info without AppKit: %s", e)
return []
workareas = []
screens = NSScreen.screens()
for screen in screens:
log("get_workareas() testing screen %s", screen)
frame = screen.frame()
visibleFrame = screen.visibleFrame()
log(" frame=%s, visibleFrame=%s", frame, visibleFrame)
try:
#10.7 onwards:
log(" backingScaleFactor=%s", screen.backingScaleFactor())
except:
pass
x = int(visibleFrame.origin.x - frame.origin.x)
y = int((frame.size.height - visibleFrame.size.height) - (frame.origin.y - visibleFrame.origin.y))
w = int(visibleFrame.size.width)
h = int(visibleFrame.size.height)
workareas.append((x, y, w, h))
log("get_workareas()=%s", workareas)
return workareas
示例6: get_icc_info
# 需要导入模块: from AppKit import NSScreen [as 别名]
# 或者: from AppKit.NSScreen import screens [as 别名]
def get_icc_info():
from AppKit import NSScreen #@UnresolvedImport
ms = NSScreen.mainScreen()
info = do_get_screen_icc_info(ms)
screens = NSScreen.screens()
for i, screen in enumerate(screens):
si = do_get_screen_icc_info(screen)
if si:
info[i] = si
return info
示例7: setup
# 需要导入模块: from AppKit import NSScreen [as 别名]
# 或者: from AppKit.NSScreen import screens [as 别名]
def setup(self):
screens = NSScreen.screens()
self.numScreens = len(screens)
tops, bottoms, lefts, rights = [], [], [], []
for s in screens:
self.parseScreen(s, tops, bottoms, lefts, rights)
self.totalWidth = max(rights) - min(lefts)
self.totalHeight = max(tops) - min(bottoms)
self.cleanSides(self.verticalLines)
self.cleanSides(self.horizontalLines)
示例8: setBackgroundOSX
# 需要导入模块: from AppKit import NSScreen [as 别名]
# 或者: from AppKit.NSScreen import screens [as 别名]
def setBackgroundOSX(fullPath):
# generate a fileURL for the desktop picture
file_path = NSURL.fileURLWithPath_(fullPath)
# 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_path, screen, {}, None)
示例9: set_wallpaper_image
# 需要导入模块: from AppKit import NSScreen [as 别名]
# 或者: from AppKit.NSScreen import screens [as 别名]
def set_wallpaper_image(imgs, mode='stretched'):
"""Set the given file as wallpaper."""
if not len(imgs):
return
default_image = imgs[0]
file_url = NSURL.fileURLWithPath_(default_image)
options = {}
ws = NSWorkspace.sharedWorkspace()
for screen in NSScreen.screens():
(result, error) = ws.setDesktopImageURL_forScreen_options_error_(file_url, screen, options, None)
示例10: setFile
# 需要导入模块: from AppKit import NSScreen [as 别名]
# 或者: from AppKit.NSScreen import screens [as 别名]
def setFile():
# generate a fileURL for the desktop picture
file_path = NSURL.fileURLWithPath_(base_dir + image_file.decode("utf-8"))
# 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_path, screen, ws.desktopImageOptionsForScreen_(screen), None)
if error:
print error
示例11: displays
# 需要导入模块: from AppKit import NSScreen [as 别名]
# 或者: from AppKit.NSScreen import screens [as 别名]
def displays(self):
screens = NSScreen.screens()
connected = []
for screen in screens:
screen = screen.frame()
origin_y = screen.origin.y
# Flip coordinate space because Apple is weird
# https://developer.apple.com/documentation/coregraphics/cgrect
if len(connected) > 0:
origin_y = -screen.size.height - (origin_y - connected[0]["y"])
connected.append({
"x": int(screen.size.width),
"y": int(screen.size.height),
"offset_x": int(screen.origin.x),
"offset_y": int(origin_y)
})
return connected
示例12: main
# 需要导入模块: from AppKit import NSScreen [as 别名]
# 或者: from AppKit.NSScreen import screens [as 别名]
def main():
width = 550
height = 550
print("Updating...")
j = urllib2.urlopen("http://himawari8-dl.nict.go.jp/himawari8/img/D531106/latest.json")
latest = strptime(json.load(j)["date"], "%Y-%m-%d %H:%M:%S")
print("Latest version: {} GMT\n".format(strftime("%Y/%m/%d/%H:%M:%S", latest)))
url_format = "http://himawari8.nict.go.jp/img/D531106/{}d/{}/{}_{}_{}.png"
png = Image.new('RGB', (width*level, height*level))
print("Downloading tiles: 0/{} completed".format(level*level))
for x in range(level):
for y in range(level):
tile_w = urllib2.urlopen(url_format.format(level, width, strftime("%Y/%m/%d/%H%M%S", latest), x, y))
tiledata = tile_w.read()
tile = Image.open(BytesIO(tiledata))
png.paste(tile, (width*x, height*y, width*(x+1), height*(y+1)))
print("Downloading tiles: {}/{} completed".format(x*level + y + 1, level*level))
print("\nDownloaded\n")
output_file = tempfile.NamedTemporaryFile().name + ".png"
png.save(output_file, "PNG")
file_url = NSURL.fileURLWithPath_(output_file)
options = {'NSImageScaleProportionallyUpOrDown': True}
# 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, options, None)
if error:
print error
exit(-1)
print("Done!\n")
示例13: get
# 需要导入模块: from AppKit import NSScreen [as 别名]
# 或者: from AppKit.NSScreen import screens [as 别名]
def get(self):
from AppKit import NSScreen
return [(int(screen.frame().size.width), int(screen.frame().size.height))
for screen in NSScreen.screens()]
示例14: vars
# 需要导入模块: from AppKit import NSScreen [as 别名]
# 或者: from AppKit.NSScreen import screens [as 别名]
parser = argparse.ArgumentParser(description='Sets the desktop picture on all screens')
parser.add_argument('--path', help='The path of the image')
args = vars(parser.parse_args())
#already loggedin so we can skip any kind of security
getusername = os.getlogin()
#desktop_path = subprocess.check_output(['xdg-user-dir', 'DOCUMENTS'])
#name of the file to be used. Store in the same folder as the script I recommend a nice one of hasselhoff
file_name = 'background.jpg'
#the directory where stuff will be copied tp
directory_path = '/Users/' + getusername + '/Documents/'
shutil.copy2(file_name, directory_path)
#need th final picture path
picture_path = '/Users/' + getusername + '/Documents/' + file_name
# generate a fileURL for the desktop picture
file_url = NSURL.fileURLWithPath_(picture_path)
# make image options dictionary
# we just make an empty one because the defaults are fine
options = {}
# 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, options, None)
if error:
print error
exit(-1)
示例15: screenIdOf
# 需要导入模块: from AppKit import NSScreen [as 别名]
# 或者: from AppKit.NSScreen import screens [as 别名]
# Hide Dock icon since it will interfere with what we're doing here
# See: http://stackoverflow.com/a/9220911/390044
# See: https://developer.apple.com/library/mac/#documentation/AppKit/Reference/NSRunningApplication_Class/Reference/Reference.html
NSApplicationActivationPolicyRegular = 0
NSApplicationActivationPolicyAccessory = 1
NSApplicationActivationPolicyProhibited = 2
NSApplication.sharedApplication()
NSApp.setActivationPolicy_(NSApplicationActivationPolicyProhibited)
# Get the mainScreen
mf = NSScreen.mainScreen().frame()
mY = mf.origin.y
mH = mf.size.height
# and all screens to process query
screens = NSScreen.screens()
def screenIdOf(screen):
return str(screen.deviceDescription()["NSScreenNumber"])
def screenDimOf(screen):
f = screen.frame()
return "%dx%d" % (f.size.width, f.size.height)
matchedScreens = [s for s in screens if screenIdOf(s) in displaysInQuestion]
if len(matchedScreens) == 0:
matchedScreens = [s for s in screens if screenDimOf(s) in displaysInQuestion]
if len(matchedScreens) == 0:
matchedScreens = []
for idx in displaysInQuestion:
try:
i = int(idx)
matchedScreens += [screens[i]]