wolfhece 2.1.82__py3-none-any.whl → 2.1.84__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/PyConfig.py CHANGED
@@ -27,6 +27,8 @@ class ConfigurationKeys(Enum):
27
27
  TICKS_SIZE = "TicksSize"
28
28
  TICKS_BOUNDS = "TicksBounds"
29
29
  COLOR_BACKGROUND = "ColorBackground"
30
+ ACTIVE_ARRAY_PALETTE_FOR_IMAGE = "Use active array palette for image"
31
+ ACTIVE_RES2D_PALETTE_FOR_IMAGE = "Use active result palette for image"
30
32
 
31
33
  class WolfConfiguration:
32
34
  """ Holds the PyWolf configuration.
@@ -66,6 +68,8 @@ class WolfConfiguration:
66
68
  ConfigurationKeys.VERSION.value: 1,
67
69
  ConfigurationKeys.PLAY_WELCOME_SOUND.value: True,
68
70
  ConfigurationKeys.TICKS_SIZE.value: 500.,
71
+ ConfigurationKeys.ACTIVE_ARRAY_PALETTE_FOR_IMAGE.value: True,
72
+ ConfigurationKeys.ACTIVE_RES2D_PALETTE_FOR_IMAGE.value: False,
69
73
  ConfigurationKeys.TICKS_BOUNDS.value: True,
70
74
  ConfigurationKeys.COLOR_BACKGROUND.value: [255, 255, 255, 255]
71
75
  }
@@ -73,6 +77,8 @@ class WolfConfiguration:
73
77
  ConfigurationKeys.VERSION.value: int,
74
78
  ConfigurationKeys.PLAY_WELCOME_SOUND.value: bool,
75
79
  ConfigurationKeys.TICKS_SIZE.value: float,
80
+ ConfigurationKeys.ACTIVE_ARRAY_PALETTE_FOR_IMAGE.value: bool,
81
+ ConfigurationKeys.ACTIVE_RES2D_PALETTE_FOR_IMAGE.value: bool,
76
82
  ConfigurationKeys.TICKS_BOUNDS.value: bool,
77
83
  ConfigurationKeys.COLOR_BACKGROUND.value: list
78
84
  }
@@ -116,12 +122,13 @@ class WolfConfiguration:
116
122
 
117
123
 
118
124
  class GlobalOptionsDialog(wx.Dialog):
125
+ """ A dialog to set global options for a WolfMapViewer. """
119
126
 
120
127
  def __init__(self, *args, **kw):
121
128
  super(GlobalOptionsDialog, self).__init__(*args, **kw)
122
129
 
123
130
  self.InitUI()
124
- self.SetSize((400, 200))
131
+ self.SetSize((400, 300))
125
132
  self.SetTitle(_("Global options"))
126
133
 
127
134
  def push_configuration(self, configuration):
@@ -129,12 +136,16 @@ class GlobalOptionsDialog(wx.Dialog):
129
136
  self.cfg_ticks_size.SetValue(str(configuration[ConfigurationKeys.TICKS_SIZE]))
130
137
  self.cfg_ticks_bounds.SetValue(configuration[ConfigurationKeys.TICKS_BOUNDS])
131
138
  self.cfg_bkg_color.SetColour(configuration[ConfigurationKeys.COLOR_BACKGROUND])
139
+ self.cfg_active_array_pal.SetValue(configuration[ConfigurationKeys.ACTIVE_ARRAY_PALETTE_FOR_IMAGE])
140
+ self.cfg_active_res_pal.SetValue(configuration[ConfigurationKeys.ACTIVE_RES2D_PALETTE_FOR_IMAGE])
132
141
 
133
142
  def pull_configuration(self, configuration):
134
143
  configuration[ConfigurationKeys.PLAY_WELCOME_SOUND] = self.cfg_welcome_voice.IsChecked()
135
144
  configuration[ConfigurationKeys.TICKS_SIZE] = float(self.cfg_ticks_size.Value)
136
145
  configuration[ConfigurationKeys.TICKS_BOUNDS] = self.cfg_ticks_bounds.IsChecked()
137
146
  configuration[ConfigurationKeys.COLOR_BACKGROUND] = list(self.cfg_bkg_color.GetColour())
147
+ configuration[ConfigurationKeys.ACTIVE_ARRAY_PALETTE_FOR_IMAGE] = self.cfg_active_array_pal.IsChecked()
148
+ configuration[ConfigurationKeys.ACTIVE_RES2D_PALETTE_FOR_IMAGE] = self.cfg_active_res_pal.IsChecked()
138
149
 
139
150
  def InitUI(self):
140
151
 
@@ -147,13 +158,26 @@ class GlobalOptionsDialog(wx.Dialog):
147
158
  sbs = wx.StaticBoxSizer(sb , orient=wx.VERTICAL)
148
159
 
149
160
  self.cfg_welcome_voice = wx.CheckBox(pnl, label=_('Welcome voice'))
161
+ self.cfg_welcome_voice.SetToolTip(_('Play a welcome message when opening the application'))
150
162
  sbs.Add(self.cfg_welcome_voice)
151
163
 
164
+ sbs.AddSpacer(5)
165
+
166
+ hsizer = wx.BoxSizer(wx.HORIZONTAL)
167
+ self.label_background_color = wx.StaticText(pnl, label=_('Background color'))
152
168
  self.cfg_bkg_color = wx.ColourPickerCtrl(pnl, colour=(255,255,255,255))
153
- sbs.Add(self.cfg_bkg_color)
169
+ self.cfg_bkg_color.SetToolTip(_('Background color for the viewer'))
170
+
171
+ hsizer.Add(self.label_background_color, 1, wx.EXPAND)
172
+ hsizer.Add(self.cfg_bkg_color, 1, wx.EXPAND)
173
+
174
+ sbs.Add(hsizer, 1, wx.EXPAND)
175
+
176
+ sbs.AddSpacer(5)
154
177
 
155
178
  pnl.SetSizer(sbs)
156
179
  pnl.Layout()
180
+
157
181
  vbox.Add(pnl, proportion=1, flag=wx.ALL|wx.EXPAND, border=5)
158
182
 
159
183
  ### Panel 'Copy to clipboard'
@@ -163,19 +187,29 @@ class GlobalOptionsDialog(wx.Dialog):
163
187
  sbs = wx.StaticBoxSizer(sb, orient=wx.VERTICAL)
164
188
 
165
189
  hboxticks = wx.BoxSizer(wx.HORIZONTAL)
166
- self.label_ticks_size = wx.StaticText(pnl, label=_('Default ticks size for copy to clipboard'))
190
+ self.label_ticks_size = wx.StaticText(pnl, label=_('Default ticks size [m]'))
167
191
  self.cfg_ticks_size = wx.TextCtrl(pnl, value='500.',style = wx.TE_CENTRE )
192
+
168
193
  hboxticks.Add(self.label_ticks_size, 1, wx.EXPAND)
169
- hboxticks.AddSpacer(5)
170
- hboxticks.Add(self.cfg_ticks_size, 0, wx.EXPAND)
194
+ hboxticks.Add(self.cfg_ticks_size, 1, wx.EXPAND)
171
195
 
172
196
  sbs.Add(hboxticks, 1, wx.EXPAND)
173
197
 
174
198
  self.cfg_ticks_bounds = wx.CheckBox(pnl, label=_('Add bounds to ticks'))
199
+ self.cfg_ticks_bounds.SetToolTip(_('If not checked, the extreme values of the ticks will not be displayed'))
175
200
  sbs.Add(self.cfg_ticks_bounds, 1, wx.EXPAND, 5)
176
201
 
202
+ self.cfg_active_array_pal = wx.CheckBox(pnl, label=_('Use active array palette for image'))
203
+ self.cfg_active_array_pal.SetToolTip(_('If checked, the active array palette will be used for the image'))
204
+ sbs.Add(self.cfg_active_array_pal, 1, wx.EXPAND, 5)
205
+
206
+ self.cfg_active_res_pal = wx.CheckBox(pnl, label=_('Use active result palette for image'))
207
+ self.cfg_active_res_pal.SetToolTip(_('If checked, the active result palette will be used for the image (but priority to active array palette if checked)'))
208
+ sbs.Add(self.cfg_active_res_pal, 1, wx.EXPAND, 5)
209
+
177
210
  pnl.SetSizer(sbs)
178
211
  pnl.Layout()
212
+
179
213
  vbox.Add(pnl, proportion=1, flag=wx.ALL|wx.EXPAND, border=5)
180
214
 
181
215
  # Buttons
wolfhece/PyDraw.py CHANGED
@@ -2059,6 +2059,34 @@ class WolfMapViewer(wx.Frame):
2059
2059
  else:
2060
2060
  return config[ConfigurationKeys.TICKS_BOUNDS]
2061
2061
 
2062
+ @property
2063
+ def palette_for_copy(self) -> wolfpalette:
2064
+ """ Return the palette for copy from configs """
2065
+
2066
+ config = self.get_configuration()
2067
+ if config is None:
2068
+ if self.active_array is not None:
2069
+ return self.active_array.palette
2070
+ elif self.active_res2d is not None:
2071
+ return self.active_res2d.palette
2072
+ else:
2073
+ return wolfpalette()
2074
+ else:
2075
+ act_array = config[ConfigurationKeys.ACTIVE_ARRAY_PALETTE_FOR_IMAGE]
2076
+ act_res2d = config[ConfigurationKeys.ACTIVE_RES2D_PALETTE_FOR_IMAGE]
2077
+
2078
+ if act_array:
2079
+ if self.active_array is not None:
2080
+ return self.active_array.mypal
2081
+ else:
2082
+ return wolfpalette()
2083
+ elif act_res2d:
2084
+ if self.active_res2d is not None:
2085
+ return self.active_res2d.mypal
2086
+ else:
2087
+ return wolfpalette()
2088
+ else:
2089
+ return wolfpalette()
2062
2090
 
2063
2091
  def GlobalOptionsDialog(self, event):
2064
2092
  handle_configuration_dialog(self, self.get_configuration())
@@ -2191,29 +2219,33 @@ class WolfMapViewer(wx.Frame):
2191
2219
 
2192
2220
  self.active_array.compare_tri(self.active_tri)
2193
2221
 
2194
- def copy_canvasogl(self, mpl=True, ds=0., figsizes=[10.,10.], palette:wolfpalette = None):
2222
+ def copy_canvasogl(self, mpl:bool= True, ds:float= 0., figsizes= [10.,10.], palette:wolfpalette = None):
2195
2223
  """
2196
-
2197
2224
  Generate image based on UI context and copy to the Clipboard
2198
2225
 
2199
- Args:
2200
- mpl (bool, optional): Using Matplolib as renderer. Defaults to True.
2201
- ds (float, optional): Ticks size. Defaults to 0..
2202
- figsizes : fig size in inches
2226
+ :param mpl: Using Matplolib as renderer. Defaults to True.
2227
+ :type mpl: bool, optional
2228
+ :parem ds: Ticks size. Defaults to 0..
2229
+ :type ds: float, optional
2230
+ :parem figsizes: fig size in inches
2231
+ :type figsizes: list, optional
2203
2232
  """
2233
+
2204
2234
  if wx.TheClipboard.Open():
2205
2235
  self.Paint()
2206
2236
 
2207
2237
  if self.SetCurrentContext():
2208
2238
 
2209
- # Récupération du buffer OpenGL
2210
- glPixelStorei(GL_PACK_ALIGNMENT, 1)
2211
- data = glReadPixels(0, 0, self.canvaswidth, self.canvasheight, GL_RGBA, GL_UNSIGNED_BYTE)
2212
- # Création d'une image sur base du buffer
2213
- myimage: Image.Image
2214
- myimage = Image.frombuffer("RGBA", (self.canvaswidth, self.canvasheight), data)
2215
- # On tranpose car OpenGL travaille avec comme référence le coin inférieur gauche
2216
- myimage = myimage.transpose(1)
2239
+ myimage = self.get_canvas_as_image()
2240
+
2241
+ # # Récupération du buffer OpenGL
2242
+ # glPixelStorei(GL_PACK_ALIGNMENT, 1)
2243
+ # data = glReadPixels(0, 0, self.canvaswidth, self.canvasheight, GL_RGBA, GL_UNSIGNED_BYTE)
2244
+ # # Création d'une image sur base du buffer
2245
+ # myimage: Image.Image
2246
+ # myimage = Image.frombuffer("RGBA", (self.canvaswidth, self.canvasheight), data)
2247
+ # # On tranpose car OpenGL travaille avec comme référence le coin inférieur gauche
2248
+ # myimage = myimage.transpose(1)
2217
2249
 
2218
2250
  metadata = PngInfo()
2219
2251
  metadata.add_text('xmin', str(self.xmin))
@@ -2223,20 +2255,17 @@ class WolfMapViewer(wx.Frame):
2223
2255
 
2224
2256
  if mpl:
2225
2257
  if ds == 0.:
2226
- ds = self.ticks_size
2227
- # dlg = wx.NumberEntryDialog(self,
2228
- # _("xmin : {:.3f} \nxmax : {:.3f} \nymin : {:.3f} \nymax : {:.3f} \n\n dx : {:.3f}\n dy : {:.3f}").format(
2229
- # self.xmin, self.xmax, self.ymin, self.ymax, self.xmax - self.xmin,
2230
- # self.ymax - self.ymin),
2231
- # _("Interval [m]"), _("Ticks interval ?"), 500, 1, 10000)
2232
- # ret = dlg.ShowModal()
2258
+ ds = self.ticks_size # Global parameters
2233
2259
 
2234
- # if ret == wx.ID_CANCEL:
2235
- # dlg.Destroy()
2236
- # return
2260
+ if ds == 0.:
2261
+ ds = 100.
2237
2262
 
2238
- # ds = float(dlg.GetValue())
2239
- # dlg.Destroy()
2263
+ nb_ticks_x = (self.xmax - self.xmin) // ds
2264
+ nb_ticks_y = (self.ymax - self.ymin) // ds
2265
+
2266
+ if nb_ticks_x > 10 or nb_ticks_y > 10:
2267
+ logging.error(_('Too many ticks for the image. Please raise the ticks size in the global options.'))
2268
+ return
2240
2269
 
2241
2270
  # Création d'une graphique Matplotlib
2242
2271
  extent = (self.xmin, self.xmax, self.ymin, self.ymax)
@@ -2253,7 +2282,6 @@ class WolfMapViewer(wx.Frame):
2253
2282
  pos = ax.imshow(myimage,
2254
2283
  origin='upper',
2255
2284
  extent=extent)
2256
- # fig.colorbar(pos,ax=ax)
2257
2285
 
2258
2286
  x1 = np.ceil((self.xmin // ds) * ds)
2259
2287
  if x1 < self.xmin:
@@ -2301,10 +2329,11 @@ class WolfMapViewer(wx.Frame):
2301
2329
  im = Image.open(buf)
2302
2330
 
2303
2331
  if palette is None:
2304
- if self.active_array is not None:
2305
- palette = self.active_array.mypal
2306
- elif self.active_res2d is not None:
2307
- palette = self.active_res2d.mypal
2332
+ palette = self.palette_for_copy
2333
+ # if self.active_array is not None:
2334
+ # palette = self.active_array.mypal
2335
+ # elif self.active_res2d is not None:
2336
+ # palette = self.active_res2d.mypal
2308
2337
 
2309
2338
  if palette is not None:
2310
2339
  bufpal = io.BytesIO()
@@ -2360,6 +2389,7 @@ class WolfMapViewer(wx.Frame):
2360
2389
  This method takes a matplotlib figure and axe and,
2361
2390
  returns a clear screenshot of the information displayed in the wolfpy GUI.
2362
2391
  """
2392
+
2363
2393
  self.Paint()
2364
2394
  myax = ax
2365
2395
  if redraw:
@@ -2431,18 +2461,21 @@ class WolfMapViewer(wx.Frame):
2431
2461
 
2432
2462
  def get_mpl_plot(self, center = [0., 0.], width = 500., height = 500., title='', toshow=True) -> tuple[Figure, Axes]:
2433
2463
  """
2434
- Récupère un graphique matplotlib sur base de la fenêtre OpenGL et de la palette de la matrice active
2464
+ Récupère un graphique matplotlib sur base de la fenêtre OpenGL et de la palette de la matrice/résultat actif.
2435
2465
  """
2436
- self.zoom_on(center=center, width=width, height= height, canvas_height=self.canvasheight, forceupdate=True)
2437
2466
 
2467
+ self.zoom_on(center=center, width=width, height= height, canvas_height=self.canvasheight, forceupdate=True)
2438
2468
 
2439
2469
  fig,axes = plt.subplots(1,2, gridspec_kw={'width_ratios': [20, 1]})
2440
2470
  self.display_canvasogl(fig=fig,ax=axes[0])
2441
2471
 
2442
- if self.active_array is not None:
2443
- self.active_array.mypal.export_image(None, h_or_v='v', figax=(fig,axes[1]))
2444
- elif self.active_res2d is not None:
2445
- self.active_res2d.mypal.export_image(None, h_or_v='v', figax=(fig,axes[1]))
2472
+ palette = self.palette_for_copy
2473
+ palette.export_image(None, h_or_v='v', figax=(fig,axes[1]))
2474
+
2475
+ # if self.active_array is not None:
2476
+ # self.active_array.mypal.export_image(None, h_or_v='v', figax=(fig,axes[1]))
2477
+ # elif self.active_res2d is not None:
2478
+ # self.active_res2d.mypal.export_image(None, h_or_v='v', figax=(fig,axes[1]))
2446
2479
 
2447
2480
  axes[0].xaxis.set_ticks_position('bottom')
2448
2481
  axes[0].xaxis.set_label_position('bottom')
@@ -2594,17 +2627,16 @@ class WolfMapViewer(wx.Frame):
2594
2627
 
2595
2628
  return myimage
2596
2629
 
2597
- def save_canvasogl(self, fn:str='', mpl:bool=True, ds:float=0.):
2630
+ def save_canvasogl(self, fn:str='', mpl:bool=True, ds:float=0., dpi:int= 300):
2598
2631
  """
2599
2632
  Sauvegarde de la fenêtre d'affichage dans un fichier
2600
2633
 
2601
- fn : File name (.png file)
2634
+ :param fn: File name (.png or .jpg file)
2635
+ :param mpl: Using Matplotlib as renderer
2636
+ :param ds: Ticks interval
2602
2637
  """
2603
2638
 
2604
- if not fn.endswith('.png'):
2605
- fn += '.png'
2606
-
2607
- self.Paint()
2639
+ fn = str(fn)
2608
2640
 
2609
2641
  if fn == '':
2610
2642
  dlg = wx.FileDialog(None, _('Choose file name'), wildcard='PNG (*.png)|*.png|JPG (*.jpg)|*.jpg',
@@ -2615,13 +2647,17 @@ class WolfMapViewer(wx.Frame):
2615
2647
  return
2616
2648
  fn = dlg.GetPath()
2617
2649
  dlg.Destroy()
2650
+ elif not fn.endswith('.png'):
2651
+ fn += '.png'
2618
2652
 
2619
2653
  if self.SetCurrentContext():
2620
- glPixelStorei(GL_PACK_ALIGNMENT, 1)
2621
- data = glReadPixels(0, 0, self.canvaswidth, self.canvasheight, GL_RGBA, GL_UNSIGNED_BYTE)
2622
- myimage: Image.Image
2623
- myimage = Image.frombuffer("RGBA", (self.canvaswidth, self.canvasheight), data)
2624
- myimage = myimage.transpose(1)
2654
+ # glPixelStorei(GL_PACK_ALIGNMENT, 1)
2655
+ # data = glReadPixels(0, 0, self.canvaswidth, self.canvasheight, GL_RGBA, GL_UNSIGNED_BYTE)
2656
+ # myimage: Image.Image
2657
+ # myimage = Image.frombuffer("RGBA", (self.canvaswidth, self.canvasheight), data)
2658
+ # myimage = myimage.transpose(1)
2659
+
2660
+ myimage = self.get_canvas_as_image()
2625
2661
 
2626
2662
  metadata = PngInfo()
2627
2663
  metadata.add_text('xmin', str(self.xmin))
@@ -2646,9 +2682,14 @@ class WolfMapViewer(wx.Frame):
2646
2682
  dlg.Destroy()
2647
2683
 
2648
2684
  extent = (self.xmin, self.xmax, self.ymin, self.ymax)
2649
- fig, ax = plt.subplots(1, 1)
2650
- pos = ax.imshow(myimage, origin='upper',
2651
- extent=extent)
2685
+ # fig, ax = plt.subplots(1, 1)
2686
+ fig,axes = plt.subplots(1,2, gridspec_kw={'width_ratios': [20, 1]})
2687
+
2688
+ ax = axes[0]
2689
+ self.display_canvasogl(fig=fig,ax=axes[0])
2690
+
2691
+ # pos = ax.imshow(myimage, origin='upper',
2692
+ # extent=extent)
2652
2693
  # fig.colorbar(pos,ax=ax)
2653
2694
 
2654
2695
  x1 = np.ceil((self.xmin // ds) * ds)
@@ -2683,7 +2724,19 @@ class WolfMapViewer(wx.Frame):
2683
2724
  ax.set_xlabel('X [m]')
2684
2725
  ax.set_ylabel('Y [m]')
2685
2726
 
2686
- plt.savefig(fn, dpi=300)
2727
+ self.palette_for_copy.export_image(None, h_or_v='v', figax=(fig,axes[1]))
2728
+
2729
+ # if self.active_array is not None:
2730
+ # self.active_array.mypal.export_image(None, h_or_v='v', figax=(fig,axes[1]))
2731
+ # elif self.active_res2d is not None:
2732
+ # self.active_res2d.mypal.export_image(None, h_or_v='v', figax=(fig,axes[1]))
2733
+
2734
+ # self.Paint()
2735
+
2736
+ fig.set_size_inches(12, 10)
2737
+ fig.tight_layout()
2738
+
2739
+ fig.savefig(fn, dpi=dpi)
2687
2740
  else:
2688
2741
  myimage.save(fn, pnginfo=metadata)
2689
2742
 
@@ -2693,6 +2746,9 @@ class WolfMapViewer(wx.Frame):
2693
2746
  'Opengl setcurrent -- maybe a conflict with an existing opengl32.dll file - please rename the opengl32.dll in the libs directory and retry')
2694
2747
 
2695
2748
  def reporting(self, dir=''):
2749
+ """ Firsdt attempr to create a reporting.
2750
+ !! Must be improved !!
2751
+ """
2696
2752
  if dir == '':
2697
2753
  dlg = wx.DirDialog(None, "Choose directory to store reporting", style=wx.FD_SAVE)
2698
2754
  ret = dlg.ShowModal()
@@ -2736,6 +2792,7 @@ class WolfMapViewer(wx.Frame):
2736
2792
  curvec.myprop.width = oldwidth
2737
2793
 
2738
2794
  def InitUI(self):
2795
+ """ Initialisation de l'interface utilisateur """
2739
2796
 
2740
2797
  self.Bind(wx.EVT_SIZE, self.OnSize)
2741
2798
  self.Bind(wx.EVT_CLOSE, self.OnClose)
@@ -6134,6 +6191,8 @@ class WolfMapViewer(wx.Frame):
6134
6191
  return linkedarrays
6135
6192
 
6136
6193
  def save_linked_canvas(self, fn, mpl=True, ds=0.):
6194
+ """ Save canvas of all linked viewers """
6195
+
6137
6196
  if self.linked:
6138
6197
  for idx, curel in enumerate(self.linkedList):
6139
6198
  curel.save_canvasogl(fn + '_' + str(idx) + '.png', mpl, ds)
wolfhece/apps/version.py CHANGED
@@ -5,7 +5,7 @@ class WolfVersion():
5
5
 
6
6
  self.major = 2
7
7
  self.minor = 1
8
- self.patch = 82
8
+ self.patch = 84
9
9
 
10
10
  def __str__(self):
11
11