Esempio n. 1
0
    def refresh(self):
        self.widget.mapEvents({
            'allow_upgrades/mouseClicked':
            self.toggle_upgrades,
        })

        # refresh taxes
        self.widget.child_finder('taxes').text = unicode(
            self._get_last_tax_paid())

        # refresh upgrade permissions
        upgrades_button = self.widget.child_finder('allow_upgrades')
        if self.__class__.LEVEL < TIER.CURRENT_MAX:  #max incr => cannot allow upgrades
            if self.settlement.upgrade_permissions[self.__class__.LEVEL]:
                upgrades_button.set_active()
                upgrades_button.helptext = _("Don't allow upgrades")
            else:
                upgrades_button.set_inactive()
                upgrades_button.helptext = _('Allow upgrades')

        # refresh residents per house info
        resident_counts = self._get_resident_counts()
        houses = 0
        residents = 0
        container = self.widget.child_finder('residents_per_house_table')
        space_per_label = container.size[0] // 6
        for number in xrange(self.min_inhabitants, self.max_inhabitants + 1):
            column = number - (self.min_inhabitants -
                               1 if self.min_inhabitants > 0 else 0)
            house_count = resident_counts.get(number, 0)
            houses += house_count
            residents += house_count * number
            position_x = (space_per_label * (column - 1)) + 10
            if not container.findChild(name="resident_" + str(column)):
                label = Label(name="resident_" + str(column),
                              position=(position_x, 0),
                              text=unicode(number))
                container.addChild(label)
                count_label = Label(name="resident_count_" + str(column),
                                    position=(position_x - 1, 20),
                                    text=unicode(house_count))
                container.addChild(count_label)
            else:
                container.findChild(name="resident_" +
                                    str(column)).text = unicode(number)
                container.findChild(name="resident_count_" +
                                    str(column)).text = unicode(house_count)

        sad = self.instance.session.db.get_settler_happiness_decrease_limit()
        happy = self.instance.session.db.get_settler_happiness_increase_requirement(
        )
        self.widget.child_finder('sad_amount').text = unicode(
            self.settlement.get_residentials_of_lvl_for_happiness(
                self.__class__.LEVEL, max_happiness=sad))
        self.widget.child_finder('avg_amount').text = unicode(
            self.settlement.get_residentials_of_lvl_for_happiness(
                self.__class__.LEVEL, sad, happy))
        self.widget.child_finder('happy_amount').text = unicode(
            self.settlement.get_residentials_of_lvl_for_happiness(
                self.__class__.LEVEL, happy))

        # refresh the summary
        self.widget.child_finder('house_count').text = unicode(houses)
        self.widget.child_finder('resident_count').text = unicode(residents)

        self.widget.adaptLayout()
        super(MainSquareSettlerLevelTab, self).refresh()