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

[WIP] Switching syntax styles option #184

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions qtconsole/mainwindow.py
Expand Up @@ -578,6 +578,15 @@ def init_view_menu(self):
self.pager_menu.addAction(vsplit_action)
self.pager_menu.addAction(inside_action)

available_syntax_styles = self.get_available_syntax_styles()
if len(available_syntax_styles) > 0:
self.syntax_style_menu = self.view_menu.addMenu("&Syntax Style")
for style in available_syntax_styles:
action = QtGui.QAction("{}".format(style), self,
triggered=lambda v, syntax_style=style:
self.set_syntax_style(syntax_style=syntax_style))
self.syntax_style_menu.addAction(action)

def init_kernel_menu(self):
self.kernel_menu = self.menuBar().addMenu("&Kernel")
# Qt on OSX maps Ctrl to Cmd, and Meta to Ctrl
Expand Down Expand Up @@ -730,6 +739,15 @@ def toggleFullScreen(self):
def set_paging_active_frontend(self, paging):
self.active_frontend._set_paging(paging)

def get_available_syntax_styles(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use a pygments function to find the available styles:
http://pygments.org/docs/styles/#getting-a-list-of-available-styles

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh this is way better! Thank you!

from pygments.styles import get_all_styles
styles = list(get_all_styles())
return sorted(styles)

def set_syntax_style(self, syntax_style):
widget = self.new_frontend_factory(syntax_style=syntax_style)
self.add_tab_with_frontend(widget)

def close_active_frontend(self):
self.close_tab(self.active_frontend)

Expand Down
6 changes: 4 additions & 2 deletions qtconsole/qtconsoleapp.py
Expand Up @@ -178,7 +178,7 @@ def parse_command_line(self, argv=None):
self.build_kernel_argv(self.extra_args)


def new_frontend_master(self):
def new_frontend_master(self, syntax_style=None):
""" Create and return new frontend attached to new kernel, launched on localhost.
"""
kernel_manager = self.kernel_manager_class(
Expand All @@ -195,8 +195,10 @@ def new_frontend_master(self):
kernel_manager.client_factory = self.kernel_client_class
kernel_client = kernel_manager.client()
kernel_client.start_channels(shell=True, iopub=True)
if syntax_style is not None:
self.config.JupyterWidget.syntax_style = syntax_style
widget = self.widget_factory(config=self.config,
local_kernel=True)
local_kernel=True)
self.init_colors(widget)
widget.kernel_manager = kernel_manager
widget.kernel_client = kernel_client
Expand Down