def get_object_info(obj, **kwargs): """ Get object info to be displayed in tooltip. Arguments: obj (Node): Data model node. **kwargs: Arbitrary keyword arguments: Returns: str: Object's info. """ node_type = get_node_type(obj) info = NodeType.value2str(node_type) if node_type == NodeType.Command: info += ": " if obj.type is None: name = translate("AsterStudy", "[noname]") else: name = obj.name info += bold(name) cata = obj.title title = translate_command(cata) tip = " ({title} / {name})" if title != cata else " ({name})" info += tip.format(title=italic(title), name=cata) if kwargs.get('with_parent_stage', False): info += "<br>" st_name = bold(obj.stage.name) info += translate("AsterStudy", "From stage: {}").format(st_name) elif node_type == NodeType.Comment: info += ":<br>" content = obj.content.split("\n") content = [" # " + i for i in content] info += italic("\n".join(content)) elif node_type == NodeType.Variable: info += ": " info += bold(obj.name) info += " ({})".format(italic(obj.expression)) elif node_type == NodeType.Case: info += ": " info += bold(obj.name) if obj.description: info += "\n\n" info += obj.description elif node_type != NodeType.History: info += ": " info += bold(obj.name) if node_type in [ NodeType.Case, NodeType.Stage, NodeType.Category, NodeType.Command ]: validity = Validity.value2str(obj.check()) if validity: info += "<br>" info += font("Invalid:", color="#ff0000") info += ", ".join([bold(i.strip()) for i in validity.split(",")]) info = preformat(info) return info
def get_object_type(obj): """ Get object catalogue name to be displayed in data view. Arguments: obj (Node): Data model node. Returns: str: Object's catalogue name. """ name = "" node_type = get_node_type(obj) if node_type == NodeType.Command: name = translate_command(obj.title) return name
def translate_command(command, keyword=None, item=None): """ Redirect all catalogs translations and force 'use business oriented translations' option explicitly set in *Parameters* panel. Note: All items of *Parameters* panel should use this method instead of function implemented at package level. See also: `gui.translate_command()` """ return translate_command(command, keyword, item, force_translations=Options.use_translations)
def _is_exist_keyword(self, command, storage, keyword, value=None): """ Checks existance the parameters in storage. Parameter should has keyword which starts with specified 'keyword' and has value which starts with specified 'value' if it's not None Arguments: storage (dict): Command storage. keyword (str): Search keyword pattern string value (str): Search value pattern string Returns: bool: Check state. 'True' if the storage contains parameter according given patterns """ res = False if isinstance(storage, dict): for key in storage.keys(): res = match_string(key, keyword) or \ match_string(translate_command(command, key), keyword) res = res and (value is None or len(value) == 0 or \ self._check_value(command, key, storage[key], value)) if not res: childstorage = storage[key] if isinstance(childstorage, dict): res = self._is_exist_keyword(command, childstorage, keyword, value) else: for param in to_list(childstorage): res = self._is_exist_keyword( command, param, keyword, value) if res: break if res: break return res
def _is_matched(self, item, pattern, context): """ Check if the specified item matched given criteries Arguments: item (QTreeWidgetItem): Checked item pattern (str): Search pattern string context (str): Search context string Returns: bool: Check state. 'True' if the item is matched otherwise 'False' """ res = False if item is not None and context is not None and len(context): res = len(pattern) == 0 if not res: uid = get_id(item) typ = get_type(item) obj = self.category(uid) if uid < 0 else \ self.history.get_node(uid) if context == Model.Context.Name: res = typ in (NodeType.Command, NodeType.Variable) and \ (match_string(obj.title, pattern) or \ match_string(translate_command(obj.title), pattern)) elif context == Model.Context.Concept: res = typ in (NodeType.Command, NodeType.Variable) and \ match_string(obj.name, pattern) elif context == Model.Context.Keyword: res = typ == NodeType.Command and \ self._is_exist_keyword(obj.title, obj.storage, pattern) elif context == Model.Context.Group: res = typ == NodeType.Command and \ self._is_exist_keyword(obj.title, obj.storage, 'GROUP', pattern) return res
def _check_value(self, command, keyword, value, pattern): """ Checks existance of the pattern in value. Arguments: command (str): Command title. keyword (str): Parameter keyword. value (str|list): Parameter value. pattern (str): Value pattern string. Returns: bool: Check state. 'True' if the value contains given pattern. """ res = False if value is not None: values = to_list(value) for item in values: val = str(item) res = match_string(val, pattern) or \ match_string(translate_command(command, keyword, val), pattern) if res: break return res
def get_object_name(obj): """ Get object name to be displayed in data view. Arguments: obj (Node): Data model node. Returns: str: Object's name. """ node_type = get_node_type(obj) if node_type == NodeType.History: return translate("AsterStudy", "History") elif node_type == NodeType.Command: if obj.gettype(ConversionLevel.NoFail) is not None: return obj.name if behavior().show_catalogue_name: return translate("AsterStudy", "[noname]") else: return translate_command(obj.title) elif node_type == NodeType.Comment: return obj.content.split("\n")[0] return obj.name