CadQuery / cadquery

A python parametric CAD scripting framework based on OCCT
https://cadquery.readthedocs.io
Other
2.93k stars 276 forks source link

CQ-Editor doesn't update when using external editor (gvim or notepad) on windows 11 #1567

Closed gitterman closed 2 months ago

gitterman commented 2 months ago

I prefer to use gvim instead of the built-in editor of CQ-Editor. After my initial installation of CQ-Editor I could save a model.py file and automatically saw the updated preview in CQ-Editor. When I now save a model.py file, reload and preview doesn't work. Sometimes I get a FileNotFoundError, but when I then open the file from the "Open" icon in CQ-Editor, it reloads and previews the result properly. I tried with some changes in the auto-reload settings but no success. With other apps, e.g. the Arduino IDE or Thonny, it is no problem to use an external editor. They instantly update if I do a save in an external editor. How can I get CQ-Editor to work with an external editor too?

adam-urbanczyk commented 2 months ago

I don't have windows 11, but on Win 10 and with vim all works as intended.

gitterman commented 2 months ago

This is what is shown in the log viewer. The file is there, though, because I can load and preview it properly from the 'File / open' dialog.

[2024-04-21 12:52:02.495095] ERROR: CQ-Editor: Uncaught exception occurred
Traceback (most recent call last):
  File "C:\ProgramData\CQ-Editor\cq_editor\widgets\editor.py", line 239, in _file_changed
    self.set_text_from_file(self._filename)
  File "C:\ProgramData\miniconda3\envs\cqgui\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 3010, in set_text_from_file
    text, _enc = encoding.read(filename)
  File "C:\ProgramData\miniconda3\envs\cqgui\lib\site-packages\spyder\utils\encoding.py", line 308, in read
    text, encoding = decode( open(filename, 'rb').read() )
FileNotFoundError: [Errno 2] No such file or directory: 'D:/Peter/Development/CadQuery/clamp.py'
jmwright commented 2 months ago

@gitterman You could try adjusting the auto-reload delay.

https://github.com/CadQuery/CQ-editor?tab=readme-ov-file#using-an-external-code-editor

Some editors delete and recreate the file when it is saved, and maybe the timing is a little bit off.

gitterman commented 2 months ago

@jimwright: Thanks a lot for the hint, the error is gone. I had decreased Autoreload delay because I assumed from the name, that a shorter delay would increase the responsiveness. But it obviously is the other way round. A higher delay assures that an externally edited file gets more properly recognized when changed. 4. If CQ-editor is not catching the saves from your external editor, increasing Autoreload delay in the right pane may help. This issue has been reported when using vim or emacs.