mwxlib 1.6.0__py3-none-any.whl → 1.6.2__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.2"
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,20 @@ 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
+ dirname_, name = os.path.split(name) # if the name is full-path:str
1073
1073
  if name.endswith(".py"):
1074
1074
  name = name[:-3]
1075
1075
 
1076
1076
  if not force:
1077
- ## 文字列参照 (root:str) による重複ロードを避ける
1077
+ ## 文字列参照 (full-path) による重複ロードを避ける
1078
1078
  module = next((v for v in self.plugins.values() if root == v.__file__), None)
1079
1079
  if module:
1080
- ## print(f"- {name!r} is already loaded as {module.__name__!r}.")
1081
1080
  plug = module.__plug__
1082
1081
  else:
1083
1082
  plug = self.get_plug(name)
@@ -1107,20 +1106,25 @@ class Frame(mwx.Frame):
1107
1106
  module = reload(sys.modules[name])
1108
1107
  else:
1109
1108
  module = import_module(name)
1109
+ except ModuleNotFoundError:
1110
+ module = types.ModuleType(name) # dummy module (cannot reload)
1111
+ module.__file__ = "<scratch>"
1112
+ ## sys.modules[name] = module
1110
1113
  except Exception:
1111
1114
  traceback.print_exc() # Unable to load the module.
1112
1115
  return False
1116
+
1117
+ ## Register dummy plug; Add module.Plugin <Layer>.
1118
+ if not hasattr(module, 'Plugin'):
1119
+ if inspect.isclass(root):
1120
+ _register__dummy_plug__(root, module)
1121
+ module.__dummy_plug__ = root
1113
1122
  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)
1119
- 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)
1123
+ if hasattr(module, '__dummy_plug__'):
1124
+ cls = module.__dummy_plug__ # old class (imported)
1125
+ cls = getattr(module, cls.__name__) # new class (reloaded)
1126
+ _register__dummy_plug__(cls, module)
1127
+ module.__dummy_plug__ = cls
1124
1128
 
1125
1129
  ## Note: name (module.__name__) != Plugin.__module__ if module is a package.
1126
1130
  try:
@@ -1150,8 +1154,8 @@ class Frame(mwx.Frame):
1150
1154
  show = show or pane.IsShown()
1151
1155
  props.update(
1152
1156
  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
1157
+ floating_pos = floating_pos or pane.floating_pos[:], # copy unloading pane
1158
+ floating_size = floating_size or pane.floating_size[:], # copy unloading pane
1155
1159
  )
1156
1160
  self.unload_plug(name)
1157
1161
 
@@ -1276,11 +1280,17 @@ class Frame(mwx.Frame):
1276
1280
 
1277
1281
  session = {}
1278
1282
  try:
1279
- print("Reloading {}...".format(plug))
1283
+ print(f"Reloading {plug}...")
1280
1284
  plug.save_session(session)
1281
1285
  except Exception:
1282
1286
  traceback.print_exc() # Failed to save the plug session.
1287
+
1283
1288
  self.load_plug(plug.__module__, force=1, session=session)
1289
+
1290
+ ## Update shell.target --> new plug
1291
+ for shell in self.shellframe.get_all_shells():
1292
+ if shell.target is plug:
1293
+ shell.handler('shell_activated', shell)
1284
1294
 
1285
1295
  def inspect_plug(self, name):
1286
1296
  """Dive into the process to inspect plugs in the shell."""
@@ -1290,6 +1300,7 @@ class Frame(mwx.Frame):
1290
1300
  return
1291
1301
 
1292
1302
  shell = self.shellframe.clone_shell(plug)
1303
+ name = plug.Name # init(shell) で名前を参照するため再定義する
1293
1304
 
1294
1305
  @shell.handler.bind("shell_activated")
1295
1306
  def init(shell):
@@ -1336,7 +1347,7 @@ class Frame(mwx.Frame):
1336
1347
 
1337
1348
  if not filename:
1338
1349
  default_path = view.frame.pathname if view.frame else None
1339
- with wx.FileDialog(self, "Select index file to import",
1350
+ with wx.FileDialog(self, "Select index file to load",
1340
1351
  defaultDir=os.path.dirname(default_path or ''),
1341
1352
  defaultFile=self.ATTRIBUTESFILE,
1342
1353
  wildcard="Index (*.index)|*.index|"
@@ -1739,7 +1750,10 @@ class Frame(mwx.Frame):
1739
1750
 
1740
1751
  for name, module in self.plugins.items():
1741
1752
  plug = self.get_plug(name)
1742
- name = module.__file__ # Replace the name with full path.
1753
+ name = module.__file__ # Replace the name with full-path.
1754
+ if not plug or not os.path.exists(name):
1755
+ print(f"Skipping dummy plugin {name!r}...")
1756
+ continue
1743
1757
  if hasattr(module, '__path__'): # is the module a package?
1744
1758
  name = os.path.dirname(name)
1745
1759
  session = {}
@@ -1747,7 +1761,7 @@ class Frame(mwx.Frame):
1747
1761
  plug.save_session(session)
1748
1762
  except Exception:
1749
1763
  traceback.print_exc() # Failed to save the plug session.
1750
- o.write("self.load_plug({!r}, session={})\n".format(name, session or None))
1764
+ o.write("self.load_plug({!r}, session={})\n".format(name, session))
1751
1765
  o.write("self._mgr.LoadPerspective({!r})\n".format(self._mgr.SavePerspective()))
1752
1766
 
1753
1767
  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.2
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=8E9hGW9YPJBpv55ZvPrIQnVcNeDtWP-RRvgXOJbvYXc,77463
5
+ mwx/graphman.py,sha256=l6SjyjZj0_aDj-_dwNDlVI6aD3BQqbhoLe95NAzAEqo,69699
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.2.dist-info/METADATA,sha256=RshZtfKDFUVVMf92eAGQhe08pmtZjPR3ClIhuYOpGRc,7381
26
+ mwxlib-1.6.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
27
+ mwxlib-1.6.2.dist-info/top_level.txt,sha256=SI1Mh118AstnUFGPNq5aMNKiAnVNmZk1S9Ij-OwAEpY,4
28
+ mwxlib-1.6.2.dist-info/RECORD,,
File without changes