File: _lookupint.py

package info (click to toggle)
pyopengl 3.1.10%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,024 kB
  • sloc: python: 108,056; sh: 13; makefile: 8
file content (48 lines) | stat: -rw-r--r-- 1,084 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""Integer values looked up via glGetIntegerv( constant )"""

import ctypes

_get = None
_get_float = None


class LookupInt(object):
    def __init__(self, lookup, format=ctypes.c_int, calculation=None):
        self.lookup = lookup
        self.format = format
        self.calculation = calculation

    def __int__(self):
        global _get
        if _get is None:
            from OpenGL.GL import glGetIntegerv

            _get = glGetIntegerv
        output = self.format()
        _get(self.lookup, output)
        if self.calculation:
            return self.calculation(output.value)
        return output.value

    __long__ = __int__

    def __eq__(self, other):
        return int(self) == other

    def __cmp__(self, other):
        test = int(self)
        return (test > other) - (test < other)

    def __lt__(self, other):
        return int(self) < other

    def __gt__(self, other):
        return int(self) > other

    def __eq__(self, other):
        return int(self) == other

    def __str__(self):
        return str(int(self))

    __repr__ = __str__