本文整理汇总了Python中spyder.widgets.findreplace.FindReplace.set_editor方法的典型用法代码示例。如果您正苦于以下问题:Python FindReplace.set_editor方法的具体用法?Python FindReplace.set_editor怎么用?Python FindReplace.set_editor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spyder.widgets.findreplace.FindReplace
的用法示例。
在下文中一共展示了FindReplace.set_editor方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RichText
# 需要导入模块: from spyder.widgets.findreplace import FindReplace [as 别名]
# 或者: from spyder.widgets.findreplace.FindReplace import set_editor [as 别名]
class RichText(QWidget):
"""
WebView widget with find dialog
"""
def __init__(self, parent):
QWidget.__init__(self, parent)
self.webview = FrameWebView(self)
if WEBENGINE:
self.webview.web_widget.page().setBackgroundColor(
QColor(MAIN_BG_COLOR))
else:
self.webview.web_widget.setStyleSheet(
"background:{}".format(MAIN_BG_COLOR))
self.find_widget = FindReplace(self)
self.find_widget.set_editor(self.webview.web_widget)
self.find_widget.hide()
layout = QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
layout.addWidget(self.webview)
layout.addWidget(self.find_widget)
self.setLayout(layout)
def set_font(self, font, fixed_font=None):
"""Set font"""
self.webview.set_font(font, fixed_font=fixed_font)
def set_html(self, html_text, base_url):
"""Set html text"""
self.webview.setHtml(html_text, base_url)
def clear(self):
self.set_html('', self.webview.url())
示例2: RichText
# 需要导入模块: from spyder.widgets.findreplace import FindReplace [as 别名]
# 或者: from spyder.widgets.findreplace.FindReplace import set_editor [as 别名]
class RichText(QWidget):
"""
WebView widget with find dialog
"""
def __init__(self, parent):
QWidget.__init__(self, parent)
self.webview = FrameWebView(self)
self.find_widget = FindReplace(self)
self.find_widget.set_editor(self.webview.web_widget)
self.find_widget.hide()
layout = QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
layout.addWidget(self.webview)
layout.addWidget(self.find_widget)
self.setLayout(layout)
def set_font(self, font, fixed_font=None):
"""Set font"""
self.webview.set_font(font, fixed_font=fixed_font)
def set_html(self, html_text, base_url):
"""Set html text"""
self.webview.setHtml(html_text, base_url)
def clear(self):
self.set_html('', self.webview.url())
示例3: editor_find_replace_bot
# 需要导入模块: from spyder.widgets.findreplace import FindReplace [as 别名]
# 或者: from spyder.widgets.findreplace.FindReplace import set_editor [as 别名]
def editor_find_replace_bot(base_editor_bot):
editor_stack, qtbot = base_editor_bot
text = ('spam bacon\n'
'spam sausage\n'
'spam egg')
finfo = editor_stack.new('spam.py', 'utf-8', text)
find_replace = FindReplace(None, enable_replace=True)
editor_stack.set_find_widget(find_replace)
find_replace.set_editor(finfo.editor)
qtbot.addWidget(editor_stack)
return editor_stack, finfo.editor, find_replace, qtbot
示例4: PlainText
# 需要导入模块: from spyder.widgets.findreplace import FindReplace [as 别名]
# 或者: from spyder.widgets.findreplace.FindReplace import set_editor [as 别名]
class PlainText(QWidget):
"""
Read-only editor widget with find dialog
"""
# Signals
focus_changed = Signal()
def __init__(self, parent):
QWidget.__init__(self, parent)
self.editor = None
# Read-only editor
self.editor = codeeditor.CodeEditor(self)
self.editor.setup_editor(linenumbers=False, language='py',
scrollflagarea=False, edge_line=False)
self.editor.focus_changed.connect(lambda: self.focus_changed.emit())
self.editor.setReadOnly(True)
# Find/replace widget
self.find_widget = FindReplace(self)
self.find_widget.set_editor(self.editor)
self.find_widget.hide()
layout = QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
layout.addWidget(self.editor)
layout.addWidget(self.find_widget)
self.setLayout(layout)
def set_font(self, font, color_scheme=None):
"""Set font"""
self.editor.set_font(font, color_scheme=color_scheme)
def set_color_scheme(self, color_scheme):
"""Set color scheme"""
self.editor.set_color_scheme(color_scheme)
def set_text(self, text, is_code):
self.editor.set_highlight_current_line(is_code)
self.editor.set_occurrence_highlighting(is_code)
if is_code:
self.editor.set_language('py')
else:
self.editor.set_language(None)
self.editor.set_text(text)
self.editor.set_cursor_position('sof')
def clear(self):
self.editor.clear()
示例5: editor_folding_bot
# 需要导入模块: from spyder.widgets.findreplace import FindReplace [as 别名]
# 或者: from spyder.widgets.findreplace.FindReplace import set_editor [as 别名]
def editor_folding_bot(base_editor_bot):
"""
Setup CodeEditor with some text useful for folding related tests.
"""
editor_stack, qtbot = base_editor_bot
text = ('# dummy test file\n'
'class a():\n' # fold-block level-0
' self.b = 1\n'
' print(self.b)\n'
' \n'
)
finfo = editor_stack.new('foo.py', 'utf-8', text)
find_replace = FindReplace(None, enable_replace=True)
editor_stack.set_find_widget(find_replace)
find_replace.set_editor(finfo.editor)
qtbot.addWidget(editor_stack)
return editor_stack, finfo.editor, find_replace, qtbot
示例6: WebBrowser
# 需要导入模块: from spyder.widgets.findreplace import FindReplace [as 别名]
# 或者: from spyder.widgets.findreplace.FindReplace import set_editor [as 别名]
class WebBrowser(QWidget):
"""
Web browser widget
"""
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.home_url = None
self.webview = WebView(self)
self.webview.loadFinished.connect(self.load_finished)
self.webview.titleChanged.connect(self.setWindowTitle)
self.webview.urlChanged.connect(self.url_changed)
home_button = create_toolbutton(self, icon=ima.icon('home'),
tip=_("Home"),
triggered=self.go_home)
zoom_out_button = action2button(self.webview.zoom_out_action)
zoom_in_button = action2button(self.webview.zoom_in_action)
pageact2btn = lambda prop: action2button(self.webview.pageAction(prop),
parent=self.webview)
refresh_button = pageact2btn(QWebEnginePage.Reload)
stop_button = pageact2btn(QWebEnginePage.Stop)
previous_button = pageact2btn(QWebEnginePage.Back)
next_button = pageact2btn(QWebEnginePage.Forward)
stop_button.setEnabled(False)
self.webview.loadStarted.connect(lambda: stop_button.setEnabled(True))
self.webview.loadFinished.connect(lambda: stop_button.setEnabled(False))
progressbar = QProgressBar(self)
progressbar.setTextVisible(False)
progressbar.hide()
self.webview.loadStarted.connect(progressbar.show)
self.webview.loadProgress.connect(progressbar.setValue)
self.webview.loadFinished.connect(lambda _state: progressbar.hide())
label = QLabel(self.get_label())
self.url_combo = UrlComboBox(self)
self.url_combo.valid.connect(self.url_combo_activated)
if not WEBENGINE:
self.webview.iconChanged.connect(self.icon_changed)
self.find_widget = FindReplace(self)
self.find_widget.set_editor(self.webview)
self.find_widget.hide()
find_button = create_toolbutton(self, icon=ima.icon('find'),
tip=_("Find text"),
toggled=self.toggle_find_widget)
self.find_widget.visibility_changed.connect(find_button.setChecked)
hlayout = QHBoxLayout()
for widget in (previous_button, next_button, home_button, find_button,
label, self.url_combo, zoom_out_button, zoom_in_button,
refresh_button, progressbar, stop_button):
hlayout.addWidget(widget)
layout = QVBoxLayout()
layout.addLayout(hlayout)
layout.addWidget(self.webview)
layout.addWidget(self.find_widget)
self.setLayout(layout)
def get_label(self):
"""Return address label text"""
return _("Address:")
def set_home_url(self, text):
"""Set home URL"""
self.home_url = QUrl(text)
def set_url(self, url):
"""Set current URL"""
self.url_changed(url)
self.go_to(url)
def go_to(self, url_or_text):
"""Go to page *address*"""
if is_text_string(url_or_text):
url = QUrl(url_or_text)
else:
url = url_or_text
self.webview.load(url)
@Slot()
def go_home(self):
"""Go to home page"""
if self.home_url is not None:
self.set_url(self.home_url)
def text_to_url(self, text):
"""Convert text address into QUrl object"""
return QUrl(text)
def url_combo_activated(self, valid):
"""Load URL from combo box first item"""
#.........这里部分代码省略.........
示例7: Console
# 需要导入模块: from spyder.widgets.findreplace import FindReplace [as 别名]
# 或者: from spyder.widgets.findreplace.FindReplace import set_editor [as 别名]
class Console(SpyderPluginWidget):
"""
Console widget
"""
CONF_SECTION = 'internal_console'
focus_changed = Signal()
redirect_stdio = Signal(bool)
edit_goto = Signal(str, int, str)
def __init__(self, parent=None, namespace=None, commands=[], message=None,
exitfunc=None, profile=False, multithreaded=False):
SpyderPluginWidget.__init__(self, parent)
logger.info("Initializing...")
self.dialog_manager = DialogManager()
# Shell
light_background = self.get_option('light_background')
self.shell = InternalShell(parent, namespace, commands, message,
self.get_option('max_line_count'),
self.get_plugin_font(), exitfunc, profile,
multithreaded,
light_background=light_background)
self.shell.status.connect(lambda msg: self.show_message.emit(msg, 0))
self.shell.go_to_error.connect(self.go_to_error)
self.shell.focus_changed.connect(lambda: self.focus_changed.emit())
# Redirecting some signals:
self.shell.redirect_stdio.connect(lambda state:
self.redirect_stdio.emit(state))
# Initialize plugin
self.initialize_plugin()
# Find/replace widget
self.find_widget = FindReplace(self)
self.find_widget.set_editor(self.shell)
self.find_widget.hide()
self.register_widget_shortcuts(self.find_widget)
# Main layout
btn_layout = QHBoxLayout()
btn_layout.setAlignment(Qt.AlignLeft)
btn_layout.addStretch()
btn_layout.addWidget(self.options_button, Qt.AlignRight)
layout = create_plugin_layout(btn_layout)
layout.addWidget(self.shell)
layout.addWidget(self.find_widget)
self.setLayout(layout)
# Parameters
self.shell.toggle_wrap_mode(self.get_option('wrap'))
# Accepting drops
self.setAcceptDrops(True)
# Traceback MessageBox
self.error_dlg = None
self.error_traceback = ""
self.dismiss_error = False
#------ Private API --------------------------------------------------------
def set_historylog(self, historylog):
"""Bind historylog instance to this console
Not used anymore since v2.0"""
historylog.add_history(self.shell.history_filename)
self.shell.append_to_history.connect(historylog.append_to_history)
def set_help(self, help_plugin):
"""Bind help instance to this console"""
self.shell.help = help_plugin
#------ SpyderPluginWidget API ---------------------------------------------
def get_plugin_title(self):
"""Return widget title"""
return _('Internal console')
def get_focus_widget(self):
"""
Return the widget to give focus to when
this plugin's dockwidget is raised on top-level
"""
return self.shell
def update_font(self):
"""Update font from Preferences"""
font = self.get_plugin_font()
self.shell.set_font(font)
def closing_plugin(self, cancelable=False):
"""Perform actions before parent main window is closed"""
self.dialog_manager.close_all()
self.shell.exit_interpreter()
return True
def refresh_plugin(self):
pass
def get_plugin_actions(self):
"""Return a list of actions related to plugin"""
#.........这里部分代码省略.........
示例8: HistoryLog
# 需要导入模块: from spyder.widgets.findreplace import FindReplace [as 别名]
# 或者: from spyder.widgets.findreplace.FindReplace import set_editor [as 别名]
class HistoryLog(SpyderPluginWidget):
"""
History log widget
"""
CONF_SECTION = "historylog"
CONFIGWIDGET_CLASS = HistoryConfigPage
focus_changed = Signal()
def __init__(self, parent):
self.tabwidget = None
self.menu_actions = None
self.dockviewer = None
self.wrap_action = None
self.editors = []
self.filenames = []
if PYQT5:
SpyderPluginWidget.__init__(self, parent, main=parent)
else:
SpyderPluginWidget.__init__(self, parent)
# Initialize plugin
self.initialize_plugin()
layout = QVBoxLayout()
self.tabwidget = Tabs(self, self.menu_actions)
self.tabwidget.currentChanged.connect(self.refresh_plugin)
self.tabwidget.move_data.connect(self.move_tab)
if sys.platform == "darwin":
tab_container = QWidget()
tab_container.setObjectName("tab-container")
tab_layout = QHBoxLayout(tab_container)
tab_layout.setContentsMargins(0, 0, 0, 0)
tab_layout.addWidget(self.tabwidget)
layout.addWidget(tab_container)
else:
layout.addWidget(self.tabwidget)
# Menu as corner widget
options_button = create_toolbutton(self, text=_("Options"), icon=ima.icon("tooloptions"))
options_button.setPopupMode(QToolButton.InstantPopup)
menu = QMenu(self)
add_actions(menu, self.menu_actions)
options_button.setMenu(menu)
self.tabwidget.setCornerWidget(options_button)
# Find/replace widget
self.find_widget = FindReplace(self)
self.find_widget.hide()
self.register_widget_shortcuts(self.find_widget)
layout.addWidget(self.find_widget)
self.setLayout(layout)
# ------ SpyderPluginWidget API ---------------------------------------------
def get_plugin_title(self):
"""Return widget title"""
return _("History log")
def get_plugin_icon(self):
"""Return widget icon"""
return ima.icon("history")
def get_focus_widget(self):
"""
Return the widget to give focus to when
this plugin's dockwidget is raised on top-level
"""
return self.tabwidget.currentWidget()
def closing_plugin(self, cancelable=False):
"""Perform actions before parent main window is closed"""
return True
def refresh_plugin(self):
"""Refresh tabwidget"""
if self.tabwidget.count():
editor = self.tabwidget.currentWidget()
else:
editor = None
self.find_widget.set_editor(editor)
def get_plugin_actions(self):
"""Return a list of actions related to plugin"""
history_action = create_action(
self,
_("History..."),
None,
ima.icon("history"),
_("Set history maximum entries"),
triggered=self.change_history_depth,
)
self.wrap_action = create_action(self, _("Wrap lines"), toggled=self.toggle_wrap_mode)
self.wrap_action.setChecked(self.get_option("wrap"))
self.menu_actions = [history_action, self.wrap_action]
return self.menu_actions
#.........这里部分代码省略.........
示例9: HistoryLog
# 需要导入模块: from spyder.widgets.findreplace import FindReplace [as 别名]
# 或者: from spyder.widgets.findreplace.FindReplace import set_editor [as 别名]
class HistoryLog(SpyderPluginWidget):
"""History log plugin."""
CONF_SECTION = 'historylog'
CONFIGWIDGET_CLASS = HistoryConfigPage
focus_changed = Signal()
def __init__(self, parent):
"""Initialize plugin and create History main widget."""
SpyderPluginWidget.__init__(self, parent)
self.tabwidget = None
self.dockviewer = None
self.wrap_action = None
self.linenumbers_action = None
self.editors = []
self.filenames = []
# Initialize plugin actions, toolbutton and general signals
self.initialize_plugin()
layout = QVBoxLayout()
self.tabwidget = Tabs(self, self.plugin_actions)
self.tabwidget.currentChanged.connect(self.refresh_plugin)
self.tabwidget.move_data.connect(self.move_tab)
if sys.platform == 'darwin':
tab_container = QWidget()
tab_container.setObjectName('tab-container')
tab_layout = QHBoxLayout(tab_container)
tab_layout.setContentsMargins(0, 0, 0, 0)
tab_layout.addWidget(self.tabwidget)
layout.addWidget(tab_container)
else:
layout.addWidget(self.tabwidget)
# Menu as corner widget
self.tabwidget.setCornerWidget(self.options_button)
# Find/replace widget
self.find_widget = FindReplace(self)
self.find_widget.hide()
self.register_widget_shortcuts(self.find_widget)
layout.addWidget(self.find_widget)
self.setLayout(layout)
#------ SpyderPluginWidget API ---------------------------------------------
def get_plugin_title(self):
"""Return widget title."""
return _('History log')
def get_plugin_icon(self):
"""Return widget icon."""
return ima.icon('history')
def get_focus_widget(self):
"""
Return the widget to give focus to when
this plugin's dockwidget is raised on top-level
"""
return self.tabwidget.currentWidget()
def closing_plugin(self, cancelable=False):
"""Perform actions before parent main window is closed"""
return True
def refresh_plugin(self):
"""Refresh tabwidget"""
if self.tabwidget.count():
editor = self.tabwidget.currentWidget()
else:
editor = None
self.find_widget.set_editor(editor)
def get_plugin_actions(self):
"""Return a list of actions related to plugin"""
self.history_action = create_action(self, _("History..."),
None, ima.icon('history'),
_("Set history maximum entries"),
triggered=self.change_history_depth)
self.wrap_action = create_action(self, _("Wrap lines"),
toggled=self.toggle_wrap_mode)
self.wrap_action.setChecked( self.get_option('wrap') )
self.linenumbers_action = create_action(
self, _("Show line numbers"), toggled=self.toggle_line_numbers)
self.linenumbers_action.setChecked(self.get_option('line_numbers'))
menu_actions = [self.history_action, self.wrap_action,
self.linenumbers_action]
return menu_actions
def on_first_registration(self):
"""Action to be performed on first plugin registration"""
self.main.tabify_plugins(self.main.ipyconsole, self)
def register_plugin(self):
"""Register plugin in Spyder's main window"""
#.........这里部分代码省略.........
示例10: History
# 需要导入模块: from spyder.widgets.findreplace import FindReplace [as 别名]
# 或者: from spyder.widgets.findreplace.FindReplace import set_editor [as 别名]
class History(QWidget):
"""History plugin main widget."""
focus_changed = Signal()
def __init__(self, parent):
"""Initialize widget and create layout."""
QWidget.__init__(self, parent)
self.editors = []
self.filenames = []
self.tabwidget = None
self.menu_actions = None
layout = QVBoxLayout()
self.tabwidget = Tabs(self, self.menu_actions)
self.tabwidget.currentChanged.connect(self.refresh)
self.tabwidget.move_data.connect(self.move_tab)
if sys.platform == 'darwin':
tab_container = QWidget()
tab_container.setObjectName('tab-container')
tab_layout = QHBoxLayout(tab_container)
tab_layout.setContentsMargins(0, 0, 0, 0)
tab_layout.addWidget(self.tabwidget)
layout.addWidget(tab_container)
else:
layout.addWidget(self.tabwidget)
# Menu as corner widget
options_button = create_toolbutton(self, text=_('Options'),
icon=ima.icon('tooloptions'))
options_button.setPopupMode(QToolButton.InstantPopup)
self.menu = QMenu(self)
options_button.setMenu(self.menu)
self.tabwidget.setCornerWidget(options_button)
# Find/replace widget
self.find_widget = FindReplace(self)
self.find_widget.hide()
layout.addWidget(self.find_widget)
self.setLayout(layout)
def set_menu_actions(self, menu_actions):
"""Add options to corner menu."""
if self.menu_actions is not None:
add_actions(self.menu, self.menu_actions)
def refresh(self):
"""Refresh tabwidget."""
if self.tabwidget.count():
editor = self.tabwidget.currentWidget()
else:
editor = None
self.find_widget.set_editor(editor)
def move_tab(self, index_from, index_to):
"""
Move tab.
(tabs themselves have already been moved by the history.tabwidget)
"""
filename = self.filenames.pop(index_from)
editor = self.editors.pop(index_from)
self.filenames.insert(index_to, filename)
self.editors.insert(index_to, editor)
def add_history(self, filename, color_scheme, font, wrap):
"""
Add new history tab.
Args:
filename (str): file to be loaded in a new tab.
"""
filename = encoding.to_unicode_from_fs(filename)
if filename in self.filenames:
return
editor = codeeditor.CodeEditor(self)
if osp.splitext(filename)[1] == '.py':
language = 'py'
else:
language = 'bat'
editor.setup_editor(linenumbers=False,
language=language,
scrollflagarea=False,
show_class_func_dropdown=False)
editor.focus_changed.connect(lambda: self.focus_changed.emit())
editor.setReadOnly(True)
editor.set_font(font, color_scheme)
editor.toggle_wrap_mode(wrap)
text, _ = encoding.read(filename)
editor.set_text(text)
editor.set_cursor_position('eof')
#.........这里部分代码省略.........
示例11: ExternalConsole
# 需要导入模块: from spyder.widgets.findreplace import FindReplace [as 别名]
# 或者: from spyder.widgets.findreplace.FindReplace import set_editor [as 别名]
#.........这里部分代码省略.........
if self.main.editor is not None:
shellwidget.open_file.connect(self.open_file_in_spyder)
if fname is None:
self.python_count += 1
tab_name = "Python %d" % self.python_count
tab_icon1 = ima.icon('python')
tab_icon2 = ima.icon('python_t')
else:
tab_name = osp.basename(fname)
tab_icon1 = ima.icon('run')
tab_icon2 = ima.icon('terminated')
else:
fname = id(shellwidget)
if os.name == 'nt':
tab_name = _("Command Window")
else:
tab_name = _("Terminal")
self.terminal_count += 1
tab_name += (" %d" % self.terminal_count)
tab_icon1 = ima.icon('cmdprompt')
tab_icon2 = ima.icon('cmdprompt_t')
self.shellwidgets.insert(index, shellwidget)
self.filenames.insert(index, fname)
self.icons.insert(index, (tab_icon1, tab_icon2))
if index is None:
index = self.tabwidget.addTab(shellwidget, tab_name)
else:
self.tabwidget.insertTab(index, shellwidget, tab_name)
shellwidget.started.connect(
lambda sid=id(shellwidget): self.process_started(sid))
shellwidget.sig_finished.connect(
lambda sid=id(shellwidget): self.process_finished(sid))
self.find_widget.set_editor(shellwidget.shell)
self.tabwidget.setTabToolTip(index, fname if wdir is None else wdir)
self.tabwidget.setCurrentIndex(index)
if self.dockwidget and not self.ismaximized:
self.dockwidget.setVisible(True)
self.dockwidget.raise_()
shellwidget.set_icontext_visible(self.get_option('show_icontext'))
# Start process and give focus to console
shellwidget.start_shell()
def open_file_in_spyder(self, fname, lineno):
"""Open file in Spyder's editor from remote process"""
self.main.editor.activateWindow()
self.main.editor.raise_()
self.main.editor.load(fname, lineno)
#------ Private API -------------------------------------------------------
def process_started(self, shell_id):
index = self.get_shell_index_from_id(shell_id)
shell = self.shellwidgets[index]
icon, _icon = self.icons[index]
self.tabwidget.setTabIcon(index, icon)
if self.help is not None:
self.help.set_shell(shell.shell)
if self.variableexplorer is not None:
self.variableexplorer.add_shellwidget(shell)
def process_finished(self, shell_id):
index = self.get_shell_index_from_id(shell_id)
if index is not None:
# Not sure why it happens, but sometimes the shellwidget has