Skip to content

Commit 7159ef3

Browse files
authored
Make autoreload delay configurable (#217)
With some editors the autoreload delay is not enough and we end up loading non-existent file. Fix this by making the interval configurable. The `self.updatePreferences()` line is moved below autoreload support setup because it changes _file_watch_timer interval, so _file_watch_timer must already exist. Fixes #215
1 parent 2f75bf6 commit 7159ef3

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

cq_editor/widgets/editor.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Editor(CodeEditor,ComponentMixin):
2525
preferences = Parameter.create(name='Preferences',children=[
2626
{'name': 'Font size', 'type': 'int', 'value': 12},
2727
{'name': 'Autoreload', 'type': 'bool', 'value': False},
28+
{'name': 'Autoreload delay', 'type': 'int', 'value': 50},
2829
{'name': 'Line wrap', 'type': 'bool', 'value': False},
2930
{'name': 'Color scheme', 'type': 'list',
3031
'values': ['Spyder','Monokai','Zenburn'], 'value': 'Spyder'}])
@@ -81,18 +82,19 @@ def __init__(self,parent=None):
8182

8283

8384
self._fixContextMenu()
84-
self.updatePreferences()
8585

8686
# autoreload support
8787
self._file_watcher = QFileSystemWatcher(self)
8888
# we wait for 50ms after a file change for the file to be written completely
8989
self._file_watch_timer = QTimer(self)
90-
self._file_watch_timer.setInterval(50)
90+
self._file_watch_timer.setInterval(self.preferences['Autoreload delay'])
9191
self._file_watch_timer.setSingleShot(True)
9292
self._file_watcher.fileChanged.connect(
9393
lambda val: self._file_watch_timer.start())
9494
self._file_watch_timer.timeout.connect(self._file_changed)
9595

96+
self.updatePreferences()
97+
9698
def _fixContextMenu(self):
9799

98100
menu = self.menu
@@ -112,6 +114,8 @@ def updatePreferences(self,*args):
112114

113115
self.findChild(QAction, 'autoreload') \
114116
.setChecked(self.preferences['Autoreload'])
117+
118+
self._file_watch_timer.setInterval(self.preferences['Autoreload delay'])
115119

116120
self.toggle_wrap_mode(self.preferences['Line wrap'])
117121

0 commit comments

Comments
 (0)