8282
8383RGB_LED_MARGIN = 12
8484
85+ # Resize editor if display is too big (e.g. 8.8" displays are 1920x480)
86+ RESIZE_FACTOR = 2 if (display .lcd .get_width () > 1000 or display .lcd .get_height () > 1000 ) else 1
87+
8588
8689def refresh_theme ():
8790 config .load_theme ()
@@ -159,35 +162,42 @@ def on_button1_press(event):
159162
160163 def on_button1_press_and_drag (event ):
161164 global x0 , y0
165+ display_width , display_height = int (display .lcd .get_width () / RESIZE_FACTOR ), int (
166+ display .lcd .get_height () / RESIZE_FACTOR )
162167 x1 , y1 = event .x , event .y
163168
164169 # Do not draw zone outside of theme preview
165170 if x1 < 0 :
166171 x1 = 0
167- elif x1 >= display . lcd . get_width () :
168- x1 = display . lcd . get_width () - 1
172+ elif x1 >= display_width :
173+ x1 = display_width - 1
169174 if y1 < 0 :
170175 y1 = 0
171- elif y1 >= display . lcd . get_height () :
172- y1 = display . lcd . get_height () - 1
176+ elif y1 >= display_height :
177+ y1 = display_height - 1
173178
174- label_coord .config (text = 'Drawing zone from [{},{}] to [{},{}]' .format (x0 , y0 , x1 , y1 ))
179+ label_coord .config (text = 'Drawing zone from [{:0.0f},{:0.0f}] to [{:0.0f},{:0.0f}]' .format (x0 * RESIZE_FACTOR ,
180+ y0 * RESIZE_FACTOR ,
181+ x1 * RESIZE_FACTOR ,
182+ y1 * RESIZE_FACTOR ))
175183 draw_zone (x0 , y0 , x1 , y1 )
176184
177185
178186 def on_button1_release (event ):
179187 global x0 , y0
188+ display_width , display_height = int (display .lcd .get_width () / RESIZE_FACTOR ), int (
189+ display .lcd .get_height () / RESIZE_FACTOR )
180190 x1 , y1 = event .x , event .y
181191 if x1 != x0 or y1 != y0 :
182192 # Do not draw zone outside of theme preview
183193 if x1 < 0 :
184194 x1 = 0
185- elif x1 >= display . lcd . get_width () :
186- x1 = display . lcd . get_width () - 1
195+ elif x1 >= display_width :
196+ x1 = display_width - 1
187197 if y1 < 0 :
188198 y1 = 0
189- elif y1 >= display . lcd . get_height () :
190- y1 = display . lcd . get_height () - 1
199+ elif y1 >= display_height :
200+ y1 = display_height - 1
191201
192202 # Display drawn zone and coordinates
193203 draw_zone (x0 , y0 , x1 , y1 )
@@ -197,11 +207,16 @@ def on_button1_release(event):
197207 y = min (y0 , y1 )
198208 width = max (x0 , x1 ) - min (x0 , x1 )
199209 height = max (y0 , y1 ) - min (y0 , y1 )
200- label_coord .config (text = 'Zone: X={}, Y={}, width={} height={}' .format (x , y , width , height ))
210+
211+ label_coord .config (text = 'Zone: X={:0.0f}, Y={:0.0f}, width={:0.0f} height={:0.0f}' .format (x * RESIZE_FACTOR ,
212+ y * RESIZE_FACTOR ,
213+ width * RESIZE_FACTOR ,
214+ height * RESIZE_FACTOR ))
201215 else :
202216 # Display click coordinates
203217 label_coord .config (
204- text = 'X={}, Y={} (click and drag to draw a zone)' .format (x0 , y0 , abs (x1 - x0 ), abs (y1 - y0 )))
218+ text = 'X={:0.0f}, Y={:0.0f} (click and drag to draw a zone)' .format (x0 * RESIZE_FACTOR ,
219+ y0 * RESIZE_FACTOR ))
205220
206221
207222 def on_zone_click (event ):
@@ -231,13 +246,15 @@ def on_zone_click(event):
231246 # Load theme file and generate first preview
232247 refresh_theme ()
233248
249+ display_width , display_height = int (display .lcd .get_width () / RESIZE_FACTOR ), int (
250+ display .lcd .get_height () / RESIZE_FACTOR )
251+
234252 # Create preview window
235253 logger .debug ("Opening theme preview window with static data" )
236254 viewer = tkinter .Tk ()
237255 viewer .title ("Turing SysMon Theme Editor" )
238256 viewer .iconphoto (True , tkinter .PhotoImage (file = config .MAIN_DIRECTORY / "res/icons/monitor-icon-17865/64.png" ))
239- viewer .geometry (str (display .lcd .get_width () + 2 * RGB_LED_MARGIN ) + "x" + str (
240- display .lcd .get_height () + 2 * RGB_LED_MARGIN + 40 ))
257+ viewer .geometry (str (display_width + 2 * RGB_LED_MARGIN ) + "x" + str (display_height + 2 * RGB_LED_MARGIN + 40 ))
241258 viewer .protocol ("WM_DELETE_WINDOW" , on_closing )
242259 viewer .call ('wm' , 'attributes' , '.' , '-topmost' , '1' ) # Preview window always on top
243260 viewer .config (cursor = "cross" )
@@ -254,7 +271,9 @@ def on_zone_click(event):
254271 if config .THEME_DATA ["display" ].get ("DISPLAY_SIZE" , '3.5"' ) == '2.1"' :
255272 # This is a circular screen: apply a circle mask over the preview
256273 display .lcd .screen_image .paste (circular_mask , mask = circular_mask )
257- display_image = ImageTk .PhotoImage (display .lcd .screen_image )
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 ))))
258277 viewer_picture = tkinter .Label (viewer , image = display_image , borderwidth = 0 )
259278 viewer_picture .place (x = RGB_LED_MARGIN , y = RGB_LED_MARGIN )
260279
@@ -264,12 +283,12 @@ def on_zone_click(event):
264283 viewer_picture .bind ("<ButtonRelease-1>" , on_button1_release )
265284
266285 label_coord = tkinter .Label (viewer , text = "Click or draw a zone to show coordinates" )
267- label_coord .place (x = 0 , y = display . lcd . get_height () + 2 * RGB_LED_MARGIN ,
268- width = display . lcd . get_width () + 2 * RGB_LED_MARGIN )
286+ label_coord .place (x = 0 , y = display_height + 2 * RGB_LED_MARGIN ,
287+ width = display_width + 2 * RGB_LED_MARGIN )
269288
270289 label_info = tkinter .Label (viewer , text = "This preview will reload when theme file is updated" )
271- label_info .place (x = 0 , y = display . lcd . get_height () + 2 * RGB_LED_MARGIN + 20 ,
272- width = display . lcd . get_width () + 2 * RGB_LED_MARGIN )
290+ label_info .place (x = 0 , y = display_height + 2 * RGB_LED_MARGIN + 20 ,
291+ width = display_width + 2 * RGB_LED_MARGIN )
273292
274293 label_zone = tkinter .Label (viewer , bg = '#%02x%02x%02x' % tuple (map (lambda x : 255 - x , led_color )))
275294 label_zone .bind ("<ButtonRelease-1>" , on_zone_click )
@@ -291,7 +310,9 @@ def on_zone_click(event):
291310 if config .THEME_DATA ["display" ].get ("DISPLAY_SIZE" , '3.5"' ) == '2.1"' :
292311 # This is a circular screen: apply a circle mask over the preview
293312 display .lcd .screen_image .paste (circular_mask , mask = circular_mask )
294- display_image = ImageTk .PhotoImage (display .lcd .screen_image )
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 ))))
295316 viewer_picture .config (image = display_image )
296317
297318 # Refresh RGB backplate LEDs color
0 commit comments