Skip to content
Browse files

Added auto-preview and preview threshold preferences

  • Loading branch information...
1 parent dad3a80 commit 88a806b2df79bbe3f3324d8259f497b537de1261 @mickael-menu mickael-menu committed
View
5 tikz_editor/controllers/preferences.py
@@ -45,6 +45,8 @@ def _connectViewAndModel(self):
self.view.editor.autoWrapChangedSignal.connect(Preferences.setAutoWrap)
self.view.editor.errorMarkersChangedSignal.connect(Preferences.setShowErrorMarkers)
self.view.editor.errorAnnotationsChangedSignal.connect(Preferences.setShowErrorAnnotations)
+ self.view.editor.autoPreviewChangedSignal.connect(Preferences.setAutoPreview)
+ self.view.editor.previewThresholdChangedSignal.connect(Preferences.setPreviewThreshold)
self.view.editor.editorFontChangedSignal.connect(EditorView.reloadUserPreferences)
self.view.editor.fileEncodingChangedSignal.connect(EditorView.reloadUserPreferences)
@@ -65,6 +67,7 @@ def _connectViewAndModel(self):
self.view.snippets.snippetsChangedSignal.connect(Preferences.setSnippets)
self.view.snippets.snippetsChangedSignal.connect(self.app_controller.loadSnippets)
+
def _syncViewAndModel(self):
self.view.editor.editor_font = Preferences.getEditorFont()
self.view.editor.file_encoding = Preferences.getFileEncoding()
@@ -74,6 +77,8 @@ def _syncViewAndModel(self):
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()
View
13 tikz_editor/controllers/preview.py
@@ -60,11 +60,12 @@ def conversionAborted(self):
self.preview_view.showErrorBackground()
def requestPreviewUpdate(self):
- self.request_preview_update = True
if self._isEndOfInstruction():
self.updatePreview()
- else:
+ elif Preferences.getAutoPreview():
self.updatePreviewAfterTypingPause()
+ else:
+ self.request_preview_update = False
def _isEndOfInstruction(self):
"""
@@ -77,10 +78,14 @@ def updatePreviewAfterTypingPause(self):
"""
Updates the preview when the user is making a pause while typing.
"""
- if (datetime.now() - self.last_time_content_changed).microseconds >= 500000:
+ 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:
- QTimer.singleShot(400, self.updatePreviewAfterTypingPause)
+ wait_for = max(100, Preferences.getPreviewThreshold() / 2)
+ QTimer.singleShot(wait_for, self.updatePreviewAfterTypingPause)
def updatePreview(self):
self.request_preview_update = False
View
2 tikz_editor/globals/defaults.py
@@ -21,6 +21,8 @@
AUTO_WRAP = True
SHOW_ERROR_MARKERS = True
SHOW_ERROR_ANNOTATIONS = True
+PREVIEW_THRESHOLD = 500 # times in ms before previewing when the user stop typing
+AUTO_PREVIEW = True
DEFAULT_PREAMBLE_TEMPLATE = u''
DEFAULT_TEMPLATE = u"""\\documentclass{article}
View
41 tikz_editor/models/preferences.py
@@ -44,6 +44,8 @@ class PreferencesModel(object):
SHOW_ERROR_MARKERS = "ShowErrorMarkers"
SHOW_ERROR_ANNOTATIONS = "ShowErrorAnnotations"
SNIPPETS = "Snippets"
+ PREVIEW_THRESHOLD = "PreviewThreshold"
+ AUTO_PREVIEW = "AutoPreview"
FEEDBACK_LOGS_VIEW = 0
FEEDBACK_ERRORS_VIEW = 1
@@ -318,6 +320,45 @@ def setShowErrorAnnotations(value):
def defaultShowErrorAnnotations():
return defaults.SHOW_ERROR_MARKERS
+ @staticmethod
+ def hasPreviewThreshold():
+ return PreferencesModel.containsKey(PreferencesModel.PREVIEW_THRESHOLD)
+
+ @staticmethod
+ def getPreviewThreshold():
+ value = PreferencesModel.getValueOrDefault(PreferencesModel.PREVIEW_THRESHOLD, PreferencesModel.defaultPreviewThreshold()).toInt()
+ convert_success = value[1]
+ value = value[0]
+ if not (convert_success and value > 0):
+ value = PreferencesModel.defaultThreshold()
+ return value
+
+ @staticmethod
+ def setPreviewThreshold(value):
+ assert value > 0
+ PreferencesModel.setValue(PreferencesModel.PREVIEW_THRESHOLD, value)
+
+ @staticmethod
+ def defaultPreviewThreshold():
+ return defaults.PREVIEW_THRESHOLD
+
+
+ @staticmethod
+ def hasAutoPreview():
+ return PreferencesModel.containsKey(PreferencesModel.AUTO_PREVIEW)
+
+ @staticmethod
+ def getAutoPreview():
+ return PreferencesModel.getValueOrDefault(PreferencesModel.AUTO_PREVIEW, PreferencesModel.defaultAutoPreview()).toBool()
+
+ @staticmethod
+ def setAutoPreview(value):
+ PreferencesModel.setValue(PreferencesModel.AUTO_PREVIEW, value)
+
+ @staticmethod
+ def defaultAutoPreview():
+ return defaults.AUTO_PREVIEW
+
################################################################################
@staticmethod
View
39 tikz_editor/views/preferences/editor.py
@@ -34,6 +34,8 @@ class EditorPreferencesView(QWidget):
autoWrapChangedSignal = pyqtSignal(bool)
errorMarkersChangedSignal = pyqtSignal(bool)
errorAnnotationsChangedSignal = pyqtSignal(bool)
+ autoPreviewChangedSignal = pyqtSignal(bool)
+ previewThresholdChangedSignal = pyqtSignal(int)
def __init__(self, parent=None):
super(EditorPreferencesView, self).__init__(parent)
@@ -60,6 +62,10 @@ def __init__(self, parent=None):
self.error_markers_choice = QCheckBox("Show error marker in margin of erroneous lines")
self.error_annotations_choice = QCheckBox("Show error annotations beneath erroneous lines")
+ self.preview_choice = QCheckBox("Trigger preview after stopping edition for")
+ self.preview_threshold_choice = QSpinBox()
+ self.preview_label = QLabel("ms")
+
def initView(self):
self._initConnections()
self._initWidgets()
@@ -74,6 +80,8 @@ def _initConnections(self):
self.wrap_choice.stateChanged.connect(self._autoWrapChanged)
self.error_markers_choice.stateChanged.connect(self._errorMarkersChanged)
self.error_annotations_choice.stateChanged.connect(self._errorAnnotationsChanged)
+ self.preview_choice.stateChanged.connect(self._autoPreviewChanged)
+ self.preview_threshold_choice.valueChanged.connect(self._previewThresholdChanged)
def _initWidgets(self):
self.font_choice.setReadOnly(True)
@@ -95,6 +103,9 @@ def _initWidgets(self):
# self.indent_size_choice.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.indent_size_choice.setMinimum(1)
+ self.preview_threshold_choice.setRange(100, 100000)
+ # self.preview_threshold_choice.setSuffix(" ms") # I think it's ugly
+
def _initLayout(self):
layout = QFormLayout()
layout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow)
@@ -113,6 +124,12 @@ def _initLayout(self):
layout.addRow(self.wrap_choice)
layout.addRow(self.error_markers_choice)
layout.addRow(self.error_annotations_choice)
+ layout.addRow(tikz_editor.views.factory.ViewFactory.createLineSeparator())
+ sublayout2 = QHBoxLayout()
+ sublayout2.addWidget(self.preview_choice)
+ sublayout2.addWidget(self.preview_threshold_choice)
+ sublayout2.addWidget(self.preview_label)
+ layout.addRow(sublayout2)
self.setLayout(layout)
@@ -143,6 +160,12 @@ def _errorMarkersChanged(self, state):
def _errorAnnotationsChanged(self, state):
self.errorAnnotationsChangedSignal.emit(state)
+ def _autoPreviewChanged(self, state):
+ self.autoPreviewChangedSignal.emit(state)
+
+ def _previewThresholdChanged(self, value):
+ self.previewThresholdChangedSignal.emit(value)
+
@property
def editor_font(self):
return self.font
@@ -210,3 +233,19 @@ def error_annotations(self):
@error_annotations.setter
def error_annotations(self, value):
self.error_annotations_choice.setChecked(value)
+
+ @property
+ def auto_preview(self):
+ return self.preview_choice.isChecked()
+
+ @auto_preview.setter
+ def auto_preview(self, value):
+ self.preview_choice.setChecked(value)
+
+ @property
+ def preview_threshold(self):
+ return self.preview_threshold_choice.value()
+
+ @preview_threshold.setter
+ def preview_threshold(self, value):
+ self.preview_threshold_choice.setValue(value)

0 comments on commit 88a806b

Please sign in to comment.
Something went wrong with that request. Please try again.