mwxlib 0.94.7__py3-none-any.whl → 0.95.0__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/__init__.py CHANGED
@@ -4,7 +4,7 @@
4
4
  from .framework import __version__, __author__
5
5
  from .framework import FSM
6
6
  from .framework import Menu, MenuBar, StatusBar
7
- from .framework import deb, App, Frame, MiniFrame, ShellFrame
7
+ from .framework import Frame, MiniFrame, ShellFrame, deb
8
8
 
9
9
  ## Controls
10
10
  ## from . import controls
mwx/bookshelf.py CHANGED
@@ -27,8 +27,7 @@ class EditorTreeCtrl(wx.TreeCtrl, CtrlInterface):
27
27
  'buffer_deleted' : [ None, self.on_buffer_deleted ],
28
28
  'buffer_activated' : [ None, self.on_buffer_selected ],
29
29
  'buffer_inactivated' : [ None, ],
30
- 'buffer_caption_reset' : [ None, self.on_buffer_filename ],
31
- 'buffer_filename_reset' : [ None, self.on_buffer_filename ],
30
+ 'buffer_caption_updated' : [ None, self.on_buffer_filename ],
32
31
  },
33
32
  }
34
33
 
@@ -43,12 +42,14 @@ class EditorTreeCtrl(wx.TreeCtrl, CtrlInterface):
43
42
  data.SetFocus()
44
43
 
45
44
  @self.handler.bind('f5 pressed')
46
- def refresh(v):
47
- self.build_tree(clear=0)
45
+ def refresh(v, clear=False):
46
+ self.build_tree(clear)
48
47
  if self.target:
49
48
  self.target.current_editor.SetFocus()
50
49
  wx.CallAfter(self.SetFocus)
51
50
 
51
+ self.handler.bind('S-f5 pressed', partial(refresh, clear=1))
52
+
52
53
  @self.handler.bind('delete pressed')
53
54
  def delete(v):
54
55
  data = self.GetItemData(self.Selection)
mwx/framework.py CHANGED
@@ -1,7 +1,7 @@
1
1
  #! python3
2
2
  """mwxlib framework.
3
3
  """
4
- __version__ = "0.94.7"
4
+ __version__ = "0.95.0"
5
5
  __author__ = "Kazuya O'moto <komoto@jeol.co.jp>"
6
6
 
7
7
  from functools import wraps, partial
@@ -55,21 +55,17 @@ def deb(target=None, loop=True, locals=None, **kwargs):
55
55
  kwargs.setdefault("execStartupScript", True)
56
56
  kwargs.setdefault("ensureClose", True)
57
57
 
58
- with App(loop):
58
+ app = wx.GetApp() or wx.App()
59
+ try:
59
60
  frame = ShellFrame(None, target, **kwargs)
60
61
  frame.Show()
61
62
  frame.rootshell.SetFocus()
62
63
  if locals:
63
64
  frame.rootshell.locals.update(locals)
64
65
  return frame
65
-
66
-
67
- @contextmanager
68
- def App(loop=True):
69
- app = wx.GetApp() or wx.App()
70
- yield app
71
- if loop and not app.GetMainLoop():
72
- app.MainLoop()
66
+ finally:
67
+ if loop and not app.GetMainLoop():
68
+ app.MainLoop()
73
69
 
74
70
 
75
71
  def postcall(f):
@@ -1252,7 +1248,7 @@ class ShellFrame(MiniFrame):
1252
1248
  'add_log' : [ None, self.add_log ],
1253
1249
  'add_help' : [ None, self.add_help ],
1254
1250
  'title_window' : [ None, self.on_title_window ],
1255
- 'buffer_caption_reset' : [ None, self.on_buffer_caption ], # => self.OnActivate
1251
+ 'buffer_caption_updated' : [ None, self.on_buffer_caption ], # => self.OnActivate
1256
1252
  },
1257
1253
  0 : {
1258
1254
  '* pressed' : (0, fork_debugger),
@@ -1262,9 +1258,9 @@ class ShellFrame(MiniFrame):
1262
1258
  'C-f pressed' : (0, self.OnFindText),
1263
1259
  'f3 pressed' : (0, self.OnFindNext),
1264
1260
  'S-f3 pressed' : (0, self.OnFindPrev),
1265
- 'f11 pressed' : (0, _F(self.toggle_window, self.ghost, doc="Toggle ghost")),
1266
- 'S-f11 pressed' : (0, _F(self.toggle_window, self.watcher, doc="Toggle watcher")),
1267
- 'f12 pressed' : (0, _F(self.Close, alias="close", doc="Close the window")),
1261
+ 'f11 pressed' : (0, _F(self.toggle_window, self.ghost, alias='toggle_ghost')),
1262
+ 'S-f11 pressed' : (0, _F(self.toggle_window, self.watcher, alias='toggle_watcher')),
1263
+ 'f12 pressed' : (0, _F(self.Close, alias="close")),
1268
1264
  '*f[0-9]* pressed' : (0, ),
1269
1265
  },
1270
1266
  })
@@ -1546,6 +1542,11 @@ class ShellFrame(MiniFrame):
1546
1542
 
1547
1543
  def toggle_window(self, win):
1548
1544
  pane = self._mgr.GetPane(win)
1545
+ if pane.IsDocked():
1546
+ if not self.console.IsShown():
1547
+ self._mgr.RestoreMaximizedPane()
1548
+ self._mgr.Update()
1549
+ return
1549
1550
  self.popup_window(win, not pane.IsShown())
1550
1551
 
1551
1552
  def popup_window(self, win, show=True):
@@ -1698,8 +1699,9 @@ class ShellFrame(MiniFrame):
1698
1699
  self.debugger.debug(obj, *args, **kwargs)
1699
1700
  elif isinstance(obj, str):
1700
1701
  filename = "<string>"
1701
- buf = self.Scratch.find_buffer(filename)\
1702
- or self.Scratch.create_buffer(filename)
1702
+ editor = self.Scratch
1703
+ buf = editor.find_buffer(filename)\
1704
+ or editor.create_buffer(filename)
1703
1705
  with buf.off_readonly():
1704
1706
  buf.Text = obj
1705
1707
  self.debugger.run(obj, filename)
@@ -1845,6 +1847,7 @@ class ShellFrame(MiniFrame):
1845
1847
  buf.SetText(text)
1846
1848
  ## Overwrite text and popup the window.
1847
1849
  self.popup_window(self.Help)
1850
+ self.Help.swap_page(buf)
1848
1851
 
1849
1852
  def clone_shell(self, target):
1850
1853
  if not hasattr(target, '__dict__'):
@@ -1883,7 +1886,7 @@ class ShellFrame(MiniFrame):
1883
1886
  @property
1884
1887
  def all_shells(self):
1885
1888
  """Yields all books in the notebooks."""
1886
- yield from self.console.get_pages(type(self.rootshell))
1889
+ return self.console.get_pages(type(self.rootshell))
1887
1890
 
1888
1891
  @property
1889
1892
  def current_shell(self):
@@ -1893,7 +1896,7 @@ class ShellFrame(MiniFrame):
1893
1896
  @property
1894
1897
  def all_editors(self):
1895
1898
  """Yields all editors in the notebooks."""
1896
- yield from self.ghost.get_pages(type(self.Log))
1899
+ return self.ghost.get_pages(type(self.Log))
1897
1900
 
1898
1901
  @property
1899
1902
  def current_editor(self):
@@ -1904,12 +1907,19 @@ class ShellFrame(MiniFrame):
1904
1907
  return next((x for x in self.all_editors if x.IsShown()), self.Scratch)
1905
1908
 
1906
1909
  def find_editor(self, fn):
1907
- """Find an editor which has the specified fn:filename or code."""
1908
- for book in self.all_editors:
1910
+ """Find an editor with the specified fn:filename or code.
1911
+ If found, switch to the buffer page.
1912
+ """
1913
+ return next(self.find_editors(fn), None)
1914
+
1915
+ def find_editors(self, fn):
1916
+ """Yields all editors with the specified fn:filename or code."""
1917
+ def _f(book):
1909
1918
  buf = book.find_buffer(fn)
1910
1919
  if buf:
1911
1920
  book.swap_page(buf)
1912
- return book
1921
+ return buf
1922
+ return filter(_f, self.all_editors)
1913
1923
 
1914
1924
  ## --------------------------------
1915
1925
  ## Find text dialog
mwx/nutshell.py CHANGED
@@ -1386,15 +1386,13 @@ class Buffer(EditWindow, EditorInterface):
1386
1386
  def filename(self):
1387
1387
  return self.__filename
1388
1388
 
1389
- @filename.setter
1390
- def filename(self, fn):
1389
+ def update_filestamp(self, fn):
1391
1390
  if fn and os.path.isfile(fn):
1392
- self.__mtime = os.path.getmtime(fn)
1391
+ self.__mtime = os.path.getmtime(fn) # update timestamp (modified time)
1393
1392
  else:
1394
1393
  self.__mtime = None
1395
1394
  if self.__filename != fn:
1396
1395
  self.__filename = fn
1397
- self.parent.handler('buffer_filename_reset', self)
1398
1396
  self.update_caption()
1399
1397
 
1400
1398
  @property
@@ -1408,10 +1406,12 @@ class Buffer(EditWindow, EditorInterface):
1408
1406
  < 0 : a url file
1409
1407
  """
1410
1408
  fn = self.filename
1411
- if fn and os.path.isfile(fn):
1412
- return os.path.getmtime(fn) - self.__mtime
1413
- if fn and re.match(url_re, fn):
1414
- return -1
1409
+ if fn:
1410
+ if os.path.isfile(fn):
1411
+ return os.path.getmtime(fn) - self.__mtime
1412
+ if re.match(url_re, fn):
1413
+ return -1
1414
+ return None
1415
1415
 
1416
1416
  @property
1417
1417
  def caption_prefix(self):
@@ -1429,9 +1429,10 @@ class Buffer(EditWindow, EditorInterface):
1429
1429
  return prefix
1430
1430
 
1431
1431
  def update_caption(self):
1432
+ caption = self.caption_prefix + self.name
1432
1433
  try:
1433
- if self.parent.set_caption(self, self.caption_prefix + self.name):
1434
- self.parent.handler('buffer_caption_reset', self)
1434
+ if self.parent.set_caption(self, caption):
1435
+ self.parent.handler('buffer_caption_updated', self)
1435
1436
  except AttributeError:
1436
1437
  pass
1437
1438
 
@@ -1465,7 +1466,7 @@ class Buffer(EditWindow, EditorInterface):
1465
1466
 
1466
1467
  self.parent = parent
1467
1468
  self.__filename = filename
1468
- self.filename = filename
1469
+ self.update_filestamp(filename)
1469
1470
  self.code = None
1470
1471
 
1471
1472
  self.Bind(stc.EVT_STC_UPDATEUI, self.OnUpdate) # skip to brace matching
@@ -1543,10 +1544,14 @@ class Buffer(EditWindow, EditorInterface):
1543
1544
  if self.IndicatorValueAt(2, pos):
1544
1545
  p = self.IndicatorStart(2, pos)
1545
1546
  q = self.IndicatorEnd(2, pos)
1546
- text = self.GetTextRange(p, q).strip()
1547
- self.message("URL {!r}".format(text))
1548
- ## Note: Need a post-call of the confirmation dialog.
1549
- wx.CallAfter(self.parent.load_url, text)
1547
+ url = self.GetTextRange(p, q).strip()
1548
+ self.message("URL {!r}".format(url))
1549
+ if wx.GetKeyState(wx.WXK_SHIFT):
1550
+ ## Note: post-call for the confirmation dialog.
1551
+ wx.CallAfter(self.parent.load_file, url)
1552
+ else:
1553
+ import webbrowser
1554
+ return webbrowser.open(url)
1550
1555
  self.anchor = pos # Clear selection
1551
1556
 
1552
1557
  def on_modified(self, buf):
@@ -1590,15 +1595,15 @@ class Buffer(EditWindow, EditorInterface):
1590
1595
  self.Text = text
1591
1596
  self.EmptyUndoBuffer()
1592
1597
  self.SetSavePoint()
1593
- self.filename = filename
1594
- self.handler('buffer_loaded', self)
1598
+ self.update_filestamp(filename)
1599
+ self.handler('buffer_loaded', self)
1595
1600
 
1596
1601
  def _load_file(self, filename):
1597
1602
  """Wrapped method of LoadFile."""
1598
1603
  if self.LoadFile(filename):
1604
+ self.update_filestamp(filename)
1599
1605
  self.EmptyUndoBuffer()
1600
1606
  self.SetSavePoint()
1601
- self.filename = filename
1602
1607
  self.handler('buffer_loaded', self)
1603
1608
  return True
1604
1609
  return False
@@ -1606,8 +1611,8 @@ class Buffer(EditWindow, EditorInterface):
1606
1611
  def _save_file(self, filename):
1607
1612
  """Wrapped method of SaveFile."""
1608
1613
  if self.SaveFile(filename):
1614
+ self.update_filestamp(filename)
1609
1615
  self.SetSavePoint()
1610
- self.filename = filename
1611
1616
  self.handler('buffer_saved', self)
1612
1617
  return True
1613
1618
  return False
@@ -1769,8 +1774,7 @@ class EditorBook(AuiNotebook, CtrlInterface):
1769
1774
  'buffer_modified' : [ None, dispatch ],
1770
1775
  'buffer_activated' : [ None, dispatch, self.on_activated ],
1771
1776
  'buffer_inactivated' : [ None, dispatch, self.on_inactivated ],
1772
- 'buffer_caption_reset' : [ None, dispatch ],
1773
- 'buffer_filename_reset' : [ None, dispatch ],
1777
+ 'buffer_caption_updated' : [ None, dispatch ],
1774
1778
  '*button* pressed' : [ None, dispatch, skip ],
1775
1779
  '*button* released' : [ None, dispatch, skip ],
1776
1780
  },
@@ -1962,6 +1966,7 @@ class EditorBook(AuiNotebook, CtrlInterface):
1962
1966
 
1963
1967
  def load_file(self, filename, lineno=0, verbose=True):
1964
1968
  """Load a file into an existing or new buffer.
1969
+ The requests module is required to use URL extension.
1965
1970
  """
1966
1971
  buf = self.find_buffer(filename)
1967
1972
  if not buf:
@@ -1979,8 +1984,6 @@ class EditorBook(AuiNotebook, CtrlInterface):
1979
1984
  self.swap_buffer(buf, lineno)
1980
1985
  return True
1981
1986
  try:
1982
- self.Freeze()
1983
- org = self.buffer
1984
1987
  if re.match(url_re, filename):
1985
1988
  import requests
1986
1989
  res = requests.get(filename, timeout=3.0)
@@ -1988,27 +1991,34 @@ class EditorBook(AuiNotebook, CtrlInterface):
1988
1991
  buf._load_textfile(res.text, filename)
1989
1992
  self.swap_buffer(buf, lineno)
1990
1993
  return True
1991
- return False
1992
- else:
1993
- if buf._load_file(filename):
1994
- self.swap_buffer(buf, lineno)
1995
- return True
1996
- return False
1994
+ ## return False
1995
+ raise Exception("The requested URL was not found.")
1996
+ if buf._load_file(filename):
1997
+ self.swap_buffer(buf, lineno)
1998
+ return True
1999
+ return False
1997
2000
  except Exception as e:
1998
2001
  self.post_message(f"Failed to load {filename!r}:", e)
1999
2002
  self.delete_buffer(buf)
2000
- if org:
2001
- self.swap_buffer(org)
2002
2003
  return False
2003
- finally:
2004
- self.Thaw()
2005
2004
 
2006
- def load_url(self, url):
2007
- if wx.GetKeyState(wx.WXK_SHIFT):
2008
- self.load_file(url)
2009
- else:
2010
- import webbrowser
2011
- webbrowser.open(url)
2005
+ load_url = load_file # for backward compatibility
2006
+
2007
+ def find_file(self, filename=None):
2008
+ """Open the specified file."""
2009
+ if not filename:
2010
+ with wx.FileDialog(self, "Open buffer",
2011
+ wildcard='|'.join(self.wildcards),
2012
+ style=wx.FD_OPEN|wx.FD_MULTIPLE) as dlg:
2013
+ if dlg.ShowModal() == wx.ID_OK:
2014
+ for fn in dlg.Paths:
2015
+ self.find_file(fn)
2016
+ return
2017
+ if not self.load_file(filename):
2018
+ buf = self.create_buffer(filename)
2019
+ self.swap_buffer(buf)
2020
+
2021
+ open_buffer = find_file # for backward compatibility
2012
2022
 
2013
2023
  def save_file(self, filename, buf=None, verbose=True):
2014
2024
  """Save the current buffer to a file.
@@ -2075,16 +2085,6 @@ class EditorBook(AuiNotebook, CtrlInterface):
2075
2085
  if buf.need_buffer_save:
2076
2086
  self.save_buffer(buf)
2077
2087
 
2078
- def open_buffer(self):
2079
- """Confirm the open with the dialog."""
2080
- with wx.FileDialog(self, "Open buffer",
2081
- wildcard='|'.join(self.wildcards),
2082
- style=wx.FD_OPEN|wx.FD_FILE_MUST_EXIST
2083
- |wx.FD_MULTIPLE) as dlg:
2084
- if dlg.ShowModal() == wx.ID_OK:
2085
- for fn in dlg.Paths:
2086
- self.load_file(fn)
2087
-
2088
2088
  def kill_buffer(self, buf=None):
2089
2089
  """Confirm the close with the dialog."""
2090
2090
  buf = buf or self.buffer
@@ -2884,7 +2884,7 @@ class Nautilus(Shell, EditorInterface):
2884
2884
  wx.CallAfter(_del)
2885
2885
 
2886
2886
  def on_activated(self, shell):
2887
- """Called when shell:self is activated.
2887
+ """Called when the shell:self is activated.
2888
2888
  Reset localvars assigned for the shell target.
2889
2889
  """
2890
2890
  self.trace_position()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mwxlib
3
- Version: 0.94.7
3
+ Version: 0.95.0
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
- mwx/__init__.py,sha256=zLsXDgqyC5NsPCjRxjS2huvZ3uDyeOJ1vapotqe2ULM,834
2
- mwx/bookshelf.py,sha256=UVVIwHaGO4aEHwZ8x5SKjpL-3MmQ1s6kkyuyRZqKWvU,5070
1
+ mwx/__init__.py,sha256=2D6y5mnxxp5qNbBb0-Mng40JeUKCGbqohfcuHdihZx4,829
2
+ mwx/bookshelf.py,sha256=U_UQUJkOqugAXYm2HpgqTIWPBREKLzJzRvJWCEWnT3c,5091
3
3
  mwx/controls.py,sha256=prp1NhZqv1XANhi2PPxW9jtrgwj_02XMOOyyzZ48klM,47185
4
- mwx/framework.py,sha256=9mvG3E0sx1gTuEcuz4RK4e3bhd4il_rduRrHkgJ9U4c,75109
4
+ mwx/framework.py,sha256=9WFR5E68rqxFzRcyZ1SSzPGNw5LCexu6TuUeJ9DSKTE,75517
5
5
  mwx/graphman.py,sha256=9MG0BzQh5lDDadyPPXps2M0hf6mPN3G0MQbBGdplY_I,70027
6
6
  mwx/images.py,sha256=mrnUYH12I3XLVSZcEXlpVltX0XMxufbl2yRvDIQJZqc,49957
7
7
  mwx/matplot2.py,sha256=qaF_gvLoLn-TimLbRR59KUavNr1ZpZQdSMqjzJk47rk,32682
8
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=c7VYeOmDSr1WcIzAjAIVmjTXBJqtxKzAz6EhZ9YmnAw,135633
11
+ mwx/nutshell.py,sha256=4yFPmBfjUGyx9GGXEvKadWsPkIHwOloNp44UCGu7f9U,135788
12
12
  mwx/utilus.py,sha256=FTJhVFmx6TAE5rvZ_nfxZgyyaW4zMpXEz74v72X6m7Y,37399
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.7.dist-info/LICENSE,sha256=PGtRKCaTkmUDlBQwpptJAxJtdqxIUtAmdBsaT9nUVkA,1091
25
- mwxlib-0.94.7.dist-info/METADATA,sha256=_il1CbhksQkqZv4Gbmb_tr6DuQf8usLLIoGqXm1U6Ic,1925
26
- mwxlib-0.94.7.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
27
- mwxlib-0.94.7.dist-info/top_level.txt,sha256=SI1Mh118AstnUFGPNq5aMNKiAnVNmZk1S9Ij-OwAEpY,4
28
- mwxlib-0.94.7.dist-info/RECORD,,
24
+ mwxlib-0.95.0.dist-info/LICENSE,sha256=PGtRKCaTkmUDlBQwpptJAxJtdqxIUtAmdBsaT9nUVkA,1091
25
+ mwxlib-0.95.0.dist-info/METADATA,sha256=ybRT30kEPrD9gLt1a8MReKmNeSGbYiqLPfe3N79UABM,1925
26
+ mwxlib-0.95.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
27
+ mwxlib-0.95.0.dist-info/top_level.txt,sha256=SI1Mh118AstnUFGPNq5aMNKiAnVNmZk1S9Ij-OwAEpY,4
28
+ mwxlib-0.95.0.dist-info/RECORD,,