import os, sys
parentPath = os.path.abspath("../")
if parentPath not in sys.path:
	sys.path.insert(0, parentPath)
from asciimatics.widgets import *

from gui.utils.widget import CustomFileBrowser
from tag_controller import getTagFromPath
from gui.dialog import ADD_END
from gui.utils.utils import ColorTheme, getColor, getAttr
from gui.utils.widget import CustomText, TextView

CONTROL_INFO = """
<q> <Q> - quit
<i>     - information

"""

CLOCK_INFO = """
CLOCK WINDOW
<space> - on/off seconds in clock

"""

PLAYER_CONTROL_INFO = """
PLAYER CONTROL

<p> - play/pause
<S> - stop
<>> - next song
<<> - previously song
<.> - move ->
<,> - move <-
<-> - volume down
<=> - volume up
<v> - mute
<b> - play mode
<c> - crossfade

"""


MAINPLAYLIST_INFO = """
MAIN PLAYLIST

<Enter> <e> - play song
<j> <k>     - swich song
<d>         - delete song from playlist
<E>         - open menu to add song in any playlist

"""

PLAYLISTS_INFO = """
PLAYLISTS

<e>     - add song to main playlist
<E>     - open menu to add song in any playlist
<l>     - load song from Sound cloud and add to main playlist
<L>     - open menu to load song from Sound cloud
<d>     - delete playlist or song from playlist
<j> <k> - swich songs in playlist
<Enter> - play song

"""

BROWSER_INFO = """
BROWSER

<e>     - add song to main playlist
<E>     - open menu to add song in any playlist

"""

EQUALIZER_INFO = """
EQUALIZER

<Right> <Left> - bar control

"""

MEDIALIB_INFO = """
MEDIA LIBRARY

<e>     - add song to main playlist
<E>     - open menu to add song in any local playlist
<Enter> - play song

"""

SEARCH_INFO = """
SEARCH

<e>     - add song to main playlist
<E>     - open menu to add song in any local playlist
<f>     - like song from Sound cloud
<l>     - load song from Sound cloud and add to main playlist
<L>     - open menu to load song from Sound cloud
<Enter> - play song

"""

VIZUALIZER_INFO = """
VIZUALIZER

<space> - change vizualization

"""


class InfoDialog(Frame):
	def __init__(self, screen, text, buttons, config, has_shadow=False,
			win=""):

		self._buttons = buttons
		width = screen.width // 2
		self._message = text
		height = 17
		self.win = win
		# Construct the Frame
		self._data = {"message": self._message}
		super(InfoDialog, self).__init__(
			screen, height, width, self._data, has_shadow=has_shadow, is_modal=True)

		# Build up the message box
		layout = Layout([100], fill_frame=True)
		self.add_layout(layout)
		
		#TITLE
		_h = height - 4
		if self._message != "":
			layout.add_widget(Label(self._message))
			layout.add_widget(Divider())
			_h -= 2

		c = config.dialog.color.split(':')
		tcolor = ColorTheme(getColor(c[0]), getAttr(c[1]), getColor(c[2]))
		self.text = TextView(_h, tcolor, name="info")
		self.text._w = screen.width // 2
		self.text._h = _h
		layout.add_widget(self.text)
		layout.add_widget(Divider())
		self.setText()

		layoutBtns = Layout([1 for _ in buttons])
		self.add_layout(layoutBtns)
		for i, button in enumerate(buttons):
			func = partial(self._destroy, i)
			layoutBtns.add_widget(Button(button, func), i)
		self.fix()

	def _destroy(self, selected):
		self._scene.remove_effect(self)
	
	textInfo = {
		'Clock': CLOCK_INFO,
		'Browser': BROWSER_INFO,
		'ArtistInfo': '',
		'Equalizer': EQUALIZER_INFO,
		'Lyrics': '',
		'MainPlaylist': MAINPLAYLIST_INFO,
		'Medialib': MEDIALIB_INFO,
		'Playlists': PLAYLISTS_INFO,
		'Search': SEARCH_INFO,
		'Visualizer': VIZUALIZER_INFO
	}

	def setText(self):
		text = CONTROL_INFO + PLAYER_CONTROL_INFO
		text += self.textInfo[self.win]
		self.text.setText(text)
import os, sys
parentPath = os.path.abspath("../")
if parentPath not in sys.path:
	sys.path.insert(0, parentPath)
from asciimatics.widgets import *

from gui.utils.widget import CustomFileBrowser
from tag_controller import getTagFromPath
from gui.dialog import ADD_END
from gui.utils.utils import ColorTheme, getColor, getAttr
from gui.utils.widget import CustomText, TextView

CONTROL_INFO = """
<q> <Q> - quit
<i>     - information

"""

CLOCK_INFO = """
CLOCK WINDOW
<space> - on/off seconds in clock

"""

PLAYER_CONTROL_INFO = """
PLAYER CONTROL

<p> - play/pause
<S> - stop
<>> - next song
<<> - previously song
<.> - move ->
<,> - move <-
<-> - volume down
<=> - volume up
<v> - mute
<b> - play mode
<c> - crossfade

"""


MAINPLAYLIST_INFO = """
MAIN PLAYLIST

<Enter> <e> - play song
<j> <k>     - swich song
<d>         - delete song from playlist
<E>         - open menu to add song in any playlist

"""

PLAYLISTS_INFO = """
PLAYLISTS

<e>     - add song to main playlist
<E>     - open menu to add song in any playlist
<l>     - load song from Sound cloud and add to main playlist
<L>     - open menu to load song from Sound cloud
<d>     - delete playlist or song from playlist
<j> <k> - swich songs in playlist
<Enter> - play song

"""

BROWSER_INFO = """
BROWSER

<e>     - add song to main playlist
<E>     - open menu to add song in any playlist

"""

EQUALIZER_INFO = """
EQUALIZER

<Right> <Left> - bar control

"""

MEDIALIB_INFO = """
MEDIA LIBRARY

<e>     - add song to main playlist
<E>     - open menu to add song in any local playlist
<Enter> - play song

"""

SEARCH_INFO = """
SEARCH

<e>     - add song to main playlist
<E>     - open menu to add song in any local playlist
<f>     - like song from Sound cloud
<l>     - load song from Sound cloud and add to main playlist
<L>     - open menu to load song from Sound cloud
<Enter> - play song

"""

VIZUALIZER_INFO = """
VIZUALIZER

<space> - change vizualization

"""


class InfoDialog(Frame):
	def __init__(self, screen, text, buttons, config, has_shadow=False,
			win=""):

		self._buttons = buttons
		width = screen.width // 2
		self._message = text
		height = 17
		self.win = win
		# Construct the Frame
		self._data = {"message": self._message}
		super(InfoDialog, self).__init__(
			screen, height, width, self._data, has_shadow=has_shadow, is_modal=True)

		# Build up the message box
		layout = Layout([100], fill_frame=True)
		self.add_layout(layout)
		
		#TITLE
		_h = height - 4
		if self._message != "":
			layout.add_widget(Label(self._message))
			layout.add_widget(Divider())
			_h -= 2

		c = config.dialog.color.split(':')
		tcolor = ColorTheme(getColor(c[0]), getAttr(c[1]), getColor(c[2]))
		self.text = TextView(_h, tcolor, name="info")
		self.text._w = screen.width // 2
		self.text._h = _h
		layout.add_widget(self.text)
		layout.add_widget(Divider())
		self.setText()

		layoutBtns = Layout([1 for _ in buttons])
		self.add_layout(layoutBtns)
		for i, button in enumerate(buttons):
			func = partial(self._destroy, i)
			layoutBtns.add_widget(Button(button, func), i)
		self.fix()

	def _destroy(self, selected):
		self._scene.remove_effect(self)
	
	textInfo = {
		'Clock': CLOCK_INFO,
		'Browser': BROWSER_INFO,
		'ArtistInfo': '',
		'Equalizer': EQUALIZER_INFO,
		'Lyrics': '',
		'MainPlaylist': MAINPLAYLIST_INFO,
		'Medialib': MEDIALIB_INFO,
		'Playlists': PLAYLISTS_INFO,
		'Search': SEARCH_INFO,
		'Visualizer': VIZUALIZER_INFO
	}

	def setText(self):
		text = CONTROL_INFO + PLAYER_CONTROL_INFO
		text += self.textInfo[self.win]
		self.text.setText(text)
<q> <Q> - quit <i>     - information CLOCK WINDOW <space> - on/off seconds in clock PLAYER CONTROL  <p> - play/pause <S> - stop <>> - next song <<> - previously song <.> - move -> <,> - move <- <-> - volume down <=> - volume up <v> - mute <b> - play mode <c> - crossfade MAIN PLAYLIST  <Enter> <e> - play song <j> <k>     - swich song <d>         - delete song from playlist <E>         - open menu to add song in any playlist PLAYLISTS  <e>     - add song to main playlist <E>     - open menu to add song in any playlist <l>     - load song from Sound cloud and add to main playlist <L>     - open menu to load song from Sound cloud <d>     - delete playlist or song from playlist <j> <k> - swich songs in playlist <Enter> - play song BROWSER  <e>     - add song to main playlist <E>     - open menu to add song in any playlist EQUALIZER  <Right> <Left> - bar control MEDIA LIBRARY  <e>     - add song to main playlist <E>     - open menu to add song in any local playlist <Enter> - play song SEARCH  <e>     - add song to main playlist <E>     - open menu to add song in any local playlist <f>     - like song from Sound cloud <l>     - load song from Sound cloud and add to main playlist <L>     - open menu to load song from Sound cloud <Enter> - play song VIZUALIZER  <space> - change vizualization # Construct the Frame # Build up the message box #TITLE