# Path: tests/setup.py
# class TestPygletGUI(unittest.TestCase):
#     """
#     Default configuration of testing unit.
#     """
#     def setUp(self):
#         # define a theme
#         self.theme = pyglet_gui.theme.ThemeFromPath(os.path.join(sys.path[0], '../theme'))
# 
#         self.window = pyglet.window.Window(640, 480, resizable=True, vsync=True)
#         self.batch = pyglet.graphics.Batch()
# 
#         @self.window.event
#         def on_draw():
#             self.window.clear()
#             self.batch.draw()
# 
#     def tearDown(self):
#         self.window.close()
# 
# Path: pyglet_gui/manager.py
# class Manager(ViewerManager, ControllerManager):
#     def __init__(self,
#                  content,
#                  theme,
#                  window=None,
#                  batch=None,
#                  group=None,
#                  is_movable=True,
#                  anchor=ANCHOR_CENTER,
#                  offset=(0, 0)):
#         ControllerManager.__init__(self)
#         ViewerManager.__init__(self, content, theme, window, batch, group, anchor, offset)
# 
#         self.is_movable = is_movable
#         self._is_dragging = False
# 
#     def hit_test(self, x, y):
#         return self.is_inside(x, y)
# 
#     def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
#         if not ControllerManager.on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
#             if self.is_movable and self._is_dragging:
#                 x, y = self._offset
#                 self._offset = (int(x + dx), int(y + dy))
#                 self.set_position(*self.get_position())
#                 return True
# 
#     def on_mouse_motion(self, x, y, dx, dy):
#         ControllerManager.on_mouse_motion(self, x, y, dx, dy)
#         if self.hit_test(x, y):
#             if not self._root_group.is_on_top():
#                 self.pop_to_top()
#             return True
# 
#     def on_mouse_press(self, x, y, button, modifiers):
#         retval = ControllerManager.on_mouse_press(self, x, y, button, modifiers)
#         if self.hit_test(x, y):
#             if not retval:
#                 self._is_dragging = True
#                 retval = True
#         return retval
# 
#     def on_mouse_release(self, x, y, button, modifiers):
#         self._is_dragging = False
#         return ControllerManager.on_mouse_release(self, x, y, button, modifiers)
# 
#     def on_resize(self, width, height):
#         """
#         Update our knowledge of the window's width and height.
#         """
#         if self.screen.width != width or self.screen.height != height:
#             self.screen.width, self.screen.height = width, height
#             self.set_position(*self.get_position())
# 
#     def delete(self):
#         ViewerManager.delete(self)
#         ControllerManager.delete(self)
# 
# Path: pyglet_gui/core.py
# class Viewer(Rectangle, Managed):
#     def __init__(self, width=0, height=0):
#         super(Managed, self).__init__()
#         self._parent = None
#         self._is_loaded = False
# 
#         Rectangle.__init__(self, 0, 0, width, height)
# 
#     @property
#     def parent(self):
#         return self._parent
# 
#     @parent.setter
#     def parent(self, widget):
#         self._parent = widget
# 
#     @property
#     def is_loaded(self):
#         return self._is_loaded
# 
#     def is_expandable(self):
#         return False
# 
#     def set_position(self, x, y):
#         super(Viewer, self).set_position(x, y)
#         self.layout()
# 
#     def get_path(self):
#         raise NotImplementedError
# 
#     def load(self):
#         assert not self._is_loaded
#         self._is_loaded = True
#         self.load_graphics()
# 
#     def unload(self):
#         assert self._is_loaded
#         self._is_loaded = False
#         self.unload_graphics()
# 
#     def reload(self):
#         self.unload()
#         self.load()
# 
#     def load_graphics(self):
#         pass
# 
#     def unload_graphics(self):
#         pass
# 
#     def layout(self):
#         pass
# 
#     def compute_size(self):
#         return self.width, self.height
# 
#     def reset_size(self, reset_parent=True):
#         width, height = self.compute_size()
# 
#         # if out size changes
#         if self.width != width or self.height != height:
#             self.width, self.height = width, height
# 
#             # This will eventually call our layout
#             if reset_parent:
#                 self.parent.reset_size(reset_parent)
#         # else, the parent is never affected and thus we layout.
#         else:
#             self.layout()
# 
#     def delete(self):
#         if self.is_loaded:
#             self.unload()
#         self.parent = None
#         Managed.delete(self)


from .setup import TestPygletGUI
from pyglet_gui.manager import Manager
from pyglet_gui.core import Viewer
import pyglet_gui.constants
    import unittest
        according to the child size.
        """
        # manager size is correct
        self.assertEqual(self.manager.width, 50)
        self.assertEqual(self.manager.height, 50)

        # widget is centered in the window
        self.assertEqual(self.widget.x, self.window.width/2 - self.widget.width/2)
        self.assertEqual(self.widget.y, self.window.height/2 - self.widget.height/2)

    def test_bottom_up_draw(self):
        """
        Tests that the manager's size is modified
        if we set a new size to the widget.
        """
        self.widget.width = 60
        self.widget.parent.reset_size()

        # manager size was reset
        self.assertEqual(self.manager.width, self.widget.width)

        # widget and manager were re-centered in the window
        self.assertEqual(self.widget.x, self.window.width/2 - self.widget.width/2)
        self.assertEqual(self.manager.x, self.window.width/2 - self.manager.width/2)

    def test_substitute_widget(self):
        """
        Tests substitution of manager's content
        by other widget.
        """

# Path: tests/setup.py
# class TestPygletGUI(unittest.TestCase):
#     """
#     Default configuration of testing unit.
#     """
#     def setUp(self):
#         # define a theme
#         self.theme = pyglet_gui.theme.ThemeFromPath(os.path.join(sys.path[0], '../theme'))
# 
#         self.window = pyglet.window.Window(640, 480, resizable=True, vsync=True)
#         self.batch = pyglet.graphics.Batch()
# 
#         @self.window.event
#         def on_draw():
#             self.window.clear()
#             self.batch.draw()
# 
#     def tearDown(self):
#         self.window.close()
# 
# Path: pyglet_gui/manager.py
# class Manager(ViewerManager, ControllerManager):
#     def __init__(self,
#                  content,
#                  theme,
#                  window=None,
#                  batch=None,
#                  group=None,
#                  is_movable=True,
#                  anchor=ANCHOR_CENTER,
#                  offset=(0, 0)):
#         ControllerManager.__init__(self)
#         ViewerManager.__init__(self, content, theme, window, batch, group, anchor, offset)
# 
#         self.is_movable = is_movable
#         self._is_dragging = False
# 
#     def hit_test(self, x, y):
#         return self.is_inside(x, y)
# 
#     def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
#         if not ControllerManager.on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
#             if self.is_movable and self._is_dragging:
#                 x, y = self._offset
#                 self._offset = (int(x + dx), int(y + dy))
#                 self.set_position(*self.get_position())
#                 return True
# 
#     def on_mouse_motion(self, x, y, dx, dy):
#         ControllerManager.on_mouse_motion(self, x, y, dx, dy)
#         if self.hit_test(x, y):
#             if not self._root_group.is_on_top():
#                 self.pop_to_top()
#             return True
# 
#     def on_mouse_press(self, x, y, button, modifiers):
#         retval = ControllerManager.on_mouse_press(self, x, y, button, modifiers)
#         if self.hit_test(x, y):
#             if not retval:
#                 self._is_dragging = True
#                 retval = True
#         return retval
# 
#     def on_mouse_release(self, x, y, button, modifiers):
#         self._is_dragging = False
#         return ControllerManager.on_mouse_release(self, x, y, button, modifiers)
# 
#     def on_resize(self, width, height):
#         """
#         Update our knowledge of the window's width and height.
#         """
#         if self.screen.width != width or self.screen.height != height:
#             self.screen.width, self.screen.height = width, height
#             self.set_position(*self.get_position())
# 
#     def delete(self):
#         ViewerManager.delete(self)
#         ControllerManager.delete(self)
# 
# Path: pyglet_gui/core.py
# class Viewer(Rectangle, Managed):
#     def __init__(self, width=0, height=0):
#         super(Managed, self).__init__()
#         self._parent = None
#         self._is_loaded = False
# 
#         Rectangle.__init__(self, 0, 0, width, height)
# 
#     @property
#     def parent(self):
#         return self._parent
# 
#     @parent.setter
#     def parent(self, widget):
#         self._parent = widget
# 
#     @property
#     def is_loaded(self):
#         return self._is_loaded
# 
#     def is_expandable(self):
#         return False
# 
#     def set_position(self, x, y):
#         super(Viewer, self).set_position(x, y)
#         self.layout()
# 
#     def get_path(self):
#         raise NotImplementedError
# 
#     def load(self):
#         assert not self._is_loaded
#         self._is_loaded = True
#         self.load_graphics()
# 
#     def unload(self):
#         assert self._is_loaded
#         self._is_loaded = False
#         self.unload_graphics()
# 
#     def reload(self):
#         self.unload()
#         self.load()
# 
#     def load_graphics(self):
#         pass
# 
#     def unload_graphics(self):
#         pass
# 
#     def layout(self):
#         pass
# 
#     def compute_size(self):
#         return self.width, self.height
# 
#     def reset_size(self, reset_parent=True):
#         width, height = self.compute_size()
# 
#         # if out size changes
#         if self.width != width or self.height != height:
#             self.width, self.height = width, height
# 
#             # This will eventually call our layout
#             if reset_parent:
#                 self.parent.reset_size(reset_parent)
#         # else, the parent is never affected and thus we layout.
#         else:
#             self.layout()
# 
#     def delete(self):
#         if self.is_loaded:
#             self.unload()
#         self.parent = None
#         Managed.delete(self)


# Path: tests/test_dialog.py
from .setup import TestPygletGUI
from pyglet_gui.manager import Manager
from pyglet_gui.core import Viewer
import pyglet_gui.constants
    import unittest

        according to the child size.
        """
        # manager size is correct
        self.assertEqual(self.manager.width, 50)
        self.assertEqual(self.manager.height, 50)

        # widget is centered in the window
        self.assertEqual(self.widget.x, self.window.width/2 - self.widget.width/2)
        self.assertEqual(self.widget.y, self.window.height/2 - self.widget.height/2)

    def test_bottom_up_draw(self):
        """
        Tests that the manager's size is modified
        if we set a new size to the widget.
        """
        self.widget.width = 60
        self.widget.parent.reset_size()

        # manager size was reset
        self.assertEqual(self.manager.width, self.widget.width)

        # widget and manager were re-centered in the window
        self.assertEqual(self.widget.x, self.window.width/2 - self.widget.width/2)
        self.assertEqual(self.manager.x, self.window.width/2 - self.manager.width/2)

    def test_substitute_widget(self):
        """
        Tests substitution of manager's content
        by other widget.
        """

        self.new_widget = Viewer(width=60, height=50)