本文整理汇总了Python中pyglet.libs.darwin._oscheck函数的典型用法代码示例。如果您正苦于以下问题:Python _oscheck函数的具体用法?Python _oscheck怎么用?Python _oscheck使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_oscheck函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_device_interface
def _get_device_interface(self, generic_device):
plug_in_interface = \
ctypes.POINTER(ctypes.POINTER(IUnknown))()
score = ctypes.c_int32()
_oscheck(
carbon.IOCreatePlugInInterfaceForService(
generic_device,
kIOHIDDeviceUserClientTypeID,
kIOCFPlugInInterfaceID,
ctypes.byref(plug_in_interface),
ctypes.byref(score))
)
carbon.CFUUIDGetUUIDBytes.restype = CFUUIDBytes
hid_device_interface = \
ctypes.POINTER(ctypes.POINTER(IOHIDDeviceInterface))()
_oscheck(
plug_in_interface.contents.contents.QueryInterface(
plug_in_interface,
carbon.CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID),
ctypes.byref(hid_device_interface))
)
plug_in_interface.contents.contents.Release(plug_in_interface)
return hid_device_interface
示例2: open
def open(self, exclusive=False):
flags = 0
if exclusive:
flags |= kIOHIDOptionsTypeSeizeDevice
result = self._device.contents.contents.open(self._device, flags)
if result == 0:
self._open = True
elif result == kIOReturnExclusiveAccess:
raise input.InputDeviceExclusiveException()
# Create event queue
self._queue = self._device.contents.contents.allocQueue(self._device)
_oscheck(
self._queue.contents.contents.create(self._queue,
0, self._queue_depth)
)
# Add all elements into queue
# TODO: only "interesting/known" elements?
for element in self.elements:
r = self._queue.contents.contents.addElement(self._queue,
element._cookie, 0)
if r != 0:
print('error adding %r' % element)
_oscheck(
self._queue.contents.contents.start(self._queue)
)
# HACK TODO:
pyglet.clock.schedule(self.dispatch_events)
示例3: restore_mode
def restore_mode(self):
if self._initial_mode:
_oscheck(carbon.CGDisplaySwitchToMode(self.id,
self._initial_mode.mode))
self._initial_mode = None
if self._captured:
_oscheck(carbon.CGDisplayRelease(self.id))
self._captured = False
示例4: set_mode
def set_mode(self, mode):
assert mode.screen is self
if not self._initial_mode:
self._initial_mode = self.get_mode()
_oscheck(carbon.CGDisplayCapture(self.id))
_oscheck(carbon.CGDisplaySwitchToMode(self.id, mode.mode))
self.width = mode.width
self.height = mode.height
示例5: set_layout_attributes
def set_layout_attributes(layout, attributes):
if attributes:
# attributes is a dict of ATSUAttributeTag => ctypes value
tags, values = list(zip(*list(attributes.items())))
tags = (c_int * len(tags))(*tags)
sizes = (c_uint * len(values))(*[sizeof(v) for v in values])
values = (c_void_p * len(values))(*[cast(pointer(v), c_void_p) \
for v in values])
r = carbon.ATSUSetLayoutControls(layout, len(tags), tags, sizes, values)
_oscheck(r)
示例6: set_mode
def set_mode(self, mode):
if mode is not None:
assert mode.screen is self
if not self._initial_mode:
self._initial_mode = self.get_mode()
if not self._captured:
_oscheck(carbon.CGDisplayCapture(self.id))
self._captured = True
if mode is not None:
_oscheck(carbon.CGDisplaySwitchToMode(self.id, mode.mode))
self.width = mode.width
self.height = mode.height
示例7: get_matching_services
def get_matching_services(master_port, matching_dictionary):
# Consumes reference to matching_dictionary
iterator = io_iterator_t()
_oscheck(carbon.IOServiceGetMatchingServices(master_port, matching_dictionary, ctypes.byref(iterator)))
services = []
while carbon.IOIteratorIsValid(iterator):
service = carbon.IOIteratorNext(iterator)
if not service:
break
services.append(service)
carbon.IOObjectRelease(iterator)
return services
示例8: _init_properties
def _init_properties(self, generic_device):
properties = CFMutableDictionaryRef()
_oscheck(
carbon.IORegistryEntryCreateCFProperties(generic_device,
ctypes.byref(properties),
None, 0)
)
self.name = get_property(properties, "Product")
self.manufacturer = get_property(properties, "Manufacturer")
carbon.CFRelease(properties)
示例9: open
def open(self, window=None, exclusive=False):
super(DarwinHIDDevice, self).open(window, exclusive)
flags = 0
if exclusive:
flags |= kIOHIDOptionsTypeSeizeDevice
result = self._device.contents.contents.open(self._device, flags)
if result == 0:
self._open = True
elif result == kIOReturnExclusiveAccess:
raise DeviceExclusiveException()
# Create event queue
self._queue = self._device.contents.contents.allocQueue(self._device)
_oscheck(self._queue.contents.contents.create(self._queue, 0, self._queue_depth))
# Add all controls into queue
for control in self._controls:
r = self._queue.contents.contents.addElement(self._queue, control._cookie, 0)
if r != 0:
print "error adding %r" % control
self._event_source = CFRunLoopSourceRef()
self._queue_callback_func = IOHIDCallbackFunction(self._queue_callback)
_oscheck(self._queue.contents.contents.createAsyncEventSource(self._queue, ctypes.byref(self._event_source)))
_oscheck(self._queue.contents.contents.setEventCallout(self._queue, self._queue_callback_func, None, None))
event_loop = pyglet.app.platform_event_loop._event_loop
carbon.GetCFRunLoopFromEventLoop.restype = void_p
run_loop = carbon.GetCFRunLoopFromEventLoop(event_loop)
kCFRunLoopDefaultMode = CFStringRef.in_dll(carbon, "kCFRunLoopDefaultMode")
carbon.CFRunLoopAddSource(run_loop, self._event_source, kCFRunLoopDefaultMode)
_oscheck(self._queue.contents.contents.start(self._queue))
示例10: get_existing_devices
def get_existing_devices(master_port, matching_dictionary):
# Consumes reference to matching_dictionary
iterator = io_iterator_t()
_oscheck(
carbon.IOServiceGetMatchingServices(master_port,
matching_dictionary,
ctypes.byref(iterator))
)
devices = list()
while carbon.IOIteratorIsValid(iterator):
device = carbon.IOIteratorNext(iterator)
if not device:
break
devices.append(Device(device))
carbon.IOObjectRelease(iterator)
return devices
示例11: _tablet_event
def _tablet_event(self, next_handler, ev, data):
'''Process tablet event and return True if some event was processed.
Return True if no tablet event found.
'''
event_type = ctypes.c_uint32()
r = carbon.GetEventParameter(ev, kEventParamTabletEventType,
typeUInt32, None,
ctypes.sizeof(event_type), None,
ctypes.byref(event_type))
if r != noErr:
return False
if event_type.value == kEventTabletProximity:
proximity_rec = TabletProximityRec()
_oscheck(
carbon.GetEventParameter(ev, kEventParamTabletProximityRec,
typeTabletProximityRec, None,
ctypes.sizeof(proximity_rec), None,
ctypes.byref(proximity_rec))
)
cursor = self._get_cursor(proximity_rec)
if proximity_rec.enterProximity:
self.dispatch_event('on_enter', cursor)
else:
self.dispatch_event('on_leave', cursor)
elif event_type.value == kEventTabletPoint:
point_rec = TabletPointRec()
_oscheck(
carbon.GetEventParameter(ev, kEventParamTabletPointRec,
typeTabletPointRec, None,
ctypes.sizeof(point_rec), None,
ctypes.byref(point_rec))
)
#x = point_rec.absX
#y = point_rec.absY
x, y = self.window._get_mouse_position(ev)
pressure = point_rec.pressure / float(0xffff)
#point_rec.tiltX,
#point_rec.tiltY,
#point_rec.rotation,
#point_rec.tangentialPressure,
self.dispatch_event('on_motion', self._cursor, x, y, pressure,
0., 0.)
carbon.CallNextEventHandler(next_handler, ev)
return noErr
示例12: _init_controls
def _init_controls(self):
elements_array = CFArrayRef()
_oscheck(self._device.contents.contents.copyMatchingElements(self._device, None, ctypes.byref(elements_array)))
self._control_cookies = {}
controls = []
n_elements = carbon.CFArrayGetCount(elements_array)
for i in range(n_elements):
properties = carbon.CFArrayGetValueAtIndex(elements_array, i)
control = _create_control(properties)
if control:
controls.append(control)
self._control_cookies[control._cookie] = control
carbon.CFRelease(elements_array)
return controls
示例13: _get_elements
def _get_elements(self):
elements_array = CFArrayRef()
_oscheck(
self._device.contents.contents.copyMatchingElements(self._device,
None, ctypes.byref(elements_array))
)
self._element_cookies = {}
elements = []
n_elements = carbon.CFArrayGetCount(elements_array)
for i in range(n_elements):
properties = carbon.CFArrayGetValueAtIndex(elements_array, i)
element = DeviceElement(self, properties)
elements.append(element)
self._element_cookies[element._cookie] = element
carbon.CFRelease(elements_array)
return elements
示例14: _layout_callback
def _layout_callback(self, operation, line, ref, extra, callback_status):
if not line:
return 0
records = c_void_p()
n_records = c_uint()
r = carbon.ATSUDirectGetLayoutDataArrayPtrFromLineRef(line,
kATSUDirectDataLayoutRecordATSLayoutRecordVersion1,
0,
byref(records),
byref(n_records))
_oscheck(r)
records = cast(records,
POINTER(ATSLayoutRecord * n_records.value)).contents
self._glyph_advance = fix2float(records[-1].realPos)
callback_status.contents = kATSULayoutOperationCallbackStatusContinue
return 0
示例15: __init__
def __init__(self, display, generic_device):
super(DarwinHIDDevice, self).__init__(display, name=None)
self._device = self._get_device_interface(generic_device)
properties = CFMutableDictionaryRef()
_oscheck(carbon.IORegistryEntryCreateCFProperties(generic_device, ctypes.byref(properties), None, 0))
self.name = get_property(properties, "Product")
self.manufacturer = get_property(properties, "Manufacturer")
self.usage_page = get_property(properties, "PrimaryUsagePage")
self.usage = get_property(properties, "PrimaryUsage")
carbon.CFRelease(properties)
self._controls = self._init_controls()
self._open = False
self._queue = None
self._queue_depth = 8 # Number of events queue can buffer