示例#1
0
        def __init__(self, file):
            self.__file = file
            self.__parser = BibTeXParser(quiet=True)
            self.__issue_handler = MockIssueHandler()
            self.__mtime = 0
            self.__document = None

            self.synchronize()
示例#2
0
文件: cache.py 项目: Sbte/gedit-latex
    class Entry(object):
        """
        An entry in the cache
        """
        _log = getLogger("bibtex.cache.BibTeXDocumentCache.Entry")

        def __init__(self, file):
            self.__file = file
            self.__parser = BibTeXParser(quiet=True)
            self.__issue_handler = MockIssueHandler()
            self.__mtime = 0
            self.__document = None

            self.synchronize()

        @property
        def modified(self):
            return (self.__file.mtime > self.__mtime)

        @property
        def document(self):
            return self.__document

        def synchronize(self):
            """
            Synchronize document model with file contents.

            This may throw OSError
            """
            # update timestamp
            self.__mtime = self.__file.mtime

            # parse
            self.__document = self.__parser.parse(open(self.__file.path, "r").read(), self.__file, self.__issue_handler)
示例#3
0
文件: cache.py 项目: Sbte/gedit-latex
        def __init__(self, file):
            self.__file = file
            self.__parser = BibTeXParser(quiet=True)
            self.__issue_handler = MockIssueHandler()
            self.__mtime = 0
            self.__document = None

            self.synchronize()
示例#4
0
    def init(self, file, context):
        LOG.debug("init(%s)" % file)

        self._preferences = Preferences()

        self._file = file
        self._context = context

        self.register_marker_type("bibtex-error", self._preferences.get("error-background-color"))
        self.register_marker_type("bibtex-warning", self._preferences.get("warning-background-color"))

        self._issue_view = context.find_view(self, "IssueView")
        self._parser = BibTeXParser()
        self._validator = BibTeXValidator()
        self._outline_view = context.find_view(self, "BibTeXOutlineView")

        self._parse_job = ParseJob()
        self._parse_job.set_change_listener(self)

        # initially parse
        self.__parse()
示例#5
0
    class Entry(object):
        """
		An entry in the cache
		"""
        _log = getLogger("bibtex.cache.BibTeXDocumentCache.Entry")

        def __init__(self, file):
            self.__file = file
            self.__parser = BibTeXParser(quiet=True)
            self.__issue_handler = MockIssueHandler()
            self.__mtime = 0
            self.__document = None

            self.synchronize()

        @property
        def modified(self):
            return (self.__file.mtime > self.__mtime)

        @property
        def document(self):
            return self.__document

        def synchronize(self):
            """
			Synchronize document model with file contents.

			This may throw OSError
			"""
            # update timestamp
            self.__mtime = self.__file.mtime

            # parse
            self.__document = self.__parser.parse(
                open(self.__file.path, "r").read(), self.__file,
                self.__issue_handler)
示例#6
0
class BibTeXEditor(Editor, IIssueHandler, JobChangeListener):

	_log = getLogger("BibTeXEditor")
	extensions = [".bib"]

	@property
	def completion_handlers(self):
		self.__bibtex_completion_handler = BibTeXCompletionHandler()
		return [ self.__bibtex_completion_handler ]

	def __init__(self, tab_decorator, file):
		Editor.__init__(self, tab_decorator, file)
		self._parse_job = None

	def init(self, file, context):
		self._log.debug("init(%s)" % file)

		self._preferences = Preferences()

		self._file = file
		self._context = context

		self.register_marker_type("bibtex-error", self._preferences.get("ErrorBackgroundColor"))
		self.register_marker_type("bibtex-warning", self._preferences.get("WarningBackgroundColor"))

		self._issue_view = context.find_view(self, "IssueView")
		self._parser = BibTeXParser()
		self._validator = BibTeXValidator()
		self._outline_view = context.find_view(self, "BibTeXOutlineView")

		self._parse_job = ParseJob()
		self._parse_job.set_change_listener(self)


		# initially parse
		self.__parse()

	def on_save(self):
		"""
		The file has been saved

		Update models
		"""
		self.__parse()


#	def _on_state_changed(self, state):
#		#
#		# job.JobChangeListener._on_state_changed
#		#
#		if (state == JobManager.STATE_COMPLETED):
#			self._log.debug("Parser finished")
#
#			self._document = self._parse_job.get_returned()
#
#			#self._log.debug(str(self._document))
#
#			for entry in self._document.entries:
#				print entry.key
#
#			# FIXME: pluma crashes here with:
#			# pluma: Fatal IO error 11 (Resource temporarily unavailable) on X server :0.0.
#
#			self._log.debug("Validating...")
#			self._validator.validate(self._document, self._file, self)
#			self._log.debug("Validating finished")
#
#			self._outline_view.set_outline(self._document)
#
#
#	def __parse_async(self):
#
#		# reset highlight
#		self.remove_markers("bibtex-error")
#		self.remove_markers("bibtex-warning")
#
#		# reset issues
#		self._issue_view.clear()
#
#		self._log.debug("Starting parser job")
#
#		self._parse_job.set_argument([self._file, self.content])
#		self._parse_job.schedule()


	@verbose
	def __parse(self):
		"""
		"""
		self._log.debug("__parse")

		content = self.content

		# reset highlight
		self.remove_markers("bibtex-error")
		self.remove_markers("bibtex-warning")

		# reset issues
		self._issue_view.clear()

#		self.parse(self._file)

		if BENCHMARK: t = time.clock()

		# parse document
		self._document = self._parser.parse(content, self._file, self)

		if BENCHMARK: self._log.info("BibTeXParser.parse: %f" % (time.clock() - t))

		self._log.debug("Parsed %s bytes of content" % len(content))

		# validate
		if BENCHMARK: t = time.clock()

		self._validator.validate(self._document, self._file, self)

		# 0.11
		if BENCHMARK: self._log.info("BibTeXValidator.validate: %f" % (time.clock() - t))

		self._outline_view.set_outline(self._document)

#	def _on_parser_finished(self, model):
#		"""
#		"""
#		self._document = model
#		self._outline_view.set_outline(self._document)

	def issue(self, issue):
		# overriding IIssueHandler.issue

		self._issue_view.append_issue(issue)

		if issue.file == self._file:
			if issue.severity == Issue.SEVERITY_ERROR:
				self.create_marker("bibtex-error", issue.start, issue.end)
			elif issue.severity == Issue.SEVERITY_WARNING:
				self.create_marker("bibtex-warning", issue.start, issue.end)

	def on_cursor_moved(self, offset):
		"""
		The cursor has moved
		"""
		if self._preferences.get_bool("ConnectOutlineToEditor", True):
			self._outline_view.select_path_by_offset(offset)

	def destroy(self):
		# unreference the window context
		del self._context

		# remove parse listener
		if self._parse_job != None:
			self._parse_job.set_change_listener(None)

		Editor.destroy(self)

	def __del__(self):
		self._log.debug("Properly destroyed %s" % self)
示例#7
0
	def _run(self, arguments):
		file = arguments[0]
		content = arguments[1]
		self._parser = BibTeXParser()
		return self._parser.parse(content, file, MockIssueHandler())
示例#8
0
 def __init__(self):
     self._model = BibTeXModel()
     self._parser = BibTeXParser()
     self._issue_handler = MockIssueHandler()