def highlightBlock(self, text): #pcache = BibConfigParsingCache() blockno = self.currentBlock().blockNumber() for m in rxsrc.finditer(text): self.setFormat(m.start('src'), len(m.group('src')), self.fmt_src) #pcache.add_sourcelist(line=blockno) for m in rxfilter.finditer(text): self.setFormat(m.start('filter'), len(m.group('filter')), self.fmt_filter) fmtname = self.fmt_filtername try: # try to load the filter module to see if it exists filtmodule = filters_factory.get_module(m.group('filtername')) except (filters_factory.NoSuchFilter, filters_factory.NoSuchFilterPackage): fmtname = self.fmt_filtername_nonex #pcache.add_filter(line=blockno, filtername=m.group('filtername')) self.setFormat(m.start('filtername'), len(m.group('filtername')), fmtname) for m in rxstring1.finditer(text): self.setFormat(m.start('str'), len(m.group('str')), self.fmt_string) for m in rxstring2.finditer(text): self.setFormat(m.start('str'), len(m.group('str')), self.fmt_string) for m in rxcomment.finditer(text): self.setFormat(m.start(), len(m.group()), self.fmt_comment)
def setData(self, index, value, role=Qt.EditRole): col = index.column() row = index.row() if (col != 1): return False if (self._fopts is None): return False if (role != Qt.EditRole): return False filteroptions = self._fopts.filterOptions() if (row < 0 or row >= len(filteroptions)): return False arg = filteroptions[row] value = value.toPyObject() if (isinstance(value, QString)): value = unicode(value); # make sure we're dealing with Python strings and not Qt strings logger.debug("Got value: %r", value) # validate type typ = None if (arg.argtypename is not None): typ = butils.resolve_type(arg.argtypename, filters_factory.get_module(self._filtername, False)) if (typ == None): typ = unicode value = typ(value) logger.debug("Got final value: %r ; typ=%r", value, typ) self._kwargs[arg.argname] = value self._update_optionstring() self.dataChanged.emit(index, index) self._emitOptionStringChanged() logger.debug("_kwargs is %r", self._kwargs) return True
def data(self, index, role=Qt.DisplayRole): if (self._fopts is None): return QVariant() filteroptions = self._fopts.filterOptions() col = index.column() row = index.row() if (row < 0 or row >= len(filteroptions)): return QVariant() # the argument specification of the current row (_ArgDoc namedtuple instance) arg = filteroptions[row] if (col == 0): # argument name if (role == Qt.DisplayRole): return QVariant(QString(self._fopts.getSOptNameFromArg(filteroptions[row].argname))) # tool-tip documentation if (role == Qt.ToolTipRole): return QVariant(QString(arg.doc)) return QVariant() # the value of the argument of the current row. val = self._kwargs.get(arg.argname) if (col == 1): # argument value if (role == overlistbuttonwidget.ROLE_OVERBUTTON): if (val is not None): return QVariant(overlistbuttonwidget.OVERBUTTON_REMOVE) return QVariant(overlistbuttonwidget.OVERBUTTON_ADD) if (role == overlistbuttonwidget.ROLE_ARGNAME): return QVariant(QString(arg.argname)) if (role == Qt.DisplayRole): if (val is None): return QVariant() return QVariant(QString(unicode(val))) # request editing value of argument if (role == Qt.EditRole): if (arg.argtypename is not None): fmodule = filters_factory.get_module(self._filtername, False) typ = butils.resolve_type(arg.argtypename, fmodule) else: typ = unicode if (hasattr(typ, 'type_arg_input')): editval = RegisteredArgInputType(typ, val) elif (issubclass(typ, basestring) and val is None): editval = typ('') elif (issubclass(typ, CommaStrList)): editval = unicode(val) else: editval = typ(val) return QVariant(editval) return QVariant() return QVariant()