本文整理汇总了Python中spyder.config.base._函数的典型用法代码示例。如果您正苦于以下问题:Python _函数的具体用法?Python _怎么用?Python _使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_options_menu
def get_options_menu(self):
"""Return options menu"""
env_action = create_action(
self,
_("Show environment variables"),
icon=ima.icon('environ'),
triggered=self.shellwidget.get_env
)
syspath_action = create_action(
self,
_("Show sys.path contents"),
icon=ima.icon('syspath'),
triggered=self.shellwidget.get_syspath
)
self.show_time_action.setChecked(self.show_elapsed_time)
additional_actions = [MENU_SEPARATOR,
env_action,
syspath_action,
self.show_time_action]
if self.menu_actions is not None:
console_menu = self.menu_actions + additional_actions
return console_menu
else:
return additional_actions
示例2: restart_kernel
def restart_kernel(self):
"""
Restart the associanted kernel
Took this code from the qtconsole project
Licensed under the BSD license
"""
message = _('Are you sure you want to restart the kernel?')
buttons = QMessageBox.Yes | QMessageBox.No
result = QMessageBox.question(self, _('Restart kernel?'),
message, buttons)
if result == QMessageBox.Yes:
sw = self.shellwidget
if sw.kernel_manager:
try:
sw.kernel_manager.restart_kernel()
except RuntimeError as e:
sw._append_plain_text(
_('Error restarting kernel: %s\n') % e,
before_prompt=True
)
else:
sw._append_html(_("<br>Restarting kernel...\n<hr><br>"),
before_prompt=True,
)
else:
sw._append_plain_text(
_('Cannot restart a kernel not started by Spyder\n'),
before_prompt=True
)
示例3: set_label_path
def set_label_path(self, path, folder=False):
text = truncate_path(path)
if not folder:
status_str = _(u' Scanning: {0}').format(text)
else:
status_str = _(u' Searching for files in folder: {0}').format(text)
self.status_text.setText(status_str)
示例4: setup_top_toolbar
def setup_top_toolbar(self, layout):
toolbar = []
movetop_button = create_toolbutton(self,
text=_("Move to top"),
icon=ima.icon('2uparrow'),
triggered=lambda: self.move_to(absolute=0),
text_beside_icon=True)
toolbar.append(movetop_button)
moveup_button = create_toolbutton(self,
text=_("Move up"),
icon=ima.icon('1uparrow'),
triggered=lambda: self.move_to(relative=-1),
text_beside_icon=True)
toolbar.append(moveup_button)
movedown_button = create_toolbutton(self,
text=_("Move down"),
icon=ima.icon('1downarrow'),
triggered=lambda: self.move_to(relative=1),
text_beside_icon=True)
toolbar.append(movedown_button)
movebottom_button = create_toolbutton(self,
text=_("Move to bottom"),
icon=ima.icon('2downarrow'),
triggered=lambda: self.move_to(absolute=1),
text_beside_icon=True)
toolbar.append(movebottom_button)
self.selection_widgets.extend(toolbar)
self._add_widgets_to_layout(layout, toolbar)
return toolbar
示例5: get_toolbar_buttons
def get_toolbar_buttons(self):
"""Return toolbar buttons list"""
buttons = []
# Code to add the stop button
if self.stop_button is None:
self.stop_button = create_toolbutton(self, text=_("Stop"),
icon=self.stop_icon,
tip=_("Stop the current command"))
self.disable_stop_button()
# set click event handler
self.stop_button.clicked.connect(self.stop_button_click_handler)
if self.stop_button is not None:
buttons.append(self.stop_button)
if self.options_button is None:
options = self.get_options_menu()
if options:
self.options_button = create_toolbutton(self,
text=_('Options'), icon=ima.icon('tooloptions'))
self.options_button.setPopupMode(QToolButton.InstantPopup)
menu = QMenu(self)
add_actions(menu, options)
self.options_button.setMenu(menu)
if self.options_button is not None:
buttons.append(self.options_button)
return buttons
示例6: run
def run(self):
html_text = self.html_text_no_doc
doc = self.doc
if doc is not None:
if type(doc) is dict and 'docstring' in doc.keys():
try:
context = generate_context(name=doc['name'],
argspec=doc['argspec'],
note=doc['note'],
math=self.math_option,
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']]):
msg = _("No further documentation available")
html_text += '<div class="hr"></div>'
else:
msg = _("No documentation available")
html_text += '<div id="doc-warning">%s</div>' % msg
except Exception as error:
self.error_msg.emit(to_text_string(error))
return
elif self.context is not None:
try:
html_text = sphinxify(doc, self.context)
except Exception as error:
self.error_msg.emit(to_text_string(error))
return
self.html_ready.emit(html_text)
示例7: run_script
def run_script(self, filename=None, silent=False, set_focus=False,
args=None):
"""Run a Python script"""
if filename is None:
self.shell.interpreter.restore_stds()
filename, _selfilter = getopenfilename(
self, _("Run Python script"), getcwd_or_home(),
_("Python scripts")+" (*.py ; *.pyw ; *.ipy)")
self.shell.interpreter.redirect_stds()
if filename:
os.chdir( osp.dirname(filename) )
filename = osp.basename(filename)
else:
return
logger.debug("Running script with %s", args)
filename = osp.abspath(filename)
rbs = remove_backslashes
command = "runfile('%s', args='%s')" % (rbs(filename), rbs(args))
if set_focus:
self.shell.setFocus()
if self.dockwidget and not self.ismaximized:
self.dockwidget.setVisible(True)
self.dockwidget.raise_()
self.shell.write(command+'\n')
self.shell.run_command(command)
示例8: create_file_combobox
def create_file_combobox(self, text, choices, option, default=NoDefault,
tip=None, restart=False, filters=None,
adjust_to_contents=False,
default_line_edit=False):
"""choices: couples (name, key)"""
combobox = FileComboBox(self, adjust_to_contents=adjust_to_contents,
default_line_edit=default_line_edit)
combobox.restart_required = restart
combobox.label_text = text
edit = combobox.lineEdit()
edit.label_text = text
edit.restart_required = restart
self.lineedits[edit] = (option, default)
if tip is not None:
combobox.setToolTip(tip)
combobox.addItems(choices)
msg = _('Invalid file path')
self.validate_data[edit] = (osp.isfile, msg)
browse_btn = QPushButton(ima.icon('FileIcon'), '', self)
browse_btn.setToolTip(_("Select file"))
browse_btn.clicked.connect(lambda: self.select_file(edit, filters))
layout = QGridLayout()
layout.addWidget(combobox, 0, 0, 0, 9)
layout.addWidget(browse_btn, 0, 10)
layout.setContentsMargins(0, 0, 0, 0)
widget = QWidget(self)
widget.combobox = combobox
widget.browse_btn = browse_btn
widget.setLayout(layout)
return widget
示例9: open_project
def open_project(self, path=None, restart_consoles=True,
save_previous_files=True):
"""Open the project located in `path`"""
if path is None:
basedir = get_home_dir()
path = getexistingdirectory(parent=self,
caption=_("Open project"),
basedir=basedir)
if not self.is_valid_project(path):
if path:
QMessageBox.critical(self, _('Error'),
_("<b>%s</b> is not a Spyder project!") % path)
return
else:
self.add_to_recent(path)
# A project was not open before
if self.current_active_project is None:
if save_previous_files:
self.editor.save_open_files()
self.editor.set_option('last_working_dir', getcwd_or_home())
self.show_explorer()
else: # we are switching projects
self.set_project_filenames(self.editor.get_open_filenames())
self.current_active_project = EmptyProject(path)
self.latest_project = EmptyProject(path)
self.set_option('current_project_path', self.get_active_project_path())
self.setup_menu_actions()
self.sig_project_loaded.emit(path)
self.pythonpath_changed.emit()
if restart_consoles:
self.restart_consoles()
示例10: get_toolbar_buttons
def get_toolbar_buttons(self):
if self.run_button is None:
self.run_button = create_toolbutton(self, text=_("Run"),
icon=ima.icon('run'),
tip=_("Run again this program"),
triggered=self.start_shell)
if self.kill_button is None:
self.kill_button = create_toolbutton(self, text=_("Kill"),
icon=ima.icon('kill'),
tip=_("Kills the current process, "
"causing it to exit immediately"))
buttons = [self.run_button]
if self.options_button is None:
options = self.get_options_menu()
if options:
self.options_button = create_toolbutton(self, text=_('Options'),
icon=ima.icon('tooloptions'))
self.options_button.setPopupMode(QToolButton.InstantPopup)
menu = QMenu(self)
add_actions(menu, options)
self.options_button.setMenu(menu)
if self.options_button is not None:
buttons.append(self.options_button)
buttons.append(self.kill_button)
return buttons
示例11: create_scedit
def create_scedit(self, text, option, default=NoDefault, tip=None,
without_layout=False):
label = QLabel(text)
clayout = ColorLayout(QColor(Qt.black), self)
clayout.lineedit.setMaximumWidth(80)
if tip is not None:
clayout.setToolTip(tip)
cb_bold = QCheckBox()
cb_bold.setIcon(ima.icon('bold'))
cb_bold.setToolTip(_("Bold"))
cb_italic = QCheckBox()
cb_italic.setIcon(ima.icon('italic'))
cb_italic.setToolTip(_("Italic"))
self.scedits[(clayout, cb_bold, cb_italic)] = (option, default)
if without_layout:
return label, clayout, cb_bold, cb_italic
layout = QHBoxLayout()
layout.addWidget(label)
layout.addLayout(clayout)
layout.addSpacing(10)
layout.addWidget(cb_bold)
layout.addWidget(cb_italic)
layout.addStretch(1)
layout.setContentsMargins(0, 0, 0, 0)
widget = QWidget(self)
widget.setLayout(layout)
return widget
示例12: set_user_env
def set_user_env(reg, parent=None):
"""Set HKCU (current user) environment variables"""
reg = listdict2envdict(reg)
types = dict()
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Environment")
for name in reg:
try:
_x, types[name] = winreg.QueryValueEx(key, name)
except WindowsError:
types[name] = winreg.REG_EXPAND_SZ
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Environment", 0,
winreg.KEY_SET_VALUE)
for name in reg:
winreg.SetValueEx(key, name, 0, types[name], reg[name])
try:
from win32gui import SendMessageTimeout
from win32con import (HWND_BROADCAST, WM_SETTINGCHANGE,
SMTO_ABORTIFHUNG)
SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0,
"Environment", SMTO_ABORTIFHUNG, 5000)
except ImportError:
QMessageBox.warning(parent, _("Warning"),
_("Module <b>pywin32 was not found</b>.<br>"
"Please restart this Windows <i>session</i> "
"(not the computer) for changes to take effect."))
示例13: _sel_to_text
def _sel_to_text(self, cell_range):
"""Copy an array portion to a unicode string"""
if not cell_range:
return
row_min, row_max, col_min, col_max = get_idx_rect(cell_range)
if col_min == 0 and col_max == (self.model().cols_loaded-1):
# we've selected a whole column. It isn't possible to
# select only the first part of a column without loading more,
# so we can treat it as intentional and copy the whole thing
col_max = self.model().total_cols-1
if row_min == 0 and row_max == (self.model().rows_loaded-1):
row_max = self.model().total_rows-1
_data = self.model().get_data()
if PY3:
output = io.BytesIO()
else:
output = io.StringIO()
try:
np.savetxt(output, _data[row_min:row_max+1, col_min:col_max+1],
delimiter='\t', fmt=self.model().get_format())
except:
QMessageBox.warning(self, _("Warning"),
_("It was not possible to copy values for "
"this array"))
return
contents = output.getvalue().decode('utf-8')
output.close()
return contents
示例14: setup_page
def setup_page(self):
# Widgets
self.table = ShortcutsTable(self)
self.finder = ShortcutFinder(self.table, self.table.set_regex)
self.table.finder = self.finder
self.label_finder = QLabel(_('Search: '))
self.reset_btn = QPushButton(_("Reset to default values"))
# Layout
hlayout = QHBoxLayout()
vlayout = QVBoxLayout()
hlayout.addWidget(self.label_finder)
hlayout.addWidget(self.finder)
vlayout.addWidget(self.table)
vlayout.addLayout(hlayout)
vlayout.addWidget(self.reset_btn)
self.setLayout(vlayout)
self.setTabOrder(self.table, self.finder)
self.setTabOrder(self.finder, self.reset_btn)
# Signals and slots
if PYQT5:
# Qt5 'dataChanged' has 3 parameters
self.table.proxy_model.dataChanged.connect(
lambda i1, i2, roles, opt='': self.has_been_modified(opt))
else:
self.table.proxy_model.dataChanged.connect(
lambda i1, i2, opt='': self.has_been_modified(opt))
self.reset_btn.clicked.connect(self.reset_to_default)
示例15: setup
def setup(self, fname):
"""Setup Run Configuration dialog with filename *fname*"""
combo_label = QLabel(_("Select a run configuration:"))
self.combo = QComboBox()
self.combo.setMaxVisibleItems(20)
self.combo.setSizeAdjustPolicy(QComboBox.AdjustToMinimumContentsLength)
self.combo.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
self.stack = QStackedWidget()
configurations = _get_run_configurations()
for index, (filename, options) in enumerate(configurations):
if fname == filename:
break
else:
# There is no run configuration for script *fname*:
# creating a temporary configuration that will be kept only if
# dialog changes are accepted by the user
configurations.insert(0, (fname, RunConfiguration(fname).get()))
index = 0
for filename, options in configurations:
widget = RunConfigOptions(self)
widget.set(options)
self.combo.addItem(filename)
self.stack.addWidget(widget)
self.combo.currentIndexChanged.connect(self.stack.setCurrentIndex)
self.combo.setCurrentIndex(index)
self.add_widgets(combo_label, self.combo, 10, self.stack)
self.add_button_box(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
self.setWindowTitle(_("Run configuration per file"))