1919"""
2020
2121from datetime import datetime
22- import json
2322
2423import wx
2524import wx .lib .scrolledpanel as SP
@@ -233,9 +232,30 @@ def _updateRegionSettingsGrid(self, command_info):
233232 self .sizer_region_settings_grid .Clear (True )
234233
235234 self .region_settings = command_info ["region" ]
235+
236+ Display_Order = [
237+ "n" ,
238+ "s" ,
239+ "e" ,
240+ "w" ,
241+ "nsres" ,
242+ "ewres" ,
243+ "rows" ,
244+ "cols" ,
245+ "t" ,
246+ "b" ,
247+ "tbres" ,
248+ "nsres3" ,
249+ "ewres3" ,
250+ "rows3" ,
251+ "cols3" ,
252+ "depths" ,
253+ ]
254+
236255 idx = 0
237- for key , value in self .region_settings .items ():
238- if self ._region_settings_filter (key ):
256+ for key in Display_Order :
257+ if key in self .region_settings :
258+ value = self .region_settings [key ]
239259 self .sizer_region_settings_grid .Add (
240260 StaticText (
241261 parent = self .region_settings_box ,
@@ -263,42 +283,37 @@ def _updateRegionSettingsGrid(self, command_info):
263283 self .region_settings_box .Show ()
264284
265285 def _get_saved_region_name (self , history_region ):
266- """Find if history region matches any saved region in the current mapset ."""
286+ """Find if history region matches any saved region in the entire project ."""
267287 try :
268- res = self .tools .g_list (type = "region" , mapset = "." , format = "json" )
269- regions = json .loads (res .stdout )
270- region_names = [r ["name" ] for r in regions ]
271- except Exception :
288+ res = self .tools .g_list (type = "region" , mapset = "*" , format = "json" )
289+ region_names = [r ["name" ] for r in res ]
290+ except (KeyError , TypeError ):
272291 return None
273292
274293 for region_name in region_names :
275294 region_name = region_name .strip ()
276- if not region_name :
277- continue
278- try :
279- saved_region = self .tools .g_region (
280- region = region_name , flags = "u3" , format = "shell"
281- ).keyval
295+ if region_name :
296+ try :
297+ saved_region = self .tools .g_region (
298+ region = region_name , flags = "u3" , format = "shell"
299+ ).keyval
282300
283- if self ._compare_regions (history_region , saved_region ):
284- return region_name
285- except Exception :
286- continue
301+ if self ._compare_regions (history_region , saved_region ):
302+ return region_name
303+ except AttributeError :
304+ continue
287305
288306 return None
289307
290308 def _compare_regions (self , r1 , r2 ):
291309 """Compare two region dictionaries for equality."""
292- skip_keys = {"projection" , "zone" , "cells" , "cells3" }
293-
294310 for k , v in r1 .items ():
295- if k in skip_keys :
296- continue
297- try :
298- if abs (float (v ) - float (r2 [k ])) > 1e-8 :
311+ if self ._region_settings_filter (k ):
312+ try :
313+ if abs (float (v ) - float (r2 [k ])) > 1e-8 :
314+ return False
315+ except (KeyError , ValueError , TypeError ):
299316 return False
300- except (KeyError , ValueError , TypeError ):
301- return False
302317 return True
303318
304319 def _updateRegionSettingsMatch (self ):
@@ -312,17 +327,17 @@ def _updateRegionSettingsMatch(self):
312327 region_matches = self ._compare_regions (history_region , current_region )
313328 saved_name = self ._get_saved_region_name (history_region )
314329
315- region_label = saved_name or _ ( "Not set" )
316-
317- self . sizer_region_name . Add (
318- StaticText (
319- parent = self . region_settings_box ,
320- id = wx . ID_ANY ,
321- label = _ ( "Region name: {}" ). format ( region_label ),
322- ) ,
323- proportion = 0 ,
324- flag = wx . ALIGN_CENTER_VERTICAL ,
325- )
330+ if saved_name :
331+ self . sizer_region_name . Add (
332+ StaticText (
333+ parent = self . region_settings_box ,
334+ id = wx . ID_ANY ,
335+ label = _ ( "Region name: {}" ). format ( saved_name ) ,
336+ ),
337+ proportion = 0 ,
338+ flag = wx . ALIGN_CENTER_VERTICAL | wx . RIGHT ,
339+ border = 10 ,
340+ )
326341
327342 # Icon and button according to the condition
328343 if region_matches :
@@ -396,11 +411,24 @@ def _get_current_region(self):
396411
397412 def _get_history_region (self ):
398413 """Get computational region settings of executed command."""
414+ valid_keys = {
415+ "n" ,
416+ "s" ,
417+ "e" ,
418+ "w" ,
419+ "nsres" ,
420+ "ewres" ,
421+ "t" ,
422+ "b" ,
423+ "tbres" ,
424+ "nsres3" ,
425+ "ewres3" ,
426+ }
427+
399428 return {
400429 key : value
401430 for key , value in self .region_settings .items ()
402- if self ._region_settings_filter (key )
403- and key not in {"rows3" , "cols3" , "depths" }
431+ if key in valid_keys
404432 }
405433
406434 def OnUpdateRegion (self , event ):
0 commit comments