wolfhece 2.0.55__py3-none-any.whl → 2.1.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
wolfhece/PyPalette.py CHANGED
@@ -322,6 +322,7 @@ class wolfpalette(wx.Frame,LinearSegmentedColormap):
322
322
 
323
323
  On copie les valeurs, on ne pointe pas l'objet
324
324
  """
325
+
325
326
  for k in range(len(srcpal.values)):
326
327
  self.values[k]=srcpal.values[k]
327
328
 
@@ -374,6 +375,7 @@ class wolfpalette(wx.Frame,LinearSegmentedColormap):
374
375
 
375
376
  def default16(self):
376
377
  """Palette 16 coulrurs par défaut dans WOLF"""
378
+
377
379
  self.nb=16
378
380
  self.values = np.linspace(0.,1.,16)
379
381
  self.colors = np.zeros((self.nb,4) , dtype=int)
@@ -398,6 +400,51 @@ class wolfpalette(wx.Frame,LinearSegmentedColormap):
398
400
 
399
401
  self.fill_segmentdata()
400
402
 
403
+ def set_values_colors(self,
404
+ values:typing.Union[list[float], np.ndarray],
405
+ colors:typing.Union[list[tuple[int]], np.ndarray]):
406
+ """ Mise à jour des valeurs et couleurs de la palette """
407
+
408
+ assert len(values) == len(colors), "Length of values and colors must be the same"
409
+ assert len(values) > 1, "At least 2 values are required"
410
+ assert len(colors[0]) in [3,4], "Colors must be in RGB or RGBA format"
411
+
412
+ self.nb = len(values)
413
+ self.values = np.asarray(values)
414
+
415
+ self.colors = np.zeros((self.nb,4) , dtype=int)
416
+ self.colorsflt = np.zeros((self.nb,4) , dtype=float)
417
+
418
+ if isinstance(colors, list):
419
+ if len(colors[0]) == 3:
420
+ for curcol in range(self.nb):
421
+ self.colors[curcol,0] = colors[curcol][0]
422
+ self.colors[curcol,1] = colors[curcol][1]
423
+ self.colors[curcol,2] = colors[curcol][2]
424
+ self.colors[curcol,3] = 255
425
+ elif len(colors[0]) == 4:
426
+ for curcol in range(self.nb):
427
+ self.colors[curcol,0] = colors[curcol][0]
428
+ self.colors[curcol,1] = colors[curcol][1]
429
+ self.colors[curcol,2] = colors[curcol][2]
430
+ self.colors[curcol,3] = colors[curcol][3]
431
+ elif isinstance(colors, np.ndarray):
432
+ if colors.shape[1] == 3:
433
+ for curcol in range(self.nb):
434
+ self.colors[curcol,0] = colors[curcol,0]
435
+ self.colors[curcol,1] = colors[curcol,1]
436
+ self.colors[curcol,2] = colors[curcol,2]
437
+ self.colors[curcol,3] = 255
438
+ elif colors.shape[1] == 4:
439
+ for curcol in range(self.nb):
440
+ self.colors[curcol,0] = colors[curcol,0]
441
+ self.colors[curcol,1] = colors[curcol,1]
442
+ self.colors[curcol,2] = colors[curcol,2]
443
+ self.colors[curcol,3] = colors[curcol,3]
444
+
445
+
446
+ self.fill_segmentdata()
447
+
401
448
  def defaultgray(self):
402
449
  """Palette grise par défaut dans WOLF"""
403
450
  self.nb=2
wolfhece/PyParams.py CHANGED
@@ -62,7 +62,7 @@ class Buttons(Enum):
62
62
  Apply = 'Apply'
63
63
  Reload = 'Reload'
64
64
 
65
- def new_json(values:dict, fullcomment:str='') -> dict:
65
+ def new_json(values:dict=None, fullcomment:str='') -> dict:
66
66
  """
67
67
  Create a new JSON string from values and fullcomment
68
68
 
@@ -311,10 +311,141 @@ class Wolf_Param(wx.Frame):
311
311
  if to_read:
312
312
  self.ReadFile(filename)
313
313
 
314
+ self.prop = None
315
+ self.sizer = None
316
+
314
317
  if self.wx_exists and init_GUI:
315
318
  self._set_gui(parent,title,w,h,ontop,to_read,withbuttons,DestroyAtClosing,toShow)
316
- else:
317
- self.prop = None
319
+
320
+ @property
321
+ def has_prop(self) -> bool:
322
+ """ Return True if the property grid is available """
323
+ return self.prop is not None
324
+
325
+ @property
326
+ def has_gui(self) -> bool:
327
+ """ Return True if the own GUI is available"""
328
+
329
+ return self.sizer is not None
330
+
331
+ def ensure_prop(self, wxparent = None, show_in_active_if_default:bool = False):
332
+ """ Ensure that the property grid is available """
333
+
334
+ if self.wx_exists:
335
+ if not self.has_prop:
336
+ self._set_only_prop(wxparent)
337
+ self.show_in_active_if_default = show_in_active_if_default
338
+ self.prop.SetSizeHints(0,600)
339
+
340
+ self.Populate()
341
+
342
+
343
+ def ensure_gui(self,
344
+ title:str = "Default Title",
345
+ w:int = 500, h:int = 800,
346
+ ontop:bool = False,
347
+ to_read:bool = True,
348
+ withbuttons:bool = True,
349
+ DestroyAtClosing:bool = True,
350
+ toShow:bool = True,
351
+ full_style:bool = False):
352
+ """ Ensure that the GUI is available """
353
+
354
+ if not self.has_gui and self.wx_exists:
355
+ self._set_gui(title=title,
356
+ w=w, h=h,
357
+ ontop=ontop,
358
+ to_read=to_read,
359
+ withbuttons=withbuttons,
360
+ DestroyAtClosing=DestroyAtClosing,
361
+ toShow=toShow,
362
+ full_style=full_style,
363
+ )
364
+
365
+ def copy(self):
366
+ """ Return a deep copy of the object """
367
+
368
+ newparams = Wolf_Param()
369
+
370
+ for group, params in self.myparams.items():
371
+ newparams.myparams[group] = deepcopy(params)
372
+
373
+ for group, params in self.myparams_default.items():
374
+ newparams.myparams_default[group] = deepcopy(params)
375
+
376
+ newparams.myIncGroup = deepcopy(self.myIncGroup)
377
+
378
+ newparams.myIncParam = deepcopy(self.myIncParam)
379
+
380
+ return newparams
381
+
382
+ def is_like(self, other:"Wolf_Param") -> bool:
383
+ """ Test if the object is like another object """
384
+
385
+ # if self.filename != other.filename:
386
+ # return False
387
+
388
+ if self.myparams != other.myparams:
389
+ return False
390
+
391
+ if self.myparams_default != other.myparams_default:
392
+ return False
393
+
394
+ if self.myIncGroup != other.myIncGroup:
395
+ return False
396
+
397
+ if self.myIncParam != other.myIncParam:
398
+ return False
399
+
400
+ return True
401
+
402
+ def diff(self, other:"Wolf_Param", exclude_incremental:bool = False) -> dict:
403
+ """ Return the differences between two objects """
404
+
405
+ diff = {}
406
+
407
+ # if self.filename != other.filename:
408
+ # diff["filename"] = (self.filename, other.filename)
409
+
410
+ if self.myparams != other.myparams:
411
+ for group in self.myparams.keys():
412
+ for param in self.myparams[group].keys():
413
+ try:
414
+ if self.myparams[group][param] != other.myparams[group][param]:
415
+ diff[(group, param)] = (self.myparams[group][param], other.myparams[group][param])
416
+ except:
417
+ diff[(group, param)] = (self.myparams[group][param], None)
418
+
419
+ if self.myparams_default != other.myparams_default:
420
+ for group in self.myparams_default.keys():
421
+ for param in self.myparams_default[group].keys():
422
+ try:
423
+ if self.myparams_default[group][param] != other.myparams_default[group][param]:
424
+ diff[(group, param)] = (self.myparams_default[group][param], other.myparams_default[group][param])
425
+ except:
426
+ diff[(group, param)] = (self.myparams_default[group][param], None)
427
+
428
+ if exclude_incremental:
429
+ return diff
430
+
431
+ if self.myIncGroup != other.myIncGroup:
432
+ for group in self.myIncGroup.keys():
433
+ try:
434
+ if self.myIncGroup[group] != other.myIncGroup[group]:
435
+ diff["myIncGroup"] = (self.myIncGroup[group], other.myIncGroup[group])
436
+ except:
437
+ diff["myIncGroup"] = (self.myIncGroup[group], None)
438
+
439
+ if self.myIncParam != other.myIncParam:
440
+ for group in self.myIncParam.keys():
441
+ try:
442
+ for param in self.myIncParam[group].keys():
443
+ if self.myIncParam[group][param] != other.myIncParam[group][param]:
444
+ diff["myIncParam"] = (self.myIncParam[group][param], other.myIncParam[group][param])
445
+ except:
446
+ diff["myIncParam"] = (self.myIncParam[group][param], None)
447
+
448
+ return diff
318
449
 
319
450
  def set_callbacks(self, callback_update, callback_destroy):
320
451
  """ Set the callbacks for the update and destroy events """
@@ -370,7 +501,8 @@ class Wolf_Param(wx.Frame):
370
501
  to_read:bool = True,
371
502
  withbuttons:bool = True,
372
503
  DestroyAtClosing:bool = True,
373
- toShow:bool = True):
504
+ toShow:bool = True,
505
+ full_style = False):
374
506
  """
375
507
  Set the GUI if wxPython is running
376
508
 
@@ -390,9 +522,15 @@ class Wolf_Param(wx.Frame):
390
522
  :param withbuttons : if True, buttons will be displayed
391
523
  :param DestroyAtClosing : if True, the frame will be destroyed when closed
392
524
  :param toShow : if True, the frame will be displayed
393
-
525
+ :param full_style : if True, the full style of the PropertyGridManager will be displayed even if ontop is True
394
526
  """
395
527
 
528
+ self.wx_exists = wx.App.Get() is not None # test if wx App is running
529
+
530
+ if not self.wx_exists:
531
+ logging.error("wxPython is not running - Impossible to set the GUI")
532
+ return
533
+
396
534
  #Appel à l'initialisation d'un frame général
397
535
  if ontop:
398
536
  wx.Frame.__init__(self, parent, title=title, size=(w,h),style=wx.DEFAULT_FRAME_STYLE| wx.STAY_ON_TOP)
@@ -421,11 +559,24 @@ class Wolf_Param(wx.Frame):
421
559
 
422
560
  #ajout d'un widget de gestion de propriétés
423
561
  if ontop:
424
- self.prop = pg.PropertyGridManager(self,
425
- style = pg.PG_BOLD_MODIFIED|pg.PG_SPLITTER_AUTO_CENTER|
426
- # Plus defaults.
427
- pg.PGMAN_DEFAULT_STYLE
428
- )
562
+ if full_style:
563
+ self.prop = pg.PropertyGridManager(self,
564
+ style = pg.PG_BOLD_MODIFIED|pg.PG_SPLITTER_AUTO_CENTER|
565
+ # Include toolbar.
566
+ pg.PG_TOOLBAR |
567
+ # Include description box.
568
+ pg.PG_DESCRIPTION |
569
+ pg.PG_TOOLTIPS |
570
+ # Plus defaults.
571
+ pg.PGMAN_DEFAULT_STYLE
572
+ )
573
+ else:
574
+ self.prop = pg.PropertyGridManager(self,
575
+ style = pg.PG_BOLD_MODIFIED|pg.PG_SPLITTER_AUTO_CENTER|
576
+ pg.PG_TOOLTIPS |
577
+ # Plus defaults.
578
+ pg.PGMAN_DEFAULT_STYLE
579
+ )
429
580
  else:
430
581
  self.prop = pg.PropertyGridManager(self,
431
582
  style = pg.PG_BOLD_MODIFIED|pg.PG_SPLITTER_AUTO_CENTER|
@@ -463,6 +614,22 @@ class Wolf_Param(wx.Frame):
463
614
  #affichage de la page
464
615
  self.Show(toShow)
465
616
 
617
+ def _set_only_prop(self, wxparent):
618
+ """ Set only the property grid """
619
+
620
+ self.prop = pg.PropertyGridManager(wxparent,
621
+ style = pg.PG_BOLD_MODIFIED|pg.PG_SPLITTER_AUTO_CENTER|
622
+ # Include toolbar.
623
+ pg.PG_TOOLBAR |
624
+ # Include description box.
625
+ pg.PG_DESCRIPTION |
626
+ pg.PG_TOOLTIPS |
627
+ # Plus defaults.
628
+ pg.PGMAN_DEFAULT_STYLE
629
+ )
630
+
631
+ self.prop.Bind(pg.EVT_PG_DOUBLE_CLICK,self.OnDblClick)
632
+
466
633
  def hide_selected_buttons(self, to_hide:list[Buttons] = [Buttons.Load, Buttons.Save, Buttons.Reload]):
467
634
  """ Mask selected buttons - Default conserve only 'Apply change' """
468
635
 
@@ -476,6 +643,8 @@ class Wolf_Param(wx.Frame):
476
643
  elif locbutton == Buttons.Apply:
477
644
  self.sizerbut.Hide(self.applychange)
478
645
 
646
+ self.Layout()
647
+
479
648
  def OnDblClick(self, event:wx.MouseEvent):
480
649
  """
481
650
  Double-click event handler to add a parameter to the active tab or reset to default value.
@@ -599,11 +768,11 @@ class Wolf_Param(wx.Frame):
599
768
  self._update_IncGroup(withGUI=True)
600
769
  self._update_IncParam(withGUI=True)
601
770
 
602
- if not self._callback is None:
771
+ if self._callback is not None:
603
772
  self._callback()
604
773
  else:
605
- if self.wx_exists:
606
- dlg = wx.MessageDialog(self,'Nothing to do!')
774
+ if self.has_gui:
775
+ dlg = wx.MessageDialog(None,'Nothing to do!')
607
776
  dlg.ShowModal()
608
777
 
609
778
  @property
@@ -633,6 +802,9 @@ class Wolf_Param(wx.Frame):
633
802
 
634
803
  """
635
804
 
805
+ if not self.wx_exists:
806
+ logging.error("wxPython is not running - Impossible to apply changes to memory")
807
+
636
808
  assert self.wx_exists, "wxPython is not running"
637
809
 
638
810
  if isIncrementable:
@@ -686,7 +858,7 @@ class Wolf_Param(wx.Frame):
686
858
  """ Position the frame """
687
859
  self.SetPosition(wx.Point(position[0],position[1]+50))
688
860
 
689
- def Populate(self):
861
+ def Populate(self, sorted_groups:bool = False):
690
862
  """
691
863
  Filling the property management object based on dictionaries
692
864
 
@@ -696,7 +868,7 @@ class Wolf_Param(wx.Frame):
696
868
  """
697
869
 
698
870
  if self.prop is None:
699
- logging.error("ERROR : wxPython is not running - Impossible to populate the property grid")
871
+ logging.debug("ERROR : wxPython is not running - Impossible to populate the property grid")
700
872
  return
701
873
 
702
874
  self.prop.Clear()
@@ -734,6 +906,10 @@ class Wolf_Param(wx.Frame):
734
906
 
735
907
  # Display a header above the grid
736
908
  self.prop.ShowHeader()
909
+
910
+ if sorted_groups:
911
+ self.prop.Sort()
912
+
737
913
  self.prop.Refresh()
738
914
 
739
915
  def _insert_elem_to_page(self, page:pg.PropertyGridPage, group:str, param:dict, param_def:dict = None, prefix:str=''):
@@ -754,44 +930,102 @@ class Wolf_Param(wx.Frame):
754
930
  param[key_Param.COMMENT] = param_def[key_Param.COMMENT]
755
931
  param[key_Param.TYPE] = param_def[key_Param.TYPE]
756
932
 
757
- if key_Param.ADDED_JSON in param.keys() and param[key_Param.ADDED_JSON] is not None:
933
+ if key_Param.ADDED_JSON in param.keys() and param[key_Param.ADDED_JSON] is not None:
758
934
  # Ajout des choix via chaîne JSON
759
- list_keys = [ k for k in param[key_Param.ADDED_JSON]['Values'].keys()]
760
- list_values = [ k for k in param[key_Param.ADDED_JSON]['Values'].values()]
935
+ if param[key_Param.ADDED_JSON]['Values'] is not None:
761
936
 
762
- page.AppendIn(parent, pg.EnumProperty(param_name, name=locname, labels=list_keys, values=list_values, value=int(param[key_Param.VALUE])))
937
+ list_keys = [ k for k in param[key_Param.ADDED_JSON]['Values'].keys()]
938
+ list_values = [ k for k in param[key_Param.ADDED_JSON]['Values'].values()]
763
939
 
764
- self.prop.SetPropertyHelpString(locname , param[key_Param.ADDED_JSON]['Full_Comment'])
940
+ value_param = self.value_as_type(param[key_Param.VALUE], param[key_Param.TYPE], )
941
+ if type(value_param) == str:
942
+ try:
943
+ value_param = int(value_param)
944
+ except:
945
+ logging.debug("String type will be conserved! -- {}".format(value_param))
946
+
947
+ page.AppendIn(parent, pg.EnumProperty(param_name, name=locname, labels=list_keys, values=list_values, value=value_param))
948
+ else:
949
+ self._insert_with_type_based_on_value(page, group, param, prefix)
950
+
951
+ self.prop.SetPropertyHelpString(locname , param[key_Param.ADDED_JSON]['Full_Comment'] + '\n\n' + param[key_Param.COMMENT])
765
952
  else:
766
953
 
767
- locvalue = self[(group, param_name)]
954
+ self._insert_with_type_based_on_value(page, group, param, prefix)
768
955
 
769
- if isinstance(locvalue, float):
770
- page.AppendIn(parent, pg.FloatProperty(label = param_name, name = locname, value = locvalue))
956
+ self.prop.SetPropertyHelpString(locname, param[key_Param.COMMENT])
771
957
 
772
- elif isinstance(locvalue, int):
773
- # bool is also an int
774
- if isinstance(locvalue, bool):
775
- page.AppendIn(parent, pg.BoolProperty(label=param_name, name = locname, value = locvalue))
776
- else:
777
- page.AppendIn(parent, pg.IntProperty(label = param_name, name = locname, value = locvalue))
958
+ def _insert_with_type_based_on_value(self, page:pg.PropertyGridPage, group:str, param:dict, prefix:str=''):
778
959
 
779
- elif param[key_Param.TYPE]==Type_Param.File:
780
- page.AppendIn(parent, pg.FileProperty(label=param_name, name = locname, value = param[key_Param.VALUE]))
960
+ param_name = param[key_Param.NAME]
961
+ locname = prefix + group + param_name
962
+ locvalue = self[(group, param_name)]
781
963
 
782
- elif param[key_Param.TYPE]==Type_Param.Directory:
783
- page.AppendIn(parent, pg.DirProperty(label = param_name, name = locname, value = locvalue))
964
+ # Get parent item based on group name
965
+ parent = page.GetPropertyByName(group)
966
+ assert parent is not None, "Group {} not found in page".format(group)
967
+ assert isinstance(parent, pg.PropertyCategory), "Parent is not a PropertyCategory"
784
968
 
785
- elif param[key_Param.TYPE]==Type_Param.Color:
786
- page.AppendIn(parent, pg.ColourProperty(label = param_name, name = locname, value = locvalue))
969
+ if isinstance(locvalue, float):
970
+ page.AppendIn(parent,pg.FloatProperty(label = param_name, name = locname, value = locvalue))
787
971
 
788
- elif param[key_Param.TYPE]==Type_Param.Fontname:
789
- page.AppendIn(parent, pg.FontProperty(label = param_name, name = locname, value = locvalue))
972
+ elif isinstance(locvalue, int):
973
+ # bool is also an int
974
+ if isinstance(locvalue, bool):
975
+ page.AppendIn(parent,pg.BoolProperty(label=param_name, name = locname, value = locvalue))
976
+ else:
977
+ page.AppendIn(parent,pg.IntProperty(label = param_name, name = locname, value = locvalue))
978
+
979
+ elif param[key_Param.TYPE]==Type_Param.File:
980
+ page.AppendIn(parent,pg.FileProperty(label=param_name, name = locname, value = param[key_Param.VALUE]))
981
+
982
+ elif param[key_Param.TYPE]==Type_Param.Directory:
983
+ page.AppendIn(parent,pg.DirProperty(label = param_name, name = locname, value = locvalue))
984
+ # newobj.SetLabel(param_name)
985
+ # page.Append(newobj)
986
+
987
+ elif param[key_Param.TYPE]==Type_Param.Color:
988
+ page.AppendIn(parent,pg.ColourProperty(label = param_name, name = locname, value = locvalue))
989
+
990
+ elif param[key_Param.TYPE]==Type_Param.Fontname:
991
+ page.AppendIn(parent,pg.FontProperty(label = param_name, name = locname, value = locvalue))
992
+
993
+ else:
994
+ page.AppendIn(parent,pg.StringProperty(label = param_name, name = locname, value = locvalue))
995
+
996
+ def _add_with_type_based_on_value(self, page:pg.PropertyGridPage, group:str, param:dict, prefix:str=''):
997
+
998
+ param_name = param[key_Param.NAME]
999
+ locname = prefix + group + param_name
1000
+
1001
+ locvalue = self._get_param_def(group, param_name) if prefix == PREFIX_DEFAULT else self[(group, param_name)]
1002
+
1003
+ if isinstance(locvalue, float):
1004
+ page.Append(pg.FloatProperty(label = param_name, name = locname, value = locvalue))
790
1005
 
1006
+ elif isinstance(locvalue, int):
1007
+ # bool is also an int
1008
+ if isinstance(locvalue, bool):
1009
+ page.Append(pg.BoolProperty(label=param_name, name = locname, value = locvalue))
791
1010
  else:
792
- page.AppendIn(parent, pg.StringProperty(label = param_name, name = locname, value = locvalue))
1011
+ page.Append(pg.IntProperty(label = param_name, name = locname, value = locvalue))
793
1012
 
794
- self.prop.SetPropertyHelpString(locname, param[key_Param.COMMENT])
1013
+ elif param[key_Param.TYPE]==Type_Param.File:
1014
+ page.Append(pg.FileProperty(label=param_name, name = locname, value = param[key_Param.VALUE]))
1015
+
1016
+ elif param[key_Param.TYPE]==Type_Param.Directory:
1017
+ page.Append(pg.DirProperty(label = param_name, name = locname, value = locvalue))
1018
+ # newobj.SetLabel(param_name)
1019
+ # page.Append(newobj)
1020
+
1021
+ elif param[key_Param.TYPE]==Type_Param.Color:
1022
+ page.Append(pg.ColourProperty(label = param_name, name = locname, value = locvalue))
1023
+
1024
+ elif param[key_Param.TYPE]==Type_Param.Fontname:
1025
+ page.Append(pg.FontProperty(label = param_name, name = locname, value = locvalue))
1026
+
1027
+ else:
1028
+ page.Append(pg.StringProperty(label = param_name, name = locname, value = locvalue))
795
1029
 
796
1030
  def _add_elem_to_page(self, page:pg.PropertyGridPage, group:str, param:dict, param_def:dict = None, prefix:str=''):
797
1031
  """ Add an element to a page """
@@ -807,51 +1041,36 @@ class Wolf_Param(wx.Frame):
807
1041
  param[key_Param.TYPE] = param_def[key_Param.TYPE]
808
1042
 
809
1043
  if key_Param.ADDED_JSON in param.keys() and param[key_Param.ADDED_JSON] is not None:
810
- # Ajout des choix via chaîne JSON
811
- list_keys = [ k for k in param[key_Param.ADDED_JSON]['Values'].keys()]
812
- list_values = [ k for k in param[key_Param.ADDED_JSON]['Values'].values()]
813
- # FIXME : TO GENERALIZE!!!
814
- value_param = self.value_as_type(param[key_Param.VALUE], param[key_Param.TYPE], )
815
- if type(value_param) == str:
816
- try:
817
- value_param = int(value_param)
818
- except:
819
- logging.debug("String type will be conserved! -- {}".format(value_param))
820
- # print(value_param)
821
- page.Append(pg.EnumProperty(param_name, name=locname, labels=list_keys, values=list_values, value=value_param))
822
- if "Full_Comment" in param[key_Param.ADDED_JSON]:
823
- self.prop.SetPropertyHelpString(locname , param[key_Param.ADDED_JSON]["Full_Comment"])
824
-
825
- else:
826
1044
 
827
- locvalue = self[(group, param_name)]
1045
+ # Ajout des choix via chaîne JSON
1046
+ if param[key_Param.ADDED_JSON]['Values'] is not None:
828
1047
 
829
- if isinstance(locvalue, float):
830
- page.Append(pg.FloatProperty(label = param_name, name = locname, value = locvalue))
1048
+ list_keys = [ k for k in param[key_Param.ADDED_JSON]['Values'].keys()]
1049
+ list_values = [ k for k in param[key_Param.ADDED_JSON]['Values'].values()]
831
1050
 
832
- elif isinstance(locvalue, int):
833
- # bool is also an int
834
- if isinstance(locvalue, bool):
835
- page.Append(pg.BoolProperty(label=param_name, name = locname, value = locvalue))
836
- else:
837
- page.Append(pg.IntProperty(label = param_name, name = locname, value = locvalue))
1051
+ # FIXME : TO GENERALIZE!!!
1052
+ value_param = self.value_as_type(param[key_Param.VALUE], param[key_Param.TYPE], )
1053
+ if type(value_param) == str:
1054
+ try:
1055
+ value_param = int(value_param)
1056
+ except:
1057
+ logging.debug("String type will be conserved! -- {}".format(value_param))
1058
+ # print(value_param)
1059
+ page.Append(pg.EnumProperty(param_name, name=locname, labels=list_keys, values=list_values, value=value_param))
838
1060
 
839
- elif param[key_Param.TYPE]==Type_Param.File:
840
- page.Append(pg.FileProperty(label=param_name, name = locname, value = param[key_Param.VALUE]))
1061
+ else:
1062
+ # Pas de chaîne JSON mais un commentaire complet
1063
+ self._add_with_type_based_on_value(page, group, param, prefix)
841
1064
 
842
- elif param[key_Param.TYPE]==Type_Param.Directory:
843
- page.Append(pg.DirProperty(label = param_name, name = locname, value = locvalue))
844
- # newobj.SetLabel(param_name)
845
- # page.Append(newobj)
846
1065
 
847
- elif param[key_Param.TYPE]==Type_Param.Color:
848
- page.Append(pg.ColourProperty(label = param_name, name = locname, value = locvalue))
1066
+ if "Full_Comment" in param[key_Param.ADDED_JSON]:
1067
+ self.prop.SetPropertyHelpString(locname , param[key_Param.ADDED_JSON]["Full_Comment"] + '\n\n' + param[key_Param.COMMENT])
1068
+ else:
1069
+ self.prop.SetPropertyHelpString(locname , param[key_Param.COMMENT])
849
1070
 
850
- elif param[key_Param.TYPE]==Type_Param.Fontname:
851
- page.Append(pg.FontProperty(label = param_name, name = locname, value = locvalue))
1071
+ else:
852
1072
 
853
- else:
854
- page.Append(pg.StringProperty(label = param_name, name = locname, value = locvalue))
1073
+ self._add_with_type_based_on_value(page, group, param, prefix)
855
1074
 
856
1075
  self.prop.SetPropertyHelpString(locname, param[key_Param.COMMENT])
857
1076
 
@@ -1234,6 +1453,8 @@ class Wolf_Param(wx.Frame):
1234
1453
 
1235
1454
  if not paramloc[0] in self.myIncParam[groupname]:
1236
1455
  curdict = self.myIncParam[groupname][paramloc[0]] = self._new_IncParam_dict(groupname, groupname if len(iterInfo)==3 else iterInfo[0], iterInfo[-3], iterInfo[-2], iterInfo[-1])
1456
+ else:
1457
+ curdict = self.myIncParam[groupname][paramloc[0]]
1237
1458
 
1238
1459
  if not "Saved" in curdict:
1239
1460
  curdict["Saved"] = {}
@@ -1392,6 +1613,7 @@ class Wolf_Param(wx.Frame):
1392
1613
  jsonstr:str = None,
1393
1614
  whichdict:Literal['All', 'Default', 'Active', 'IncGroup', '']=''):
1394
1615
  """alias of addparam"""
1616
+
1395
1617
  return self.addparam(groupname, name, value, type, comment, jsonstr, whichdict)
1396
1618
 
1397
1619
  def __getitem__(self, key:tuple[str, str]):
@@ -1549,6 +1771,22 @@ class Wolf_Param(wx.Frame):
1549
1771
  curType = self.get_type(group, name)
1550
1772
  return self.value_as_type(element, curType)
1551
1773
 
1774
+ def _get_param_def(self, group:str, name:str, default_value=None):
1775
+ """
1776
+ Returns the default value of the parameter if found, otherwise None obj
1777
+
1778
+ """
1779
+
1780
+ if self.is_in_default(group, name):
1781
+ element = self.myparams_default[group][name][key_Param.VALUE]
1782
+ else:
1783
+ element = default_value
1784
+ return element
1785
+
1786
+ # String conversion according to its type
1787
+ curType = self.get_type(group, name)
1788
+ return self.value_as_type(element, curType)
1789
+
1552
1790
  def get_group(self, group:str) -> dict:
1553
1791
  """
1554
1792
  Return the group dictionnary if found, otherwise None obj
@@ -1564,6 +1802,69 @@ class Wolf_Param(wx.Frame):
1564
1802
  else:
1565
1803
  return None
1566
1804
 
1805
+ def get_help(self, group:str, name:str) -> list[str, str]:
1806
+ """
1807
+ Return the help string if found, otherwise None obj
1808
+
1809
+ :return: [comment, full_comment]
1810
+ """
1811
+
1812
+ if self.is_in_default(group, name):
1813
+ curdict = self.myparams_default[group][name]
1814
+ ret = [curdict[key_Param.COMMENT]]
1815
+
1816
+ if key_Param.ADDED_JSON in curdict.keys():
1817
+ if curdict[key_Param.ADDED_JSON] is not None:
1818
+ if 'Full_Comment' in curdict[key_Param.ADDED_JSON].keys():
1819
+ ret += [curdict[key_Param.ADDED_JSON]['Full_Comment']]
1820
+ else:
1821
+ ret += ['']
1822
+ else:
1823
+ ret += ['']
1824
+ else:
1825
+ ret += ['']
1826
+
1827
+ return ret
1828
+
1829
+ elif self.is_in_active(group, name):
1830
+ curdict = self.myparams[group][name]
1831
+ ret = [curdict[key_Param.COMMENT]]
1832
+ if key_Param.ADDED_JSON in curdict.keys():
1833
+ if curdict[key_Param.ADDED_JSON] is not None:
1834
+ if 'Full Comment' in curdict[key_Param.ADDED_JSON].keys():
1835
+ ret += [curdict[key_Param.ADDED_JSON]['Full_Comment']]
1836
+ else:
1837
+ ret += ['']
1838
+ else:
1839
+ ret += ['']
1840
+ else:
1841
+ ret += ['']
1842
+
1843
+ return ret
1844
+
1845
+ else:
1846
+ return None
1847
+
1848
+ def get_json_values(self, group:str, name:str) -> dict:
1849
+ """
1850
+ Return the 'values' in json string if found, otherwise None obj
1851
+ """
1852
+
1853
+ if self.is_in_default(group, name):
1854
+ curdict = self.myparams_default[group][name]
1855
+ if key_Param.ADDED_JSON in curdict.keys():
1856
+ if 'Values' in curdict[key_Param.ADDED_JSON].keys():
1857
+ return curdict[key_Param.ADDED_JSON]['Values']
1858
+
1859
+ elif self.is_in_active(group, name):
1860
+ curdict = self.myparams[group][name]
1861
+ if key_Param.ADDED_JSON in curdict.keys():
1862
+ if 'Values' in curdict[key_Param.ADDED_JSON].keys():
1863
+ return curdict[key_Param.ADDED_JSON]['Values']
1864
+
1865
+ else:
1866
+ return {}
1867
+
1567
1868
  def _detect_type_from_value(self, value:Union[float, int, str, bool, tuple[int, int, int]]) -> Type_Param:
1568
1869
  """ Detect the type from the value """
1569
1870