mwxlib 0.94.2__py3-none-any.whl → 0.94.4__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 CHANGED
@@ -2,29 +2,17 @@
2
2
  import re
3
3
  import wx
4
4
 
5
- from .utilus import TreeList
6
- from .nutshell import EditorBook
7
- from .framework import CtrlInterface
5
+ from .framework import CtrlInterface, postcall
8
6
 
9
7
 
10
- class ItemData:
11
- """Item data for TreeListCtrl
12
- """
13
- def __init__(self, tree, buffer):
14
- self.tree = tree
15
- self.buffer = buffer
16
- self._itemId = None #: reference <TreeItemId>
17
-
18
-
19
- class EditorTreeCtrl(wx.TreeCtrl, CtrlInterface, TreeList):
20
- """TreeList control
8
+ class EditorTreeCtrl(wx.TreeCtrl, CtrlInterface):
9
+ """TreeList/Ctrl
21
10
 
22
11
  Construct treectrl in the order of tree:list.
23
12
  """
24
13
  def __init__(self, parent, *args, **kwargs):
25
14
  wx.TreeCtrl.__init__(self, parent, *args, **kwargs)
26
15
  CtrlInterface.__init__(self)
27
- TreeList.__init__(self)
28
16
 
29
17
  self.Font = wx.Font(9, wx.DEFAULT, wx.NORMAL, wx.NORMAL)
30
18
 
@@ -52,18 +40,20 @@ class EditorTreeCtrl(wx.TreeCtrl, CtrlInterface, TreeList):
52
40
  def enter(v):
53
41
  data = self.GetItemData(self.Selection)
54
42
  if data:
55
- data.buffer.SetFocus()
43
+ data.SetFocus()
56
44
 
57
45
  @self.handler.bind('f5 pressed')
58
46
  def refresh(v):
59
- self.reset(clear=0)
47
+ self.update(clear=0)
48
+ if self.target:
49
+ self.target.current_editor.SetFocus()
50
+ wx.CallAfter(self.SetFocus)
60
51
 
61
52
  @self.handler.bind('delete pressed')
62
53
  def delete(v):
63
54
  data = self.GetItemData(self.Selection)
64
55
  if data:
65
- buf = data.buffer
66
- buf.parent.kill_buffer(buf) # -> focus moves
56
+ data.parent.kill_buffer(data) # -> focus moves
67
57
  wx.CallAfter(self.SetFocus)
68
58
 
69
59
  @self.handler.bind('*button* pressed')
@@ -75,28 +65,41 @@ class EditorTreeCtrl(wx.TreeCtrl, CtrlInterface, TreeList):
75
65
 
76
66
  def OnDestroy(self, evt):
77
67
  if evt.EventObject is self:
78
- self.unwatch()
68
+ self.detach()
79
69
  evt.Skip()
80
70
 
71
+ def attach(self, target):
72
+ self.detach()
73
+ self.target = target
74
+ for editor in self.target.all_editors:
75
+ editor.handler.append(self.context)
76
+ self.update()
77
+
78
+ def detach(self):
79
+ if not self.target:
80
+ return
81
+ for editor in self.target.all_editors:
82
+ editor.handler.remove(self.context)
83
+ self.target = None
84
+ self.update()
85
+
81
86
  ## --------------------------------
82
87
  ## TreeList/Ctrl wrapper interface
83
88
  ## --------------------------------
84
89
 
85
- def reset(self, clear=True):
90
+ def update(self, clear=True):
86
91
  """Build tree control.
87
- All items will be reset after clear if specified.
92
+ All items will be cleared if specified.
88
93
  """
89
94
  try:
90
95
  self.Freeze()
91
- wnd = wx.Window.FindFocus() # original focus
92
96
  if clear:
93
97
  self.DeleteAllItems()
94
98
  self.AddRoot(self.Name)
95
- for branch in self:
96
- self._set_item(self.RootItem, *branch)
99
+ if self.target:
100
+ for editor in self.target.all_editors:
101
+ self._set_item(self.RootItem, editor.Name, editor.all_buffers)
97
102
  finally:
98
- if wnd:
99
- wnd.SetFocus() # restore focus
100
103
  self.Thaw()
101
104
 
102
105
  def _get_item(self, root, key):
@@ -110,83 +113,46 @@ class EditorTreeCtrl(wx.TreeCtrl, CtrlInterface, TreeList):
110
113
  return item
111
114
  item, cookie = self.GetNextChild(root, cookie)
112
115
 
113
- def _set_item(self, root, key, *values):
114
- """Set the item [root/key] with values recursively.
116
+ def _set_item(self, root, key, data):
117
+ """Set the item [root/key] with data recursively.
115
118
  """
116
119
  item = self._get_item(root, key) or self.AppendItem(root, key)
117
- branches = next((x for x in values if isinstance(x, (tuple, list))), [])
118
- rest = [x for x in values if x not in branches]
119
- if rest:
120
- ## Take the first element assuming it's client data.
121
- ## Set the item client data. (override as needed)
122
- try:
123
- data = rest[0]
124
- data._itemId = item
125
- self.SetItemData(item, data)
126
- buf = data.buffer
127
- self.SetItemText(item, buf.caption_prefix + buf.name)
128
- except AttributeError:
129
- pass
130
- for branch in branches:
131
- self._set_item(item, *branch)
120
+ if isinstance(data, list):
121
+ for buf in data:
122
+ self._set_item(item, buf.name, buf)
123
+ else:
124
+ data.__itemId = item
125
+ self.SetItemData(item, data)
126
+ self.SetItemText(item, data.caption_prefix + data.name)
132
127
 
133
128
  ## --------------------------------
134
129
  ## Actions for bookshelf interfaces
135
130
  ## --------------------------------
136
131
 
137
- def reset_tree(self, editor):
138
- """Reset a branch for EditorBook/Buffer."""
139
- self[editor.Name] = [
140
- [buf.name, ItemData(self, buf)] for buf in editor.all_buffers
141
- ]
142
-
143
- def watch(self, target):
144
- self.unwatch()
145
- self.target = target
146
- if self.target:
147
- for editor in self.target.get_pages(EditorBook):
148
- editor.handler.append(self.context)
149
- self.reset_tree(editor)
150
- self.reset()
151
-
152
- def unwatch(self):
153
- if self.target:
154
- for editor in self.target.get_pages(EditorBook):
155
- editor.handler.remove(self.context)
156
- self[:] = [] # clear tree
157
- self.reset()
158
- self.target = None
159
-
132
+ @postcall
160
133
  def on_buffer_new(self, buf):
161
- self[f"{buf.parent.Name}/{buf.name}"] = ItemData(self, buf)
162
- self.reset(clear=0)
134
+ self.update(clear=0)
163
135
 
136
+ @postcall
164
137
  def on_buffer_deleted(self, buf):
165
- del self[f"{buf.parent.Name}/{buf.name}"]
166
- self.reset()
138
+ self.Delete(buf.__itemId)
167
139
 
140
+ @postcall
168
141
  def on_buffer_selected(self, buf):
169
- data = self[f"{buf.parent.Name}/{buf.name}"]
170
- self.SelectItem(data._itemId)
142
+ self.SelectItem(buf.__itemId)
171
143
 
144
+ @postcall
172
145
  def on_buffer_caption(self, buf):
173
- data = self[f"{buf.parent.Name}/{buf.name}"]
174
- self.SetItemText(data._itemId, buf.caption_prefix + buf.name)
146
+ self.SetItemText(buf.__itemId, buf.caption_prefix + buf.name)
175
147
 
148
+ @postcall
176
149
  def on_buffer_filename(self, buf):
177
- self.reset_tree(buf.parent)
178
- self.reset()
150
+ self.SetItemText(buf.__itemId, buf.caption_prefix + buf.name)
179
151
 
180
152
  def OnSelChanged(self, evt):
181
153
  if self and self.HasFocus():
182
154
  data = self.GetItemData(evt.Item)
183
- if data and data.buffer:
184
- data.buffer.SetFocus()
155
+ if data:
156
+ data.SetFocus()
185
157
  self.SetFocus()
186
158
  evt.Skip()
187
-
188
- ## def OnItemTooltip(self, evt):
189
- ## data = self.GetItemData(evt.Item)
190
- ## if data and data.buffer:
191
- ## evt.SetToolTip(data.buffer.filename)
192
- ## evt.Skip()
mwx/framework.py CHANGED
@@ -1,7 +1,7 @@
1
1
  #! python3
2
2
  """mwxlib framework.
3
3
  """
4
- __version__ = "0.94.2"
4
+ __version__ = "0.94.4"
5
5
  __author__ = "Kazuya O'moto <komoto@jeol.co.jp>"
6
6
 
7
7
  from functools import wraps, partial
@@ -1016,7 +1016,7 @@ class FileDropLoader(wx.DropTarget):
1016
1016
  def __init__(self, target):
1017
1017
  wx.DropTarget.__init__(self)
1018
1018
 
1019
- self.book = target
1019
+ self.editor = target
1020
1020
  self.textdo = wx.TextDataObject()
1021
1021
  self.filedo = wx.FileDataObject()
1022
1022
  self.DataObject = wx.DataObjectComposite()
@@ -1024,7 +1024,7 @@ class FileDropLoader(wx.DropTarget):
1024
1024
  self.DataObject.Add(self.filedo, True)
1025
1025
 
1026
1026
  def OnData(self, x, y, result):
1027
- editor = self.book
1027
+ editor = self.editor
1028
1028
  self.GetData()
1029
1029
  if self.textdo.TextLength > 1:
1030
1030
  f = self.textdo.Text.strip()
@@ -1156,12 +1156,9 @@ class ShellFrame(MiniFrame):
1156
1156
 
1157
1157
  self.Bookshelf = EditorTreeCtrl(self, name="Bookshelf",
1158
1158
  style=wx.TR_DEFAULT_STYLE|wx.TR_HIDE_ROOT)
1159
- self.Bookshelf.watch(self.ghost)
1159
+ self.Bookshelf.attach(self)
1160
1160
 
1161
1161
  self.ghost.AddPage(self.Bookshelf, "Bookshelf", bitmap=Icon('book'))
1162
- ## self._mgr.AddPane(self.Bookshelf,
1163
- ## aui.AuiPaneInfo().Name("bookshelf")
1164
- ## .Caption("Bookshelf").Right().Show(1))
1165
1162
 
1166
1163
  self.ghost.SetDropTarget(FileDropLoader(self.Scratch))
1167
1164
 
@@ -1250,7 +1247,7 @@ class ShellFrame(MiniFrame):
1250
1247
  'add_log' : [ None, self.add_log ],
1251
1248
  'add_help' : [ None, self.add_help ],
1252
1249
  'title_window' : [ None, self.on_title_window ],
1253
- 'buffer_caption_reset' : [ None, self.on_buffer_caption ],
1250
+ 'buffer_caption_reset' : [ None, self.on_buffer_caption ], # => self.OnActivate
1254
1251
  },
1255
1252
  0 : {
1256
1253
  '* pressed' : (0, fork_debugger),
@@ -1638,7 +1635,7 @@ class ShellFrame(MiniFrame):
1638
1635
  filename, ln = m.groups()
1639
1636
  lineno = int(ln)
1640
1637
  editor = self.find_editor(filename) or self.Log
1641
- ret = self._load(filename, lineno, editor, verbose=1)
1638
+ ret = editor.load_file(filename, lineno, verbose=1)
1642
1639
  if ret:
1643
1640
  self.popup_window(editor, show, focus)
1644
1641
  return ret
@@ -1912,13 +1909,21 @@ class ShellFrame(MiniFrame):
1912
1909
  """Yields all editors in the notebooks."""
1913
1910
  yield from self.ghost.get_pages(type(self.Log))
1914
1911
 
1912
+ @property
1913
+ def current_editor(self):
1914
+ """Currently selected editor or scratch."""
1915
+ editor = self.ghost.CurrentPage
1916
+ if isinstance(editor, type(self.Log)):
1917
+ return editor
1918
+ return next((x for x in self.all_editors if x.IsShown()), self.Scratch)
1919
+
1915
1920
  def find_editor(self, fn):
1916
1921
  """Find an editor which has the specified fn:filename or code."""
1917
- for editor in self.all_editors:
1918
- buf = editor.find_buffer(fn)
1922
+ for book in self.all_editors:
1923
+ buf = book.find_buffer(fn)
1919
1924
  if buf:
1920
- editor.swap_page(buf)
1921
- return editor
1925
+ book.swap_page(buf)
1926
+ return book
1922
1927
 
1923
1928
  ## --------------------------------
1924
1929
  ## Find text dialog
mwx/matplot2g.py CHANGED
@@ -946,8 +946,6 @@ class GraphPlot(MatplotPanel):
946
946
  xr, yr = max(nx), max(ny) # bottom-right
947
947
  self.message("[Region] "
948
948
  "crop={}:{}:{}:{}".format(xr-xo, yr-yo, xo, yo)) # (W:H:left:top)
949
- else:
950
- return self.trace_point(x[[0,-1]], y[[0,-1]], type)
951
949
 
952
950
  def writeln(self):
953
951
  """Puts (override) attributes of current frame to the modeline."""
mwx/nutshell.py CHANGED
@@ -290,7 +290,7 @@ class EditorInterface(CtrlInterface):
290
290
  self.__mark = -1
291
291
  self.__stylus = {}
292
292
 
293
- ## Custom constants embedded in stc
293
+ ## Custom constants embedded in wx.stc
294
294
  stc.STC_P_WORD3 = 20
295
295
  stc.STC_STYLE_CARETLINE = 40
296
296
  stc.STC_STYLE_ANNOTATION = 41
@@ -986,7 +986,7 @@ class EditorInterface(CtrlInterface):
986
986
  self.EnsureVisible(self.cline)
987
987
  yield err
988
988
 
989
- def grep_barckward(self, pattern, flags=re.M):
989
+ def grep_backward(self, pattern, flags=re.M):
990
990
  text = self.GetTextRange(0, self.cpos)
991
991
  errs = re.finditer(pattern, text, flags)
992
992
  for err in reversed(list(errs)):
@@ -1965,7 +1965,7 @@ class EditorBook(AuiNotebook, CtrlInterface):
1965
1965
  """
1966
1966
  buf = self.find_buffer(filename)
1967
1967
  if not buf:
1968
- buf = self.create_buffer(filename)
1968
+ buf = self.create_buffer("*temp file*")
1969
1969
  elif buf.need_buffer_save and verbose:
1970
1970
  if wx.MessageBox( # Confirm load.
1971
1971
  "You are leaving unsaved content.\n\n"
@@ -3141,10 +3141,6 @@ class Nautilus(Shell, EditorInterface):
3141
3141
 
3142
3142
  def help(self, obj):
3143
3143
  """Full description."""
3144
- ## if obj is None:
3145
- ## self.message("Currently redirected to stdin/stdout.")
3146
- ## wx.CallAfter(pydoc.help)
3147
- ## return
3148
3144
  doc = pydoc.plain(pydoc.render_doc(obj))\
3149
3145
  or "No description about {}".format(obj)
3150
3146
  self.parent.handler('add_help', doc) or print(doc)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mwxlib
3
- Version: 0.94.2
3
+ Version: 0.94.4
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,14 +1,14 @@
1
1
  mwx/__init__.py,sha256=zLsXDgqyC5NsPCjRxjS2huvZ3uDyeOJ1vapotqe2ULM,834
2
- mwx/bookshelf.py,sha256=FrissUYdGXLABOzJmMaQU6GXvu6n_9DVW3d5wGwQzjM,6613
2
+ mwx/bookshelf.py,sha256=OWeEXMqdSF1IqAKV15TnZ_R5578AV5VDyaB7CWd2sjs,5258
3
3
  mwx/controls.py,sha256=1eguX5eofsA6hmS2y7R4hvlFjFikVoZ8v2S1ES7rjEU,47196
4
- mwx/framework.py,sha256=1QVxdGh9q2auq4hQV-DaJsAZellHuUd9jpYfPBUj0fA,75394
4
+ mwx/framework.py,sha256=3Yn4lK7_qnafFitJGTtdRHetZmdxFms-PVDpOdX4kWY,75522
5
5
  mwx/graphman.py,sha256=UsNBo5Z1eiuXj3VkxCZds_Uy8R0cQV7mXoCwLtejbCE,70001
6
6
  mwx/images.py,sha256=mrnUYH12I3XLVSZcEXlpVltX0XMxufbl2yRvDIQJZqc,49957
7
7
  mwx/matplot2.py,sha256=qaF_gvLoLn-TimLbRR59KUavNr1ZpZQdSMqjzJk47rk,32682
8
- mwx/matplot2g.py,sha256=Ca-3RJZmSiZcvNrXmeK_lFf2fdG-0gkp7dYkCtrKi2I,65530
8
+ mwx/matplot2g.py,sha256=mDaD367wjq6xsyIDX9ot8jLwYYGayoavWMhqsQVBHac,65442
9
9
  mwx/matplot2lg.py,sha256=tg8u7w4DxiJdPN-E197NOmbQpc_1gZkgDHYv_xUhbFA,27224
10
10
  mwx/mgplt.py,sha256=ITzxA97yDwr_35BUk5OqnyskSuKVDbpf2AQCKY1jHTI,5671
11
- mwx/nutshell.py,sha256=iJEFzcu5qfp-HxXORB8ci-Q1z7a8zTPwbfFxik5h6pY,135802
11
+ mwx/nutshell.py,sha256=tlpYJEpe9sRSnILZBHqu85kQ0VGzTGeLT4PpRDcJPno,135647
12
12
  mwx/utilus.py,sha256=5GVSNKyvNWxsDftIrTJUhBlnQAh3zvrW5BuQSGasJv8,37395
13
13
  mwx/wxmon.py,sha256=Qk86VbuuW2rR46pqEYLur13G_aloWz5SVv6sib30YY0,12717
14
14
  mwx/wxpdb.py,sha256=2z3ZD9Oo1H-ONBHlaprkB9hrTmAI7o03sqO46ppEFE4,19129
@@ -21,8 +21,8 @@ mwx/plugins/frame_listview.py,sha256=T-2xSv_D2bk9fJ64aiSEe1rJRTeqaIpLVAYEUXW5vz8
21
21
  mwx/plugins/line_profile.py,sha256=WJB5z7F53yg4dII2R36IFZvtkSOGWT669b1HmAAXSnQ,816
22
22
  mwx/py/__init__.py,sha256=xykgfOytOwNuvXsfkLoumFZSTN-iBsHOjczYXngjmUE,12
23
23
  mwx/py/filling.py,sha256=KaHooM32hrGGgqw75Cbt8lAvACwC6RXadob9LGgNnEc,16806
24
- mwxlib-0.94.2.dist-info/LICENSE,sha256=PGtRKCaTkmUDlBQwpptJAxJtdqxIUtAmdBsaT9nUVkA,1091
25
- mwxlib-0.94.2.dist-info/METADATA,sha256=nG8tQUyP23iDpjnaedgv9mFikcFoIBpFhFhfgI0wlWY,1925
26
- mwxlib-0.94.2.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
27
- mwxlib-0.94.2.dist-info/top_level.txt,sha256=SI1Mh118AstnUFGPNq5aMNKiAnVNmZk1S9Ij-OwAEpY,4
28
- mwxlib-0.94.2.dist-info/RECORD,,
24
+ mwxlib-0.94.4.dist-info/LICENSE,sha256=PGtRKCaTkmUDlBQwpptJAxJtdqxIUtAmdBsaT9nUVkA,1091
25
+ mwxlib-0.94.4.dist-info/METADATA,sha256=kgPD9dBMgo_dMK-YF1Fye0nl2LqFpduWFVt9EgdXn7c,1925
26
+ mwxlib-0.94.4.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
27
+ mwxlib-0.94.4.dist-info/top_level.txt,sha256=SI1Mh118AstnUFGPNq5aMNKiAnVNmZk1S9Ij-OwAEpY,4
28
+ mwxlib-0.94.4.dist-info/RECORD,,