mwxlib 1.2.3__py3-none-any.whl → 1.2.5__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.

Potentially problematic release.


This version of mwxlib might be problematic. Click here for more details.

mwx/controls.py CHANGED
@@ -770,6 +770,7 @@ class Clipboard:
770
770
  return text
771
771
  else:
772
772
  print("- Unable to open clipboard.")
773
+ return None
773
774
 
774
775
  @staticmethod
775
776
  def write(text, verbose=False):
@@ -792,7 +793,7 @@ class Clipboard:
792
793
  bmp = do.GetBitmap()
793
794
  else:
794
795
  print("- Unable to open clipboard.")
795
- return
796
+ return None
796
797
  try:
797
798
  ## Convert bmp --> buf
798
799
  img = bmp.ConvertToImage()
@@ -802,7 +803,8 @@ class Clipboard:
802
803
  w, h = img.GetSize()
803
804
  return buf.reshape(h, w, 3)
804
805
  except Exception:
805
- print("- The contents of the clipboard are not images.")
806
+ print("- Contents of the clipboard are not images.")
807
+ return None
806
808
 
807
809
  @staticmethod
808
810
  def imwrite(buf, verbose=False):
@@ -815,7 +817,7 @@ class Clipboard:
815
817
  img = wx.Image(w, h, buf.tobytes())
816
818
  bmp = img.ConvertToBitmap()
817
819
  except Exception:
818
- print("- The contents of the clipboard are not images.")
820
+ print("- Argument 'buf' is not a 2d array.")
819
821
  return
820
822
  do = wx.BitmapDataObject(bmp)
821
823
  if wx.TheClipboard.Open():
mwx/framework.py CHANGED
@@ -1,7 +1,7 @@
1
1
  #! python3
2
2
  """mwxlib framework.
3
3
  """
4
- __version__ = "1.2.3"
4
+ __version__ = "1.2.5"
5
5
  __author__ = "Kazuya O'moto <komoto@jeol.co.jp>"
6
6
 
7
7
  from contextlib import contextmanager
mwx/matplot2g.py CHANGED
@@ -1,7 +1,6 @@
1
1
  #! python3
2
2
  """mwxlib graph plot for images.
3
3
  """
4
- import traceback
5
4
  import wx
6
5
 
7
6
  from matplotlib import cm
@@ -49,6 +48,11 @@ def _to_buffer(img):
49
48
  w, h = img.GetSize()
50
49
  img = np.frombuffer(img.GetDataBuffer(), dtype='uint8').reshape(h, w, 3)
51
50
 
51
+ if not isinstance(img, np.ndarray):
52
+ raise ValueError("targets must be arrays or images.")
53
+
54
+ assert img.ndim > 1, "targets must be 2d arrays."
55
+
52
56
  if img.ndim > 2:
53
57
  return cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
54
58
  return img
@@ -73,20 +77,18 @@ def _to_image(src, cutoff=0, threshold=None, binning=1):
73
77
  if src.dtype in (np.complex64, np.complex128): # maybe fft pattern
74
78
  src = np.log(1 + abs(src))
75
79
 
76
- bins = binning
77
80
  if threshold:
78
- ## Converted to <uint8(=1byte)> finally, binning should be reduced by itemsize.
79
- n = int(np.sqrt(src.nbytes / threshold / src.itemsize)) + 1
80
- if bins < n:
81
- bins = n # binning or threshold; Select the larger one.
82
-
83
- if bins > 1:
84
- ## src = src[::bins,::bins]
81
+ ## Reduce the binning by itemsize before finally converting to <uint8>.
82
+ ## Select the larger value between binning and threshold.
83
+ n = max(binning, int(np.sqrt(src.nbytes / threshold / src.itemsize)) + 1)
84
+ else:
85
+ n = binning
86
+ if n > 1:
85
87
  src = _to_cvtype(src)
86
- src = cv2.resize(src, None, fx=1/bins, fy=1/bins, interpolation=cv2.INTER_AREA)
88
+ src = cv2.resize(src, None, fx=1/n, fy=1/n, interpolation=cv2.INTER_AREA)
87
89
 
88
90
  if src.dtype == np.uint8: # RGB or gray image <uint8>
89
- return bins, (0, 255), src
91
+ return n, (0, 255), src
90
92
 
91
93
  if hasattr(cutoff, '__iter__'): # cutoff vlim: (vmin, vmax) is specified.
92
94
  a, b = cutoff
@@ -99,10 +101,10 @@ def _to_image(src, cutoff=0, threshold=None, binning=1):
99
101
 
100
102
  r = (255 / (b - a)) if a < b else 1
101
103
  ## img = cv2.convertScaleAbs(src, alpha=r, beta=-r*a) # 負数は絶対値になるので以下に変更
102
- img = np.uint8((src - a) * r) # copy buffer
104
+ img = np.uint8((src - a) * r)
103
105
  img[src < a] = 0
104
106
  img[src > b] = 255
105
- return bins, (a, b), img
107
+ return n, (a, b), img
106
108
 
107
109
 
108
110
  def _Property(name):
@@ -155,6 +157,7 @@ class AxesImagePhantom:
155
157
  return getattr(self.__art, attr)
156
158
 
157
159
  def __eq__(self, x):
160
+ ## Called in `on_pick` and `__contains__` to check objects in.
158
161
  return x is self.__art
159
162
 
160
163
  def update_attributes(self, attr=None, **kwargs):
@@ -221,7 +224,7 @@ class AxesImagePhantom:
221
224
 
222
225
  image = property(
223
226
  lambda self: self.__art.get_array(),
224
- doc="A displayed image array<uint8>.")
227
+ doc="Displayed image array<uint8>.")
225
228
 
226
229
  clim = property(
227
230
  lambda self: self.__art.get_clim(),
@@ -235,7 +238,7 @@ class AxesImagePhantom:
235
238
  pathname = property(
236
239
  lambda self: self.__attributes.get('pathname'),
237
240
  lambda self,v: self.update_attributes({'pathname': v}),
238
- doc="A fullpath of buffer, when bounds to file.")
241
+ doc="Fullpath of the buffer, if bound to a file.")
239
242
 
240
243
  annotation = property(
241
244
  lambda self: self.__attributes.get('annotation', ''),
@@ -697,22 +700,19 @@ class GraphPlot(MatplotPanel):
697
700
  return buffers[j] # j can also be slicing
698
701
 
699
702
  def __setitem__(self, j, v):
703
+ if v is None:
704
+ raise ValueError("values must be buffers, not NoneType.")
705
+
700
706
  if isinstance(j, str):
701
- try:
702
- j = self.index(j) # overwrite buffer
703
- except ValueError:
704
- return self.load(v, name=j) # new buffer
707
+ return self.load(v, name=j) # update buffer or new buffer
705
708
 
706
709
  if isinstance(j, slice):
707
710
  raise ValueError("attempt to assign buffers via slicing")
708
711
 
709
- if v is None:
710
- raise ValueError("values must be buffers, not NoneType.")
711
- else:
712
- art = self.__Arts[j]
713
- art.update_buffer(v) # update buffer
714
- art.update_extent()
715
- self.select(j)
712
+ art = self.__Arts[j]
713
+ art.update_buffer(v) # update buffer
714
+ art.update_extent()
715
+ self.select(j)
716
716
 
717
717
  def __delitem__(self, j):
718
718
  if isinstance(j, str):
@@ -829,8 +829,8 @@ class GraphPlot(MatplotPanel):
829
829
  self.canvas.draw_idle()
830
830
 
831
831
  def kill_buffer(self):
832
- if self.buffer is not None:
833
- del self.buffer
832
+ if self.frame:
833
+ del self[self.__index]
834
834
 
835
835
  def kill_buffer_all(self):
836
836
  del self[:]
@@ -959,34 +959,28 @@ class GraphPlot(MatplotPanel):
959
959
  if not frame:
960
960
  self.message("No frame")
961
961
  return
962
- try:
963
- name = frame.name
964
- data = frame.roi
965
- GraphPlot.clipboard_name = name
966
- GraphPlot.clipboard_data = data
967
- bins, vlim, img = _to_image(data, frame.cuts)
968
- Clipboard.imwrite(img)
969
- self.message("Write buffer to clipboard.")
970
- except Exception as e:
971
- traceback.print_exc()
972
- self.message("- Failed to write to clipboard.", e)
962
+
963
+ name = frame.name
964
+ data = frame.roi
965
+ GraphPlot.clipboard_name = name
966
+ GraphPlot.clipboard_data = data
967
+ bins, vlim, img = _to_image(data, frame.cuts)
968
+ Clipboard.imwrite(img)
969
+ self.message("Write buffer to clipboard.")
973
970
 
974
971
  def read_buffer_from_clipboard(self):
975
972
  """Read buffer data from clipboard."""
976
- try:
977
- name = GraphPlot.clipboard_name
978
- data = GraphPlot.clipboard_data
979
- if name:
980
- self.message("Read buffer from clipboard.")
981
- GraphPlot.clipboard_name = None
982
- GraphPlot.clipboard_data = None
983
- else:
984
- self.message("Read image from clipboard.")
985
- data = Clipboard.imread()
973
+ name = GraphPlot.clipboard_name
974
+ data = GraphPlot.clipboard_data
975
+ if name:
976
+ self.message("Read buffer from clipboard.")
977
+ GraphPlot.clipboard_name = None
978
+ GraphPlot.clipboard_data = None
979
+ else:
980
+ self.message("Read image from clipboard.")
981
+ data = Clipboard.imread()
982
+ if data is not None:
986
983
  self.load(data)
987
- except Exception as e:
988
- traceback.print_exc()
989
- self.message("- No data in clipboard.", e)
990
984
 
991
985
  def destroy_colorbar(self):
992
986
  if self.cbar:
mwx/utilus.py CHANGED
@@ -37,15 +37,16 @@ def ignore(*category):
37
37
  yield
38
38
 
39
39
 
40
- def warn(message, category=None):
41
- frame = inspect.currentframe().f_back # previous call stack frame
42
- skip = [frame.f_code.co_filename]
43
- stacklevel = 1
44
- while frame.f_code.co_filename in skip:
45
- frame = frame.f_back
46
- if not frame:
47
- break
48
- stacklevel += 1
40
+ def warn(message, category=None, stacklevel=None):
41
+ if stacklevel is None:
42
+ frame = inspect.currentframe().f_back # previous call stack frame
43
+ skip = [frame.f_code.co_filename]
44
+ stacklevel = 1
45
+ while frame.f_code.co_filename in skip:
46
+ frame = frame.f_back
47
+ if not frame:
48
+ break
49
+ stacklevel += 1
49
50
  return warnings.warn(message, category, stacklevel+1)
50
51
 
51
52
 
mwx/wxpdb.py CHANGED
@@ -53,7 +53,6 @@ class Debugger(Pdb):
53
53
  use_rawinput = False
54
54
  prompt = property(lambda self: self.indents + '(Pdb) ',
55
55
  lambda self,v: None) # fake setter
56
- parent = property(lambda self: self.__shellframe)
57
56
  handler = property(lambda self: self.__handler)
58
57
 
59
58
  @property
@@ -90,12 +89,12 @@ class Debugger(Pdb):
90
89
  def __init__(self, parent, *args, **kwargs):
91
90
  Pdb.__init__(self, *args, **kwargs)
92
91
 
93
- self.__shellframe = parent
94
- self.__hookpoint = None
92
+ self.parent = parent
95
93
  self.indents = ' ' * 2
96
94
  self.interactive_shell = parent.rootshell
97
95
  self.editor = None
98
96
  self.code = None
97
+ self.__hookpoint = None
99
98
 
100
99
  def _input(msg):
101
100
  ## redirects input such as cl(ear)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mwxlib
3
- Version: 1.2.3
3
+ Version: 1.2.5
4
4
  Summary: A wrapper of matplotlib and wxPython (phoenix)
5
5
  Home-page: https://github.com/komoto48g/mwxlib
6
6
  Author: Kazuya O'moto
@@ -1,18 +1,18 @@
1
1
  mwx/__init__.py,sha256=pS7ZG8QKRypiFFiaWAq_opBB6I_1viZ0zUMk2TbjzE0,667
2
2
  mwx/bookshelf.py,sha256=b_TMDaNIzLHoL0xbbqb3tt0BnRvhLAqaCn_pBdrigZw,7523
3
- mwx/controls.py,sha256=X4zx2h6oggUsQxi2PRk4RUsJieYTmcAPIvWwaz-ysTI,48107
4
- mwx/framework.py,sha256=wXI4nzQcG0NV3c5ne4io9HJ1y7jd7xbjB_cOao8HKsU,76125
3
+ mwx/controls.py,sha256=5PCy3zguDRuwYl89P9tOCUU7xAGUETs944qZBy5MS9g,48146
4
+ mwx/framework.py,sha256=c0o6IXrdgvfpnPXHPNYU7isqzOydXwtiMY7-qRXMFyQ,76125
5
5
  mwx/graphman.py,sha256=RqD0W9I2BvJ3Q2kyMiyyg4n-T4-_x7PDuCI5bGAg5k4,70110
6
6
  mwx/images.py,sha256=oxCn0P-emiWujSS2gUgU5TUnr5cPjix2jBcjOBDr24I,48701
7
7
  mwx/matplot2.py,sha256=Zwte-wwzCg_OHzsBniVgKdaNLzsvJaa1gc0n7VdAqxw,33150
8
- mwx/matplot2g.py,sha256=tShPGy7whj51yvANja-MDmjfxiLubQ1C6rCsBZ0DAnY,64473
8
+ mwx/matplot2g.py,sha256=ywvu5-QAIgv4jc1kalNYgVGcl4RoY9Y1Dx1qtteaqXk,64195
9
9
  mwx/matplot2lg.py,sha256=JRWjWnLJUytbSq6wxs4P0gbVUr3xoLSF6Wwqd5V_pJI,27404
10
10
  mwx/mgplt.py,sha256=8mXbHpCmm7lz3XbAxOg7IVC7DaSGBEby1UfTlMl9kjk,5604
11
11
  mwx/nutshell.py,sha256=7nQ7UUFM9kvjDjHNUEdOkkeqZPiU6zOERwamqBdJpQs,140856
12
12
  mwx/testsuite.py,sha256=kiM3-BVhr42LRRN7xG7pYl3at8o2vnypWSxD8KRvA7c,1228
13
- mwx/utilus.py,sha256=HFvP682SyeSp8yNfUrdUXPhWdLuWVlsUSg6LqNBJOT8,37451
13
+ mwx/utilus.py,sha256=bDeooo2bOcZwvkIdi0ElkT-qoblqzHNFsIveb72NFOo,37528
14
14
  mwx/wxmon.py,sha256=yzWqrbY6LzpfRwQeytYUeqFhFuLVm_XEvrVAL_k0HBQ,12756
15
- mwx/wxpdb.py,sha256=AObuf4JLAmlQLj-yf0_mkBBd-Bhhz2Vb8hbTVcHEZOs,18875
15
+ mwx/wxpdb.py,sha256=ge4hNfeigHGcpnioU1B_BJX_QZjNdtnokUrcZOxcEcI,18814
16
16
  mwx/wxwil.py,sha256=hhyB1lPrF9ixeObxCOKQv0Theu-B-kpJg_yVU3EGSNg,5406
17
17
  mwx/wxwit.py,sha256=1hHtMi2YEy2T_LnUpwdmrIdtCuvxMOFyykqnbq6jLP0,7294
18
18
  mwx/plugins/__init__.py,sha256=jnJ-Sl9XJ_7BFDslD_r7dsbxsOT57q_IaEriV53XIGY,41
@@ -22,8 +22,8 @@ mwx/plugins/frame_listview.py,sha256=gowjQ-ARNonMkDSXkQgPKq4U9YBJ-vQ0jK2krBVOdCs
22
22
  mwx/plugins/line_profile.py,sha256=zzm6_7lnAnNepLbh07ordp3nRWDFQJtu719ZVjrVf8s,819
23
23
  mwx/py/__init__.py,sha256=xykgfOytOwNuvXsfkLoumFZSTN-iBsHOjczYXngjmUE,12
24
24
  mwx/py/filling.py,sha256=fumUG1F5M9TL-Dfqni4G85uk7TmvnUunTbdcPDV0vfo,16857
25
- mwxlib-1.2.3.dist-info/LICENSE,sha256=PGtRKCaTkmUDlBQwpptJAxJtdqxIUtAmdBsaT9nUVkA,1091
26
- mwxlib-1.2.3.dist-info/METADATA,sha256=2sSF51qYRi78w0McPUzYn2yr9H1ISRKXMfvWSB-ATls,7258
27
- mwxlib-1.2.3.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
28
- mwxlib-1.2.3.dist-info/top_level.txt,sha256=SI1Mh118AstnUFGPNq5aMNKiAnVNmZk1S9Ij-OwAEpY,4
29
- mwxlib-1.2.3.dist-info/RECORD,,
25
+ mwxlib-1.2.5.dist-info/LICENSE,sha256=PGtRKCaTkmUDlBQwpptJAxJtdqxIUtAmdBsaT9nUVkA,1091
26
+ mwxlib-1.2.5.dist-info/METADATA,sha256=HZpDkw3rpf_1eFrLWB4UFT2sGfuJQ0nDV7cUyWuot-w,7258
27
+ mwxlib-1.2.5.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
28
+ mwxlib-1.2.5.dist-info/top_level.txt,sha256=SI1Mh118AstnUFGPNq5aMNKiAnVNmZk1S9Ij-OwAEpY,4
29
+ mwxlib-1.2.5.dist-info/RECORD,,
File without changes