def updatePreviewAfterTypingPause(self): """ Updates the preview when the user is making a pause while typing. """ preview_threshold = Preferences.getPreviewThreshold() time_delta = datetime.now() - self.last_time_content_changed elapsed_ms = time_delta.seconds * 1000 + time_delta.microseconds / 1000 if elapsed_ms >= preview_threshold: self.updatePreview() else: wait_for = max(100, Preferences.getPreviewThreshold() / 2) QTimer.singleShot(wait_for, self.updatePreviewAfterTypingPause)
def requestPreviewUpdate(self): if self._isEndOfInstruction(): self.updatePreview() elif Preferences.getAutoPreview(): self.updatePreviewAfterTypingPause() else: self.request_preview_update = False
def _convertSourceFileToPDF(self): latex2pdf_command = Template(Preferences.getLatexToPDFCommand()) latex2pdf_command = latex2pdf_command.safe_substitute( OUTPUT_DIR=self.output_directory, FILE_NAME=self.unique_random_file_name, FILE_PATH=self.source_file_path) self._latex_process.start(latex2pdf_command)
def loadSnippets(self): snippets_menu = self.actions[actions.SNIPPETS_MENU] snippets_menu.clear() snippets = Preferences.getSnippets() for snippet_name in sorted(snippets.iterkeys()): snippet_code = snippets[snippet_name] action = ActionFactory.createAction(self, snippet_name, "Insert \"%s\" Snippet" % snippet_name, None, self.insertSnippet) action.setData(QVariant(snippet_code)) snippets_menu.addAction(action)
def _initSubViews(self): self.editor_splitter = QSplitter(self) self.editor_splitter.setOrientation(Qt.Vertical) self.editor_splitter.addWidget(self.content_view) self.editor_splitter.addWidget(self.feedback_view) self.editor_splitter.setStretchFactor(0, 2) self.editor_splitter.setStretchFactor(1, 1) if Preferences.hasEditorSplitterState(): self.editor_splitter.restoreState(Preferences.getEditorSplitterState()) self.main_splitter = QSplitter(self) self.main_splitter.setOrientation(Qt.Horizontal) self.main_splitter.addWidget(self.editor_splitter) self.main_splitter.addWidget(self.preview_view) if Preferences.hasMainSplitterState(): self.main_splitter.restoreState(Preferences.getMainSplitterState()) else: self.main_splitter.setSizes([self.width() / 2] * 2) self.setCentralWidget(self.main_splitter)
def _initSubViews(self): self.editor_splitter = QSplitter(self) self.editor_splitter.setOrientation(Qt.Vertical) self.editor_splitter.addWidget(self.content_view) self.editor_splitter.addWidget(self.feedback_view) self.editor_splitter.setStretchFactor(0, 2) self.editor_splitter.setStretchFactor(1, 1) if Preferences.hasEditorSplitterState(): self.editor_splitter.restoreState( Preferences.getEditorSplitterState()) self.main_splitter = QSplitter(self) self.main_splitter.setOrientation(Qt.Horizontal) self.main_splitter.addWidget(self.editor_splitter) self.main_splitter.addWidget(self.preview_view) if Preferences.hasMainSplitterState(): self.main_splitter.restoreState(Preferences.getMainSplitterState()) else: self.main_splitter.setSizes([self.width() / 2] * 2) self.setCentralWidget(self.main_splitter)
def _sourceSelectionChanged(self): select_tags = Preferences.getSelectTags() if (not select_tags): source = self.source_editor_view (line_from, index_from, line_to, index_to) = source.getSelection() selection_changed = False if line_from == 0 and index_from < 19: index_from = 19 selection_changed = True if line_to == source.lines() - 1: line_to = source.lines() - 2 index_to = source.lineSize(line_to + 1) selection_changed = True if selection_changed: source.setSelection(line_from, index_from, line_to, index_to)
def _sourceCursorPositionChanged(self, line, index): select_tags = Preferences.getSelectTags() if (not select_tags): source = self.source_editor_view content = source.content if not (content.startswith("\\begin{tikzpicture}") and content.startswith("\\begin{tikzpicture")): source.content = "\\begin{tikzpicture}" + content[18:] if line == 0 and index < 20: source.setCursorPosition(0, 19) source.setReadOnly(True) elif line == source.lines() - 1: source.setCursorPosition(source.lines() - 2, source.lineSize(source.lines() - 1)) source.setReadOnly(True)
def loadUserPreferences(self): # editor font font = Preferences.getEditorFont() font.setPointSize(12) self.setFont(font) lexer = LexerTikZ() lexer.setDefaultFont(font) self.setLexer(lexer) # margins if self.show_margin: self._setMarginFont(font) else: self._hideMargin() # auto-wrap auto_wrap = Preferences.getAutoWrap() self.setWrapMode(auto_wrap) if auto_wrap: # hide horizontal scrollbar self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0) else: # show horizontal scrollbar self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 1) self.SendScintilla(QsciScintilla.SCI_SETSCROLLWIDTH, 1) self.SendScintilla(QsciScintilla.SCI_SETSCROLLWIDTHTRACKING, 1) # file encoding encoding = Preferences.getFileEncoding() self.setUtf8(encoding == Preferences.ENCODING_UTF8) # line endings line_endings = Preferences.getLineEndings() if line_endings == Preferences.LINE_ENDINGS_WINDOWS: self.setEolMode(EditorView.EolWindows) elif line_endings == Preferences.LINE_ENDINGS_MAC: self.setEolMode(EditorView.EolMac) else: self.setEolMode(EditorView.EolUnix) # indentation type indentation_type = Preferences.getIndentationType() self.setIndentationsUseTabs(indentation_type == Preferences.INDENT_TAB) # indentation size self.setTabWidth(Preferences.getIndentationSize())
def loadUserPreferences(self): # editor font font = Preferences.getEditorFont() self.setFont(font) lexer = LexerTikZ() lexer.setDefaultFont(font) self.setLexer(lexer) # margins if self.show_margin: self._setMarginFont(font) else: self._hideMargin() # auto-wrap auto_wrap = Preferences.getAutoWrap() self.setWrapMode(auto_wrap) if auto_wrap: # hide horizontal scrollbar self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0) else: # show horizontal scrollbar self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 1) self.SendScintilla(QsciScintilla.SCI_SETSCROLLWIDTH, 1) self.SendScintilla(QsciScintilla.SCI_SETSCROLLWIDTHTRACKING, 1) # file encoding encoding = Preferences.getFileEncoding() self.setUtf8(encoding == Preferences.ENCODING_UTF8) # line endings line_endings = Preferences.getLineEndings() if line_endings == Preferences.LINE_ENDINGS_WINDOWS: self.setEolMode(EditorView.EolWindows) elif line_endings == Preferences.LINE_ENDINGS_MAC: self.setEolMode(EditorView.EolMac) else: self.setEolMode(EditorView.EolUnix) # indentation type indentation_type = Preferences.getIndentationType() self.setIndentationsUseTabs(indentation_type == Preferences.INDENT_TAB) # indentation size self.setTabWidth(Preferences.getIndentationSize())
def _restoreAllSnippets(self): self.snippets = Preferences.defaultSnippets() self.snippetsChangedSignal.emit(self.snippets)
def _restoreWindowState(self): if Preferences.hasWindowGeometry(): self.restoreGeometry(Preferences.getWindowGeometry())
def _initSelectedView(self): selected_view = Preferences.getSelectedFeedbackView() if selected_view == ERRORS_VIEW: self.showErrorsView() else: self.showLogsView()
def showErrorsView(self): self.stacked_widget.setCurrentWidget(self.errors_view) Preferences.setSelectedFeedbackView(ERRORS_VIEW) if not self.actions[actions.SHOW_ERRORS].isChecked(): self.actions[actions.SHOW_ERRORS].setChecked(True)
def _restoreDefaultTemplate(self): self.latex_file_editor.content = Preferences.defaultLatexFileTemplate()
def _convertPDFToImage(self): pdf2image_command = Template(Preferences.getPDFToImageCommand()) pdf2image_command = pdf2image_command.safe_substitute( PDF_PATH=self.pdf_file_path, IMAGE_PATH=self.png_file_path) self._convert_process.start(pdf2image_command)
def _restoreDefaultLatex2PDF(self): self.latex2pdf_text.setText(Preferences.defaultLatexToPDFCommand())
def _syncViewAndModel(self): self.view.editor.editor_font = Preferences.getEditorFont() self.view.editor.file_encoding = Preferences.getFileEncoding() self.view.editor.line_endings = Preferences.getLineEndings() self.view.editor.indentation_type = Preferences.getIndentationType() self.view.editor.indentation_size = Preferences.getIndentationSize() self.view.editor.auto_wrap = Preferences.getAutoWrap() self.view.editor.error_markers = Preferences.getShowErrorMarkers() self.view.editor.error_annotations = Preferences.getShowErrorAnnotations() self.view.editor.auto_preview = Preferences.getAutoPreview() self.view.editor.preview_threshold = Preferences.getPreviewThreshold() self.view.document.latex_file_template = Preferences.getLatexFileTemplate() self.view.document.preamble_template = Preferences.getPreambleTemplate() self.view.preview.preview_template = Preferences.getPreviewTemplate() self.view.preview.latex_to_pdf_command = Preferences.getLatexToPDFCommand() self.view.preview.pdf_to_image_command = Preferences.getPDFToImageCommand() self.view.snippets.snippets = Preferences.getSnippets()
def _restoreDefaultPreviewTemplate(self): self.preview_template_editor.content = Preferences.defaultPreviewTemplate( )
def showLogsView(self): self.stacked_widget.setCurrentWidget(self.logs_view) Preferences.setSelectedFeedbackView(LOGS_VIEW) if not self.actions[actions.SHOW_LOGS].isChecked(): self.actions[actions.SHOW_LOGS].setChecked(True)
def _restoreDefaultPDF2Image(self): self.pdf2image_text.setText(Preferences.defaultPDFToImageCommand())
def _convertPDFToImage(self): pdf2image_command = Template(Preferences.getPDFToImageCommand()) pdf2image_command = pdf2image_command.safe_substitute(PDF_PATH=self.pdf_file_path, IMAGE_PATH=self.png_file_path) self._convert_process.start(pdf2image_command)
def _restoreDefaultPreviewTemplate(self): self.preview_template_editor.content = Preferences.defaultPreviewTemplate()
def _restoreDefaultPreamble(self): self.preamble_editor.content = Preferences.defaultPreambleTemplate()
def _convertSourceFileToPDF(self): latex2pdf_command = Template(Preferences.getLatexToPDFCommand()) latex2pdf_command = latex2pdf_command.safe_substitute(OUTPUT_DIR=self.output_directory, FILE_NAME=self.unique_random_file_name, FILE_PATH=self.source_file_path) self._latex_process.start(latex2pdf_command)
def _restoreWindowState(self): if Preferences.hasWindowGeometry(): self.restoreGeometry(Preferences.getWindowGeometry()) else: self.setWindowState(Qt.WindowMaximized)
def loadUserPreferences(self): self.show_error_markers = Preferences.getShowErrorMarkers() self.show_error_annotations = Preferences.getShowErrorAnnotations() self.clearErrorMarginMarkersAndAnnotations() self._updateEditorsMarginsAndAnnotations()
def _saveWindowState(self): Preferences.setWindowGeometry(self.saveGeometry()) Preferences.setEditorSplitterState(self.editor_splitter.saveState()) Preferences.setMainSplitterState(self.main_splitter.saveState())
def updatePreview(self): self.request_preview_update = False doc = self.doc_controller.model template = Preferences.getPreviewTemplate() source = documentIO.buildFileContentFromDocument(template, doc) self.latex2image_converter.convertLatexToImage(source)