mwxlib 0.94.8__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
@@ -42,12 +42,14 @@ class EditorTreeCtrl(wx.TreeCtrl, CtrlInterface):
42
42
  data.SetFocus()
43
43
 
44
44
  @self.handler.bind('f5 pressed')
45
- def refresh(v):
46
- self.build_tree(clear=0)
45
+ def refresh(v, clear=False):
46
+ self.build_tree(clear)
47
47
  if self.target:
48
48
  self.target.current_editor.SetFocus()
49
49
  wx.CallAfter(self.SetFocus)
50
50
 
51
+ self.handler.bind('S-f5 pressed', partial(refresh, clear=1))
52
+
51
53
  @self.handler.bind('delete pressed')
52
54
  def delete(v):
53
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.8"
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):
@@ -1703,8 +1699,9 @@ class ShellFrame(MiniFrame):
1703
1699
  self.debugger.debug(obj, *args, **kwargs)
1704
1700
  elif isinstance(obj, str):
1705
1701
  filename = "<string>"
1706
- buf = self.Scratch.find_buffer(filename)\
1707
- or self.Scratch.create_buffer(filename)
1702
+ editor = self.Scratch
1703
+ buf = editor.find_buffer(filename)\
1704
+ or editor.create_buffer(filename)
1708
1705
  with buf.off_readonly():
1709
1706
  buf.Text = obj
1710
1707
  self.debugger.run(obj, filename)
@@ -1850,6 +1847,7 @@ class ShellFrame(MiniFrame):
1850
1847
  buf.SetText(text)
1851
1848
  ## Overwrite text and popup the window.
1852
1849
  self.popup_window(self.Help)
1850
+ self.Help.swap_page(buf)
1853
1851
 
1854
1852
  def clone_shell(self, target):
1855
1853
  if not hasattr(target, '__dict__'):
@@ -1888,7 +1886,7 @@ class ShellFrame(MiniFrame):
1888
1886
  @property
1889
1887
  def all_shells(self):
1890
1888
  """Yields all books in the notebooks."""
1891
- yield from self.console.get_pages(type(self.rootshell))
1889
+ return self.console.get_pages(type(self.rootshell))
1892
1890
 
1893
1891
  @property
1894
1892
  def current_shell(self):
@@ -1898,7 +1896,7 @@ class ShellFrame(MiniFrame):
1898
1896
  @property
1899
1897
  def all_editors(self):
1900
1898
  """Yields all editors in the notebooks."""
1901
- yield from self.ghost.get_pages(type(self.Log))
1899
+ return self.ghost.get_pages(type(self.Log))
1902
1900
 
1903
1901
  @property
1904
1902
  def current_editor(self):
@@ -1909,12 +1907,19 @@ class ShellFrame(MiniFrame):
1909
1907
  return next((x for x in self.all_editors if x.IsShown()), self.Scratch)
1910
1908
 
1911
1909
  def find_editor(self, fn):
1912
- """Find an editor which has the specified fn:filename or code."""
1913
- 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):
1914
1918
  buf = book.find_buffer(fn)
1915
1919
  if buf:
1916
1920
  book.swap_page(buf)
1917
- return book
1921
+ return buf
1922
+ return filter(_f, self.all_editors)
1918
1923
 
1919
1924
  ## --------------------------------
1920
1925
  ## Find text dialog
mwx/nutshell.py CHANGED
@@ -1544,10 +1544,14 @@ class Buffer(EditWindow, EditorInterface):
1544
1544
  if self.IndicatorValueAt(2, pos):
1545
1545
  p = self.IndicatorStart(2, pos)
1546
1546
  q = self.IndicatorEnd(2, pos)
1547
- text = self.GetTextRange(p, q).strip()
1548
- self.message("URL {!r}".format(text))
1549
- ## Note: Need a post-call of the confirmation dialog.
1550
- 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)
1551
1555
  self.anchor = pos # Clear selection
1552
1556
 
1553
1557
  def on_modified(self, buf):
@@ -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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mwxlib
3
- Version: 0.94.8
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=WEILqqxzGtdNUiUvn8oa4aTCSnzO11_MrV2L8sXKjXI,5000
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=9ZWmc31eMBdtFPqTTd21dtyiYsiBA8U0MRuLzIMMVoI,75272
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=SWlACsEHGtsLxw3l16TnNALNAB2_ObE7IO0eqo1s4eQ,135627
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.8.dist-info/LICENSE,sha256=PGtRKCaTkmUDlBQwpptJAxJtdqxIUtAmdBsaT9nUVkA,1091
25
- mwxlib-0.94.8.dist-info/METADATA,sha256=fHCSJqHLZhgT8iK4xUBbA2apLus3rSQMqMh0w-O7DxU,1925
26
- mwxlib-0.94.8.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
27
- mwxlib-0.94.8.dist-info/top_level.txt,sha256=SI1Mh118AstnUFGPNq5aMNKiAnVNmZk1S9Ij-OwAEpY,4
28
- mwxlib-0.94.8.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,,