# Path: PyOpenGLng/GlApi/ApiNumber.py
# class ApiNumber(object):
# 
#     """ This class implements a basic API number suitable for OpenGL.
# 
#     Use case::
# 
#       >>> api_number = ApiNumber('4.4')
#       >>> str(api_number)
#       '4.4'
#       >>> ApiNumber('4.0') < ApiNumber('4.1')
#       True
#       >>> ApiNumber('4.0') <= ApiNumber('4.0')
#       True
# 
#     """
# 
#     ##############################################
# 
#     def __init__(self, number):
# 
#         """ The argument *number* must be of the form "x.y". """
# 
#         try:
#             self.major, self.minor = [int(x) for x in number.split('.')]
#         except ValueError:
#             # self.major, self.minor = int(number), 0
#             raise NameError("Version number must be of the form x.y")
# 
#     ##############################################
# 
#     def __int__(self):
# 
#         return self.major * 1000 + self.minor
# 
#     ##############################################
# 
#     def __str__(self):
# 
#         return "%u.%u" % (self.major, self.minor)
# 
#     ##############################################
# 
#     def __le__(self, api_number):
# 
#         return int(self) <= int(api_number)
# 
#     ##############################################
# 
#     def __lt__(self, api_number):
# 
#         return int(self) < int(api_number)
# 
# Path: PyOpenGLng/Tools/Timer.py
# class TimerContextManager(object):
# 
#     ##############################################
# 
#     def __init__(self, logger, title):
# 
#         self._logger = logger
#         self._title = title
# 
#     ##############################################
# 
#     def __enter__(self):
# 
#         self._start = time.clock()
# 
#     ##############################################
#     
#     def __exit__(self, type_, value, traceback):
# 
#         dt = time.clock() - self._start
#         self._logger.info("{} dt = {} s".format(self._title, dt))


import logging
import sys
import PyGlfwCffi as glfw
import PyOpenGLng.Wrapper as GlWrapper
from PyOpenGLng.GlApi import ApiNumber
from PyOpenGLng.Tools.Timer import TimerContextManager


####################################################################################################

logging.basicConfig(
    format='\033[1;32m%(asctime)s\033[0m - \033[1;34m%(name)s.%(funcName)s\033[0m - \033[1;31m%(levelname)s\033[0m - %(message)s',
    level=logging.INFO,
)

####################################################################################################
#
# GLFW Callbacks
#

@glfw.key_callback
def on_key(window, key, scancode, action, mods):
    if key == glfw.KEY_ESCAPE and action == glfw.PRESS:
        glfw.set_window_should_close(window, 1)

def error_callback(error, description):
    raise NameError("{} {}".format(error, description))

####################################################################################################

# Initialize the GLFW library
if not glfw.init():
    sys.exit()
glfw.set_error_callback(error_callback)

# Create a windowed mode window and its OpenGL context

# Path: PyOpenGLng/GlApi/ApiNumber.py
# class ApiNumber(object):
# 
#     """ This class implements a basic API number suitable for OpenGL.
# 
#     Use case::
# 
#       >>> api_number = ApiNumber('4.4')
#       >>> str(api_number)
#       '4.4'
#       >>> ApiNumber('4.0') < ApiNumber('4.1')
#       True
#       >>> ApiNumber('4.0') <= ApiNumber('4.0')
#       True
# 
#     """
# 
#     ##############################################
# 
#     def __init__(self, number):
# 
#         """ The argument *number* must be of the form "x.y". """
# 
#         try:
#             self.major, self.minor = [int(x) for x in number.split('.')]
#         except ValueError:
#             # self.major, self.minor = int(number), 0
#             raise NameError("Version number must be of the form x.y")
# 
#     ##############################################
# 
#     def __int__(self):
# 
#         return self.major * 1000 + self.minor
# 
#     ##############################################
# 
#     def __str__(self):
# 
#         return "%u.%u" % (self.major, self.minor)
# 
#     ##############################################
# 
#     def __le__(self, api_number):
# 
#         return int(self) <= int(api_number)
# 
#     ##############################################
# 
#     def __lt__(self, api_number):
# 
#         return int(self) < int(api_number)
# 
# Path: PyOpenGLng/Tools/Timer.py
# class TimerContextManager(object):
# 
#     ##############################################
# 
#     def __init__(self, logger, title):
# 
#         self._logger = logger
#         self._title = title
# 
#     ##############################################
# 
#     def __enter__(self):
# 
#         self._start = time.clock()
# 
#     ##############################################
#     
#     def __exit__(self, type_, value, traceback):
# 
#         dt = time.clock() - self._start
#         self._logger.info("{} dt = {} s".format(self._title, dt))


# Path: examples/basic-wrapper-test.py
import logging
import sys
import PyGlfwCffi as glfw
import PyOpenGLng.Wrapper as GlWrapper
from PyOpenGLng.GlApi import ApiNumber
from PyOpenGLng.Tools.Timer import TimerContextManager



####################################################################################################

logging.basicConfig(
    format='\033[1;32m%(asctime)s\033[0m - \033[1;34m%(name)s.%(funcName)s\033[0m - \033[1;31m%(levelname)s\033[0m - %(message)s',
    level=logging.INFO,
)

####################################################################################################
#
# GLFW Callbacks
#

@glfw.key_callback
def on_key(window, key, scancode, action, mods):
    if key == glfw.KEY_ESCAPE and action == glfw.PRESS:
        glfw.set_window_should_close(window, 1)

def error_callback(error, description):
    raise NameError("{} {}".format(error, description))

####################################################################################################

# Initialize the GLFW library
if not glfw.init():
    sys.exit()
glfw.set_error_callback(error_callback)

# Create a windowed mode window and its OpenGL context

api_number = ApiNumber('2.1')