-
-
Notifications
You must be signed in to change notification settings - Fork 77
/
confpage.py
112 lines (97 loc) · 4.12 KB
/
confpage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# -*- coding: utf-8 -*-
#
# Copyright © Spyder Project Contributors
# Licensed under the terms of the MIT License
# (see spyder/__init__.py for details)
"""Spyder terminal configuration page."""
# Standard library imports
from distutils.version import LooseVersion
import os
import platform
import sys
# Third party imports
from qtpy.QtWidgets import (QVBoxLayout, QGroupBox, QGridLayout, QButtonGroup,
QRadioButton, QWidget)
from spyder.api.preferences import PluginConfigPage
from spyder.config.base import get_translation
from spyder.utils.programs import find_program
# Constants
WINDOWS = os.name == 'nt'
UNIX_SHELLS = ['bash', 'sh', 'ksh', 'zsh', 'csh', 'pwsh', 'rbash', 'dash',
'screen', 'tmux', 'tcsh', 'fish', 'xonsh']
WINDOWS_SHELLS = ['cmd', 'powershell', 'xonsh']
# For translations
_ = get_translation('spyder_terminal')
class TerminalConfigPage(PluginConfigPage):
def setup_page(self):
"""Create configuration page."""
options_layout = QGridLayout()
# Custom shell options
shell_group = QGroupBox(_("Terminal shell"))
shell_layout = QVBoxLayout()
if WINDOWS:
self.shells = WINDOWS_SHELLS
else:
self.shells = UNIX_SHELLS
valid_shells = []
for shell in self.shells:
if find_program(shell) is not None:
valid_shells.append(shell)
valid_shells = zip(valid_shells, valid_shells)
if WINDOWS:
default_option = 'cmd'
elif sys.platform.startswith('linux'):
default_option = 'bash'
else:
mac_ver = LooseVersion(platform.mac_ver()[0])
if mac_ver >= LooseVersion('10.15.0'):
# Catalina changed the default shell to zsh
default_option = 'zsh'
else:
default_option = 'bash'
shell_combo = self.create_combobox(_("Select the shell interpreter:"),
valid_shells, 'shell', restart=True,
default=default_option)
shell_combo.combobox.setMinimumContentsLength(15)
shell_layout.addWidget(shell_combo)
shell_group.setLayout(shell_layout)
shell_layout.addStretch(1)
options_layout.addWidget(shell_group)
# Display preferences
display_group = QGroupBox(_("Terminal display preferences"))
display_layout = QVBoxLayout()
# Custom buffer limit
self.buffer_sb = self.create_spinbox(_("Buffer limit: "), "",
'buffer_limit', min_=100,
default=1000,
max_=1000000, step=1)
display_layout.addWidget(self.buffer_sb)
display_group.setLayout(display_layout)
display_layout.addStretch(1)
options_layout.addWidget(display_group)
# Style preferences
terminal_group = QGroupBox(_("Terminal style preferences"))
# Custom bar option
cursor_choices = [(_("Block"), 0), (_("Underline"), 1), (_("Bar"), 2)]
self.cursor_combo = self.create_combobox(_("Type of cursor:"),
cursor_choices,
'cursor_type')
self.cursor_combo.combobox.setMinimumContentsLength(15)
options_layout.addWidget(self.cursor_combo)
# Custom sound option
self.sound_cb = self.create_checkbox(
_("Enable bell sound"), 'sound',
tip=_("Enable bell sound on terminal"))
options_layout.addWidget(self.sound_cb)
# Visual bell option
self.cursor_blink_cb = self.create_checkbox(
_("Enable cursor blink"), 'cursor_blink',
tip=_("_Enable cursor blink on terminal"))
options_layout.addWidget(self.cursor_blink_cb)
terminal_group.setLayout(options_layout)
layout = QVBoxLayout()
layout.addWidget(shell_group)
layout.addWidget(display_group)
layout.addWidget(terminal_group)
layout.addStretch(1)
self.setLayout(layout)