import weakref
import unittest
import pathlib
import omni.kit.test
import omni.ui as ui
import carb
from pathlib import Path
from pxr import Sdf, UsdShade, UsdGeom
from omni.ui.tests.test_base import OmniUiTest
from omni.kit import ui_test
from omni.kit.test_suite.helpers import (
    open_stage,
    get_test_data_path,
    arrange_windows,
    select_prims,
    wait_stage_loading,
    )


class TestMaterialThumb(OmniUiTest):
    async def setUp(self):
        await super().setUp()
        await open_stage(get_test_data_path(__name__, "thumbnail_test.usda"))
        await wait_stage_loading()

        from omni.kit.property.usd.usd_attribute_widget import UsdPropertiesWidget
        import omni.kit.window.property as p

        self._w = p.get_window()

    async def tearDown(self):
        await super().tearDown()
        await wait_stage_loading()

    async def test_material_thumb(self):
        stage = omni.usd.get_context().get_stage()

        golden_img_dir = pathlib.Path(get_test_data_path(__name__, "golden_img"))

        await self.docked_test_window(
            window=self._w._window,
            width=450,
            height=285,
            restore_window = ui.Workspace.get_window("Layer") or ui.Workspace.get_window("Stage"),
            restore_position = ui.DockPosition.BOTTOM)

        # select source prim
        await select_prims(["/World/Sphere"])
        await wait_stage_loading()
        await ui_test.human_delay(50)

        await self.finalize_test(golden_img_dir=golden_img_dir, golden_img_name="test_thumb_with_alpha.png")
        await select_prims([])
