mwxlib 1.5.0__py3-none-any.whl → 1.5.10__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/bookshelf.py +19 -13
- mwx/controls.py +10 -10
- mwx/framework.py +85 -71
- mwx/graphman.py +114 -112
- mwx/matplot2.py +13 -12
- mwx/matplot2g.py +22 -30
- mwx/matplot2lg.py +10 -10
- mwx/mgplt.py +1 -1
- mwx/nutshell.py +110 -79
- mwx/plugins/ffmpeg_view.py +3 -4
- mwx/plugins/fft_view.py +2 -2
- mwx/plugins/frame_listview.py +12 -7
- mwx/testsuite.py +10 -10
- mwx/utilus.py +17 -11
- mwx/wxpdb.py +3 -3
- {mwxlib-1.5.0.dist-info → mwxlib-1.5.10.dist-info}/METADATA +1 -1
- mwxlib-1.5.10.dist-info/RECORD +28 -0
- {mwxlib-1.5.0.dist-info → mwxlib-1.5.10.dist-info}/WHEEL +1 -1
- mwxlib-1.5.0.dist-info/RECORD +0 -28
- {mwxlib-1.5.0.dist-info → mwxlib-1.5.10.dist-info}/top_level.txt +0 -0
mwx/graphman.py
CHANGED
|
@@ -113,7 +113,6 @@ class Thread:
|
|
|
113
113
|
Allows only this worker (but no other thread) to enter.
|
|
114
114
|
"""
|
|
115
115
|
frame = inspect.currentframe().f_back.f_back
|
|
116
|
-
filename = frame.f_code.co_filename
|
|
117
116
|
name = frame.f_code.co_name
|
|
118
117
|
|
|
119
118
|
## Other threads are not allowed to enter.
|
|
@@ -125,12 +124,16 @@ class Thread:
|
|
|
125
124
|
yield self
|
|
126
125
|
|
|
127
126
|
def enters(self, f):
|
|
128
|
-
"""Decorator to
|
|
129
|
-
|
|
127
|
+
"""Decorator to add a one-time handler for the enter event.
|
|
128
|
+
The specified function will be called from the main thread.
|
|
129
|
+
"""
|
|
130
|
+
return self.handler.binds('thread_begin', _F(f))
|
|
130
131
|
|
|
131
132
|
def exits(self, f):
|
|
132
|
-
"""Decorator to
|
|
133
|
-
|
|
133
|
+
"""Decorator to add a one-time handler for the exit event.
|
|
134
|
+
The specified function will be called from the main thread.
|
|
135
|
+
"""
|
|
136
|
+
return self.handler.binds('thread_end', _F(f))
|
|
134
137
|
|
|
135
138
|
def wraps(self, f, *args, **kwargs):
|
|
136
139
|
"""Decorator for a function that starts a new thread."""
|
|
@@ -190,11 +193,14 @@ class Thread:
|
|
|
190
193
|
pass
|
|
191
194
|
except KeyboardInterrupt as e:
|
|
192
195
|
print("- Thread terminated by user:", e)
|
|
193
|
-
## wx.CallAfter(self.handler, 'thread_quit', self)
|
|
194
196
|
except Exception as e:
|
|
197
|
+
tbstr = traceback.format_tb(e.__traceback__)
|
|
198
|
+
wx.CallAfter(wx.MessageBox,
|
|
199
|
+
f"{e}\n\n" + tbstr[-1] + f"{type(e).__name__}: {e}",
|
|
200
|
+
f"Error in the thread running {f.__name__!r}\n\n",
|
|
201
|
+
style=wx.ICON_ERROR)
|
|
195
202
|
traceback.print_exc()
|
|
196
203
|
print("- Thread failed in error:", e)
|
|
197
|
-
## wx.CallAfter(self.handler, 'thread_error', self)
|
|
198
204
|
finally:
|
|
199
205
|
self.active = 0
|
|
200
206
|
wx.CallAfter(self.handler, 'thread_end', self)
|
|
@@ -226,7 +232,7 @@ class Thread:
|
|
|
226
232
|
self.worker.join(1)
|
|
227
233
|
if self.running:
|
|
228
234
|
self.active = 0
|
|
229
|
-
wx.CallAfter(_stop)
|
|
235
|
+
wx.CallAfter(_stop) # main thread で終了させる
|
|
230
236
|
|
|
231
237
|
|
|
232
238
|
class LayerInterface(CtrlInterface):
|
|
@@ -371,12 +377,12 @@ class LayerInterface(CtrlInterface):
|
|
|
371
377
|
lambda v: reset_params(v, checked_only=wx.GetKeyState(wx.WXK_SHIFT)),
|
|
372
378
|
lambda v: v.Enable(bool(self.parameters))),
|
|
373
379
|
(),
|
|
374
|
-
(mwx.ID_(201), "&Reload
|
|
380
|
+
(mwx.ID_(201), "&Reload {!r}".format(self.__module__), "Reload", Icon('load'),
|
|
375
381
|
lambda v: self.parent.reload_plug(self.__module__),
|
|
376
382
|
lambda v: v.Enable(self.reloadable
|
|
377
383
|
and not (self.thread and self.thread.active))),
|
|
378
384
|
|
|
379
|
-
(mwx.ID_(202), "&Unload
|
|
385
|
+
(mwx.ID_(202), "&Unload {!r}".format(self.__module__), "Unload", Icon('delete'),
|
|
380
386
|
lambda v: self.parent.unload_plug(self.__module__),
|
|
381
387
|
lambda v: v.Enable(self.unloadable
|
|
382
388
|
and not (self.thread and self.thread.active))),
|
|
@@ -440,7 +446,7 @@ class LayerInterface(CtrlInterface):
|
|
|
440
446
|
|
|
441
447
|
Shown = property(
|
|
442
448
|
lambda self: self.IsShown(),
|
|
443
|
-
lambda self,v: self.Show(v))
|
|
449
|
+
lambda self, v: self.Show(v))
|
|
444
450
|
|
|
445
451
|
def IsShown(self):
|
|
446
452
|
"""Return True if the window is physically visible on the screen.
|
|
@@ -457,11 +463,11 @@ class LayerInterface(CtrlInterface):
|
|
|
457
463
|
(override) Show associated pane window.
|
|
458
464
|
Note: This might be called from a thread.
|
|
459
465
|
"""
|
|
460
|
-
wx.CallAfter(self.parent.show_pane, self, show)
|
|
466
|
+
wx.CallAfter(self.parent.show_pane, self, show) # Show pane windows in the main thread.
|
|
461
467
|
|
|
462
468
|
Drawn = property(
|
|
463
469
|
lambda self: self.IsDrawn(),
|
|
464
|
-
lambda self,v: self.Draw(v))
|
|
470
|
+
lambda self, v: self.Draw(v))
|
|
465
471
|
|
|
466
472
|
def IsDrawn(self):
|
|
467
473
|
return any(art.get_visible() for art in self.Arts)
|
|
@@ -495,6 +501,30 @@ class Layer(LayerInterface, KnobCtrlPanel):
|
|
|
495
501
|
LayerInterface.__init__(self, parent, session)
|
|
496
502
|
|
|
497
503
|
|
|
504
|
+
def register(cls, module=None):
|
|
505
|
+
"""Register dummy plug; Add module.Plugin <Layer>.
|
|
506
|
+
"""
|
|
507
|
+
if not module:
|
|
508
|
+
module = inspect.getmodule(cls) # rebase module or __main__
|
|
509
|
+
|
|
510
|
+
if issubclass(cls, LayerInterface):
|
|
511
|
+
cls.__module__ = module.__name__ # __main__ to module
|
|
512
|
+
warn(f"Duplicate iniheritance of LayerInterface by {cls}.")
|
|
513
|
+
module.Plugin = cls
|
|
514
|
+
return cls
|
|
515
|
+
|
|
516
|
+
class _Plugin(LayerInterface, cls):
|
|
517
|
+
def __init__(self, parent, session=None, **kwargs):
|
|
518
|
+
cls.__init__(self, parent, **kwargs)
|
|
519
|
+
LayerInterface.__init__(self, parent, session)
|
|
520
|
+
|
|
521
|
+
_Plugin.__module__ = cls.__module__ = module.__name__
|
|
522
|
+
_Plugin.__name__ = cls.__name__ + str("~")
|
|
523
|
+
_Plugin.__doc__ = cls.__doc__
|
|
524
|
+
module.Plugin = _Plugin
|
|
525
|
+
return _Plugin
|
|
526
|
+
|
|
527
|
+
|
|
498
528
|
class Graph(GraphPlot):
|
|
499
529
|
"""GraphPlot (override) to better make use for graph manager
|
|
500
530
|
|
|
@@ -575,7 +605,7 @@ class MyFileDropLoader(wx.FileDropTarget):
|
|
|
575
605
|
self.loader = loader
|
|
576
606
|
|
|
577
607
|
def OnDropFiles(self, x, y, filenames):
|
|
578
|
-
pos = self.view.ScreenPosition + (x,y)
|
|
608
|
+
pos = self.view.ScreenPosition + (x, y)
|
|
579
609
|
paths = []
|
|
580
610
|
for fn in filenames:
|
|
581
611
|
name, ext = os.path.splitext(fn)
|
|
@@ -652,7 +682,7 @@ class Frame(mwx.Frame):
|
|
|
652
682
|
self.histogram.Name = "histogram"
|
|
653
683
|
|
|
654
684
|
self._mgr.AddPane(self.graph,
|
|
655
|
-
aui.AuiPaneInfo().CenterPane()
|
|
685
|
+
aui.AuiPaneInfo().CenterPane()
|
|
656
686
|
.Name("graph").Caption("graph").CaptionVisible(1))
|
|
657
687
|
|
|
658
688
|
size = (200, 200)
|
|
@@ -777,7 +807,7 @@ class Frame(mwx.Frame):
|
|
|
777
807
|
self.menubar.reset()
|
|
778
808
|
|
|
779
809
|
def show_frameview(frame):
|
|
780
|
-
wx.CallAfter(self.show_pane, frame.parent)
|
|
810
|
+
wx.CallAfter(self.show_pane, frame.parent) # Show graph / output in the main thread.
|
|
781
811
|
|
|
782
812
|
self.graph.handler.append({ # DNA<Graph:Frame>
|
|
783
813
|
None : {
|
|
@@ -816,8 +846,8 @@ class Frame(mwx.Frame):
|
|
|
816
846
|
_display(self.graph, show)
|
|
817
847
|
_display(self.output, show)
|
|
818
848
|
evt.Skip()
|
|
819
|
-
self.Bind(wx.EVT_MOVE_START, lambda v
|
|
820
|
-
self.Bind(wx.EVT_MOVE_END, lambda v
|
|
849
|
+
self.Bind(wx.EVT_MOVE_START, lambda v: on_move(v, show=0))
|
|
850
|
+
self.Bind(wx.EVT_MOVE_END, lambda v: on_move(v, show=1))
|
|
821
851
|
|
|
822
852
|
## Custom Key Bindings
|
|
823
853
|
self.define_key('* C-g', self.Quit)
|
|
@@ -835,13 +865,13 @@ class Frame(mwx.Frame):
|
|
|
835
865
|
def sync(self, a, b):
|
|
836
866
|
"""Synchronize b to a."""
|
|
837
867
|
if (self.SYNC_SWITCH
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
868
|
+
and a.frame and b.frame
|
|
869
|
+
and a.frame.unit == b.frame.unit
|
|
870
|
+
and a.buffer.shape == b.buffer.shape):
|
|
871
|
+
b.xlim = a.xlim
|
|
872
|
+
b.ylim = a.ylim
|
|
873
|
+
b.OnDraw(None)
|
|
874
|
+
b.canvas.draw_idle()
|
|
845
875
|
|
|
846
876
|
def set_title(self, frame):
|
|
847
877
|
ssn = os.path.basename(self.session_file or '--')
|
|
@@ -919,7 +949,7 @@ class Frame(mwx.Frame):
|
|
|
919
949
|
## ドッキング時に再計算される
|
|
920
950
|
if name == "output" or name is self.output:
|
|
921
951
|
w, h = self.graph.GetClientSize()
|
|
922
|
-
pane.best_size = (w//2 - 3, h)
|
|
952
|
+
pane.best_size = (w//2 - 3, h) # 分割線幅補正 -12pix (Windows only ?)
|
|
923
953
|
|
|
924
954
|
## Force Layer windows to show.
|
|
925
955
|
if interactive:
|
|
@@ -935,12 +965,8 @@ class Frame(mwx.Frame):
|
|
|
935
965
|
pane.Float()
|
|
936
966
|
show = True
|
|
937
967
|
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
## - pane.window is floating (win.Parent is AuiFloatingFrame) or docked.
|
|
941
|
-
|
|
942
|
-
plug = self.get_plug(name) # -> None if pane.window is a Graph
|
|
943
|
-
win = pane.window # -> Window (plug / notebook / Graph)
|
|
968
|
+
plug = self.get_plug(name) # -> None if pane.window is a Graph
|
|
969
|
+
win = pane.window
|
|
944
970
|
try:
|
|
945
971
|
shown = plug.IsShown()
|
|
946
972
|
except AttributeError:
|
|
@@ -950,7 +976,7 @@ class Frame(mwx.Frame):
|
|
|
950
976
|
if isinstance(win, aui.AuiNotebook):
|
|
951
977
|
j = win.GetPageIndex(plug)
|
|
952
978
|
if j != win.Selection:
|
|
953
|
-
win.Selection = j
|
|
979
|
+
win.Selection = j # the focus moves => EVT_SHOW
|
|
954
980
|
else:
|
|
955
981
|
plug.handler('page_shown', plug)
|
|
956
982
|
else:
|
|
@@ -991,7 +1017,7 @@ class Frame(mwx.Frame):
|
|
|
991
1017
|
pane.dock_direction = dock
|
|
992
1018
|
if not plug.caption:
|
|
993
1019
|
pane.CaptionVisible(False) # no caption bar
|
|
994
|
-
pane.Gripper(dock not in (0,
|
|
1020
|
+
pane.Gripper(dock not in (0,5)) # show a grip when docked
|
|
995
1021
|
pane.Dockable(dock)
|
|
996
1022
|
|
|
997
1023
|
if pane.dock_direction:
|
|
@@ -1042,30 +1068,6 @@ class Frame(mwx.Frame):
|
|
|
1042
1068
|
elif isinstance(name, LayerInterface):
|
|
1043
1069
|
return name
|
|
1044
1070
|
|
|
1045
|
-
@staticmethod
|
|
1046
|
-
def register(cls, module=None):
|
|
1047
|
-
"""Register dummy plug; Add module.Plugin <Layer>.
|
|
1048
|
-
"""
|
|
1049
|
-
if not module:
|
|
1050
|
-
module = inspect.getmodule(cls) # rebase module or __main__
|
|
1051
|
-
|
|
1052
|
-
if issubclass(cls, LayerInterface):
|
|
1053
|
-
cls.__module__ = module.__name__ # __main__ to module
|
|
1054
|
-
warn(f"Duplicate iniheritance of LayerInterface by {cls}.")
|
|
1055
|
-
module.Plugin = cls
|
|
1056
|
-
return cls
|
|
1057
|
-
|
|
1058
|
-
class _Plugin(LayerInterface, cls):
|
|
1059
|
-
def __init__(self, parent, session=None, **kwargs):
|
|
1060
|
-
cls.__init__(self, parent, **kwargs)
|
|
1061
|
-
LayerInterface.__init__(self, parent, session)
|
|
1062
|
-
|
|
1063
|
-
_Plugin.__module__ = cls.__module__ = module.__name__
|
|
1064
|
-
_Plugin.__name__ = cls.__name__ + str("~")
|
|
1065
|
-
_Plugin.__doc__ = cls.__doc__
|
|
1066
|
-
module.Plugin = _Plugin
|
|
1067
|
-
return _Plugin
|
|
1068
|
-
|
|
1069
1071
|
def load_module(self, root):
|
|
1070
1072
|
"""Load module of plugin (internal use only).
|
|
1071
1073
|
|
|
@@ -1094,17 +1096,17 @@ class Frame(mwx.Frame):
|
|
|
1094
1096
|
print(f"- Unable to load {root!r}.", e)
|
|
1095
1097
|
return False
|
|
1096
1098
|
|
|
1097
|
-
## the module
|
|
1099
|
+
## Check if the module has a class `Plugin`.
|
|
1098
1100
|
if not hasattr(module, 'Plugin'):
|
|
1099
1101
|
if isinstance(root, type):
|
|
1100
1102
|
warn(f"Use dummy plug for debugging {name!r}.")
|
|
1101
1103
|
module.__dummy_plug__ = root
|
|
1102
|
-
|
|
1104
|
+
register(root, module)
|
|
1103
1105
|
else:
|
|
1104
1106
|
if hasattr(module, '__dummy_plug__'):
|
|
1105
1107
|
root = module.__dummy_plug__ # old class (imported)
|
|
1106
1108
|
cls = getattr(module, root.__name__) # new class (reloaded)
|
|
1107
|
-
|
|
1109
|
+
register(cls, module)
|
|
1108
1110
|
return module
|
|
1109
1111
|
|
|
1110
1112
|
def load_plug(self, root, force=False, session=None, show=False,
|
|
@@ -1151,48 +1153,47 @@ class Frame(mwx.Frame):
|
|
|
1151
1153
|
|
|
1152
1154
|
module = self.load_module(root)
|
|
1153
1155
|
if not module:
|
|
1154
|
-
return False
|
|
1156
|
+
return False
|
|
1155
1157
|
|
|
1158
|
+
## assert name == Plugin.__module__
|
|
1156
1159
|
try:
|
|
1157
|
-
|
|
1158
|
-
title =
|
|
1159
|
-
|
|
1160
|
-
pane = self._mgr.GetPane(title)
|
|
1160
|
+
Plugin = module.Plugin # Check if the module has a class `Plugin`.
|
|
1161
|
+
title = Plugin.category # Plugin <LayerInterface>
|
|
1161
1162
|
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
if not isinstance(
|
|
1165
|
-
raise NameError("Notebook name must not be the same as any other
|
|
1166
|
-
|
|
1167
|
-
pane = self.get_pane(name)
|
|
1163
|
+
pane = self._mgr.GetPane(title) # Check if <pane:title> is already registered.
|
|
1164
|
+
if pane.IsOk():
|
|
1165
|
+
if not isinstance(pane.window, aui.AuiNotebook):
|
|
1166
|
+
raise NameError("Notebook name must not be the same as any other plugin")
|
|
1168
1167
|
|
|
1169
|
-
|
|
1168
|
+
pane = self.get_pane(name) # Check if <pane:name> is already registered.
|
|
1169
|
+
if pane.IsOk():
|
|
1170
1170
|
if name not in self.plugins:
|
|
1171
|
-
raise NameError("Plugin name must not be the same as any other
|
|
1172
|
-
|
|
1173
|
-
show = show or pane.IsShown()
|
|
1174
|
-
props.update(
|
|
1175
|
-
dock_direction = pane.IsDocked() and pane.dock_direction,
|
|
1176
|
-
floating_pos = floating_pos or pane.floating_pos[:], # copy unloading pane
|
|
1177
|
-
floating_size = floating_size or pane.floating_size[:], # copy unloading pane
|
|
1178
|
-
)
|
|
1171
|
+
raise NameError("Plugin name must not be the same as any other pane")
|
|
1172
|
+
|
|
1179
1173
|
except (AttributeError, NameError) as e:
|
|
1180
1174
|
traceback.print_exc()
|
|
1181
|
-
wx.CallAfter(wx.MessageBox,
|
|
1175
|
+
wx.CallAfter(wx.MessageBox, # Show the message after load_session has finished.
|
|
1182
1176
|
f"{e}\n\n" + traceback.format_exc(),
|
|
1183
1177
|
f"Error in loading {module.__name__!r}",
|
|
1184
1178
|
style=wx.ICON_ERROR)
|
|
1185
1179
|
return False
|
|
1186
1180
|
|
|
1187
|
-
##
|
|
1181
|
+
## Unload the plugin if loaded.
|
|
1188
1182
|
if pane.IsOk():
|
|
1189
|
-
|
|
1183
|
+
show = show or pane.IsShown()
|
|
1184
|
+
props.update(
|
|
1185
|
+
dock_direction = pane.IsDocked() and pane.dock_direction,
|
|
1186
|
+
floating_pos = floating_pos or pane.floating_pos[:], # copy unloading pane
|
|
1187
|
+
floating_size = floating_size or pane.floating_size[:], # copy unloading pane
|
|
1188
|
+
)
|
|
1189
|
+
self.unload_plug(name)
|
|
1190
1190
|
|
|
1191
|
+
## Create the plugin object.
|
|
1191
1192
|
try:
|
|
1192
|
-
plug =
|
|
1193
|
+
plug = Plugin(self, session, **kwargs)
|
|
1193
1194
|
except Exception as e:
|
|
1194
1195
|
traceback.print_exc()
|
|
1195
|
-
wx.CallAfter(wx.MessageBox,
|
|
1196
|
+
wx.CallAfter(wx.MessageBox, # Show the message after load_session has finished.
|
|
1196
1197
|
f"{e}\n\n" + traceback.format_exc(),
|
|
1197
1198
|
f"Error in loading {name!r}",
|
|
1198
1199
|
style=wx.ICON_ERROR)
|
|
@@ -1201,10 +1202,10 @@ class Frame(mwx.Frame):
|
|
|
1201
1202
|
## Add to the list after the plug is created successfully.
|
|
1202
1203
|
self.plugins[name] = module
|
|
1203
1204
|
|
|
1204
|
-
##
|
|
1205
|
+
## Set reference of a plug (one module, one plugin).
|
|
1205
1206
|
module.__plug__ = plug
|
|
1206
1207
|
|
|
1207
|
-
## Create pane or notebook pane
|
|
1208
|
+
## Create pane or notebook pane.
|
|
1208
1209
|
caption = plug.caption
|
|
1209
1210
|
if not isinstance(caption, str):
|
|
1210
1211
|
caption = name
|
|
@@ -1216,7 +1217,7 @@ class Frame(mwx.Frame):
|
|
|
1216
1217
|
nb = pane.window
|
|
1217
1218
|
nb.AddPage(plug, caption)
|
|
1218
1219
|
else:
|
|
1219
|
-
size = plug.GetSize() + (2,30)
|
|
1220
|
+
size = plug.GetSize() + (2,30) # padding for notebook
|
|
1220
1221
|
nb = AuiNotebook(self, name=title)
|
|
1221
1222
|
nb.AddPage(plug, caption)
|
|
1222
1223
|
self._mgr.AddPane(nb, aui.AuiPaneInfo()
|
|
@@ -1238,11 +1239,11 @@ class Frame(mwx.Frame):
|
|
|
1238
1239
|
self.update_pane(name, **props)
|
|
1239
1240
|
self.show_pane(name, show)
|
|
1240
1241
|
|
|
1241
|
-
## Create a menu
|
|
1242
|
+
## Create a menu.
|
|
1242
1243
|
plug.__Menu_item = None
|
|
1243
1244
|
|
|
1244
|
-
if not hasattr(module, 'ID_'):
|
|
1245
|
-
global __plug_ID__
|
|
1245
|
+
if not hasattr(module, 'ID_'): # give a unique index to the module
|
|
1246
|
+
global __plug_ID__ # cache ID *not* in [ID_LOWEST(4999):ID_HIGHEST(5999)]
|
|
1246
1247
|
try:
|
|
1247
1248
|
__plug_ID__
|
|
1248
1249
|
except NameError:
|
|
@@ -1314,11 +1315,6 @@ class Frame(mwx.Frame):
|
|
|
1314
1315
|
traceback.print_exc()
|
|
1315
1316
|
print("- Failed to save session of", plug)
|
|
1316
1317
|
self.load_plug(plug.__module__, force=1, session=session)
|
|
1317
|
-
|
|
1318
|
-
## Update shell.target --> new plug
|
|
1319
|
-
for shell in self.shellframe.get_all_shells():
|
|
1320
|
-
if shell.target is plug:
|
|
1321
|
-
shell.handler('shell_activated', shell)
|
|
1322
1318
|
|
|
1323
1319
|
def inspect_plug(self, name):
|
|
1324
1320
|
"""Dive into the process to inspect plugs in the shell.
|
|
@@ -1331,10 +1327,11 @@ class Frame(mwx.Frame):
|
|
|
1331
1327
|
|
|
1332
1328
|
@shell.handler.bind("shell_activated")
|
|
1333
1329
|
def init(shell):
|
|
1330
|
+
"""Called when the plug shell is activated."""
|
|
1334
1331
|
nonlocal plug
|
|
1335
1332
|
_plug = self.get_plug(name)
|
|
1336
1333
|
if _plug is not plug:
|
|
1337
|
-
shell.target = _plug or self
|
|
1334
|
+
shell.target = _plug or self # Reset the target to the reloaded plug.
|
|
1338
1335
|
plug = _plug
|
|
1339
1336
|
init(shell)
|
|
1340
1337
|
self.shellframe.Show()
|
|
@@ -1451,7 +1448,7 @@ class Frame(mwx.Frame):
|
|
|
1451
1448
|
return frames
|
|
1452
1449
|
|
|
1453
1450
|
## --------------------------------
|
|
1454
|
-
## load/save frames and attributes
|
|
1451
|
+
## load/save frames and attributes
|
|
1455
1452
|
## --------------------------------
|
|
1456
1453
|
|
|
1457
1454
|
@classmethod
|
|
@@ -1716,7 +1713,7 @@ class Frame(mwx.Frame):
|
|
|
1716
1713
|
filename = dlg.Path
|
|
1717
1714
|
|
|
1718
1715
|
if flush:
|
|
1719
|
-
for name in list(self.plugins):
|
|
1716
|
+
for name in list(self.plugins): # plugins:dict mutates during iteration
|
|
1720
1717
|
self.unload_plug(name)
|
|
1721
1718
|
del self.graph[:]
|
|
1722
1719
|
del self.output[:]
|
|
@@ -1736,14 +1733,18 @@ class Frame(mwx.Frame):
|
|
|
1736
1733
|
self._mgr.Update()
|
|
1737
1734
|
self.menubar.reset()
|
|
1738
1735
|
|
|
1739
|
-
dirname_ = os.path.dirname(i.name)
|
|
1740
|
-
if dirname_:
|
|
1741
|
-
os.chdir(dirname_)
|
|
1742
|
-
|
|
1743
1736
|
## Reposition the window if it is not on the desktop.
|
|
1744
1737
|
if wx.Display.GetFromWindow(self) == -1:
|
|
1745
1738
|
self.Position = (0, 0)
|
|
1746
1739
|
|
|
1740
|
+
## LoadPerspective => 表示状態の不整合.手動でイベントを発生させる.
|
|
1741
|
+
for pane in self._mgr.GetAllPanes():
|
|
1742
|
+
if pane.IsShown():
|
|
1743
|
+
win = pane.window
|
|
1744
|
+
if isinstance(win, aui.AuiNotebook):
|
|
1745
|
+
win = win.CurrentPage
|
|
1746
|
+
win.handler('page_shown', win)
|
|
1747
|
+
|
|
1747
1748
|
self.message("\b done.")
|
|
1748
1749
|
|
|
1749
1750
|
def save_session_as(self):
|
|
@@ -1766,24 +1767,25 @@ class Frame(mwx.Frame):
|
|
|
1766
1767
|
self.message("Saving session to {!r}...".format(self.session_file))
|
|
1767
1768
|
|
|
1768
1769
|
with open(self.session_file, 'w') as o,\
|
|
1769
|
-
np.printoptions(threshold=np.inf):
|
|
1770
|
+
np.printoptions(threshold=np.inf): # printing all(inf) elements
|
|
1770
1771
|
o.write("#! Session file (This file is generated automatically)\n")
|
|
1771
1772
|
o.write("self.SetSize({})\n".format(self.Size))
|
|
1772
1773
|
o.write("self.SetPosition({})\n".format(self.Position))
|
|
1773
1774
|
|
|
1774
1775
|
for name, module in self.plugins.items():
|
|
1775
1776
|
plug = self.get_plug(name)
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1777
|
+
if '.' not in name:
|
|
1778
|
+
name = os.path.abspath(module.__file__) # Replace name with full path.
|
|
1779
|
+
basename = os.path.basename(name)
|
|
1780
|
+
if basename == "__init__.py": # is module package?
|
|
1781
|
+
name = name[:-12]
|
|
1780
1782
|
session = {}
|
|
1781
1783
|
try:
|
|
1782
1784
|
plug.save_session(session)
|
|
1783
1785
|
except Exception:
|
|
1784
1786
|
traceback.print_exc()
|
|
1785
1787
|
print("- Failed to save session of", plug)
|
|
1786
|
-
o.write("self.load_plug({!r}, session={})\n".format(
|
|
1788
|
+
o.write("self.load_plug({!r}, session={})\n".format(name, session or None))
|
|
1787
1789
|
o.write("self._mgr.LoadPerspective({!r})\n".format(self._mgr.SavePerspective()))
|
|
1788
1790
|
|
|
1789
1791
|
def _save(view):
|
|
@@ -1791,8 +1793,8 @@ class Frame(mwx.Frame):
|
|
|
1791
1793
|
o.write(f"self.{view.Name}.unit = {view.unit:g}\n")
|
|
1792
1794
|
o.write(f"self.load_frame({paths!r}, self.{view.Name})\n")
|
|
1793
1795
|
try:
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
+
if view.frame.pathname in paths:
|
|
1797
|
+
o.write(f"self.{view.Name}.select({view.frame.name!r})\n")
|
|
1796
1798
|
except Exception:
|
|
1797
1799
|
pass
|
|
1798
1800
|
|
mwx/matplot2.py
CHANGED
|
@@ -11,7 +11,7 @@ from matplotlib.figure import Figure
|
|
|
11
11
|
import numpy as np
|
|
12
12
|
|
|
13
13
|
from . import framework as mwx
|
|
14
|
-
from .framework import hotkey, regulate_key, pack, Menu, FSM
|
|
14
|
+
from .framework import hotkey, regulate_key, postcall, pack, Menu, FSM
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
## state constants
|
|
@@ -178,8 +178,6 @@ class MatplotPanel(wx.Panel):
|
|
|
178
178
|
'axes_enter' : [ None, ],
|
|
179
179
|
'axes_leave' : [ None, ],
|
|
180
180
|
'home pressed' : [ None, self.OnHomePosition ],
|
|
181
|
-
'left pressed' : [ None, self.OnBackPosition ],
|
|
182
|
-
'right pressed' : [ None, self.OnForwardPosition ],
|
|
183
181
|
'Xbutton1 pressed' : [ None, self.OnBackPosition ],
|
|
184
182
|
'Xbutton2 pressed' : [ None, self.OnForwardPosition ],
|
|
185
183
|
},
|
|
@@ -314,6 +312,8 @@ class MatplotPanel(wx.Panel):
|
|
|
314
312
|
self.cursor = Cursor(self.axes, useblit=True, color='grey', linewidth=1)
|
|
315
313
|
self.cursor.visible = 1
|
|
316
314
|
|
|
315
|
+
## Note: To avoid a wxAssertionError when running in a thread.
|
|
316
|
+
@postcall
|
|
317
317
|
def draw(self, art=None):
|
|
318
318
|
"""Draw plots.
|
|
319
319
|
Call each time the drawing should be updated.
|
|
@@ -345,22 +345,22 @@ class MatplotPanel(wx.Panel):
|
|
|
345
345
|
|
|
346
346
|
xbound = property(
|
|
347
347
|
lambda self: np.array(self.axes.get_xbound()),
|
|
348
|
-
lambda self,v: self.axes.set_xbound(v),
|
|
348
|
+
lambda self, v: self.axes.set_xbound(v),
|
|
349
349
|
doc="X-axis numerical bounds where lowerBound < upperBound)")
|
|
350
350
|
|
|
351
351
|
ybound = property(
|
|
352
352
|
lambda self: np.array(self.axes.get_ybound()),
|
|
353
|
-
lambda self,v: self.axes.set_ybound(v),
|
|
353
|
+
lambda self, v: self.axes.set_ybound(v),
|
|
354
354
|
doc="Y-axis numerical bounds where lowerBound < upperBound)")
|
|
355
355
|
|
|
356
356
|
xlim = property(
|
|
357
357
|
lambda self: np.array(self.axes.get_xlim()),
|
|
358
|
-
lambda self,v: self.axes.set_xlim(v),
|
|
358
|
+
lambda self, v: self.axes.set_xlim(v),
|
|
359
359
|
doc="X-axis range [left, right]")
|
|
360
360
|
|
|
361
361
|
ylim = property(
|
|
362
362
|
lambda self: np.array(self.axes.get_ylim()),
|
|
363
|
-
lambda self,v: self.axes.set_ylim(v),
|
|
363
|
+
lambda self, v: self.axes.set_ylim(v),
|
|
364
364
|
doc="Y-axis range [bottom, top]")
|
|
365
365
|
|
|
366
366
|
@property
|
|
@@ -418,7 +418,7 @@ class MatplotPanel(wx.Panel):
|
|
|
418
418
|
wx.UIActionSimulator().KeyUp(wx.WXK_ESCAPE)
|
|
419
419
|
|
|
420
420
|
## --------------------------------
|
|
421
|
-
## External I/O file and clipboard
|
|
421
|
+
## External I/O file and clipboard
|
|
422
422
|
## --------------------------------
|
|
423
423
|
|
|
424
424
|
def copy_to_clipboard(self):
|
|
@@ -561,7 +561,7 @@ class MatplotPanel(wx.Panel):
|
|
|
561
561
|
## Overwrite evt.key with modifiers.
|
|
562
562
|
key = self.__key
|
|
563
563
|
if evt.button in (1,2,3):
|
|
564
|
-
key += 'LMR'[evt.button-1] #{1:L, 2:M, 3:R}
|
|
564
|
+
key += 'LMR'[evt.button-1] # {1:L, 2:M, 3:R}
|
|
565
565
|
evt.key = key + 'button'
|
|
566
566
|
elif evt.button in ('up', 'down'):
|
|
567
567
|
key += 'wheel{}'.format(evt.button) # wheel[up|down]
|
|
@@ -621,10 +621,11 @@ class MatplotPanel(wx.Panel):
|
|
|
621
621
|
self.p_event = None
|
|
622
622
|
|
|
623
623
|
## --------------------------------
|
|
624
|
-
## Pan/Zoom actions
|
|
624
|
+
## Pan/Zoom actions
|
|
625
625
|
## --------------------------------
|
|
626
626
|
|
|
627
|
-
ZOOM_RATIO = 10**0.2
|
|
627
|
+
ZOOM_RATIO = 10 ** 0.2
|
|
628
|
+
ZOOM_LIMIT = 0.1 # logical limit <= epsilon
|
|
628
629
|
|
|
629
630
|
def OnDraw(self, evt):
|
|
630
631
|
"""Called before canvas.draw."""
|
|
@@ -663,7 +664,7 @@ class MatplotPanel(wx.Panel):
|
|
|
663
664
|
if c is None:
|
|
664
665
|
c = (lim[1] + lim[0]) / 2
|
|
665
666
|
y = c - M * (c - lim)
|
|
666
|
-
if abs(y[1] - y[0]) >
|
|
667
|
+
if abs(y[1] - y[0]) > self.ZOOM_LIMIT:
|
|
667
668
|
return y
|
|
668
669
|
|
|
669
670
|
def OnZoom(self, evt):
|