from axipy import Style

from LoadMiWor.ui.processTool.parserWor.ParserMiCommand.utils import StringToBoolean
from LoadMiWor.ui.processTool.parserWor.parse import search
class MiLegend:
    parser_token_layer="layer {id}"
    def create(self,item,wor_source):
        self.__dispalay=False
        self.__style_title=None
        self.__style_subtitle=None
        self.__style_item=None
        item_legend=item['children'][0]
        self.__id_layer=int(item_legend['words'][1])
        for item in item_legend['children']:
            mi_line=wor_source[item['index']].strip()+" "
            mi_line_low=mi_line.lower()
            token_display=search('display {value} ',mi_line_low)
            if token_display is not None:
                self.__dispalay=StringToBoolean(token_display['value'])
            if mi_line_low.find('title')==0:
                token_title_font=search('Font {value} ',mi_line)
                if token_title_font is not None:
                    self.__style_title=Style.from_mapinfo('Font '+token_title_font['value'])
                continue
            if mi_line_low.find('subtitle')==0:
                token_subtitle_font=search('Font {value} ',mi_line)
                if token_subtitle_font is not None:
                    self.__style_subtitle=Style.from_mapinfo('Font '+token_subtitle_font['value'])
                continue
            if mi_line_low.find('ranges')==0:
                token_ranges_font=search('Font {value} ',mi_line)
                if token_ranges_font is not None:
                    self.__style_subtitle=Style.from_mapinfo('Font '+token_ranges_font['value'])
                continue
    @property
    def IdLayer(self):
        return self.__id_layer

