本文整理汇总了Python中AppKit.NSScreen类的典型用法代码示例。如果您正苦于以下问题:Python NSScreen类的具体用法?Python NSScreen怎么用?Python NSScreen使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NSScreen类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self):
super(SplshApp, self).__init__('Splsh')
self.icon = 'img/icon.png'
try:
self.screen_width = int(NSScreen.mainScreen().frame().size.width)
self.screen_height = int(NSScreen.mainScreen().frame().size.height)
except:
self.screen_width = 1024
self.screen_height = 768
self.menu = [
'x'.join([str(self.screen_width), str(self.screen_height)]),
None,
rumps.MenuItem('Next', key='n'),
None,
rumps.MenuItem('Gray Mood'),
rumps.MenuItem('Blur'),
rumps.MenuItem('Clear Cache', key='c'),
None,
]
# Path to dir for downloaded images
self.media_dir = 'media/'
# Extra url parameters
self.gray_mood = False
self.blur = False
示例2: get_icc_info
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
示例3: run
def run(self):
self._logger.debug('MainAction::run')
destination = os.path.realpath('wllpx.jpg')
tempFilename = os.path.realpath('temp.jpg')
media = self._instagramFeed.getNext()
self._settingsController.set('CURRENT_MEDIA_ID', media.id)
self._downloader.fromUrl(media.url, tempFilename)
width, height = int(NSScreen.mainScreen().frame().size.width), int(NSScreen.mainScreen().frame().size.height)
self._wallpaperGenerator.generate(width, height, tempFilename, destination)
self._wallpaperController.setWallpaper(destination)
示例4: next_image
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')
示例5: __init__
def __init__(self, style = 'standard', zoomable = None, **kwds):
# We ignore zoomable, since it's the same as resizable.
self._style = style
options = dict(_default_options_for_style[style])
for option in ['movable', 'closable', 'hidable', 'resizable']:
if option in kwds:
options[option] = kwds.pop(option)
self._ns_style_mask = self._ns_window_style_mask(**options)
if style == 'fullscreen':
ns_rect = NSScreen.mainScreen().frame()
else:
ns_rect = NSRect(NSPoint(0, 0), NSSize(self._default_width, self._default_height))
ns_window = PyGUI_NSWindow.alloc()
ns_window.initWithContentRect_styleMask_backing_defer_(
ns_rect, self._ns_style_mask, AppKit.NSBackingStoreBuffered, True)
ns_content = PyGUI_NS_ContentView.alloc()
ns_content.initWithFrame_(NSRect(NSPoint(0, 0), NSSize(0, 0)))
ns_content.pygui_component = self
ns_window.setContentView_(ns_content)
ns_window.setAcceptsMouseMovedEvents_(True)
ns_window.setDelegate_(ns_window)
ns_window.pygui_component = self
self._ns_window = ns_window
GWindow.__init__(self, style = style, closable = options['closable'],
_ns_view = ns_window.contentView(), _ns_responder = ns_window,
_ns_set_autoresizing_mask = False,
**kwds)
示例6: get_workareas
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
示例7: set_background
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)
示例8: change_desktop_background
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)
示例9: set_desktop_background
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)
示例10: reflow
def reflow(self, window_manager = None, screen = NSScreen.mainScreen(), space_id = None):
menubar_offset = 0 if self.ignore_menu else 22
windows = window_manager.get_managed_windows(screen, space_id)
screen_frame = screen.frame()
left = screen_frame[0][0] + self.border
top = screen_frame[0][1] + self.border + menubar_offset
right = screen_frame[1][0] - self.border
bottom = screen_frame[1][1] - self.border - menubar_offset
gutter_left = screen_frame[1][0] * self.ratio - self.gutter / 2
gutter_right = gutter_left + self.gutter
slave_count = len(windows) - 1
logging.debug('Number of slave windows: %d.', slave_count)
slave_height = ((bottom - top) - self.gutter * (slave_count - 1)) / slave_count
logging.debug('Slave window height is %f.', slave_height)
count = 0
offset = 0
for window in windows:
if count == 0:
window.frame = (left, top, gutter_left - left, bottom - top)
else:
window.position = (gutter_right, top + offset)
window.size = (right - gutter_right, slave_height)
offset += slave_height + self.gutter
logging.debug('New window frame: %f, %f, %f, %f', window.position[0], window.position[1], window.size[0], window.size[1])
count += 1
示例11: get_desktop_size
def get_desktop_size():
""" Get the current desktop resolution. No more than 2K.
Return a tuple of pixels (width, height)
"""
from AppKit import NSScreen
frame = NSScreen.mainScreen().frame()
height = frame.size.height
width = frame.size.width
MAX_WIDTH = 2000
MAX_HEIGHT = 2000
if width > MAX_WIDTH or height > MAX_HEIGHT:
if width > height:
max = width
ratio = max / MAX_WIDTH
else:
max = height
ratio = max / MAX_HEIGHT
width = width / ratio
height = height / ratio
return (int(width), int(height))
示例12: getScreenResolution
def getScreenResolution(cls, index =-1):
#-------------------------------------------------------------------------------------------
if cls.isMac():
try:
import AppKit
from AppKit import NSScreen
if index == -1:
return int(NSScreen.mainScreen().frame().size.width), \
int(NSScreen.mainScreen().frame().size.height)
i = 0
for screen in AppKit.NSScreen.screens():
if i != index:
continue
return screen.frame().size.width, screen.frame().size.height
return None
except Exception:
pass
result = cls._getOsxDisplayInfo()
if result['code'] or not 'out' in result:
return None
if index < 0:
index = 0
screenIndex = 0
for line in result['out'].split('\n'):
line = line.strip().lower()
if not line.startswith('resolution:'):
continue
if screenIndex != index:
continue
result = re.search(r'(?P<width>[0-9]{3,})[^0-9]+(?P<height>[0-9]{3,})', line)
return int(result.group('width')), int(result.group('height'))
return None
#-------------------------------------------------------------------------------------------
if cls.isWindows():
try:
import ctypes
except Exception:
return None
user32 = ctypes.windll.user32
return int(user32.GetSystemMetrics(0)), int(user32.GetSystemMetrics(1))
示例13: isfullscreen
def isfullscreen(self):
"""return true if fullscreen"""
if len(self.windows)==0:
return False
f=NSScreen.mainScreen().frame()
m=([f.origin.x,f.origin.y,f.size.width,f.size.height])
w=self.windows[0].bounds
return ([w[0],w[2],w[3]])==([m[0],m[2],m[3]])
示例14: setup
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)
示例15: _stagger
def _stagger(self):
key_win = application()._ns_key_window
if key_win:
(x, y), (w, h) = key_win._ns_window.frame()
p = self._ns_window.cascadeTopLeftFromPoint_(NSPoint(x, y + h))
self._ns_window.setFrameTopLeftPoint_(p)
else:
(x, y), (w, h) = NSScreen.mainScreen().visibleFrame()
ns_vis_topleft = NSPoint(x, y + h)
self._ns_window.setFrameTopLeftPoint_(ns_vis_topleft)