def __init__(self, line): """ Initialize with a valid string that fits the pattern for this class If this fails, a Value error will be thrown """ pattern = self._get_pattern() exp = pattern.match(line) if not exp: raise ValueError("The provided line was not a valid widget") self.os_type = "widget" self.parameters = {} self.parameters['column'] = exp.group(2) self.parameters['row'] = exp.group(3) self.parameters['column_span'] = exp.group(4) self.parameters['row_span'] = exp.group(5) self.parameters['type'] = exp.group(6) self.keywords = {} try: keyword_list = exp.group('keywords') except IndexError: pass else: if keyword_list: self.keywords = self._get_keywords(keyword_list.split()) Statement.__init__(self, self.os_type, self.parameters, self.keywords)
def __init__(self, line): """ Initialize with a valid string that fits the pattern for this class. If this fails, a Value error wil be thrown All parameters and keywords will be read from line and stored as instance variables in the parameters and keywords dicts. """ exp = self._get_match(line) if not exp: raise ValueError( "The provided line was not a valid draw statement") self.os_type = "draw" self.parameters = {} self.parameters['type'] = exp.group(2) # pylint: disable=bad-whitespace if self.parameters['type'] == 'ellipse': self.parameters['left'] = exp.group(3) self.parameters['top'] = exp.group(4) self.parameters['width'] = exp.group(5) self.parameters['height'] = exp.group(6) elif self.parameters['type'] == 'rect': self.parameters['left'] = exp.group(3) self.parameters['top'] = exp.group(4) self.parameters['width'] = exp.group(5) self.parameters['height'] = exp.group(6) elif self.parameters['type'] == 'circle': self.parameters['x'] = exp.group(3) self.parameters['y'] = exp.group(4) self.parameters['radius'] = exp.group(5) elif self.parameters['type'] in ('line', 'arrow'): self.parameters['left'] = exp.group(3) self.parameters['right'] = exp.group(4) self.parameters['top'] = exp.group(5) self.parameters['bottom'] = exp.group(6) elif self.parameters['type'] == 'textline': self.parameters['x'] = exp.group(3) self.parameters['y'] = exp.group(4) self.parameters['text'] = exp.group(5) elif self.parameters['type'] == 'image': self.parameters['x'] = exp.group(3) self.parameters['y'] = exp.group(4) self.parameters['path'] = exp.group(5) elif self.parameters['type'] in ('gabor', 'noise', 'fixdot'): self.parameters['x'] = exp.group(3) self.parameters['y'] = exp.group(4) self.keywords = {} try: keyword_list = exp.group('keywords') except IndexError: pass else: if keyword_list: splitted = re.findall(self.SPLIT_PAT, keyword_list) self.keywords = self._get_keywords(splitted) Statement.__init__(self, self.os_type, self.parameters, self.keywords)
def __init__(self, line): """ Initialize with a valid string that fits the pattern for this class. If this fails, a Value error wil be thrown All parameters and keywords will be read from line and stored as instance variables in the parameters and keywords dicts. """ exp = self._get_match(line) if not exp: raise ValueError("The provided line was not a valid draw statement") self.os_type = "draw" self.parameters = {} self.parameters['type'] = exp.group(2) # pylint: disable=bad-whitespace if self.parameters['type'] == 'ellipse': self.parameters['left'] = exp.group(3) self.parameters['top'] = exp.group(4) self.parameters['width'] = exp.group(5) self.parameters['height'] = exp.group(6) elif self.parameters['type'] == 'rect': self.parameters['left'] = exp.group(3) self.parameters['top'] = exp.group(4) self.parameters['width'] = exp.group(5) self.parameters['height'] = exp.group(6) elif self.parameters['type'] == 'circle': self.parameters['x'] = exp.group(3) self.parameters['y'] = exp.group(4) self.parameters['radius'] = exp.group(5) elif self.parameters['type'] in ('line','arrow'): self.parameters['left'] = exp.group(3) self.parameters['right'] = exp.group(4) self.parameters['top'] = exp.group(5) self.parameters['bottom'] = exp.group(6) elif self.parameters['type'] == 'textline': self.parameters['x'] = exp.group(3) self.parameters['y'] = exp.group(4) self.parameters['text'] = exp.group(5) elif self.parameters['type'] == 'image': self.parameters['x'] = exp.group(3) self.parameters['y'] = exp.group(4) self.parameters['path'] = exp.group(5) elif self.parameters['type'] in ('gabor','noise','fixdot'): self.parameters['x'] = exp.group(3) self.parameters['y'] = exp.group(4) self.keywords = {} try: keyword_list = exp.group('keywords') except IndexError: pass else: if keyword_list: splitted = re.findall(self.SPLIT_PAT, keyword_list) self.keywords = self._get_keywords(splitted) Statement.__init__(self, self.os_type, self.parameters, self.keywords)
def __init__(self, line): """ Initialize with a valid string that fits the pattern for this class. If this fails, a Value error will be thrown """ pattern = self._get_pattern() exp = pattern.match(line) if not exp: raise ValueError("The provided line was not a valid log statement") self.os_type = "log" self.parameters = {} self.parameters['name'] = exp.group(2) Statement.__init__(self, self.os_type, self.parameters)
def __init__(self, line): """ Initialize with a valid string that fits the pattern for this class. If this fails, a Value error will be thrown """ pattern = self._get_pattern() exp = pattern.match(line) if not exp: raise ValueError("(" + line + ") was not a valid Variable") self.os_type = "set" self.parameters = {} self.parameters['name'] = exp.group(2) self.parameters['value'] = exp.group(3) Statement.__init__(self, self.os_type, self.parameters)
def __init__(self, line): """ Initialize with a valid string that fits the pattern for this class If this fails, a Value error will be thrown """ self.done = False pattern = self._get_pattern() exp = pattern.match(line) if not exp: raise ValueError("The provided line was not a valid Multiline") # Strip the quotes from the name self.os_type = "multi-line" self.parameters = {} self.parameters['name'] = exp.group(1) self.parameters['lines'] = "" Statement.__init__(self, self.os_type, self.parameters)
def __init__(self, line): """ Initialize with a valid string that fits the pattern for this class. If this fails, a Value error will be thrown """ pattern = self._get_pattern() exp = pattern.match(line) if not exp: raise ValueError("(" + line+ ") was not a valid Variable") self.os_type = "set" self.parameters = {} self.parameters['name'] = exp.group(2) self.parameters['value'] = exp.group(3) Statement.__init__(self, self.os_type, self.parameters)
def __init__(self, line): """ Initialize with a valid string that fits the pattern for this class. If this fails, a Value error will be thrown """ pattern = self._get_pattern() exp = pattern.match(line) if not exp: raise ValueError("{} was not a valid Define"\ .format(line)) # Strip the quotes from the name self.os_type = "define" self.parameters = {} self.parameters['type'] = exp.group(2) self.parameters['name'] = exp.group(3) Statement.__init__(self, self.os_type, self.parameters, has_extra_attributes=True)