def update(self): if self.node and self.buff.get_modified(): start, end = self.buff.get_bounds() key = self.node['key'] text = self.buff.get_text(start, end).encode('latin-1') if text.strip(): self.entry[key] = Fields.LongText(text) else: del self.entry[key] self.node.setdefault('modified', True)
def lt_new(self): d = LT_Dialog_1(parent=self.w.get_toplevel()) newname = d.run() if not newname: return new = {'key': newname.lower(), 'name': newname, 'mandatory': False} pos = len(self.lt_nodes) self.lt_nodes.append(new) assert self.lt_nodes[pos] == new self.set_buttons(len(self.lt_nodes) - 1) self.entry[new['key']] = Fields.LongText('') self.lt_listvw.display_list(self.entry, self.lt_nodes) self.lt_display(pos)
def display(self, node, item): self.node = node self.entry = item self.label.set_text(node.get('name', _('Text'))) key = node['key'] if not item.has_key(key): item[key] = Fields.LongText(_('Enter text here')) self.buff.set_text(str(item[key]).decode('latin-1'), -1) self.buff.set_modified(False) self.page.show_all() if self.hidden: self.hidden = False self.notebook.insert_page(self.page, self.label, self.position) self.notebook.page_num(self.page) self.notebook.set_current_page(self.position)
def next(self): dict = {} # read entry till next blank line text = [] field = '' while 1: line = self.file.readline() if line == '': break line = string.rstrip(line) # starting with a blank ? if line == '' or line[0] == ' ': # ...then we continue the current text text.append(string.lstrip(line)) continue # new entry ? if separator_re.match(line): break # else, this is a new field if field: # save the previous one if needed dict[field] = '\n'.join(text) text = [] # store the name of this new field field = string.lower(line) # don't waste the last field content if field: dict[field] = '\n'.join(text) # did we parse a field ? if len(dict) == 0: return None # create the entry content entry = Base.Entry(type=self.deftype) for key in dict.keys(): if not self.mapping.has_key(key): #print "warning: unused key `%s'" % key continue (name, type) = self.mapping[key] text_type = Types.get_field(name).type # parse a simple text field if type == SimpleField: entry[name] = text_type(string.strip(dict[key])) elif type == KeywordField: text = string.strip(dict[key]) if entry.has_key(name): text = str(entry[name]) + '\n ' + text entry[name] = text_type(text) # parse an author field elif type == AuthorField: entry[name] = self.parse_author(dict[key]) continue # parse a source field elif type == SourceField: dict_key = ' '.join(dict[key].split('\n')) m = self.source_re.match(dict_key.strip()) if m: year, month, day = None, None, None j, v, s, n, p, o, y, d = m.group('journal', 'volume', 'inseries', 'number', 'pages', 'other', 'year', 'month') if s: ### article in a monograph series entry['booktitle'] = Fields.Text(j) if d: entry['beigabevermerk'] = Fields.LongText(d) entry.type = Types.get_entry('incollection') elif j: entry['journal'] = Fields.Text(j) if d and not d.isspace(): dates = d.split() try: month = long_month[dates[0]] except KeyError: pass ## import warnings ## warnings.filterwarnings ('once', ## message='date', ## module='OvidLike') ## warnings.warn ( ## 'OVID: %s is not representable in date ' ## 'field %s' %(dates[0], d), stacklevel=2) if len(dates) > 1: day = int(dates[1]) if v: entry['volume'] = Fields.Text(v) if n: entry['number'] = Fields.Text(n) if p: entry['pages'] = Fields.Text(p) if o: entry['other-note'] = Fields.Text(o) if y: year = int(y) entry['date'] = Fields.Date((year, month, day)) else: print '>>> Error: Source field does not parse correctly:' print dict_key print entry continue return entry