Skip to content

Commit

Permalink
only set shell wx if LarchWxApp is imported, for whatever reaseon
Browse files Browse the repository at this point in the history
  • Loading branch information
newville committed Nov 9, 2024
1 parent 1eaaf9b commit 5245480
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions larch/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
except ImportError:
wx = None

SHOW_LIBS = ['numpy', 'scipy', 'matplotlib', 'h5py',
'lmfit', 'xraydb', 'wx','wxmplot']

class Shell(cmd.Cmd):
"""command shell for Larch"""
Expand Down Expand Up @@ -57,33 +59,29 @@ def __init__(self, completekey='tab', debug=False, quiet=False,
if with_wx and HAS_WXPYTHON:
symtable = self.larch.symtable
try:
from .wxlib import LarchWxApp
from .wxlib import LarchWxApp, inputhook
app = LarchWxApp(redirect=False, clearSigInt=False)
except SystemExit:
with_wx = False

symtable.set_symbol('_sys.wx.wxapp', app)
symtable.set_symbol('_sys.wx.force_wxupdate', False)
symtable.set_symbol('_sys.wx.parent', None)

from .wxlib import inputhook
symtable.set_symbol('_sys.wx.inputhook', inputhook)
if uname == 'darwin':
symtable.set_symbol('_sys.wx.ping', inputhook.ping_darwin)
else:
symtable.set_symbol('_sys.wx.ping', inputhook.ping)

inputhook.ON_INTERRUPT = self.onCtrlC
inputhook.WXLARCH_SYM = symtable
symtable.set_symbol('_sys.wx.wxapp', app)
symtable.set_symbol('_sys.wx.force_wxupdate', False)
symtable.set_symbol('_sys.wx.parent', None)
symtable.set_symbol('_sys.wx.inputhook', inputhook)
if uname == 'darwin':
symtable.set_symbol('_sys.wx.ping', inputhook.ping_darwin)
else:
symtable.set_symbol('_sys.wx.ping', inputhook.ping)

inputhook.ON_INTERRUPT = self.onCtrlC
inputhook.WXLARCH_SYM = symtable
except:
pass

signal.signal(signal.SIGINT, self.onCtrlC)
self.prompt = self.larch.input.prompt
writer = self.larch.writer
self.color_writer = (uname != 'win' and hasattr(writer, 'set_textstyle'))
if not quiet:
if banner_msg is None:
banner_msg = make_banner(show_libraries=['numpy', 'scipy', 'matplotlib', 'h5py',
'lmfit', 'xraydb', 'wx','wxmplot'])
banner_msg = make_banner(show_libraries=SHOW_LIBS)
if self.color_writer:
writer.set_textstyle('error')
writer.write(banner_msg)
Expand Down

0 comments on commit 5245480

Please sign in to comment.