Source code for picogl.ui.abc_window

"""
ABC Window
"""

from abc import ABC, abstractmethod
from typing import Optional

from OpenGL.GLUT import glutMainLoop, glutSwapBuffers


[docs] class AbstractGLWindow(ABC): """ A strict ABC base class for a GLUT/OpenGL window. Subclasses must implement: - initializeGL - paintGL - resizeGL - on_keyboard - on_special_key - on_mouse - on_mousemove """
[docs] def __init__( self, width: int = 800, height: int = 480, title: bytes = b"GL Window" ):
[docs] self.controller: Optional[object] = None
[docs] self.width = width
[docs] self.height = height
[docs] self.window = None
[docs] self.title = title
@abstractmethod
[docs] def initializeGL(self) -> None: """Set up OpenGL state. Must be implemented by subclass."""
@abstractmethod
[docs] def paintGL(self) -> None: """Render the scene. Must be implemented by subclass."""
@abstractmethod
[docs] def resizeGL(self, width: int, height: int) -> None: """Handle window resize. Must be implemented by subclass."""
[docs] def display(self) -> None: """Default display path calls paintGL, then swaps buffers""" self.paintGL() glutSwapBuffers()
[docs] def idle(self) -> None: """Optional idle hook (override if needed)."""
@abstractmethod
[docs] def keyPressEvent(self, key, x, y) -> None: """Handle ASCII keyboard input. Must be implemented by subclass."""
@abstractmethod
[docs] def on_special_key(self, key, x, y) -> None: """Handle special keys (arrows, function keys). Must be implemented by subclass."""
@abstractmethod
[docs] def mousePressEvent(self, *args, **kwargs) -> None: """Handle mouse button events. Must be implemented by subclass."""
@abstractmethod
[docs] def mouseMoveEvent(self, *args, **kwargs) -> None: """Handle mouse movement events. Must be implemented by subclass."""
[docs] def run(self) -> None: glutMainLoop()