当前位置: 首页>>代码示例>>Python>>正文


Python UI.get_error方法代码示例

本文整理汇总了Python中ui.UI.get_error方法的典型用法代码示例。如果您正苦于以下问题:Python UI.get_error方法的具体用法?Python UI.get_error怎么用?Python UI.get_error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ui.UI的用法示例。


在下文中一共展示了UI.get_error方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _insert_or_replace_apartment_parse

# 需要导入模块: from ui import UI [as 别名]
# 或者: from ui.UI import get_error [as 别名]
    def _insert_or_replace_apartment_parse(self, command, command_type):
        """
        Protected parse method for insert and replace
        Input:
            command - the user command
            command_type - the command_type, can be insert or replace
        Return:
            True on valid and False otherwise
        Raises:
            Exception on invalid command_type
        """
        self.set_command(command)

        # get the correct pattern
        if command_type is "insert":
            pattern = self._regex_search(self._PATTERN_INSERT)
            if not pattern:
                UI.set_message(UI.get_error("insert <amount>, <expense_type> at <apartment_id>"))
                return False
        elif command_type is "replace":
            pattern = self._regex_search(self._PATTERN_REPLACE)
            if not pattern:
                UI.set_message(UI.get_error("replace <amount>, <expense_type> at <apartment_id>"))
                return False
        else:
            raise Exception("command type is incorrect")

        # get the data
        amount = pattern.group(1)
        expense_type = pattern.group(2)
        apartment_id = pattern.group(3)

        # wrong type
        if not Apartment.is_expense_type(expense_type):
            UI.set_message(UI.get_error_types())
            return False

        if command_type is "insert":
            # apartment does  exist in the list
            if self.is_apartment(apartment_id):
                UI.set_message("Apartment " + apartment_id + " does exist in the list. "
                                                             "Use this command to replace: replace " + amount + ", " +
                               expense_type + " at " + apartment_id)
                return False
        elif command_type is "replace":
            # apartment does not exist in the list
            if not self.is_apartment(apartment_id):
                UI.set_message("Apartment " + apartment_id + " does not exist in the list. "
                                                             "Use this command to add: insert " + amount + ", " +
                               expense_type + " at " + apartment_id)
                return False

        # all good
        self._parsed_command = {"type": expense_type, "amount": amount, "id": apartment_id}
        return True
开发者ID:leyyin,项目名称:university,代码行数:57,代码来源:bloc.py

示例2: list_greater_than_parse

# 需要导入模块: from ui import UI [as 别名]
# 或者: from ui.UI import get_error [as 别名]
    def list_greater_than_parse(self, command):
        """
        Parses and validates the 'list greater than' command
        Input:
            command - the user command
        Return:
            True on valid and False otherwise
        """
        # list greater than <amount>
        self.set_command(command)
        pattern_greater = self._regex_search(self._PATTERN_LIST_GREATER)
        if pattern_greater:
            greater = pattern_greater.group(1)

            self._parsed_command = {"greater": greater}
            return True

        UI.set_message(UI.get_error("list greater than <amount>"))
        return False
开发者ID:leyyin,项目名称:university,代码行数:21,代码来源:bloc.py

示例3: remove_apartment_parse

# 需要导入模块: from ui import UI [as 别名]
# 或者: from ui.UI import get_error [as 别名]
    def remove_apartment_parse(self, command):
        """
        Parses and validates the remove command
        Input:
            command - the user command
        Return:
            True on valid and False otherwise
        """
        self.set_command(command)
        # first case by apartment id
        pattern_remove_by_id = self._regex_search(self._PATTERN_REMOVE_BY_ID)
        if pattern_remove_by_id:
            apartment_id = pattern_remove_by_id.group(1)
            if not self.is_apartment(apartment_id):
                UI.set_message(
                    "Apartment " + apartment_id + " does not exist in this list so all the expenses are by default 0")
                return False

            self._parsed_command = {"id": apartment_id}
            return True

        # second case remove from interval
        pattern_remove_by_interval = self._regex_search(self._PATTERN_REMOVE_BY_INTERVAL)
        if pattern_remove_by_interval:
            id_min = pattern_remove_by_interval.group(1)
            id_max = pattern_remove_by_interval.group(2)

            self._parsed_command = {"id_min": id_min, "id_max": id_max}
            return True

        # third case by type
        pattern_remove_by_type = self._regex_search(self._PATTERN_REMOVE_BY_TYPE)
        if pattern_remove_by_type:
            expense_type = pattern_remove_by_type.group(1)
            if not Apartment.is_expense_type(expense_type):
                UI.set_message(UI.get_error_types())
                return False

            self._parsed_command = {"type": expense_type}
            return True

        UI.set_message(UI.get_error("remove <apartment_id> \n\tremove from 5 to 10 \n\tremove type"))
        return False
开发者ID:leyyin,项目名称:university,代码行数:45,代码来源:bloc.py

示例4: list_less_than_parse

# 需要导入模块: from ui import UI [as 别名]
# 或者: from ui.UI import get_error [as 别名]
    def list_less_than_parse(self, command):
        """
        Parses and validates the 'list less than' command
        Input:
            command - the user command
        Return:
            True on valid and False otherwise
        """
        # less than <amount> before <id>
        self.set_command(command)
        pattern_less = self._regex_search(self._PATTERN_LIST_LESS)
        if pattern_less:
            less = pattern_less.group(1)
            upper_id_limit = pattern_less.group(2)

            self._parsed_command = {"less": less, "upper_id_limit": upper_id_limit}
            return True

        UI.set_message(UI.get_error("list less than <amount> before <apartment_id>"))
        return False
开发者ID:leyyin,项目名称:university,代码行数:22,代码来源:bloc.py

示例5: stat_max_apartment_parse

# 需要导入模块: from ui import UI [as 别名]
# 或者: from ui.UI import get_error [as 别名]
    def stat_max_apartment_parse(self, command):
        """
        Parses and validates the 'max id' command
        Input:
            command - the user command
        Return:
            True on valid and False otherwise
        """
        self.set_command(command)

        # max <id>
        pattern_max = self._regex_search(self._PATTERN_STAT_MAX_APARTMENT)
        if pattern_max:
            apartment_id = pattern_max.group(1)
            if not self.is_apartment(apartment_id):
                UI.set_message("Apartment " + apartment_id + " does not exist in the list")
                return False

            self._parsed_command = {"id": apartment_id}
            return True

        UI.set_message(UI.get_error("max <apartment_number>"))
        return False
开发者ID:leyyin,项目名称:university,代码行数:25,代码来源:bloc.py

示例6: stat_total_type_parse

# 需要导入模块: from ui import UI [as 别名]
# 或者: from ui.UI import get_error [as 别名]
    def stat_total_type_parse(self, command):
        """
        Parses and validates the 'sum type' command
        Input:
            command - the user command
        Return:
            True on valid and False otherwise
        """
        self.set_command(command)

        # sum <type>
        pattern_sum = self._regex_search(self._PATTERN_STAT_TOTAL_TYPE)
        if pattern_sum:
            expense_type = pattern_sum.group(1)
            if not Apartment.is_expense_type(expense_type):
                UI.set_message(UI.get_error_types())
                return False

            self._parsed_command = {"expense_type": expense_type}
            return True

        UI.set_message(UI.get_error("sum <type>"))
        return False
开发者ID:leyyin,项目名称:university,代码行数:25,代码来源:bloc.py

示例7: list_total_apartment_parse

# 需要导入模块: from ui import UI [as 别名]
# 或者: from ui.UI import get_error [as 别名]
    def list_total_apartment_parse(self, command):
        """
        Parses and validates the 'list total' command
        Input:
            command - the user command
        Return:
            True on valid and False otherwise
        """
        self.set_command(command)

        # sold|total <apartment_number>
        pattern_total = self._regex_search(self._PATTERN_LIST_TOTAL_APARTMENT)
        if pattern_total:
            apartment_id = pattern_total.group(1)
            if not self.is_apartment(apartment_id):
                UI.set_message("Apartment " + apartment_id + " does not exist in the list")
                return False

            self._parsed_command = {"id": apartment_id}
            return True

        UI.set_message(UI.get_error("list total <apartment_id>"))
        return False
开发者ID:leyyin,项目名称:university,代码行数:25,代码来源:bloc.py

示例8: list_by_type_parse

# 需要导入模块: from ui import UI [as 别名]
# 或者: from ui.UI import get_error [as 别名]
    def list_by_type_parse(self, command):
        """
        Parses and validates the list command
        Input:
            command - the user command
        Return:
            True on valid and False otherwise
        """
        self.set_command(command)

        # list <type>
        pattern_type = self._regex_search(self._PATTERN_LIST_BY_TYPE)
        if pattern_type:
            expense_type = pattern_type.group(1)
            if not Apartment.is_expense_type(expense_type):
                UI.set_message(UI.get_error_types())
                return False

            self._parsed_command = {"expense_type": expense_type}
            return True

        UI.set_message(UI.get_error("list <expense_type>"))
        return False
开发者ID:leyyin,项目名称:university,代码行数:25,代码来源:bloc.py


注:本文中的ui.UI.get_error方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。