def getFromFile(self, fn): with open(fn, "r") as f: text = f.readlines() f.close() lines = [] for i in range(len(text)): lines.append(text[i].rstrip('\n')) current = -1 for i in range(len(lines)): if lines[i].find("VOYP") > -1: self.voyAppearance = float(get_between_keys(lines[i], "VOYP ")) elif lines[i].find("VOY") > -1: current = VOY self.doubleVoy = float(get_between_keys(lines[i], "VOY ")) elif lines[i].find("CONSHP") > -1: current = CONSH self.conshAppearance = float( get_between_keys(lines[i], "CONSHP ")) elif lines[i].find("CONSH") > -1: current = CONSH elif lines[i].find("CONSS") > -1: current = CONSS self.doubleCons = float(get_between_keys(lines[i], "CONSS ")) elif lines[i].find("SPEC") > -1: current = SPEC self.specAppearance = float(get_between_keys( lines[i], "SPEC ")) else: l = lines[i].split() if len(l) != 2: l.append(1.11) # print l if current == VOY: for i in range(int(100 * float(l[1]))): self.voyP.append(l[0]) elif current == CONSH: for i in range(int(100 * float(l[1]))): self.conshP.append(l[0]) elif current == CONSS: for i in range(int(100 * float(l[1]))): self.conssP.append(l[0]) elif current == SPEC: for i in range(int(100 * float(l[1]))): self.specP.append(l[0]) self.voy = list(set(self.voyP)) self.consh = list(set(self.conshP)) self.conss = list(set(self.conssP)) self.spec = list(set(self.specP))
def get_data_name(filename, name, delimiter=" = ", stop=" "): lines = get_lines_as_list(filename) true_name = name + delimiter for line in lines: try: found = get_between_keys(line, true_name, stop) return found except: pass return -1
def __init__(self, text, writer=None, pos=None, space=None, align=None, cut_word=None): """ <text> is the text to be produced. Markers can be used (see constants.SYNTAX_*) <writer> is the writer used to produce the text. <pos> is the relative position to painter.img. <space> is the interline spacing. <align> can be 'left', 'right' or 'center'. <cut_word> is the terminating string used if the text is too long to fit the dimensions. """ pos = style.TITLE_POS if pos is None else pos space = style.TITLE_SPACE if space is None else space align = style.TITLE_ALIGN if align is None else align cut_word = style.CUT_WORD if cut_word is None else cut_word t = get_between_keys(text, SYNTAX_BEG, SYNTAX_END, SYNTAX_FIRST, SYNTAX_LAST) if t: self._text = t else: self._text = text if writer is None: self._writer = painterstyle.WRITER() else: self._writer = writer self._pos = pos self._space = space if not self._space: self._space = self._writer.font.get_linesize() self._align = align self._cut_word = cut_word self._lines = None self._imgs = None self.refresh_imgs()
def __init__(self, text, writer=None, pos=None, space=None, align=None, cut_word=None): """ <text> is the text to be produced. Markers can be used (see constants.SYNTAX_*) <writer> is the writer used to produce the text. <pos> is the relative position to painter.img. <space> is the interline spacing. <align> can be 'left', 'right' or 'center'. <cut_word> is the terminating string used if the text is too long to fit the dimensions. """ pos=style.TITLE_POS if pos is None else pos space=style.TITLE_SPACE if space is None else space align=style.TITLE_ALIGN if align is None else align cut_word=style.CUT_WORD if cut_word is None else cut_word t = get_between_keys( text, SYNTAX_BEG, SYNTAX_END, SYNTAX_FIRST, SYNTAX_LAST) if t: self._text = t else: self._text = text if writer is None: self._writer = painterstyle.WRITER() else: self._writer = writer self._pos = pos self._space = space if not self._space: self._space = self._writer.font.get_linesize() self._align = align self._cut_word = cut_word self._lines = None self._imgs = None self.refresh_imgs()