8585# Resize editor if display is too big (e.g. 8.8" displays are 1920x480)
8686RESIZE_FACTOR = 2 if (display .lcd .get_width () > 1000 or display .lcd .get_height () > 1000 ) else 1
8787
88+ ERROR_IN_THEME = Image .open ("res/docs/error-in-theme.png" )
89+
8890
8991def refresh_theme ():
9092 config .load_theme ()
@@ -244,7 +246,12 @@ def on_zone_click(event):
244246 subprocess .call (('xdg-open' , config .MAIN_DIRECTORY / theme_file ))
245247
246248 # Load theme file and generate first preview
247- refresh_theme ()
249+ try :
250+ refresh_theme ()
251+ error_in_theme = False
252+ except Exception as e :
253+ logger .error (f"Error in theme: { e } " )
254+ error_in_theme = True
248255
249256 display_width , display_height = int (display .lcd .get_width () / RESIZE_FACTOR ), int (
250257 display .lcd .get_height () / RESIZE_FACTOR )
@@ -268,12 +275,16 @@ def on_zone_click(event):
268275 circular_mask = Image .open (config .MAIN_DIRECTORY / "res/backgrounds/circular-mask.png" )
269276
270277 # Display preview in the window
271- if config .THEME_DATA ["display" ].get ("DISPLAY_SIZE" , '3.5"' ) == '2.1"' :
272- # This is a circular screen: apply a circle mask over the preview
273- display .lcd .screen_image .paste (circular_mask , mask = circular_mask )
274- screen_image = display .lcd .screen_image
275- display_image = ImageTk .PhotoImage (
276- screen_image .resize ((int (screen_image .width / RESIZE_FACTOR ), int (screen_image .height / RESIZE_FACTOR ))))
278+ if not error_in_theme :
279+ screen_image = display .lcd .screen_image
280+ if config .THEME_DATA ["display" ].get ("DISPLAY_SIZE" , '3.5"' ) == '2.1"' :
281+ # This is a circular screen: apply a circle mask over the preview
282+ screen_image .paste (circular_mask , mask = circular_mask )
283+ display_image = ImageTk .PhotoImage (
284+ screen_image .resize ((int (screen_image .width / RESIZE_FACTOR ), int (screen_image .height / RESIZE_FACTOR ))))
285+ else :
286+ size = display_width if display_width < display_height else display_height
287+ display_image = ImageTk .PhotoImage (ERROR_IN_THEME .resize ((display_width , display_width )))
277288 viewer_picture = tkinter .Label (viewer , image = display_image , borderwidth = 0 )
278289 viewer_picture .place (x = RGB_LED_MARGIN , y = RGB_LED_MARGIN )
279290
@@ -300,19 +311,29 @@ def on_zone_click(event):
300311 while True :
301312 if os .path .exists (theme_file ) and os .path .getmtime (theme_file ) > last_edit_time :
302313 logger .debug ("The theme file has been updated, the preview window will refresh" )
303- refresh_theme ()
314+ try :
315+ refresh_theme ()
316+ error_in_theme = False
317+ except Exception as e :
318+ logger .error (f"Error in theme: { e } " )
319+ error_in_theme = True
304320 last_edit_time = os .path .getmtime (theme_file )
305321
306322 # Update the preview.png that is in the theme folder
307323 display .lcd .screen_image .save (config .THEME_DATA ['PATH' ] + "preview.png" , "PNG" )
308324
309325 # Display new picture
310- if config .THEME_DATA ["display" ].get ("DISPLAY_SIZE" , '3.5"' ) == '2.1"' :
311- # This is a circular screen: apply a circle mask over the preview
312- display .lcd .screen_image .paste (circular_mask , mask = circular_mask )
313- screen_image = display .lcd .screen_image
314- display_image = ImageTk .PhotoImage (screen_image .resize (
315- (int (screen_image .width / RESIZE_FACTOR ), int (screen_image .height / RESIZE_FACTOR ))))
326+ if not error_in_theme :
327+ screen_image = display .lcd .screen_image
328+ if config .THEME_DATA ["display" ].get ("DISPLAY_SIZE" , '3.5"' ) == '2.1"' :
329+ # This is a circular screen: apply a circle mask over the preview
330+ screen_image .paste (circular_mask , mask = circular_mask )
331+ display_image = ImageTk .PhotoImage (
332+ screen_image .resize (
333+ (int (screen_image .width / RESIZE_FACTOR ), int (screen_image .height / RESIZE_FACTOR ))))
334+ else :
335+ size = display_width if display_width < display_height else display_height
336+ display_image = ImageTk .PhotoImage (ERROR_IN_THEME .resize ((display_width , display_width )))
316337 viewer_picture .config (image = display_image )
317338
318339 # Refresh RGB backplate LEDs color
0 commit comments