Coverage for pyPhotoAlbum/gl_imports.py: 12%
26 statements
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-20 12:55 +0000
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-20 12:55 +0000
1"""
2Centralized OpenGL imports for pyPhotoAlbum.
4Provides a single point of import for all OpenGL functions used throughout
5the application. This centralizes GL dependency management and provides
6graceful handling when OpenGL is not available (e.g., during testing).
8Usage:
9 from pyPhotoAlbum.gl_imports import glBegin, glEnd, GL_QUADS, GL_AVAILABLE
11 if GL_AVAILABLE:
12 # Safe to use GL functions
13 glBegin(GL_QUADS)
14 ...
15"""
17try:
18 from OpenGL.GL import (
19 # Drawing primitives
20 glBegin,
21 glEnd,
22 glVertex2f,
23 GL_QUADS,
24 GL_LINE_LOOP,
25 GL_LINE_STRIP,
26 GL_LINES,
27 GL_TRIANGLE_FAN,
28 # Colors
29 glColor3f,
30 glColor4f,
31 # Line state
32 glLineWidth,
33 glLineStipple,
34 GL_LINE_STIPPLE,
35 # General state
36 glEnable,
37 glDisable,
38 GL_DEPTH_TEST,
39 GL_BLEND,
40 GL_SRC_ALPHA,
41 GL_ONE_MINUS_SRC_ALPHA,
42 glBlendFunc,
43 # Textures
44 glGenTextures,
45 glBindTexture,
46 glTexImage2D,
47 glTexParameteri,
48 glDeleteTextures,
49 GL_TEXTURE_2D,
50 GL_RGBA,
51 GL_UNSIGNED_BYTE,
52 GL_TEXTURE_MIN_FILTER,
53 GL_TEXTURE_MAG_FILTER,
54 GL_LINEAR,
55 glTexCoord2f,
56 # Matrix operations
57 glPushMatrix,
58 glPopMatrix,
59 glScalef,
60 glTranslatef,
61 glLoadIdentity,
62 glRotatef,
63 # Clear operations
64 glClear,
65 glClearColor,
66 glFlush,
67 GL_COLOR_BUFFER_BIT,
68 GL_DEPTH_BUFFER_BIT,
69 # Viewport
70 glViewport,
71 glMatrixMode,
72 glOrtho,
73 GL_PROJECTION,
74 GL_MODELVIEW,
75 # Info/debug
76 glGetString,
77 GL_VERSION,
78 )
80 GL_AVAILABLE = True
82except ImportError:
83 GL_AVAILABLE = False
85 # Define dummy functions/constants for when OpenGL is not available
86 # This allows the code to be imported without OpenGL for testing
87 def _gl_stub(*args, **kwargs):
88 pass
90 glBegin = glEnd = glVertex2f = _gl_stub
91 glColor3f = glColor4f = _gl_stub
92 glLineWidth = glLineStipple = _gl_stub
93 glEnable = glDisable = glBlendFunc = _gl_stub
94 glGenTextures = glBindTexture = glTexImage2D = _gl_stub
95 glTexParameteri = glDeleteTextures = glTexCoord2f = _gl_stub
96 glPushMatrix = glPopMatrix = glScalef = glTranslatef = _gl_stub
97 glLoadIdentity = glRotatef = _gl_stub
98 glClear = glClearColor = glFlush = _gl_stub
99 glViewport = glMatrixMode = glOrtho = _gl_stub
100 glGetString = _gl_stub
102 # Constants
103 GL_QUADS = GL_LINE_LOOP = GL_LINE_STRIP = GL_LINES = GL_TRIANGLE_FAN = 0
104 GL_LINE_STIPPLE = GL_DEPTH_TEST = GL_BLEND = 0
105 GL_SRC_ALPHA = GL_ONE_MINUS_SRC_ALPHA = 0
106 GL_TEXTURE_2D = GL_RGBA = GL_UNSIGNED_BYTE = 0
107 GL_TEXTURE_MIN_FILTER = GL_TEXTURE_MAG_FILTER = GL_LINEAR = 0
108 GL_COLOR_BUFFER_BIT = GL_DEPTH_BUFFER_BIT = 0
109 GL_PROJECTION = GL_MODELVIEW = 0
110 GL_VERSION = 0