mwxlib 1.6.0__py3-none-any.whl → 1.6.3__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/framework.py CHANGED
@@ -1,7 +1,7 @@
1
1
  #! python3
2
2
  """mwxlib framework.
3
3
  """
4
- __version__ = "1.6.0"
4
+ __version__ = "1.6.3"
5
5
  __author__ = "Kazuya O'moto <komoto@jeol.co.jp>"
6
6
 
7
7
  from contextlib import contextmanager
mwx/graphman.py CHANGED
@@ -9,6 +9,7 @@ from pprint import pformat
9
9
  import threading
10
10
  import traceback
11
11
  import inspect
12
+ import types
12
13
  import sys
13
14
  import os
14
15
  import platform
@@ -487,15 +488,9 @@ class Layer(LayerInterface, KnobCtrlPanel):
487
488
  LayerInterface.__init__(self, parent, session)
488
489
 
489
490
 
490
- def register(cls, module=None):
491
- """Register dummy plug; Add module.Plugin <Layer>.
492
- """
493
- if not module:
494
- module = inspect.getmodule(cls) # rebase module or __main__
495
-
491
+ def _register__dummy_plug__(cls, module):
496
492
  if issubclass(cls, LayerInterface):
497
- cls.__module__ = module.__name__ # __main__ to module
498
- warn(f"Duplicate iniheritance of LayerInterface by {cls}.")
493
+ ## warn(f"Duplicate iniheritance of LayerInterface by {cls}.")
499
494
  module.Plugin = cls
500
495
  return cls
501
496
 
@@ -504,8 +499,8 @@ def register(cls, module=None):
504
499
  cls.__init__(self, parent, **kwargs)
505
500
  LayerInterface.__init__(self, parent, session)
506
501
 
507
- _Plugin.__module__ = cls.__module__ = module.__name__
508
- _Plugin.__name__ = cls.__name__ + str("~")
502
+ _Plugin.__module__ = module.__name__
503
+ _Plugin.__name__ = cls.__name__ + "~"
509
504
  _Plugin.__doc__ = cls.__doc__
510
505
  module.Plugin = _Plugin
511
506
  return _Plugin
@@ -1005,6 +1000,13 @@ class Frame(mwx.Frame):
1005
1000
  ## --------------------------------
1006
1001
  plugins = property(lambda self: self.__plugins)
1007
1002
 
1003
+ def register(self, cls=None, **kwargs):
1004
+ """Decorator of plugin class register."""
1005
+ if cls is None:
1006
+ return lambda f: self.register(f, **kwargs)
1007
+ self.load_plug(cls, force=1, show=1, **kwargs)
1008
+ return cls
1009
+
1008
1010
  def require(self, name):
1009
1011
  """Get named plug window.
1010
1012
  If not found, try to load it once.
@@ -1027,13 +1029,14 @@ class Frame(mwx.Frame):
1027
1029
  if name in self.plugins:
1028
1030
  return self.plugins[name].__plug__
1029
1031
  elif isinstance(name, LayerInterface):
1030
- return name
1032
+ ## return name
1033
+ return next((x for x in self.get_all_plugs() if x is name), None)
1031
1034
 
1032
1035
  def get_all_plugs(self):
1033
1036
  for name, module in self.plugins.items():
1034
1037
  yield module.__plug__
1035
1038
 
1036
- def load_plug(self, root, force=False, session=None, show=False,
1039
+ def load_plug(self, root, session=None, force=False, show=False,
1037
1040
  dock=0, floating_pos=None, floating_size=None,
1038
1041
  **kwargs):
1039
1042
  """Load plugin.
@@ -1042,14 +1045,12 @@ class Frame(mwx.Frame):
1042
1045
  root: Plugin <Layer> module, or name of the module.
1043
1046
  Any wx.Window object can be specified (as dummy-plug).
1044
1047
  However, do not use this mode in release versions.
1045
- force: force loading even if it is already loaded
1046
1048
  session: Conditions for initializing the plug and starting session
1047
-
1049
+ force: force loading even if it is already loaded
1048
1050
  show: the pane is shown after loaded
1049
1051
  dock: dock_direction (1:top, 2:right, 3:bottom, 4:left, 5:center)
1050
1052
  floating_pos: posision of floating window
1051
1053
  floating_size: size of floating window
1052
-
1053
1054
  **kwargs: keywords for Plugin <Layer>
1054
1055
 
1055
1056
  Returns:
@@ -1062,22 +1063,23 @@ class Frame(mwx.Frame):
1062
1063
  floating_pos=floating_pos,
1063
1064
  floating_size=floating_size)
1064
1065
 
1065
- if inspect.ismodule(root): # @TODO: Change root module name
1066
- name = root.__file__
1067
- ## name = root.__name__
1066
+ if inspect.ismodule(root):
1067
+ name = root.__name__
1068
1068
  elif inspect.isclass(root):
1069
- name = inspect.getsourcefile(root)
1069
+ name = root.__module__
1070
1070
  else:
1071
1071
  name = root
1072
- dirname_, name = os.path.split(name) # if the name is full path,...
1072
+ if name == "__main__":
1073
+ name = inspect.getfile(__import__("__main__"))
1074
+
1075
+ dirname_, name = os.path.split(name) # if the name is full-path:str
1073
1076
  if name.endswith(".py"):
1074
1077
  name = name[:-3]
1075
1078
 
1076
1079
  if not force:
1077
- ## 文字列参照 (root:str) による重複ロードを避ける
1080
+ ## 文字列参照 (full-path) による重複ロードを避ける
1078
1081
  module = next((v for v in self.plugins.values() if root == v.__file__), None)
1079
1082
  if module:
1080
- ## print(f"- {name!r} is already loaded as {module.__name__!r}.")
1081
1083
  plug = module.__plug__
1082
1084
  else:
1083
1085
  plug = self.get_plug(name)
@@ -1108,19 +1110,26 @@ class Frame(mwx.Frame):
1108
1110
  else:
1109
1111
  module = import_module(name)
1110
1112
  except Exception:
1111
- traceback.print_exc() # Unable to load the module.
1112
- return False
1113
- else:
1114
- if not hasattr(module, 'Plugin'):
1115
- if isinstance(root, type):
1116
- ## warn(f"Use dummy plug for {name!r}.")
1117
- module.__dummy_plug__ = root
1118
- register(root, module)
1113
+ module = inspect.getmodule(name) # __main__ ? Check if the module is dummy.
1114
+ if module:
1115
+ traceback.print_exc() # Unable to load the module.
1116
+ return False
1119
1117
  else:
1120
- if hasattr(module, '__dummy_plug__'):
1121
- root = module.__dummy_plug__ # old class (imported)
1122
- cls = getattr(module, root.__name__) # new class (reloaded)
1123
- register(cls, module)
1118
+ module = types.ModuleType(name) # dummy module (cannot reload)
1119
+ module.__file__ = "<scratch>"
1120
+ ## sys.modules[name] = module
1121
+
1122
+ ## Register dummy plug; Add module.Plugin <Layer>.
1123
+ if not hasattr(module, 'Plugin'):
1124
+ if inspect.isclass(root):
1125
+ _register__dummy_plug__(root, module)
1126
+ module.__dummy_plug__ = root
1127
+ else:
1128
+ if hasattr(module, '__dummy_plug__'):
1129
+ cls = module.__dummy_plug__ # old class (imported)
1130
+ cls = getattr(module, cls.__name__) # new class (reloaded)
1131
+ _register__dummy_plug__(cls, module)
1132
+ module.__dummy_plug__ = cls
1124
1133
 
1125
1134
  ## Note: name (module.__name__) != Plugin.__module__ if module is a package.
1126
1135
  try:
@@ -1150,8 +1159,8 @@ class Frame(mwx.Frame):
1150
1159
  show = show or pane.IsShown()
1151
1160
  props.update(
1152
1161
  dock_direction = pane.IsDocked() and pane.dock_direction,
1153
- floating_pos = floating_pos or pane.floating_pos[:], # copy unloading pane
1154
- floating_size = floating_size or pane.floating_size[:], # copy unloading pane
1162
+ floating_pos = floating_pos or pane.floating_pos[:], # copy unloading pane
1163
+ floating_size = floating_size or pane.floating_size[:], # copy unloading pane
1155
1164
  )
1156
1165
  self.unload_plug(name)
1157
1166
 
@@ -1276,11 +1285,17 @@ class Frame(mwx.Frame):
1276
1285
 
1277
1286
  session = {}
1278
1287
  try:
1279
- print("Reloading {}...".format(plug))
1288
+ print(f"Reloading {plug}...")
1280
1289
  plug.save_session(session)
1281
1290
  except Exception:
1282
1291
  traceback.print_exc() # Failed to save the plug session.
1292
+
1283
1293
  self.load_plug(plug.__module__, force=1, session=session)
1294
+
1295
+ ## Update shell.target --> new plug
1296
+ for shell in self.shellframe.get_all_shells():
1297
+ if shell.target is plug:
1298
+ shell.handler('shell_activated', shell)
1284
1299
 
1285
1300
  def inspect_plug(self, name):
1286
1301
  """Dive into the process to inspect plugs in the shell."""
@@ -1290,6 +1305,7 @@ class Frame(mwx.Frame):
1290
1305
  return
1291
1306
 
1292
1307
  shell = self.shellframe.clone_shell(plug)
1308
+ name = plug.Name # init(shell) で名前を参照するため再定義する
1293
1309
 
1294
1310
  @shell.handler.bind("shell_activated")
1295
1311
  def init(shell):
@@ -1336,7 +1352,7 @@ class Frame(mwx.Frame):
1336
1352
 
1337
1353
  if not filename:
1338
1354
  default_path = view.frame.pathname if view.frame else None
1339
- with wx.FileDialog(self, "Select index file to import",
1355
+ with wx.FileDialog(self, "Select index file to load",
1340
1356
  defaultDir=os.path.dirname(default_path or ''),
1341
1357
  defaultFile=self.ATTRIBUTESFILE,
1342
1358
  wildcard="Index (*.index)|*.index|"
@@ -1739,7 +1755,10 @@ class Frame(mwx.Frame):
1739
1755
 
1740
1756
  for name, module in self.plugins.items():
1741
1757
  plug = self.get_plug(name)
1742
- name = module.__file__ # Replace the name with full path.
1758
+ name = module.__file__ # Replace the name with full-path.
1759
+ if not plug or not os.path.exists(name):
1760
+ print(f"Skipping dummy plugin {name!r}...")
1761
+ continue
1743
1762
  if hasattr(module, '__path__'): # is the module a package?
1744
1763
  name = os.path.dirname(name)
1745
1764
  session = {}
@@ -1747,7 +1766,7 @@ class Frame(mwx.Frame):
1747
1766
  plug.save_session(session)
1748
1767
  except Exception:
1749
1768
  traceback.print_exc() # Failed to save the plug session.
1750
- o.write("self.load_plug({!r}, session={})\n".format(name, session or None))
1769
+ o.write("self.load_plug({!r}, session={})\n".format(name, session))
1751
1770
  o.write("self._mgr.LoadPerspective({!r})\n".format(self._mgr.SavePerspective()))
1752
1771
 
1753
1772
  def _save(view):
mwx/testsuite.py CHANGED
@@ -17,7 +17,7 @@ Is equivalent to:
17
17
  from contextlib import contextmanager
18
18
  import wx
19
19
 
20
- __all__ = ["testApp", "testFrame", "testPlugin", "testPanel"]
20
+ __all__ = ["testApp", "testFrame"]
21
21
 
22
22
 
23
23
  @contextmanager
@@ -36,23 +36,3 @@ def testFrame(**kwargs):
36
36
  yield frm
37
37
  frm.Show()
38
38
  ## wx.Frame.run = staticmethod(testFrame)
39
-
40
-
41
- @contextmanager
42
- def testPanel(**kwargs):
43
- import mwx
44
- with testApp():
45
- frm = mwx.Frame(None)
46
- panel = mwx.ControlPanel(frm, **kwargs)
47
- yield panel
48
- panel.Sizer.Fit(frm)
49
- frm.Show()
50
-
51
-
52
- @contextmanager
53
- def testPlugin(**kwargs):
54
- import mwx.graphman
55
- with testApp():
56
- frm = mwx.graphman.Frame(None, **kwargs)
57
- yield frm
58
- frm.Show()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mwxlib
3
- Version: 1.6.0
3
+ Version: 1.6.3
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,15 +1,15 @@
1
1
  mwx/__init__.py,sha256=pS7ZG8QKRypiFFiaWAq_opBB6I_1viZ0zUMk2TbjzE0,667
2
2
  mwx/bookshelf.py,sha256=yW17nMNPXKHM7LLXLpr9DaRhyFHz_OBAZ_DsuEK2QzA,8387
3
3
  mwx/controls.py,sha256=B9f_A0ev3SPf75K-LIZCusMLeDGYz1O3cMml7IOrDrM,49870
4
- mwx/framework.py,sha256=xVov9uy6gheXOphdorERXQ-Pivj2I3Ir3N0t829gkKM,77463
5
- mwx/graphman.py,sha256=Cmg0mwIGTAHtdXArFxJXPZC7yPGvSvAZexw7zgp02L8,69099
4
+ mwx/framework.py,sha256=J6f1PekG4O0fwH5n4aNnR6qvXV6FAgmA0QOIEE8PCvY,77463
5
+ mwx/graphman.py,sha256=SL0msdXDqbw2GswBbspFa916z2fJbHYTDph9vcRP1yU,69917
6
6
  mwx/images.py,sha256=Kkfy9QI_hMtwShSjUS4-ZpC_EkVuah_XhpBOR4wAKkM,49792
7
7
  mwx/matplot2.py,sha256=cjdN12RENqWFw1v9QyO05XQc6dK3Pn_ltdC3OfmhGfg,32995
8
8
  mwx/matplot2g.py,sha256=0gxjl7UKx8QGRI2thpniA7dQu9fpHGG0mvl7Ml2exrc,65474
9
9
  mwx/matplot2lg.py,sha256=jE-LYPEVaEapQN8L-eviRyEx4Lw-8GyLGzZotrIZShU,27413
10
10
  mwx/mgplt.py,sha256=SVUJ0ls4gC9xulbWxK2qqmDxf0uBCflvwoPkxoF5s3M,5566
11
11
  mwx/nutshell.py,sha256=Sa5PKSiXxT74Mj_vE9fUinxkfm5Xtg1MGGUjwbRH-yY,147552
12
- mwx/testsuite.py,sha256=0Q_n_XOOsZ8lsLWUkuO8QW00hts9wEQfnUKMpf0BAyU,1235
12
+ mwx/testsuite.py,sha256=pBB7ZNicI_thrg6LmNPgUOgfMWwRoAaYWN1nFy6t6S4,790
13
13
  mwx/utilus.py,sha256=JOYBTHoo_GmYykX72PgiPzgD2M-1pcOR8gMBLc2bnck,39016
14
14
  mwx/wxmon.py,sha256=aS6lSjDm0PxIhfyBPtg-wIP0v-R3g2K5a3k2mclWSrQ,12798
15
15
  mwx/wxpdb.py,sha256=ehRawAnqQberUeDN9j_-drWYQzu23w5UeQyto4nj53g,18812
@@ -22,7 +22,7 @@ mwx/plugins/frame_listview.py,sha256=yd2NCgspqGfTNhj1wxuW8r1zapIm7vNzVX2iytk8CDM
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=vWCJoHd_oyXOeXTHtXGY7wfNQeNAZhV3GZu4xlc8GDY,16867
25
- mwxlib-1.6.0.dist-info/METADATA,sha256=ZLDHrIHbEvcB3Ee4lLQxk6ZnDFkL5aXN3gT5QdkcyBc,7381
26
- mwxlib-1.6.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
27
- mwxlib-1.6.0.dist-info/top_level.txt,sha256=SI1Mh118AstnUFGPNq5aMNKiAnVNmZk1S9Ij-OwAEpY,4
28
- mwxlib-1.6.0.dist-info/RECORD,,
25
+ mwxlib-1.6.3.dist-info/METADATA,sha256=QbzAtx8OsYdp8LIL8pvOgmh_qgGAIxGLtGsdKuOj-9w,7381
26
+ mwxlib-1.6.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
27
+ mwxlib-1.6.3.dist-info/top_level.txt,sha256=SI1Mh118AstnUFGPNq5aMNKiAnVNmZk1S9Ij-OwAEpY,4
28
+ mwxlib-1.6.3.dist-info/RECORD,,
File without changes