from __future__ import absolute_import
from traits.api import Any, Str, Float, Bool, Instance

# ============= standard library imports ========================
# ============= local library imports  ==========================
from pychron.graph.tools.info_inspector import InfoOverlay, InfoInspector


class ExtractionLineInfoTool(InfoInspector):
    active_item = Any
    scene = Any

    manager = Any
    name = Str
    volume = Float

    active = Bool(False)
    display_volume = Bool(False)
    volume_key = Str('v')

    def assemble_lines(self):
        return [self.name, 'volume= {}'.format(self.volume)]

    def normal_mouse_move(self, event):
        if self.active:
            x, y = event.x, event.y
            item = self.scene.get_is_in(x, y)
            if not item:
                self.active = False
                self.current_position = None
                self.metadata_changed = True

    def normal_key_pressed(self, event):
        ok = event.character == self.volume_key and not self.active
        if not self.manager:
            return

        if self.manager.use_network and ok:
            x, y = event.x, event.y
            self.current_screen = x, y
            item = self.scene.get_is_in(x, y)

            if item:
                self.current_position = x, y

                self.volume = self.manager.get_volume(item.name)
                self.name = item.name
                self.active = True
                self.metadata_changed = True


class ExtractionLineInfoOverlay(InfoOverlay):
    tool = Instance(ExtractionLineInfoTool)

# ============= EOF =============================================

