Ejemplo n.º 1
0
    def initial_babyname(self):
        # self.babyname = BabyName(self.setting['selected_texts'], self.setting['firstname'], min_len=2, max_len=2, duplication='n', num_option=8)
        
        self.babyname = BabyName()
        self.babyname.load_last_session()

        settings_screen.setting = self.babyname.setting
        settings_screen.session = self.babyname.session
        candidates_screen.candidates = [settings_screen.setting['first_name']+name for name in list(self.babyname.candidates)]

        self.first_name = self.babyname.setting['first_name']
Ejemplo n.º 2
0
class NamesScreen(Screen):
    char1_1 = ObjectProperty()
    char1_2 = ObjectProperty()
    char2_1 = ObjectProperty()
    char2_2 = ObjectProperty()
    char3_1 = ObjectProperty()
    char3_2 = ObjectProperty()
    char4_1 = ObjectProperty()
    char4_2 = ObjectProperty()
    char5_1 = ObjectProperty()
    char5_2 = ObjectProperty()
    char6_1 = ObjectProperty()
    char6_2 = ObjectProperty()
    char7_1 = ObjectProperty()
    char7_2 = ObjectProperty()
    char8_1 = ObjectProperty()
    char8_2 = ObjectProperty()

    checkbox1 = ObjectProperty()
    checkbox2 = ObjectProperty()
    checkbox3 = ObjectProperty()
    checkbox4 = ObjectProperty()
    checkbox5 = ObjectProperty()
    checkbox6 = ObjectProperty()
    checkbox7 = ObjectProperty()
    checkbox8 = ObjectProperty()

    first_name = StringProperty()

    # setting = DictProperty({'firstname': '', 'selected_texts': []})
    choices = {"name_prefer": [], "name_deny": [], "character_deny": []}



    def initial_babyname(self):
        # self.babyname = BabyName(self.setting['selected_texts'], self.setting['firstname'], min_len=2, max_len=2, duplication='n', num_option=8)
        
        self.babyname = BabyName()
        self.babyname.load_last_session()

        settings_screen.setting = self.babyname.setting
        settings_screen.session = self.babyname.session
        candidates_screen.candidates = [settings_screen.setting['first_name']+name for name in list(self.babyname.candidates)]

        self.first_name = self.babyname.setting['first_name']


    def reset_screen(self):
    	
    	# reset button states
        for i in range(1,9):
            cb = getattr(self, 'checkbox'+str(i))
            cb.disabled = False
            cb.active = False
            for j in range(1,3):
                getattr(self, 'char'+str(i)+"_"+str(j)).state = 'normal'

        # get new options and display
        self.options = self.babyname.generate_options(1)[0]

        for i in range(1,9):
            for j in range(1,3):
                getattr(self, 'char'+str(i)+'_'+str(j)).text = ""

        for index_name, name in enumerate(self.options):
            for index_ch, ch in enumerate(name):
                if index_ch < 2:
                    getattr(self, 'char'+str(index_name+1)+'_'+str(index_ch+1)).text = ch


        # reset choices
        self.choices['name_prefer'] = []
        self.choices['name_deny'] = copy.deepcopy(self.options)
        self.choices['character_deny'] = []


    def next(self):

        self.babyname.adjust_by_choices(self.choices)
        candidates_screen.candidates = [settings_screen.setting['first_name']+name for name in list(self.babyname.candidates)]
        self.reset_screen()
        

    def set_active(self, cb, index):
        # print "options: %d" % len(self.options)
        # print self.options
        if cb.active:
            # print "checkbox %d checked." % index
            name = self.options[index-1]
            if not name in self.choices["name_prefer"]:
                self.choices["name_prefer"].append(name)
            if name in self.choices["name_deny"]:
                self.choices["name_deny"].remove(name)
        else:
            # print "checkbox %d unchecked." % index
            if self.options[index-1] in self.choices["name_prefer"]:
                self.choices["name_prefer"].remove(self.options[index-1])
            if not self.options[index-1] in self.choices['name_deny']:
                self.choices['name_deny'].append(self.options[index-1])
        # print "options: %d" % len(self.options)
        # print self.options


    def toggle_character(self, btn, index1, index2):
        print "button %d-%d is toggled." % (index1, index2)

        if btn.state == 'down':
            # deal with meanings
            print self.options[index1-1][index2-1]
            if not self.options[index1-1][index2-1] in self.choices['character_deny']:
                self.choices['character_deny'].append(self.options[index1-1][index2-1])
            if self.options[index1-1] in self.choices["name_prefer"]:
                self.choices["name_prefer"].remove(self.options[index1-1])
            if not self.options[index1-1] in self.choices["name_deny"]:
                self.choices["name_deny"].append(self.options[index1-1])

            # btn.background_color = [1,0,0,0.5]

            # deal with checkbox
            cb = getattr(self, 'checkbox'+str(index1))
            if cb.active:
                cb.active = False
            if not cb.disabled:
                cb.disabled = True

        else:
            if self.options[index1-1][index2-1] in self.choices['character_deny']:
                self.choices['character_deny'].remove(self.options[index1-1][index2-1])
            cb = getattr(self, 'checkbox'+str(index1))
            if cb.disabled:
                another_btn = getattr(self, 'char'+str(index1)+"_"+str(3-index2))
                if another_btn.state == 'normal':
                    cb.disabled = False


    def toggle_all_characters_in_name(self, index):
        btn1 = getattr(self, "char"+str(index)+"_1")
        btn2 = getattr(self, "char"+str(index)+"_2")

        btn1.state = 'down'
        self.toggle_character(btn1, index, 0)
        btn2.state = 'down'
        self.toggle_character(btn2, index, 1)