<commit_before># ogf4py3
# Copyright (C) 2017  <NAME> @cat_dotoscat

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.

# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from datetime import datetime
import pyglet
from pyglet.window import key
from pyglet.gl import glViewport, glOrtho, glMatrixMode, glLoadIdentity
from pyglet import gl

class Director(pyglet.window.Window):
    """A director manages scenes and have convenients methods such manipulate
    color background of the window or make screenshots.
    
    Parameters:
        vwidth (int or float): Virtual width.
        vheight (int or float): Virtual height.
        
    Returns:
        An instance of Director.
    """
    _director = None
    _scenes = {}

    @staticmethod
    def add_scene(key, scene):
        """Add an scene assigned to a key."""
        Director._scenes[key] = scene

    @staticmethod
    def set_scene(key):
        """Set the current scene by its key."""
        if Director.director is None: return
        Director._director.scene = Director._scenes[key]

    def __init__(self, *args, vwidth=None, vheight=None, **kwargs):
        super(Director, self).__init__(*args, **kwargs)
        self._vwidth = vwidth
        self._vheight = vheight
        self._scene = None
        Director._director = self

    def set_background_color(self, r, g, b):
        gl.glClearColor(r, g, b, 1.)

    @property
    def scene(self):
        """Set the current scene here."""
        return self._scene

    @scene.setter
    def scene(self, scene):
        if self._scene is not None:
            self.remove_handlers(self._scene)
            self._scene.quit()
            self._scene.director = None
            pyglet.clock.unschedule(self._scene.update)
        self._scene = scene
        self.push_handlers(scene)
        pyglet.clock.schedule(scene.update)
        scene.init()
        scene.director = self

    def get_virtual_xy(self, x, y):
        vx = x if self._vwidth is None else x/self.width*self._vwidth
        vy = y if self._vheight is None else y/self.height*self._vheight
        return vx, vy

    def on_key_press(self, symbol, modifiers):
        super(Director, self).on_key_press(symbol, modifiers)
        if symbol == key.F4:
            self.do_screenshot()

    def on_draw(self):
        self.clear()
        if self._scene is not None:<commit_msg>Set scene director before call init<commit_after># ogf4py3
# Copyright (C) 2017  <NAME> @cat_dotoscat

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.

# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from datetime import datetime
import pyglet
from pyglet.window import key
from pyglet.gl import glViewport, glOrtho, glMatrixMode, glLoadIdentity
from pyglet import gl

class Director(pyglet.window.Window):
    """A director manages scenes and have convenients methods such manipulate
    color background of the window or make screenshots.
    
    Parameters:
        vwidth (int or float): Virtual width.
        vheight (int or float): Virtual height.
        
    Returns:
        An instance of Director.
    """
    _director = None
    _scenes = {}

    @staticmethod
    def add_scene(key, scene):
        """Add an scene assigned to a key."""
        Director._scenes[key] = scene

    @staticmethod
    def set_scene(key):
        """Set the current scene by its key."""
        if Director.director is None: return
        Director._director.scene = Director._scenes[key]

    def __init__(self, *args, vwidth=None, vheight=None, **kwargs):
        super(Director, self).__init__(*args, **kwargs)
        self._vwidth = vwidth
        self._vheight = vheight
        self._scene = None
        Director._director = self

    def set_background_color(self, r, g, b):
        gl.glClearColor(r, g, b, 1.)

    @property
    def scene(self):
        """Set the current scene here."""
        return self._scene

    @scene.setter
    def scene(self, scene):
        if self._scene is not None:
            self.remove_handlers(self._scene)
            self._scene.quit()
            self._scene.director = None
            pyglet.clock.unschedule(self._scene.update)
        self._scene = scene
        self.push_handlers(scene)
        pyglet.clock.schedule(scene.update)
        scene.director = self
        scene.init()

    def get_virtual_xy(self, x, y):
        vx = x if self._vwidth is None else x/self.width*self._vwidth
        vy = y if self._vheight is None else y/self.height*self._vheight
        return vx, vy

    def on_key_press(self, symbol, modifiers):
        super(Director, self).on_key_press(symbol, modifiers)
        if symbol == key.F4:
            self.do_screenshot()

    def on_draw(self):
        self.clear()
        if self._scene is not None:
{'fraction_non_alphanumeric': 0.08523695874531197, 'fraction_numerical': 0.003068530514831231, 'mean_word_length': 2.666875, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2109006', 'n_tokens_mistral': 1698, 'n_tokens_neox': 1639, 'n_words': 604}