Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Add dark css for the Help and IPython Console plugins #8086

Merged
merged 9 commits into from
Oct 28, 2018
12 changes: 10 additions & 2 deletions spyder/app/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
from spyder.utils.programs import is_module_installed
from spyder.utils.misc import select_port, getcwd_or_home, get_python_executable
from spyder.widgets.fileswitcher import FileSwitcher
from spyder.plugins.help.utils.sphinxify import CSS_PATH, DARK_CSS_PATH
from spyder.plugins.lspmanager import LSPManager
from spyder.config.gui import is_dark_font_color

Expand Down Expand Up @@ -576,12 +577,19 @@ def setup(self):
logger.info("Applying theme configuration...")
ui_theme = CONF.get('color_schemes', 'ui_theme')
color_scheme = CONF.get('color_schemes', 'selected')

if ui_theme == 'dark':
self.setStyleSheet(qdarkstyle.load_stylesheet_from_environment())
css_path = DARK_CSS_PATH
elif ui_theme == 'automatic':
if not is_dark_font_color(color_scheme):
self.setStyleSheet(
qdarkstyle.load_stylesheet_from_environment())
css_path = DARK_CSS_PATH
else:
css_path = CSS_PATH
else:
css_path = CSS_PATH

logger.info("Creating core actions...")
self.close_dockwidget_action = create_action(self,
Expand Down Expand Up @@ -857,7 +865,7 @@ def create_edit_action(text, tr_text, icon):
if CONF.get('help', 'enable'):
self.set_splash(_("Loading help..."))
from spyder.plugins.help.plugin import Help
self.help = Help(self)
self.help = Help(self, css_path=css_path)
self.help.register_plugin()

# Outline explorer widget
Expand Down Expand Up @@ -918,7 +926,7 @@ def create_edit_action(text, tr_text, icon):
# IPython console
self.set_splash(_("Loading IPython console..."))
from spyder.plugins.ipythonconsole.plugin import IPythonConsole
self.ipyconsole = IPythonConsole(self)
self.ipyconsole = IPythonConsole(self, css_path=css_path)
self.ipyconsole.register_plugin()

# Explorer
Expand Down
26 changes: 16 additions & 10 deletions spyder/plugins/help/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
from spyder.py3compat import get_meth_class_inst, to_text_string
from spyder.utils import icon_manager as ima
from spyder.utils import programs
from spyder.plugins.help.utils.sphinxify import (CSS_PATH, generate_context,
from spyder.plugins.help.utils.sphinxify import (CSS_PATH,
generate_context,
usage, warning)
from spyder.utils.qthelpers import (add_actions, create_action,
create_toolbutton, create_plugin_layout,
Expand Down Expand Up @@ -53,11 +54,12 @@ class Help(SpyderPluginWidget):
# Signals
focus_changed = Signal()

def __init__(self, parent=None):
def __init__(self, parent=None, css_path=CSS_PATH):
SpyderPluginWidget.__init__(self, parent)

self.internal_shell = None
self.console = None
self.css_path = css_path

# Initialize plugin
self.initialize_plugin()
Expand Down Expand Up @@ -177,7 +179,9 @@ def __init__(self, parent=None):

# Add worker thread for handling rich text rendering
self._sphinx_thread = SphinxThread(
html_text_no_doc=warning(self.no_doc_string))
html_text_no_doc=warning(self.no_doc_string,
css_path=self.css_path),
css_path=self.css_path)
self._sphinx_thread.html_ready.connect(
self._on_sphinx_thread_html_ready)
self._sphinx_thread.error_msg.connect(self._on_sphinx_thread_error_msg)
Expand Down Expand Up @@ -426,8 +430,9 @@ def show_intro_message(self):
intro_message = intro_message % ("<b>"+shortcut+"</b>", "<br><br>",
"<i>"+prefs+"</i>")
self.set_rich_text_html(usage(title, intro_message,
tutorial_message, tutorial),
QUrl.fromLocalFile(CSS_PATH))
tutorial_message, tutorial,
css_path=self.css_path),
QUrl.fromLocalFile(self.css_path))
else:
install_sphinx = "\n\n%s" % _("Please consider installing Sphinx "
"to get documentation rendered in "
Expand All @@ -441,7 +446,8 @@ def show_rich_text(self, text, collapse=False, img_path=''):
self.visibility_changed(True)
self.raise_()
self.switch_to_rich_text()
context = generate_context(collapse=collapse, img_path=img_path)
context = generate_context(collapse=collapse, img_path=img_path,
css_path=self.css_path)
self.render_sphinx_doc(text, context)

def show_plain_text(self, text):
Expand Down Expand Up @@ -629,7 +635,7 @@ def get_shell(self):
self.shell = self.internal_shell
return self.shell

def render_sphinx_doc(self, doc, context=None):
def render_sphinx_doc(self, doc, context=None, css_path=CSS_PATH):
"""Transform doc string dictionary to HTML and show it"""
# Math rendering option could have changed
if self.main.editor is not None:
Expand All @@ -638,12 +644,12 @@ def render_sphinx_doc(self, doc, context=None):
else:
dname = ''
self._sphinx_thread.render(doc, context, self.get_option('math'),
dname)
dname, css_path=self.css_path)

def _on_sphinx_thread_html_ready(self, html_text):
"""Set our sphinx documentation based on thread result"""
self._sphinx_thread.wait()
self.set_rich_text_html(html_text, QUrl.fromLocalFile(CSS_PATH))
self.set_rich_text_html(html_text, QUrl.fromLocalFile(self.css_path))

def _on_sphinx_thread_error_msg(self, error_msg):
""" Display error message on Sphinx rich text failure"""
Expand Down Expand Up @@ -681,7 +687,7 @@ def show_help(self, obj_text, ignore_unknown=False):
is_code = False

if self.rich_help:
self.render_sphinx_doc(doc)
self.render_sphinx_doc(doc, css_path=self.css_path)
return doc is not None
elif self.docstring:
hlp_text = doc
Expand Down
14 changes: 7 additions & 7 deletions spyder/plugins/help/utils/sphinxify.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
# version of Spyder (i.e. the py2exe or cx_Freeze build)
CONFDIR_PATH = get_module_source_path('spyder.plugins.help.utils')
CSS_PATH = osp.join(CONFDIR_PATH, 'static', 'css')
DARK_CSS_PATH = osp.join(CONFDIR_PATH, 'static', 'dark_css')
JS_PATH = osp.join(CONFDIR_PATH, 'js')

# To let Debian packagers redefine the MathJax and JQuery locations so they can
Expand All @@ -73,25 +74,25 @@ def is_sphinx_markup(docstring):
return ("`" in docstring or "::" in docstring)


def warning(message):
def warning(message, css_path=CSS_PATH):
"""Print a warning message on the rich text view"""
env = Environment()
env.loader = FileSystemLoader(osp.join(CONFDIR_PATH, 'templates'))
warning = env.get_template("warning.html")
return warning.render(css_path=CSS_PATH, text=message)
return warning.render(css_path=css_path, text=message)


def usage(title, message, tutorial_message, tutorial):
def usage(title, message, tutorial_message, tutorial, css_path=CSS_PATH):
"""Print a usage message on the rich text view"""
env = Environment()
env.loader = FileSystemLoader(osp.join(CONFDIR_PATH, 'templates'))
usage = env.get_template("usage.html")
return usage.render(css_path=CSS_PATH, title=title, intro_message=message,
return usage.render(css_path=css_path, title=title, intro_message=message,
tutorial_message=tutorial_message, tutorial=tutorial)


def generate_context(name='', argspec='', note='', math=False, collapse=False,
img_path=''):
img_path='', css_path=CSS_PATH):
"""
Generate the html_context dictionary for our Sphinx conf file.

Expand Down Expand Up @@ -133,9 +134,8 @@ def generate_context(name='', argspec='', note='', math=False, collapse=False,
'note': note,
'collapse': collapse,
'img_path': img_path,

# Static variables
'css_path': CSS_PATH,
'css_path': css_path,
'js_path': JS_PATH,
'jquery_path': JQUERY_PATH,
'mathjax_path': MATHJAX_PATH,
Expand Down
13 changes: 9 additions & 4 deletions spyder/plugins/help/utils/sphinxthread.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
# Local Imports
from spyder.config.base import _
from spyder.py3compat import to_text_string
from spyder.plugins.help.utils.sphinxify import generate_context, sphinxify
from spyder.plugins.help.utils.sphinxify import (CSS_PATH, generate_context,
sphinxify)


class SphinxThread(QThread):
Expand All @@ -36,14 +37,16 @@ class SphinxThread(QThread):
error_msg = Signal(str)
html_ready = Signal(str)

def __init__(self, html_text_no_doc=''):
def __init__(self, html_text_no_doc='', css_path=CSS_PATH):
super(SphinxThread, self).__init__()
self.doc = None
self.context = None
self.html_text_no_doc = html_text_no_doc
self.math_option = False
self.css_path = css_path

def render(self, doc, context=None, math_option=False, img_path=''):
def render(self, doc, context=None, math_option=False, img_path='',
css_path=CSS_PATH):
"""Start thread to render a given documentation"""
# If the thread is already running wait for it to finish before
# starting it again.
Expand All @@ -52,6 +55,7 @@ def render(self, doc, context=None, math_option=False, img_path=''):
self.context = context
self.math_option = math_option
self.img_path = img_path
self.css_path = css_path
# This causes run() to be executed in separate thread
self.start()

Expand All @@ -65,7 +69,8 @@ def run(self):
argspec=doc['argspec'],
note=doc['note'],
math=self.math_option,
img_path=self.img_path)
img_path=self.img_path,
css_path=self.css_path)
html_text = sphinxify(doc['docstring'], context)
if doc['docstring'] == '':
if any([doc['name'], doc['argspec'], doc['note']]):
Expand Down
Loading