mathoudebine / turing-smart-screen-python

Unofficial Python system monitor and library for small IPS USB-C displays like Turing Smart Screen or XuanFang
GNU General Public License v3.0
1.1k stars 186 forks source link

Theme Editor crashes when using vim #401

Closed orzel closed 9 months ago

orzel commented 10 months ago

When using vim and saving the file, the python code freaks out and the theme editor window dissapears.

27/11/2023 14:13:34 [DEBUG] The theme file has been updated, the preview window will refresh
Traceback (most recent call last):
  File "/home/orzel/clones/turing-smart-screen-python/theme-editor.py", line 263, in <module>
    if os.path.getmtime(theme_file) > last_edit_time:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen genericpath>", line 55, in getmtime
FileNotFoundError: [Errno 2] File o directory non esistente: 'res/themes/test/theme.yaml'

I'm not sure about the details, but I think vim handles filesaving differently than other editors. It uses rename instead of overwritting.

I use the following change, which works, but might be considered a hack, or too quick & dirty, I'll let you decide:

if os.path.exists(theme_file) and os.path.getmtime(theme_file) > last_edit_time:

mathoudebine commented 10 months ago

Hi @orzel, thnaks for raising this issue! I'm okay with your change, it cannot do harm to check if the file exists in any case. Do you want to create a PR for this? Otherwise I can commit the change myself.

orzel commented 10 months ago

For this one-liner, that's probably easier for you to just commit that.