Skip to content

Commit

Permalink
Merge remote-tracking branch 'pl/develop' into macOS_bigsur_compat
Browse files Browse the repository at this point in the history
  • Loading branch information
papr committed Jan 20, 2021
2 parents a349031 + 341c376 commit c286e2f
Show file tree
Hide file tree
Showing 24 changed files with 131 additions and 46 deletions.
6 changes: 4 additions & 2 deletions pupil_src/launchables/eye.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,9 @@ def eye(

# display
import glfw
from gl_utils import GLFWErrorReporting

glfw.ERROR_REPORTING = "raise"
GLFWErrorReporting.set_default()

from pyglui import ui, graph, cygl
from pyglui.cygl.utils import draw_points, RGBA, draw_polyline
Expand Down Expand Up @@ -432,7 +433,8 @@ def toggle_general_settings(collapsed):
general_settings.collapsed = collapsed

# Initialize glfw
glfw.init()
with GLFWErrorReporting.glfw_init():
glfw.init()
glfw.window_hint(glfw.SCALE_TO_MONITOR, glfw.TRUE)
if hide_ui:
glfw.window_hint(glfw.VISIBLE, 0) # hide window
Expand Down
13 changes: 8 additions & 5 deletions pupil_src/launchables/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ def player(

# display
import glfw
from gl_utils import GLFWErrorReporting

glfw.ERROR_REPORTING = "raise"
GLFWErrorReporting.set_default()

# check versions for our own depedencies as they are fast-changing
from pyglui import __version__ as pyglui_version
Expand Down Expand Up @@ -371,10 +372,10 @@ def get_dt():

window_name = f"Pupil Player: {meta_info.recording_name} - {rec_dir}"

glfw.init()
with GLFWErrorReporting.glfw_init():
glfw.init()
glfw.window_hint(glfw.SCALE_TO_MONITOR, glfw.TRUE)
main_window = glfw.create_window(width, height, window_name, None, None)

window_position_manager = gl_utils.WindowPositionManager()
window_pos = window_position_manager.new_window_position(
window=main_window,
Expand Down Expand Up @@ -808,8 +809,9 @@ def player_drop(

try:
import glfw
from gl_utils import GLFWErrorReporting

glfw.ERROR_REPORTING = "raise"
GLFWErrorReporting.set_default()

import gl_utils
from OpenGL.GL import glClearColor
Expand Down Expand Up @@ -857,7 +859,8 @@ def on_drop(window, paths):
session_settings.clear()
w, h = session_settings.get("window_size", (1280, 720))

glfw.init()
with GLFWErrorReporting.glfw_init():
glfw.init()
glfw.window_hint(glfw.SCALE_TO_MONITOR, glfw.TRUE)
glfw.window_hint(glfw.RESIZABLE, 0)
window = glfw.create_window(w, h, "Pupil Player", None, None)
Expand Down
6 changes: 4 additions & 2 deletions pupil_src/launchables/world.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ def detection_enabled_setter(is_on: bool):

# display
import glfw
from gl_utils import GLFWErrorReporting

glfw.ERROR_REPORTING = "raise"
GLFWErrorReporting.set_default()

from version_utils import parse_version
from pyglui import ui, cygl, __version__ as pyglui_version
Expand Down Expand Up @@ -525,7 +526,8 @@ def handle_notifications(noti):
)

# window and gl setup
glfw.init()
with GLFWErrorReporting.glfw_init():
glfw.init()
glfw.window_hint(glfw.SCALE_TO_MONITOR, glfw.TRUE)
if hide_ui:
glfw.window_hint(glfw.VISIBLE, 0) # hide window
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
import typing as T

import glfw
from gl_utils import GLFWErrorReporting

glfw.ERROR_REPORTING = "raise"
GLFWErrorReporting.set_default()

try:
from typing import OrderedDict as T_OrderedDict # Python 3.7.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

import OpenGL.GL as gl
import glfw

glfw.ERROR_REPORTING = "raise"

import gl_utils
from gl_utils import GLFWErrorReporting

GLFWErrorReporting.set_default()

from pyglui.cygl.utils import draw_polyline

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
import numpy as np

import glfw
from gl_utils import GLFWErrorReporting

glfw.ERROR_REPORTING = "raise"
GLFWErrorReporting.set_default()

from methods import normalize
from pyglui import ui
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
import OpenGL.GL as gl

import glfw
from gl_utils import GLFWErrorReporting

glfw.ERROR_REPORTING = "raise"
GLFWErrorReporting.set_default()

from circle_detector import CircleTracker
from platform import system
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
import OpenGL.GL as gl

import glfw
from gl_utils import GLFWErrorReporting

glfw.ERROR_REPORTING = "raise"
GLFWErrorReporting.set_default()

from .mixin import MonitorSelectionMixin
from .controller import (
Expand Down
6 changes: 3 additions & 3 deletions pupil_src/shared_modules/camera_intrinsics_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
from pyglui.ui import get_opensans_font_path

import glfw

glfw.ERROR_REPORTING = "raise"

import gl_utils
from gl_utils import GLFWErrorReporting

GLFWErrorReporting.set_default()

from plugin import Plugin

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
import numpy as np

import glfw
from gl_utils import GLFWErrorReporting

glfw.ERROR_REPORTING = "raise"
GLFWErrorReporting.set_default()

import tasklib
from gaze_producer import model, worker
Expand Down
1 change: 1 addition & 0 deletions pupil_src/shared_modules/gl_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
make_coord_system_norm_based,
make_coord_system_pixel_based,
window_coordinate_to_framebuffer_coordinate,
GLFWErrorReporting,
)
from .window_position_manager import WindowPositionManager
61 changes: 59 additions & 2 deletions pupil_src/shared_modules/gl_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
See COPYING and COPYING.LESSER for license details.
---------------------------------------------------------------------------~(*)
"""
import contextlib
import logging
import math
import typing as T
Expand Down Expand Up @@ -41,8 +42,6 @@
)
from OpenGL.GLU import gluErrorString, gluPerspective

glfw.ERROR_REPORTING = "raise"

# OpenGL.FULL_LOGGING = True
OpenGL.ERROR_LOGGING = False

Expand Down Expand Up @@ -330,3 +329,61 @@ def get_window_title_bar_rect(window) -> _Rectangle:
return _Rectangle(
x=frame_rect.x, y=frame_rect.y, width=frame_rect.width, height=frame_edges.top
)


_GLFWErrorReportingDict = T.Dict[T.Union[None, int], str]


class GLFWErrorReporting:
@classmethod
@contextlib.contextmanager
def glfw_init(cls):
ignore = [
# GLFWError: (65544) b'Cocoa: Failed to find service port for display'
# This happens on macOS Big Sur running on Apple Silicone hardware
65544,
]
with cls.error_code_handling(ignore=tuple(ignore)):
yield

@classmethod
@contextlib.contextmanager
def error_code_handling(
cls,
*_,
ignore: T.Optional[T.Tuple[int]] = None,
debug: T.Optional[T.Tuple[int]] = None,
warn: T.Optional[T.Tuple[int]] = None,
raise_: T.Optional[T.Tuple[int]] = None,
):
old_reporting = glfw.ERROR_REPORTING

if isinstance(old_reporting, dict):
new_reporting: _GLFWErrorReportingDict = dict(old_reporting)
else:
new_reporting = cls.__default_error_reporting()

new_reporting.update({err_code: "ignore" for err_code in ignore or ()})
new_reporting.update({err_code: "log" for err_code in debug or ()})
new_reporting.update({err_code: "warn" for err_code in warn or ()})
new_reporting.update({err_code: "raise" for err_code in raise_ or ()})

glfw.ERROR_REPORTING = new_reporting

try:
yield
finally:
glfw.ERROR_REPORTING = old_reporting

@classmethod
def set_default(cls):
glfw.ERROR_REPORTING = cls.__default_error_reporting()

### Private

@staticmethod
def __default_error_reporting() -> _GLFWErrorReportingDict:
return {None: "raise"}


GLFWErrorReporting.set_default()
6 changes: 3 additions & 3 deletions pupil_src/shared_modules/gl_utils/window_position_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
import typing as T

import glfw

glfw.ERROR_REPORTING = "raise"

import gl_utils
from .utils import GLFWErrorReporting

GLFWErrorReporting.set_default()


class WindowPositionManager:
Expand Down
6 changes: 4 additions & 2 deletions pupil_src/shared_modules/head_pose_tracker/ui/gl_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

import gl_utils
import glfw
from gl_utils import GLFWErrorReporting

glfw.ERROR_REPORTING = "raise"
GLFWErrorReporting.set_default()

from observable import Observable

Expand Down Expand Up @@ -64,7 +65,8 @@ def _init_trackball():
return trackball

def _glfw_init(self):
glfw.init()
with GLFWErrorReporting.glfw_init():
glfw.init()
glfw.window_hint(glfw.SCALE_TO_MONITOR, glfw.TRUE)
window = glfw.create_window(
640,
Expand Down
6 changes: 3 additions & 3 deletions pupil_src/shared_modules/log_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
from pyglui.pyfontstash import fontstash
from pyglui.ui import get_opensans_font_path
import glfw

glfw.ERROR_REPORTING = "raise"

import gl_utils
from gl_utils import GLFWErrorReporting

GLFWErrorReporting.set_default()


def color_from_level(lvl):
Expand Down
3 changes: 2 additions & 1 deletion pupil_src/shared_modules/marker_auto_trim_marks.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
)

import glfw
from gl_utils import GLFWErrorReporting

glfw.ERROR_REPORTING = "raise"
GLFWErrorReporting.set_default()

import numpy as np
from itertools import groupby
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@

import glfw

glfw.ERROR_REPORTING = "raise"

from gl_utils import (
adjust_gl_view,
basic_gl_setup,
clear_gl_screen,
make_coord_system_norm_based,
make_coord_system_pixel_based,
GLFWErrorReporting,
)

GLFWErrorReporting.set_default()

from methods import normalize
from plugin import Plugin

Expand Down
3 changes: 2 additions & 1 deletion pupil_src/shared_modules/roi.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
from pyglui.cygl.utils import draw_polyline as cygl_draw_polyline

import glfw
from gl_utils import GLFWErrorReporting

glfw.ERROR_REPORTING = "raise"
GLFWErrorReporting.set_default()

from methods import denormalize, normalize
from observable import Observable
Expand Down
9 changes: 6 additions & 3 deletions pupil_src/shared_modules/service_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
from OpenGL.GL import GL_COLOR_BUFFER_BIT

import glfw
import gl_utils
from gl_utils import GLFWErrorReporting

glfw.ERROR_REPORTING = "raise"
GLFWErrorReporting.set_default()

import gl_utils
from pyglui import ui, cygl
from plugin import System_Plugin_Base

Expand Down Expand Up @@ -53,10 +54,12 @@ def __init__(

self.texture = np.zeros((1, 1, 3), dtype=np.uint8) + 128

glfw.init()
with GLFWErrorReporting.glfw_init():
glfw.init()
glfw.window_hint(glfw.SCALE_TO_MONITOR, glfw.TRUE)
if g_pool.hide_ui:
glfw.window_hint(glfw.VISIBLE, 0) # hide window

main_window = glfw.create_window(*window_size, "Pupil Service", None, None)

window_position_manager = gl_utils.WindowPositionManager()
Expand Down
3 changes: 2 additions & 1 deletion pupil_src/shared_modules/surface_tracker/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@

import gl_utils
import glfw
from gl_utils import GLFWErrorReporting

glfw.ERROR_REPORTING = "raise"
GLFWErrorReporting.set_default()

from .surface_marker import Surface_Marker_Type

Expand Down
5 changes: 3 additions & 2 deletions pupil_src/shared_modules/system_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
import os
import psutil
import glfw
import gl_utils
from gl_utils import GLFWErrorReporting

glfw.ERROR_REPORTING = "raise"
GLFWErrorReporting.set_default()

import gl_utils
from pyglui import ui, graph
from pyglui.cygl.utils import RGBA, mix_smooth
from plugin import System_Plugin_Base
Expand Down
Loading

0 comments on commit c286e2f

Please sign in to comment.