def __init__(self, parent, filename, actions=None, ini_message=None): """ Constructor. Parameters ---------- parent : QWidget Parent of the widget under construction. filename : str File name of the notebook. actions : list of (QAction or QMenu or None) or None, optional Actions to be added to the context menu of the widget under construction. The default is None, meaning that no actions will be added. ini_message : str or None, optional HTML to be initially displayed in the widget. The default is None, meaning that an empty page is displayed initially. """ super().__init__(parent) if os.name == 'nt': filename = filename.replace('/', '\\') self.filename = filename self.file_url = None self.server_url = None self.path = None self.notebookwidget = NotebookWidget(self, actions) if ini_message: self.notebookwidget.show_message(ini_message) self.static = True else: self.notebookwidget.show_blank() self.static = False self.find_widget = FindReplace(self) self.find_widget.set_editor(self.notebookwidget) self.find_widget.hide() layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self.notebookwidget) layout.addWidget(self.find_widget) self.setLayout(layout)
def __init__(self, name, plugin, parent=None): super().__init__(name, plugin, parent) logger.info("Initializing...") # Traceback MessageBox self.error_traceback = '' self.dismiss_error = False # Widgets self.dialog_manager = DialogManager() self.error_dlg = None self.shell = InternalShell( # TODO: Move to use SpyderWidgetMixin? parent=parent, namespace=self.get_conf('namespace', {}), commands=self.get_conf('commands', []), message=self.get_conf('message', ''), max_line_count=self.get_conf('max_line_count'), profile=self.get_conf('profile', False), multithreaded=self.get_conf('multithreaded', False), ) self.find_widget = FindReplace(self) # Setup self.setAcceptDrops(True) self.find_widget.set_editor(self.shell) self.find_widget.hide() self.shell.toggle_wrap_mode(self.get_conf('wrap')) # Layout layout = QVBoxLayout() layout.addWidget(self.shell) layout.addWidget(self.find_widget) self.setLayout(layout) # Signals self.shell.sig_help_requested.connect(self.sig_help_requested) self.shell.sig_exception_occurred.connect(self.handle_exception) self.shell.sig_focus_changed.connect(self.sig_focus_changed) self.shell.sig_go_to_error_requested.connect(self.go_to_error) self.shell.sig_redirect_stdio_requested.connect( self.sig_redirect_stdio_requested) self.shell.sig_refreshed.connect(self.sig_refreshed) self.shell.sig_show_status_requested.connect( lambda msg: self.sig_show_status_message.emit(msg, 0))
def __init__(self, parent=None, namespace=None, commands=[], message=None, exitfunc=None, profile=False, multithreaded=False): if PYQT5: SpyderPluginWidget.__init__(self, parent, main = parent) else: SpyderPluginWidget.__init__(self, parent) debug_print(" ..internal console: 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 layout = QVBoxLayout() 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)
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
def __init__(self, name=None, plugin=None, parent=None, options=DEFAULT_OPTIONS): super().__init__(name, plugin, parent=parent, options=options) self._is_running = False self.home_url = None self.server = None # Widgets self.label = QLabel(_("Package:")) self.url_combo = UrlComboBox(self) self.webview = WebView(self, handle_links=self.get_option('handle_links')) self.find_widget = FindReplace(self) # Setup self.find_widget.set_editor(self.webview) self.find_widget.hide() self.url_combo.setMaxCount(self.get_option('max_history_entries')) tip = _('Write a package name here, e.g. pandas') self.url_combo.lineEdit().setPlaceholderText(tip) self.url_combo.lineEdit().setToolTip(tip) self.webview.setup() self.webview.set_zoom_factor(self.get_option('zoom_factor')) # Layout spacing = 10 layout = QVBoxLayout() layout.addWidget(self.webview) layout.addSpacing(spacing) layout.addWidget(self.find_widget) layout.addSpacing(int(spacing / 2)) self.setLayout(layout) # Signals self.url_combo.valid.connect( lambda x: self._handle_url_combo_activation()) self.webview.loadStarted.connect(self._start) self.webview.loadFinished.connect(self._finish) self.webview.titleChanged.connect(self.setWindowTitle) self.webview.urlChanged.connect(self._change_url) if not WEBENGINE: self.webview.iconChanged.connect(self._handle_icon_change)
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 __init__(self, name=None, plugin=None, parent=None): super().__init__(name, plugin, parent=parent) self._is_running = False self.home_url = None self.server = None # Widgets self.label = QLabel(_("Package:")) self.label.ID = PydocBrowserToolbarItems.PackageLabel self.url_combo = UrlComboBox(self, id_=PydocBrowserToolbarItems.UrlCombo) # Setup web view frame self.webview = FrameWebView(self, handle_links=self.get_conf('handle_links')) self.webview.setup() self.webview.set_zoom_factor(self.get_conf('zoom_factor')) self.webview.loadStarted.connect(self._start) self.webview.loadFinished.connect(self._finish) self.webview.titleChanged.connect(self.setWindowTitle) self.webview.urlChanged.connect(self._change_url) if not WEBENGINE: self.webview.iconChanged.connect(self._handle_icon_change) # Setup find widget self.find_widget = FindReplace(self) self.find_widget.set_editor(self.webview) self.find_widget.hide() self.url_combo.setMaxCount(self.get_conf('max_history_entries')) tip = _('Write a package name here, e.g. pandas') self.url_combo.lineEdit().setPlaceholderText(tip) self.url_combo.lineEdit().setToolTip(tip) self.url_combo.valid.connect( lambda x: self._handle_url_combo_activation()) # Layout layout = QVBoxLayout() layout.addWidget(self.webview) layout.addSpacing(1) layout.addWidget(self.find_widget) self.setLayout(layout)
def __init__(self, parent=None): Qt.QSplitter.__init__(self, parent) self.editorstacks = [] self.editorwindows = [] self.menu_actions, self.io_actions = self.createMenuActions() self.find_widget = FindReplace(self, enable_replace=True) self.outlineexplorer = OutlineExplorerWidget(self, show_fullpath=False, show_all_files=False) self.outlineexplorer.edit_goto.connect(self.go_to_file) self.editor_splitter = EditorSplitter(self, self, self.menu_actions, first=True) editor_widgets = Qt.QWidget(self) editor_layout = Qt.QVBoxLayout() editor_layout.setContentsMargins(0, 0, 0, 0) editor_widgets.setLayout(editor_layout) editor_layout.addWidget(self.editor_splitter) editor_layout.addWidget(self.find_widget) self.setContentsMargins(0, 0, 0, 0) self.addWidget(editor_widgets) self.addWidget(self.outlineexplorer) self.setStretchFactor(0, 5) self.setStretchFactor(1, 1) self.toolbar_list = None self.menu_list = None self.setup_window([], []) try: # spyder v3 from spyder.utils.introspection.manager import IntrospectionManager # Set introspector introspector = IntrospectionManager() editorstack = self.editor_splitter.editorstack editorstack.set_introspector(introspector) introspector.set_editor_widget(editorstack) except ImportError: pass # TODO: support introspection with spyder v4
def __init__(self, name, plugin, parent): super().__init__(name, plugin, parent) # Attributes self.editors = [] self.filenames = [] self.tabwidget = None self.dockviewer = None self.wrap_action = None self.linenumbers_action = None self.editors = [] self.filenames = [] self.font = None # Widgets self.tabwidget = Tabs(self) self.find_widget = FindReplace(self) # Setup self.tabwidget.setStyleSheet(self._tabs_stylesheet) self.find_widget.hide() # Layout layout = QVBoxLayout() # TODO: Move this to the tab container directly if sys.platform == 'darwin': tab_container = QWidget(self) tab_container.setObjectName('tab-container') tab_layout = QVBoxLayout(tab_container) tab_layout.setContentsMargins(0, 0, 0, 0) tab_layout.addWidget(self.tabwidget) layout.addWidget(tab_container) else: layout.addWidget(self.tabwidget) layout.addWidget(self.find_widget) self.setLayout(layout) # Signals self.tabwidget.currentChanged.connect(self.refresh) self.tabwidget.move_data.connect(self.move_tab)
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)
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 __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 __init__(self, parent=None, options_button=None, handle_links=True): QWidget.__init__(self, parent) self.home_url = None self.webview = WebView(self, handle_links=handle_links) self.webview.setup() 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) def pageact2btn(prop, icon=None): return action2button(self.webview.pageAction(prop), parent=self.webview, icon=icon) refresh_button = pageact2btn(QWebEnginePage.Reload, icon=ima.icon('refresh')) stop_button = pageact2btn(QWebEnginePage.Stop, icon=ima.icon('stop')) previous_button = pageact2btn(QWebEnginePage.Back, icon=ima.icon('previous')) next_button = pageact2btn(QWebEnginePage.Forward, icon=ima.icon('next')) 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) if options_button: hlayout.addWidget(options_button) layout = create_plugin_layout(hlayout) layout.addWidget(self.webview) layout.addWidget(self.find_widget) self.setLayout(layout)
def __init__(self, parent): if PYQT5: SpyderPluginWidget.__init__(self, parent, main=parent) else: SpyderPluginWidget.__init__(self, parent) self.tabwidget = None self.menu_actions = None self.help = None # Help plugin self.historylog = None # History log plugin self.variableexplorer = None # Variable explorer plugin self.python_count = 0 self.terminal_count = 0 # Python startup file selection if not osp.isfile(self.get_option('pythonstartup', '')): self.set_option('pythonstartup', SCIENTIFIC_STARTUP) # default/custom settings are mutually exclusive: self.set_option('pythonstartup/custom', not self.get_option('pythonstartup/default')) self.shellwidgets = [] self.filenames = [] self.icons = [] self.runfile_args = "" # Initialize plugin self.initialize_plugin() layout = QVBoxLayout() self.tabwidget = Tabs(self, self.menu_actions) if hasattr(self.tabwidget, 'setDocumentMode')\ and not sys.platform == 'darwin': # Don't set document mode to true on OSX because it generates # a crash when the console is detached from the main window # Fixes Issue 561 self.tabwidget.setDocumentMode(True) self.tabwidget.currentChanged.connect(self.refresh_plugin) self.tabwidget.move_data.connect(self.move_tab) self.main.sig_pythonpath_changed.connect(self.set_path) self.tabwidget.set_close_function(self.close_console) 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) # 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) # Accepting drops self.setAcceptDrops(True)
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
def search_codeeditor(lsp_codeeditor, qtbot_module): code_editor, _ = lsp_codeeditor find_replace = FindReplace(None, enable_replace=True) find_replace.set_editor(code_editor) qtbot_module.addWidget(find_replace) return code_editor, find_replace