# @Author: Manuel Rodriguez <valle>
# @Date:   10-May-2017
# @Email:  valle.mrv@gmail.com
# @Last modified by:   valle
# @Last modified time: 23-Feb-2018
# @License: Apache license vesion 2.0


from kivy.uix.modalview import ModalView
from kivy.uix.button import Button
from kivy.properties import ObjectProperty, StringProperty, ListProperty
from kivy.lang import Builder

Builder.load_file("view/sugerencias.kv")

class Sugerencias(ModalView):
    onExit = ObjectProperty(None, allownone=True)
    content = ObjectProperty(None, allownone=True)
    texto = StringProperty("")
    des = StringProperty("")
    sug = ListProperty([])
    key = StringProperty("")
    tag = ObjectProperty(None, allownone=True)

    def __init__(self, **kargs):
        super(Sugerencias, self).__init__(**kargs)
        self.auto_dismiss=False

    def on_sug(self, key, value):
        self.lista.rm_all_widgets()
        for item in self.sug:
            btn = Button(text=item)
            btn.tag = item
            btn.bind(on_press=self.onPress)
            self.lista.add_linea(btn)

    def onPress(self, b):
        self.onExit(self.key, self.content, b.tag, self.tag)

    def clear_text(self):
        self.texto = ""

    def exit(self):
        self.texto = self.txtSug.text
        if self.onExit:
            if self.texto != "":
                self.sug.append(self.texto)
            self.onExit(self.key, self.content, self.texto, self.tag)

[((374, 414), 'kivy.lang.Builder.load_file', 'Builder.load_file', (['"""view/sugerencias.kv"""'], {}), "('view/sugerencias.kv')\n", (391, 414), False, 'from kivy.lang import Builder\n'), ((459, 495), 'kivy.properties.ObjectProperty', 'ObjectProperty', (['None'], {'allownone': '(True)'}), '(None, allownone=True)\n', (473, 495), False, 'from kivy.properties import ObjectProperty, StringProperty, ListProperty\n'), ((510, 546), 'kivy.properties.ObjectProperty', 'ObjectProperty', (['None'], {'allownone': '(True)'}), '(None, allownone=True)\n', (524, 546), False, 'from kivy.properties import ObjectProperty, StringProperty, ListProperty\n'), ((559, 577), 'kivy.properties.StringProperty', 'StringProperty', (['""""""'], {}), "('')\n", (573, 577), False, 'from kivy.properties import ObjectProperty, StringProperty, ListProperty\n'), ((588, 606), 'kivy.properties.StringProperty', 'StringProperty', (['""""""'], {}), "('')\n", (602, 606), False, 'from kivy.properties import ObjectProperty, StringProperty, ListProperty\n'), ((617, 633), 'kivy.properties.ListProperty', 'ListProperty', (['[]'], {}), '([])\n', (629, 633), False, 'from kivy.properties import ObjectProperty, StringProperty, ListProperty\n'), ((644, 662), 'kivy.properties.StringProperty', 'StringProperty', (['""""""'], {}), "('')\n", (658, 662), False, 'from kivy.properties import ObjectProperty, StringProperty, ListProperty\n'), ((673, 709), 'kivy.properties.ObjectProperty', 'ObjectProperty', (['None'], {'allownone': '(True)'}), '(None, allownone=True)\n', (687, 709), False, 'from kivy.properties import ObjectProperty, StringProperty, ListProperty\n'), ((946, 963), 'kivy.uix.button.Button', 'Button', ([], {'text': 'item'}), '(text=item)\n', (952, 963), False, 'from kivy.uix.button import Button\n')]