def add_history(self, filename): """ Create a history tab for `filename`. Parameters ---------- filename: str History filename. """ filename = encoding.to_unicode_from_fs(filename) if filename in self.filenames: return # Widgets editor = SimpleCodeEditor(self) # Setup language = 'py' if osp.splitext(filename)[1] == '.py' else 'bat' editor.setup_editor( linenumbers=self.get_conf('line_numbers'), language=language, color_scheme=self.get_conf('selected', section='appearance'), font=self.font, wrap=self.get_conf('wrap'), ) editor.setReadOnly(True) editor.set_text(self.get_filename_text(filename)) editor.set_cursor_position('eof') self.find_widget.set_editor(editor) index = self.tabwidget.addTab(editor, osp.basename(filename)) self.filenames.append(filename) self.editors.append(editor) self.tabwidget.setCurrentIndex(index) self.tabwidget.setTabToolTip(index, filename) # Signals editor.sig_focus_changed.connect(lambda: self.sig_focus_changed.emit())
class PlainText(QWidget): """ Read-only editor widget with find dialog """ # Signals focus_changed = Signal() sig_custom_context_menu_requested = Signal(QPoint) def __init__(self, parent): QWidget.__init__(self, parent) self.editor = None # Read-only simple code editor self.editor = SimpleCodeEditor(self) self.editor.setup_editor( language='py', highlight_current_line=False, linenumbers=False, ) self.editor.sig_focus_changed.connect(self.focus_changed) self.editor.setReadOnly(True) self.editor.setContextMenuPolicy(Qt.CustomContextMenu) # 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) self.editor.customContextMenuRequested.connect( self.sig_custom_context_menu_requested) def set_font(self, font, color_scheme=None): """Set font""" self.editor.set_color_scheme(color_scheme) self.editor.set_font(font) def set_color_scheme(self, color_scheme): """Set color scheme""" self.editor.set_color_scheme(color_scheme) def set_text(self, text, 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() def set_wrap_mode(self, value): self.editor.toggle_wrap_mode(value) def copy(self): self.editor.copy() def select_all(self): self.editor.selectAll()