Files
novelWriter/nw/gui/doceditor.py
T
2018-09-29 18:14:44 +02:00

124 lines
4.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*
"""novelWriter GUI Document Editor
novelWriter GUI Document Editor
===================================
Class holding the document editor
File History:
Created: 2018-09-29 [0.1.0]
"""
import logging
import nw
from os import path
from PyQt5.QtWidgets import QWidget, QTextEdit, QVBoxLayout, QFrame, QSplitter, QToolBar, QAction
from PyQt5.QtCore import Qt, QSize
from PyQt5.QtGui import QIcon
logger = logging.getLogger(__name__)
class GuiDocEditor(QWidget):
def __init__(self):
QWidget.__init__(self)
logger.debug("Initialising DocEditor ...")
self.mainConf = nw.CONFIG
self.outerBox = QVBoxLayout()
self.guiEditor = QTextEdit()
# self.outerBox.addWidget(self.guiEditor)
self.setLayout(self.outerBox)
# self.editPane = QFrame()
# self.editPane.setFrameShape(QFrame.StyledPanel)
self.metaPane = QFrame()
self.metaPane.setFrameShape(QFrame.StyledPanel)
self.splitEdit = QSplitter(Qt.Horizontal)
self.splitEdit.addWidget(self.guiEditor)
self.splitEdit.addWidget(self.metaPane)
self.editToolBar = QToolBar()
self._buildTabToolBar()
self.outerBox.addWidget(self.editToolBar)
self.outerBox.addWidget(self.splitEdit)
self.guiEditor.setPlainText("Hello Kitty!")
logger.debug("DocEditor initialisation complete")
return
def _buildTabToolBar(self):
toolBar = self.editToolBar
toolBar.setToolButtonStyle(Qt.ToolButtonIconOnly)
toolBar.setIconSize(QSize(16,16))
# Text > Bold
tbTextBold = QAction(QIcon.fromTheme("format-text-bold"), "Bold (Ctrl+B)", toolBar)
tbTextBold.setShortcut("Ctrl+B")
tbTextBold.setStatusTip("Toggle Selected Text Bold")
toolBar.addAction(tbTextBold)
# Text > Italics
tbTextItalic = QAction(QIcon.fromTheme("format-text-italic"), "Italic (Ctrl+I)", toolBar)
tbTextItalic.setShortcut("Ctrl+I")
tbTextItalic.setStatusTip("Toggle Selected Text Italic")
toolBar.addAction(tbTextItalic)
# Text > Underline
tbTextUnderline = QAction(QIcon.fromTheme("format-text-underline"), "Underline (Ctrl+U)", toolBar)
tbTextUnderline.setShortcut("Ctrl+U")
tbTextUnderline.setStatusTip("Toggle Selected Text Underline")
toolBar.addAction(tbTextUnderline)
# Text > Strikethrough
tbTextStrikethrough = QAction(QIcon.fromTheme("format-text-strikethrough"), "Strikethrough (Ctrl+D)", toolBar)
tbTextStrikethrough.setShortcut("Ctrl+D")
tbTextStrikethrough.setStatusTip("Toggle Selected Text Strikethrough")
toolBar.addAction(tbTextStrikethrough)
# --------------------
toolBar.addSeparator()
# Edit > Cut
tbEditCut = QAction(QIcon.fromTheme("edit-cut"), "Cut (Ctrl+X)", toolBar)
tbEditCut.setShortcut("Ctrl+X")
tbEditCut.setStatusTip("Cut Selected Text")
toolBar.addAction(tbEditCut)
# Edit > Copy
tbEditCopy = QAction(QIcon.fromTheme("edit-copy"), "Copy (Ctrl+C)", toolBar)
tbEditCopy.setShortcut("Ctrl+C")
tbEditCopy.setStatusTip("Copy Selected Text")
toolBar.addAction(tbEditCopy)
# Edit > Paste
tbEditPaste = QAction(QIcon.fromTheme("edit-paste"), "Paste (Ctrl+V)", toolBar)
tbEditPaste.setShortcut("Ctrl+V")
tbEditPaste.setStatusTip("Paste Text")
toolBar.addAction(tbEditPaste)
# --------------------
toolBar.addSeparator()
# Edit > Undo
tbEditUndo = QAction(QIcon.fromTheme("edit-undo"), "Undo (Ctrl+Z)", toolBar)
tbEditUndo.setShortcut("Ctrl+Z")
tbEditUndo.setStatusTip("Undo Last Change")
toolBar.addAction(tbEditUndo)
# Edit > Redo
tbEditRedo = QAction(QIcon.fromTheme("edit-redo"), "Redo (Ctrl+Y)", toolBar)
tbEditRedo.setShortcut("Ctrl+Y")
tbEditRedo.setStatusTip("Revert Last Undo")
toolBar.addAction(tbEditRedo)
return
# END Class GuiDocEditor