# Path: terminology.py
# class Term():
#   def __init__(self, word = "", meaning = "", section = ""):
#     self.word    = word
#     self.meaning = meaning
#     self.section = section


from PyQt4 import QtGui, QtCore
from PyQt4.QtGui import QTextCharFormat, QColor
from terminology import Term as Keyword
import re
import common
    # If there is no previous state, then it's -1, which makes the first line 0.
    # And every line after that increases as expected.
    line = self.previousBlockState() + 1
    self.setCurrentBlockState(line)
    
    # Make sure we aren't too long.
    if len(self.matches) > self.parent().blockCount():
      self.matches = self.matches[:self.parent().blockCount()]
      
    # Make sure our matches list is long enough to hold this line.
    for i in range(len(self.matches), line + 1):
      self.matches.append([])
    
    if len(self.keywords) == 0:
      return
    
    self.matches[line] = []
    
    text = common.qt_to_unicode(text)
    
    for keyword in self.keywords:
      #matches = [match.start() for match in re.finditer(re.escape(keyword.word), text)]
      #matches = [match for match in re.finditer(keyword.word, text, self.re_flags)]
      #matches = re.finditer(keyword.word, text, self.re_flags)
      #keyword.compiled.flags = self.re_flags
      matches = keyword.compiled.finditer(text)
      
      for match in matches:
        self.setFormat(match.start(), match.end() - match.start(), self.format)
        

# Path: terminology.py
# class Term():
#   def __init__(self, word = "", meaning = "", section = ""):
#     self.word    = word
#     self.meaning = meaning
#     self.section = section


# Path: keyword_highlighter.py
from PyQt4 import QtGui, QtCore
from PyQt4.QtGui import QTextCharFormat, QColor
from terminology import Term as Keyword
import re
import common

    # If there is no previous state, then it's -1, which makes the first line 0.
    # And every line after that increases as expected.
    line = self.previousBlockState() + 1
    self.setCurrentBlockState(line)
    
    # Make sure we aren't too long.
    if len(self.matches) > self.parent().blockCount():
      self.matches = self.matches[:self.parent().blockCount()]
      
    # Make sure our matches list is long enough to hold this line.
    for i in range(len(self.matches), line + 1):
      self.matches.append([])
    
    if len(self.keywords) == 0:
      return
    
    self.matches[line] = []
    
    text = common.qt_to_unicode(text)
    
    for keyword in self.keywords:
      #matches = [match.start() for match in re.finditer(re.escape(keyword.word), text)]
      #matches = [match for match in re.finditer(keyword.word, text, self.re_flags)]
      #matches = re.finditer(keyword.word, text, self.re_flags)
      #keyword.compiled.flags = self.re_flags
      matches = keyword.compiled.finditer(text)
      
      for match in matches:
        self.setFormat(match.start(), match.end() - match.start(), self.format)
        

        keyword_match = Keyword()