def get_extensions(self): if not gl_info.have_context(): warnings.warn("Can't query WGL until a context is created.") return [] try: return asstr(wglGetExtensionsStringEXT()).split() except MissingFunctionException: return asstr(cast(glGetString(GL_EXTENSIONS), c_char_p).value).split()
def set_active_context(self): """Store information for the currently active context. This method is called automatically for the default context. """ self.have_context = True if not self._have_info: self.extensions = asstr(cast(gluGetString(GLU_EXTENSIONS), c_char_p).value).split() self.version = asstr(cast(gluGetString(GLU_VERSION), c_char_p).value) self._have_info = True
def ffmpeg_file_info(file): """Get information on the file: - number of streams - duration - artist - album - date - track :rtype: FileInfo :return: The file info instance containing all the meta information. """ info = FileInfo() info.n_streams = file.context.contents.nb_streams info.start_time = file.context.contents.start_time info.duration = file.context.contents.duration entry = avutil.av_dict_get(file.context.contents.metadata, asbytes('title'), None, 0) if entry: info.title = asstr(entry.contents.value) entry = avutil.av_dict_get(file.context.contents.metadata, asbytes('artist'), None, 0) \ or \ avutil.av_dict_get(file.context.contents.metadata, asbytes('album_artist'), None, 0) if entry: info.author = asstr(entry.contents.value) entry = avutil.av_dict_get(file.context.contents.metadata, asbytes('copyright'), None, 0) if entry: info.copyright = asstr(entry.contents.value) entry = avutil.av_dict_get(file.context.contents.metadata, asbytes('comment'), None, 0) if entry: info.comment = asstr(entry.contents.value) entry = avutil.av_dict_get(file.context.contents.metadata, asbytes('album'), None, 0) if entry: info.album = asstr(entry.contents.value) entry = avutil.av_dict_get(file.context.contents.metadata, asbytes('date'), None, 0) if entry: info.year = asstr(entry.contents.value) entry = avutil.av_dict_get(file.context.contents.metadata, asbytes('track'), None, 0) if entry: info.track = asstr(entry.contents.value) entry = avutil.av_dict_get(file.context.contents.metadata, asbytes('genre'), None, 0) if entry: info.genre = asstr(entry.contents.value) return info
def _get_string(self, name): value = self._get_value(name) if value and value.type == FcTypeString: return asstr(value.u.s) else: return None
def __init__(self, display, device_info): super(XInputDevice, self).__init__(display, asstr(device_info.name)) self._device_id = device_info.id self._device = None # Read device info self.buttons = [] self.keys = [] self.axes = [] ptr = device_info.inputclassinfo for i in range(device_info.num_classes): cp = ctypes.cast(ptr, ctypes.POINTER(xi.XAnyClassInfo)) cls_class = getattr(cp.contents, 'class') if cls_class == xi.KeyClass: cp = ctypes.cast(ptr, ctypes.POINTER(xi.XKeyInfo)) self.min_keycode = cp.contents.min_keycode num_keys = cp.contents.num_keys for i in range(num_keys): self.keys.append(Button('key%d' % i)) elif cls_class == xi.ButtonClass: cp = ctypes.cast(ptr, ctypes.POINTER(xi.XButtonInfo)) num_buttons = cp.contents.num_buttons # Pointer buttons start at index 1, with 0 as 'AnyButton' for i in range(num_buttons + 1): self.buttons.append(Button('button%d' % i)) elif cls_class == xi.ValuatorClass: cp = ctypes.cast(ptr, ctypes.POINTER(xi.XValuatorInfo)) num_axes = cp.contents.num_axes mode = cp.contents.mode axes = ctypes.cast(cp.contents.axes, ctypes.POINTER(xi.XAxisInfo)) for i in range(num_axes): axis = axes[i] if mode == xi.Absolute: self.axes.append( AbsoluteAxis('axis%d' % i, min=axis.min_value, max=axis.max_value)) elif mode == xi.Relative: self.axes.append(RelativeAxis('axis%d' % i)) cls = cp.contents ptr = ptr_add(ptr, cls.length) self.controls = self.buttons + self.keys + self.axes # Can't detect proximity class event without opening device. Just # assume there is the possibility of a control if there are any axes. if self.axes: self.proximity_control = Button('proximity') self.controls.append(self.proximity_control) else: self.proximity_control = None
def set_active_context(self): """Store information for the currently active context. This method is called automatically for the default context. """ from pyglet.gl.gl import GLint, glGetIntegerv, glGetString, glGetStringi, GL_NUM_EXTENSIONS self.have_context = True if not self._have_info: self.vendor = asstr(cast(glGetString(GL_VENDOR), c_char_p).value) self.renderer = asstr( cast(glGetString(GL_RENDERER), c_char_p).value) self.version = asstr(cast(glGetString(GL_VERSION), c_char_p).value) num_extensions = GLint() glGetIntegerv(GL_NUM_EXTENSIONS, num_extensions) self.extensions = (asstr( cast(glGetStringi(GL_EXTENSIONS, i), c_char_p).value) for i in range(num_extensions.value)) self.extensions = set(self.extensions) self._have_info = True
def parse_obj_file(filename, file=None): materials = {} mesh_list = [] location = os.path.dirname(filename) try: if file is None: with open(filename, 'r') as f: file_contents = f.read() else: file_contents = asstr(file.read()) except (UnicodeDecodeError, OSError): raise ModelDecodeException material = None mesh = None vertices = [[0., 0., 0.]] normals = [[0., 0., 0.]] tex_coords = [[0., 0.]] diffuse = [1.0, 1.0, 1.0, 1.0] ambient = [1.0, 1.0, 1.0, 1.0] specular = [1.0, 1.0, 1.0, 1.0] emission = [0.0, 0.0, 0.0, 1.0] shininess = 100.0 default_material = Material("Default", diffuse, ambient, specular, emission, shininess) for line in file_contents.splitlines(): if line.startswith('#'): continue values = line.split() if not values: continue if values[0] == 'v': vertices.append(list(map(float, values[1:4]))) elif values[0] == 'vn': normals.append(list(map(float, values[1:4]))) elif values[0] == 'vt': tex_coords.append(list(map(float, values[1:3]))) elif values[0] == 'mtllib': material_abspath = os.path.join(location, values[1]) materials = load_material_library(filename=material_abspath) elif values[0] in ('usemtl', 'usemat'): material = materials.get(values[1]) if mesh is not None: mesh.material = material elif values[0] == 'o': mesh = Mesh(name=values[1]) mesh_list.append(mesh) elif values[0] == 'f': if mesh is None: mesh = Mesh(name='') mesh_list.append(mesh) if material is None: material = default_material if mesh.material is None: mesh.material = material # For fan triangulation, remember first and latest vertices n1 = None nlast = None t1 = None tlast = None v1 = None vlast = None for i, v in enumerate(values[1:]): v_i, t_i, n_i = (list(map(int, [j or 0 for j in v.split('/')])) + [0, 0])[:3] if v_i < 0: v_i += len(vertices) - 1 if t_i < 0: t_i += len(tex_coords) - 1 if n_i < 0: n_i += len(normals) - 1 mesh.normals += normals[n_i] mesh.tex_coords += tex_coords[t_i] mesh.vertices += vertices[v_i] if i >= 3: # Triangulate mesh.normals += n1 + nlast mesh.tex_coords += t1 + tlast mesh.vertices += v1 + vlast if i == 0: n1 = normals[n_i] t1 = tex_coords[t_i] v1 = vertices[v_i] nlast = normals[n_i] tlast = tex_coords[t_i] vlast = vertices[v_i] return mesh_list
def family_name(self): return asstr(self.ft_face.contents.family_name)
def _get_best_name(self): self._name = asstr(self.ft_face.contents.family_name) self._get_font_family_from_ttf
def get_server_vendor(self): self.check_display() return asstr(glXQueryServerString(self.display, 0, GLX_VENDOR))
def get_extensions(self): self.check_display() return asstr(glXQueryExtensionsString(self.display, 0)).split()
def get_client_extensions(self): self.check_display() return asstr(glXGetClientString(self.display, GLX_EXTENSIONS)).split()
def get_client_version(self): self.check_display() return asstr(glXGetClientString(self.display, GLX_VERSION))
def get_client_vendor(self): self.check_display() return asstr(glXGetClientString(self.display, GLX_VENDOR))
def get_server_extensions(self): self.check_display() return asstr(glXQueryServerString(self.display, 0, GLX_EXTENSIONS)).split()