novelWriter 2.4.4__py3-none-any.whl → 2.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {novelWriter-2.4.4.dist-info → novelWriter-2.5.dist-info}/METADATA +4 -5
- {novelWriter-2.4.4.dist-info → novelWriter-2.5.dist-info}/RECORD +121 -111
- {novelWriter-2.4.4.dist-info → novelWriter-2.5.dist-info}/WHEEL +1 -1
- novelwriter/__init__.py +33 -39
- novelwriter/assets/i18n/nw_de_DE.qm +0 -0
- novelwriter/assets/i18n/nw_en_US.qm +0 -0
- novelwriter/assets/i18n/nw_es_419.qm +0 -0
- novelwriter/assets/i18n/nw_fr_FR.qm +0 -0
- novelwriter/assets/i18n/nw_it_IT.qm +0 -0
- novelwriter/assets/i18n/nw_ja_JP.qm +0 -0
- novelwriter/assets/i18n/nw_nb_NO.qm +0 -0
- novelwriter/assets/i18n/nw_nl_NL.qm +0 -0
- novelwriter/assets/i18n/nw_pl_PL.qm +0 -0
- novelwriter/assets/i18n/nw_pt_BR.qm +0 -0
- novelwriter/assets/i18n/nw_zh_CN.qm +0 -0
- novelwriter/assets/i18n/project_en_GB.json +1 -0
- novelwriter/assets/i18n/project_pl_PL.json +116 -0
- novelwriter/assets/icons/typicons_dark/icons.conf +2 -0
- novelwriter/assets/icons/typicons_dark/nw_font.svg +4 -0
- novelwriter/assets/icons/typicons_dark/nw_quote.svg +4 -0
- novelwriter/assets/icons/typicons_light/icons.conf +2 -0
- novelwriter/assets/icons/typicons_light/nw_font.svg +4 -0
- novelwriter/assets/icons/typicons_light/nw_quote.svg +4 -0
- novelwriter/assets/manual.pdf +0 -0
- novelwriter/assets/sample.zip +0 -0
- novelwriter/assets/syntax/cyberpunk_night.conf +5 -3
- novelwriter/assets/syntax/default_dark.conf +32 -18
- novelwriter/assets/syntax/default_light.conf +24 -10
- novelwriter/assets/syntax/dracula.conf +44 -0
- novelwriter/assets/syntax/grey_dark.conf +5 -4
- novelwriter/assets/syntax/grey_light.conf +5 -4
- novelwriter/assets/syntax/light_owl.conf +7 -6
- novelwriter/assets/syntax/night_owl.conf +7 -6
- novelwriter/assets/syntax/snazzy.conf +42 -0
- novelwriter/assets/syntax/solarized_dark.conf +4 -3
- novelwriter/assets/syntax/solarized_light.conf +4 -3
- novelwriter/assets/syntax/tango.conf +27 -11
- novelwriter/assets/syntax/tomorrow.conf +6 -5
- novelwriter/assets/syntax/tomorrow_night.conf +7 -6
- novelwriter/assets/syntax/tomorrow_night_blue.conf +6 -5
- novelwriter/assets/syntax/tomorrow_night_bright.conf +6 -5
- novelwriter/assets/syntax/tomorrow_night_eighties.conf +6 -5
- novelwriter/assets/text/credits_en.htm +52 -41
- novelwriter/assets/themes/cyberpunk_night.conf +3 -0
- novelwriter/assets/themes/default_dark.conf +2 -0
- novelwriter/assets/themes/default_light.conf +2 -0
- novelwriter/assets/themes/dracula.conf +48 -0
- novelwriter/assets/themes/solarized_dark.conf +2 -0
- novelwriter/assets/themes/solarized_light.conf +2 -0
- novelwriter/common.py +33 -12
- novelwriter/config.py +184 -98
- novelwriter/constants.py +47 -35
- novelwriter/core/buildsettings.py +68 -69
- novelwriter/core/coretools.py +5 -23
- novelwriter/core/docbuild.py +52 -40
- novelwriter/core/document.py +3 -5
- novelwriter/core/index.py +115 -45
- novelwriter/core/item.py +8 -19
- novelwriter/core/options.py +2 -4
- novelwriter/core/project.py +37 -61
- novelwriter/core/projectdata.py +1 -3
- novelwriter/core/projectxml.py +12 -15
- novelwriter/core/sessions.py +3 -5
- novelwriter/core/spellcheck.py +4 -9
- novelwriter/core/status.py +211 -164
- novelwriter/core/storage.py +0 -8
- novelwriter/core/tohtml.py +139 -105
- novelwriter/core/tokenizer.py +278 -122
- novelwriter/core/{tomd.py → tomarkdown.py} +97 -78
- novelwriter/core/toodt.py +257 -166
- novelwriter/core/toqdoc.py +419 -0
- novelwriter/core/tree.py +5 -7
- novelwriter/dialogs/about.py +11 -18
- novelwriter/dialogs/docmerge.py +17 -19
- novelwriter/dialogs/docsplit.py +17 -19
- novelwriter/dialogs/editlabel.py +6 -10
- novelwriter/dialogs/preferences.py +200 -164
- novelwriter/dialogs/projectsettings.py +225 -189
- novelwriter/dialogs/quotes.py +12 -9
- novelwriter/dialogs/wordlist.py +9 -15
- novelwriter/enum.py +35 -30
- novelwriter/error.py +8 -15
- novelwriter/extensions/configlayout.py +55 -21
- novelwriter/extensions/eventfilters.py +1 -5
- novelwriter/extensions/modified.py +58 -14
- novelwriter/extensions/novelselector.py +1 -3
- novelwriter/extensions/pagedsidebar.py +9 -12
- novelwriter/extensions/{circularprogress.py → progressbars.py} +30 -8
- novelwriter/extensions/statusled.py +40 -26
- novelwriter/extensions/switch.py +4 -6
- novelwriter/extensions/switchbox.py +7 -6
- novelwriter/extensions/versioninfo.py +3 -9
- novelwriter/gui/doceditor.py +120 -139
- novelwriter/gui/dochighlight.py +231 -186
- novelwriter/gui/docviewer.py +69 -108
- novelwriter/gui/docviewerpanel.py +3 -10
- novelwriter/gui/editordocument.py +1 -3
- novelwriter/gui/itemdetails.py +7 -11
- novelwriter/gui/mainmenu.py +22 -18
- novelwriter/gui/noveltree.py +11 -24
- novelwriter/gui/outline.py +15 -26
- novelwriter/gui/projtree.py +35 -60
- novelwriter/gui/search.py +10 -3
- novelwriter/gui/sidebar.py +2 -6
- novelwriter/gui/statusbar.py +29 -37
- novelwriter/gui/theme.py +26 -48
- novelwriter/guimain.py +162 -160
- novelwriter/shared.py +36 -32
- novelwriter/text/patterns.py +113 -0
- novelwriter/tools/dictionaries.py +10 -20
- novelwriter/tools/lipsum.py +10 -16
- novelwriter/tools/manusbuild.py +9 -11
- novelwriter/tools/manuscript.py +71 -145
- novelwriter/tools/manussettings.py +71 -75
- novelwriter/tools/noveldetails.py +16 -21
- novelwriter/tools/welcome.py +21 -26
- novelwriter/tools/writingstats.py +9 -12
- novelwriter/types.py +49 -4
- novelwriter/extensions/simpleprogress.py +0 -55
- {novelWriter-2.4.4.dist-info → novelWriter-2.5.dist-info}/LICENSE.md +0 -0
- {novelWriter-2.4.4.dist-info → novelWriter-2.5.dist-info}/entry_points.txt +0 -0
- {novelWriter-2.4.4.dist-info → novelWriter-2.5.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,419 @@
|
|
1
|
+
"""
|
2
|
+
novelWriter – QTextDocument Converter
|
3
|
+
=====================================
|
4
|
+
|
5
|
+
File History:
|
6
|
+
Created: 2024-05-21 [2.5b1] ToQTextDocument
|
7
|
+
|
8
|
+
This file is a part of novelWriter
|
9
|
+
Copyright 2018–2024, Veronica Berglyd Olsen
|
10
|
+
|
11
|
+
This program is free software: you can redistribute it and/or modify
|
12
|
+
it under the terms of the GNU General Public License as published by
|
13
|
+
the Free Software Foundation, either version 3 of the License, or
|
14
|
+
(at your option) any later version.
|
15
|
+
|
16
|
+
This program is distributed in the hope that it will be useful, but
|
17
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
18
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
19
|
+
General Public License for more details.
|
20
|
+
|
21
|
+
You should have received a copy of the GNU General Public License
|
22
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
23
|
+
"""
|
24
|
+
from __future__ import annotations
|
25
|
+
|
26
|
+
import logging
|
27
|
+
|
28
|
+
from PyQt5.QtGui import (
|
29
|
+
QColor, QFont, QFontMetricsF, QTextBlockFormat, QTextCharFormat,
|
30
|
+
QTextCursor, QTextDocument
|
31
|
+
)
|
32
|
+
|
33
|
+
from novelwriter.constants import nwHeaders, nwHeadFmt, nwKeyWords, nwLabels, nwUnicode
|
34
|
+
from novelwriter.core.project import NWProject
|
35
|
+
from novelwriter.core.tokenizer import T_Formats, Tokenizer
|
36
|
+
from novelwriter.types import (
|
37
|
+
QtAlignAbsolute, QtAlignCenter, QtAlignJustify, QtAlignLeft, QtAlignRight,
|
38
|
+
QtBlack, QtPageBreakAfter, QtPageBreakBefore, QtTransparent,
|
39
|
+
QtVAlignNormal, QtVAlignSub, QtVAlignSuper
|
40
|
+
)
|
41
|
+
|
42
|
+
logger = logging.getLogger(__name__)
|
43
|
+
|
44
|
+
T_TextStyle = tuple[QTextBlockFormat, QTextCharFormat]
|
45
|
+
|
46
|
+
|
47
|
+
class TextDocumentTheme:
|
48
|
+
text: QColor = QtBlack
|
49
|
+
highlight: QColor = QtTransparent
|
50
|
+
head: QColor = QtBlack
|
51
|
+
comment: QColor = QtBlack
|
52
|
+
note: QColor = QtBlack
|
53
|
+
code: QColor = QtBlack
|
54
|
+
modifier: QColor = QtBlack
|
55
|
+
keyword: QColor = QtBlack
|
56
|
+
tag: QColor = QtBlack
|
57
|
+
optional: QColor = QtBlack
|
58
|
+
dialog: QColor = QtBlack
|
59
|
+
altdialog: QColor = QtBlack
|
60
|
+
|
61
|
+
|
62
|
+
def newBlock(cursor: QTextCursor, bFmt: QTextBlockFormat) -> None:
|
63
|
+
if cursor.position() > 0:
|
64
|
+
cursor.insertBlock(bFmt)
|
65
|
+
else:
|
66
|
+
cursor.setBlockFormat(bFmt)
|
67
|
+
|
68
|
+
|
69
|
+
class ToQTextDocument(Tokenizer):
|
70
|
+
"""Core: QTextDocument Writer
|
71
|
+
|
72
|
+
Extend the Tokenizer class to generate a QTextDocument output. This
|
73
|
+
is intended for usage in the document viewer and build tool preview.
|
74
|
+
"""
|
75
|
+
|
76
|
+
def __init__(self, project: NWProject) -> None:
|
77
|
+
super().__init__(project)
|
78
|
+
self._document = QTextDocument()
|
79
|
+
self._document.setUndoRedoEnabled(False)
|
80
|
+
self._document.setDocumentMargin(0)
|
81
|
+
|
82
|
+
self._theme = TextDocumentTheme()
|
83
|
+
self._styles: dict[int, T_TextStyle] = {}
|
84
|
+
self._usedNotes: dict[str, int] = {}
|
85
|
+
|
86
|
+
self._init = False
|
87
|
+
self._bold = QFont.Weight.Bold
|
88
|
+
self._normal = QFont.Weight.Normal
|
89
|
+
|
90
|
+
return
|
91
|
+
|
92
|
+
def initDocument(self, font: QFont, theme: TextDocumentTheme) -> None:
|
93
|
+
"""Initialise all computed values of the document."""
|
94
|
+
self._textFont = font
|
95
|
+
self._theme = theme
|
96
|
+
|
97
|
+
self._document.setUndoRedoEnabled(False)
|
98
|
+
self._document.blockSignals(True)
|
99
|
+
self._document.clear()
|
100
|
+
self._document.setDefaultFont(self._textFont)
|
101
|
+
|
102
|
+
qMetric = QFontMetricsF(self._textFont)
|
103
|
+
mPx = qMetric.ascent() # 1 em in pixels
|
104
|
+
fPt = self._textFont.pointSizeF()
|
105
|
+
|
106
|
+
# Scaled Sizes
|
107
|
+
# ============
|
108
|
+
|
109
|
+
self._mHead = {
|
110
|
+
self.T_TITLE: (mPx * self._marginTitle[0], mPx * self._marginTitle[1]),
|
111
|
+
self.T_HEAD1: (mPx * self._marginHead1[0], mPx * self._marginHead1[1]),
|
112
|
+
self.T_HEAD2: (mPx * self._marginHead2[0], mPx * self._marginHead2[1]),
|
113
|
+
self.T_HEAD3: (mPx * self._marginHead3[0], mPx * self._marginHead3[1]),
|
114
|
+
self.T_HEAD4: (mPx * self._marginHead4[0], mPx * self._marginHead4[1]),
|
115
|
+
}
|
116
|
+
|
117
|
+
self._sHead = {
|
118
|
+
self.T_TITLE: nwHeaders.H_SIZES.get(0, 1.0) * fPt,
|
119
|
+
self.T_HEAD1: nwHeaders.H_SIZES.get(1, 1.0) * fPt,
|
120
|
+
self.T_HEAD2: nwHeaders.H_SIZES.get(2, 1.0) * fPt,
|
121
|
+
self.T_HEAD3: nwHeaders.H_SIZES.get(3, 1.0) * fPt,
|
122
|
+
self.T_HEAD4: nwHeaders.H_SIZES.get(4, 1.0) * fPt,
|
123
|
+
}
|
124
|
+
|
125
|
+
self._mText = (mPx * self._marginText[0], mPx * self._marginText[1])
|
126
|
+
self._mMeta = (mPx * self._marginMeta[0], mPx * self._marginMeta[1])
|
127
|
+
self._mSep = (mPx * self._marginSep[0], mPx * self._marginSep[1])
|
128
|
+
|
129
|
+
self._mIndent = mPx * 2.0
|
130
|
+
self._tIndent = mPx * self._firstWidth
|
131
|
+
|
132
|
+
# Block Format
|
133
|
+
# ============
|
134
|
+
|
135
|
+
self._blockFmt = QTextBlockFormat()
|
136
|
+
self._blockFmt.setTopMargin(self._mText[0])
|
137
|
+
self._blockFmt.setBottomMargin(self._mText[1])
|
138
|
+
self._blockFmt.setAlignment(QtAlignJustify if self._doJustify else QtAlignAbsolute)
|
139
|
+
self._blockFmt.setLineHeight(
|
140
|
+
100*self._lineHeight, QTextBlockFormat.LineHeightTypes.ProportionalHeight
|
141
|
+
)
|
142
|
+
|
143
|
+
# Character Formats
|
144
|
+
# =================
|
145
|
+
|
146
|
+
self._cText = QTextCharFormat()
|
147
|
+
self._cText.setBackground(QtTransparent)
|
148
|
+
self._cText.setForeground(self._theme.text)
|
149
|
+
|
150
|
+
self._cHead = QTextCharFormat(self._cText)
|
151
|
+
self._cHead.setForeground(self._theme.head)
|
152
|
+
|
153
|
+
self._cComment = QTextCharFormat(self._cText)
|
154
|
+
self._cComment.setForeground(self._theme.comment)
|
155
|
+
|
156
|
+
self._cCommentMod = QTextCharFormat(self._cText)
|
157
|
+
self._cCommentMod.setForeground(self._theme.comment)
|
158
|
+
self._cCommentMod.setFontWeight(self._bold)
|
159
|
+
|
160
|
+
self._cNote = QTextCharFormat(self._cText)
|
161
|
+
self._cNote.setForeground(self._theme.note)
|
162
|
+
|
163
|
+
self._cCode = QTextCharFormat(self._cText)
|
164
|
+
self._cCode.setForeground(self._theme.code)
|
165
|
+
|
166
|
+
self._cModifier = QTextCharFormat(self._cText)
|
167
|
+
self._cModifier.setForeground(self._theme.modifier)
|
168
|
+
self._cModifier.setFontWeight(self._bold)
|
169
|
+
|
170
|
+
self._cKeyword = QTextCharFormat(self._cText)
|
171
|
+
self._cKeyword.setForeground(self._theme.keyword)
|
172
|
+
|
173
|
+
self._cTag = QTextCharFormat(self._cText)
|
174
|
+
self._cTag.setForeground(self._theme.tag)
|
175
|
+
|
176
|
+
self._cOptional = QTextCharFormat(self._cText)
|
177
|
+
self._cOptional.setForeground(self._theme.optional)
|
178
|
+
|
179
|
+
self._init = True
|
180
|
+
|
181
|
+
return
|
182
|
+
|
183
|
+
##
|
184
|
+
# Properties
|
185
|
+
##
|
186
|
+
|
187
|
+
@property
|
188
|
+
def document(self) -> QTextDocument:
|
189
|
+
"""Return the document."""
|
190
|
+
return self._document
|
191
|
+
|
192
|
+
##
|
193
|
+
# Class Methods
|
194
|
+
##
|
195
|
+
|
196
|
+
def doConvert(self) -> None:
|
197
|
+
"""Write text tokens into the document."""
|
198
|
+
if not self._init:
|
199
|
+
return
|
200
|
+
|
201
|
+
self._document.blockSignals(True)
|
202
|
+
cursor = QTextCursor(self._document)
|
203
|
+
cursor.movePosition(QTextCursor.MoveOperation.End)
|
204
|
+
|
205
|
+
for tType, nHead, tText, tFormat, tStyle in self._tokens:
|
206
|
+
|
207
|
+
# Styles
|
208
|
+
bFmt = QTextBlockFormat(self._blockFmt)
|
209
|
+
if tStyle is not None:
|
210
|
+
if tStyle & self.A_LEFT:
|
211
|
+
bFmt.setAlignment(QtAlignLeft)
|
212
|
+
elif tStyle & self.A_RIGHT:
|
213
|
+
bFmt.setAlignment(QtAlignRight)
|
214
|
+
elif tStyle & self.A_CENTRE:
|
215
|
+
bFmt.setAlignment(QtAlignCenter)
|
216
|
+
elif tStyle & self.A_JUSTIFY:
|
217
|
+
bFmt.setAlignment(QtAlignJustify)
|
218
|
+
|
219
|
+
if tStyle & self.A_PBB:
|
220
|
+
bFmt.setPageBreakPolicy(QtPageBreakBefore)
|
221
|
+
if tStyle & self.A_PBA:
|
222
|
+
bFmt.setPageBreakPolicy(QtPageBreakAfter)
|
223
|
+
|
224
|
+
if tStyle & self.A_Z_BTMMRG:
|
225
|
+
bFmt.setBottomMargin(0.0)
|
226
|
+
if tStyle & self.A_Z_TOPMRG:
|
227
|
+
bFmt.setTopMargin(0.0)
|
228
|
+
|
229
|
+
if tStyle & self.A_IND_L:
|
230
|
+
bFmt.setLeftMargin(self._mIndent)
|
231
|
+
if tStyle & self.A_IND_R:
|
232
|
+
bFmt.setRightMargin(self._mIndent)
|
233
|
+
if tStyle & self.A_IND_T:
|
234
|
+
bFmt.setTextIndent(self._tIndent)
|
235
|
+
|
236
|
+
if tType == self.T_TEXT:
|
237
|
+
newBlock(cursor, bFmt)
|
238
|
+
self._insertFragments(tText, tFormat, cursor, self._cText)
|
239
|
+
|
240
|
+
elif tType in self.L_HEADINGS:
|
241
|
+
bFmt, cFmt = self._genHeadStyle(tType, nHead, bFmt)
|
242
|
+
newBlock(cursor, bFmt)
|
243
|
+
cursor.insertText(tText.replace(nwHeadFmt.BR, "\n"), cFmt)
|
244
|
+
|
245
|
+
elif tType == self.T_SEP:
|
246
|
+
sFmt = QTextBlockFormat(bFmt)
|
247
|
+
sFmt.setTopMargin(self._mSep[0])
|
248
|
+
sFmt.setBottomMargin(self._mSep[1])
|
249
|
+
newBlock(cursor, sFmt)
|
250
|
+
cursor.insertText(tText, self._cText)
|
251
|
+
|
252
|
+
elif tType == self.T_SKIP:
|
253
|
+
newBlock(cursor, bFmt)
|
254
|
+
cursor.insertText(nwUnicode.U_NBSP, self._cText)
|
255
|
+
|
256
|
+
elif tType in self.L_SUMMARY and self._doSynopsis:
|
257
|
+
newBlock(cursor, bFmt)
|
258
|
+
modifier = self._localLookup(
|
259
|
+
"Short Description" if tType == self.T_SHORT else "Synopsis"
|
260
|
+
)
|
261
|
+
cursor.insertText(f"{modifier}: ", self._cModifier)
|
262
|
+
self._insertFragments(tText, tFormat, cursor, self._cNote)
|
263
|
+
|
264
|
+
elif tType == self.T_COMMENT and self._doComments:
|
265
|
+
newBlock(cursor, bFmt)
|
266
|
+
modifier = self._localLookup("Comment")
|
267
|
+
cursor.insertText(f"{modifier}: ", self._cCommentMod)
|
268
|
+
self._insertFragments(tText, tFormat, cursor, self._cComment)
|
269
|
+
|
270
|
+
elif tType == self.T_KEYWORD and self._doKeywords:
|
271
|
+
newBlock(cursor, bFmt)
|
272
|
+
self._insertKeywords(tText, cursor)
|
273
|
+
|
274
|
+
self._document.blockSignals(False)
|
275
|
+
|
276
|
+
return
|
277
|
+
|
278
|
+
def appendFootnotes(self) -> None:
|
279
|
+
"""Append the footnotes in the buffer."""
|
280
|
+
if self._usedNotes:
|
281
|
+
self._document.blockSignals(True)
|
282
|
+
|
283
|
+
cursor = QTextCursor(self._document)
|
284
|
+
cursor.movePosition(QTextCursor.MoveOperation.End)
|
285
|
+
|
286
|
+
bFmt, cFmt = self._genHeadStyle(self.T_HEAD4, -1, self._blockFmt)
|
287
|
+
newBlock(cursor, bFmt)
|
288
|
+
cursor.insertText(self._localLookup("Footnotes"), cFmt)
|
289
|
+
|
290
|
+
for key, index in self._usedNotes.items():
|
291
|
+
if content := self._footnotes.get(key):
|
292
|
+
cFmt = QTextCharFormat(self._cCode)
|
293
|
+
cFmt.setAnchor(True)
|
294
|
+
cFmt.setAnchorNames([f"footnote_{index}"])
|
295
|
+
newBlock(cursor, self._blockFmt)
|
296
|
+
cursor.insertText(f"{index}. ", cFmt)
|
297
|
+
self._insertFragments(*content, cursor, self._cText)
|
298
|
+
|
299
|
+
self._document.blockSignals(False)
|
300
|
+
|
301
|
+
return
|
302
|
+
|
303
|
+
##
|
304
|
+
# Internal Functions
|
305
|
+
##
|
306
|
+
|
307
|
+
def _insertFragments(
|
308
|
+
self, text: str, tFmt: T_Formats, cursor: QTextCursor, dFmt: QTextCharFormat
|
309
|
+
) -> None:
|
310
|
+
"""Apply formatting tags to text."""
|
311
|
+
cFmt = QTextCharFormat(dFmt)
|
312
|
+
start = 0
|
313
|
+
temp = text.replace("\n", nwUnicode.U_LSEP)
|
314
|
+
for pos, fmt, data in tFmt:
|
315
|
+
|
316
|
+
# Insert buffer with previous format
|
317
|
+
cursor.insertText(temp[start:pos], cFmt)
|
318
|
+
|
319
|
+
# Construct next format
|
320
|
+
if fmt == self.FMT_B_B:
|
321
|
+
cFmt.setFontWeight(self._bold)
|
322
|
+
elif fmt == self.FMT_B_E:
|
323
|
+
cFmt.setFontWeight(self._normal)
|
324
|
+
elif fmt == self.FMT_I_B:
|
325
|
+
cFmt.setFontItalic(True)
|
326
|
+
elif fmt == self.FMT_I_E:
|
327
|
+
cFmt.setFontItalic(False)
|
328
|
+
elif fmt == self.FMT_D_B:
|
329
|
+
cFmt.setFontStrikeOut(True)
|
330
|
+
elif fmt == self.FMT_D_E:
|
331
|
+
cFmt.setFontStrikeOut(False)
|
332
|
+
elif fmt == self.FMT_U_B:
|
333
|
+
cFmt.setFontUnderline(True)
|
334
|
+
elif fmt == self.FMT_U_E:
|
335
|
+
cFmt.setFontUnderline(False)
|
336
|
+
elif fmt == self.FMT_M_B:
|
337
|
+
cFmt.setBackground(self._theme.highlight)
|
338
|
+
elif fmt == self.FMT_M_E:
|
339
|
+
cFmt.setBackground(QtTransparent)
|
340
|
+
elif fmt == self.FMT_SUP_B:
|
341
|
+
cFmt.setVerticalAlignment(QtVAlignSuper)
|
342
|
+
elif fmt == self.FMT_SUP_E:
|
343
|
+
cFmt.setVerticalAlignment(QtVAlignNormal)
|
344
|
+
elif fmt == self.FMT_SUB_B:
|
345
|
+
cFmt.setVerticalAlignment(QtVAlignSub)
|
346
|
+
elif fmt == self.FMT_SUB_E:
|
347
|
+
cFmt.setVerticalAlignment(QtVAlignNormal)
|
348
|
+
elif fmt == self.FMT_DL_B:
|
349
|
+
cFmt.setForeground(self._theme.dialog)
|
350
|
+
elif fmt == self.FMT_DL_E:
|
351
|
+
cFmt.setForeground(self._theme.text)
|
352
|
+
elif fmt == self.FMT_ADL_B:
|
353
|
+
cFmt.setForeground(self._theme.altdialog)
|
354
|
+
elif fmt == self.FMT_ADL_E:
|
355
|
+
cFmt.setForeground(self._theme.text)
|
356
|
+
elif fmt == self.FMT_FNOTE:
|
357
|
+
xFmt = QTextCharFormat(self._cCode)
|
358
|
+
xFmt.setVerticalAlignment(QtVAlignSuper)
|
359
|
+
if data in self._footnotes:
|
360
|
+
index = len(self._usedNotes) + 1
|
361
|
+
self._usedNotes[data] = index
|
362
|
+
xFmt.setAnchor(True)
|
363
|
+
xFmt.setAnchorHref(f"#footnote_{index}")
|
364
|
+
xFmt.setFontUnderline(True)
|
365
|
+
cursor.insertText(f"[{index}]", xFmt)
|
366
|
+
else:
|
367
|
+
cursor.insertText("[ERR]", cFmt)
|
368
|
+
|
369
|
+
# Move pos for next pass
|
370
|
+
start = pos
|
371
|
+
|
372
|
+
# Insert whatever is left in the buffer
|
373
|
+
cursor.insertText(temp[start:], cFmt)
|
374
|
+
|
375
|
+
return
|
376
|
+
|
377
|
+
def _insertKeywords(self, text: str, cursor: QTextCursor) -> None:
|
378
|
+
"""Apply Markdown formatting to keywords."""
|
379
|
+
valid, bits, _ = self._project.index.scanThis("@"+text)
|
380
|
+
if valid and bits:
|
381
|
+
key = f"{self._localLookup(nwLabels.KEY_NAME[bits[0]])}: "
|
382
|
+
cursor.insertText(key, self._cKeyword)
|
383
|
+
if (num := len(bits)) > 1:
|
384
|
+
if bits[0] == nwKeyWords.TAG_KEY:
|
385
|
+
one, two = self._project.index.parseValue(bits[1])
|
386
|
+
cFmt = QTextCharFormat(self._cTag)
|
387
|
+
cFmt.setAnchor(True)
|
388
|
+
cFmt.setAnchorNames([f"tag_{one}".lower()])
|
389
|
+
cursor.insertText(one, cFmt)
|
390
|
+
if two:
|
391
|
+
cursor.insertText(" | ", self._cText)
|
392
|
+
cursor.insertText(two, self._cOptional)
|
393
|
+
else:
|
394
|
+
for n, bit in enumerate(bits[1:], 2):
|
395
|
+
cFmt = QTextCharFormat(self._cTag)
|
396
|
+
cFmt.setFontUnderline(True)
|
397
|
+
cFmt.setAnchor(True)
|
398
|
+
cFmt.setAnchorHref(f"#tag_{bit}".lower())
|
399
|
+
cursor.insertText(bit, cFmt)
|
400
|
+
if n < num:
|
401
|
+
cursor.insertText(", ", self._cText)
|
402
|
+
return
|
403
|
+
|
404
|
+
def _genHeadStyle(self, hType: int, nHead: int, rFmt: QTextBlockFormat) -> T_TextStyle:
|
405
|
+
"""Generate a heading style set."""
|
406
|
+
mTop, mBottom = self._mHead.get(hType, (0.0, 0.0))
|
407
|
+
|
408
|
+
bFmt = QTextBlockFormat(rFmt)
|
409
|
+
bFmt.setTopMargin(mTop)
|
410
|
+
bFmt.setBottomMargin(mBottom)
|
411
|
+
|
412
|
+
cFmt = QTextCharFormat(self._cText if hType == self.T_TITLE else self._cHead)
|
413
|
+
cFmt.setFontWeight(self._bold)
|
414
|
+
cFmt.setFontPointSize(self._sHead.get(hType, 1.0))
|
415
|
+
if nHead >= 0:
|
416
|
+
cFmt.setAnchorNames([f"{self._handle}:T{nHead:04d}"])
|
417
|
+
cFmt.setAnchor(True)
|
418
|
+
|
419
|
+
return bFmt, cFmt
|
novelwriter/core/tree.py
CHANGED
@@ -23,18 +23,18 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
23
23
|
"""
|
24
24
|
from __future__ import annotations
|
25
25
|
|
26
|
-
import random
|
27
26
|
import logging
|
27
|
+
import random
|
28
28
|
|
29
|
-
from typing import TYPE_CHECKING, Literal, overload
|
30
|
-
from pathlib import Path
|
31
29
|
from collections.abc import Iterable, Iterator
|
30
|
+
from pathlib import Path
|
31
|
+
from typing import TYPE_CHECKING, Literal, overload
|
32
32
|
|
33
|
-
from novelwriter.enum import nwItemClass, nwItemLayout, nwItemType
|
34
|
-
from novelwriter.error import logException
|
35
33
|
from novelwriter.common import isHandle
|
36
34
|
from novelwriter.constants import nwFiles
|
37
35
|
from novelwriter.core.item import NWItem
|
36
|
+
from novelwriter.enum import nwItemClass, nwItemLayout, nwItemType
|
37
|
+
from novelwriter.error import logException
|
38
38
|
|
39
39
|
if TYPE_CHECKING: # pragma: no cover
|
40
40
|
from novelwriter.core.project import NWProject
|
@@ -520,5 +520,3 @@ class NWTree:
|
|
520
520
|
handle = self._makeHandle()
|
521
521
|
|
522
522
|
return handle
|
523
|
-
|
524
|
-
# END Class NWTree
|
novelwriter/dialogs/about.py
CHANGED
@@ -27,20 +27,20 @@ import logging
|
|
27
27
|
|
28
28
|
from PyQt5.QtGui import QCloseEvent, QColor
|
29
29
|
from PyQt5.QtWidgets import (
|
30
|
-
|
31
|
-
QWidget
|
30
|
+
QDialogButtonBox, QHBoxLayout, QLabel, QTextBrowser, QVBoxLayout, QWidget
|
32
31
|
)
|
33
32
|
|
34
33
|
from novelwriter import CONFIG, SHARED
|
35
34
|
from novelwriter.common import cssCol, readTextFile
|
36
35
|
from novelwriter.extensions.configlayout import NColourLabel
|
36
|
+
from novelwriter.extensions.modified import NDialog
|
37
37
|
from novelwriter.extensions.versioninfo import VersionInfoWidget
|
38
38
|
from novelwriter.types import QtAlignRightTop, QtDialogClose
|
39
39
|
|
40
40
|
logger = logging.getLogger(__name__)
|
41
41
|
|
42
42
|
|
43
|
-
class GuiAbout(
|
43
|
+
class GuiAbout(NDialog):
|
44
44
|
|
45
45
|
def __init__(self, parent: QWidget) -> None:
|
46
46
|
super().__init__(parent=parent)
|
@@ -75,7 +75,7 @@ class GuiAbout(QDialog):
|
|
75
75
|
|
76
76
|
# Credits
|
77
77
|
self.lblCredits = NColourLabel(
|
78
|
-
self.tr("Credits"), scale=1.6,
|
78
|
+
self.tr("Credits"), self, scale=1.6, bold=True
|
79
79
|
)
|
80
80
|
|
81
81
|
self.txtCredits = QTextBrowser(self)
|
@@ -85,7 +85,7 @@ class GuiAbout(QDialog):
|
|
85
85
|
|
86
86
|
# Buttons
|
87
87
|
self.btnBox = QDialogButtonBox(QtDialogClose, self)
|
88
|
-
self.btnBox.rejected.connect(self.
|
88
|
+
self.btnBox.rejected.connect(self.reject)
|
89
89
|
|
90
90
|
# Assemble
|
91
91
|
self.innerBox = QVBoxLayout()
|
@@ -106,7 +106,9 @@ class GuiAbout(QDialog):
|
|
106
106
|
|
107
107
|
self.setLayout(self.outerBox)
|
108
108
|
self.setSizeGripEnabled(True)
|
109
|
+
|
109
110
|
self._setStyleSheet()
|
111
|
+
self._fillCreditsPage()
|
110
112
|
|
111
113
|
logger.debug("Ready: GuiAbout")
|
112
114
|
|
@@ -116,11 +118,6 @@ class GuiAbout(QDialog):
|
|
116
118
|
logger.debug("Delete: GuiAbout")
|
117
119
|
return
|
118
120
|
|
119
|
-
def populateGUI(self) -> None:
|
120
|
-
"""Populate tabs with text."""
|
121
|
-
self._fillCreditsPage()
|
122
|
-
return
|
123
|
-
|
124
121
|
##
|
125
122
|
# Events
|
126
123
|
##
|
@@ -128,7 +125,7 @@ class GuiAbout(QDialog):
|
|
128
125
|
def closeEvent(self, event: QCloseEvent) -> None:
|
129
126
|
"""Capture the close event and perform cleanup."""
|
130
127
|
event.accept()
|
131
|
-
self.
|
128
|
+
self.softDelete()
|
132
129
|
return
|
133
130
|
|
134
131
|
##
|
@@ -137,20 +134,16 @@ class GuiAbout(QDialog):
|
|
137
134
|
|
138
135
|
def _fillCreditsPage(self) -> None:
|
139
136
|
"""Load the content for the Credits page."""
|
140
|
-
|
141
|
-
|
142
|
-
if docText:
|
143
|
-
self.txtCredits.setHtml(docText)
|
137
|
+
if html := readTextFile(CONFIG.assetPath("text") / "credits_en.htm"):
|
138
|
+
self.txtCredits.setHtml(html)
|
144
139
|
else:
|
145
140
|
self.txtCredits.setHtml("Error loading credits text ...")
|
146
141
|
return
|
147
142
|
|
148
143
|
def _setStyleSheet(self) -> None:
|
149
|
-
"""Set stylesheet
|
144
|
+
"""Set stylesheet text document."""
|
150
145
|
baseCol = cssCol(self.palette().window().color())
|
151
146
|
self.txtCredits.setStyleSheet(
|
152
147
|
f"QTextBrowser {{border: none; background: {baseCol};}} "
|
153
148
|
)
|
154
149
|
return
|
155
|
-
|
156
|
-
# END Class GuiAbout
|
novelwriter/dialogs/docmerge.py
CHANGED
@@ -27,21 +27,21 @@ from __future__ import annotations
|
|
27
27
|
import logging
|
28
28
|
|
29
29
|
from PyQt5.QtCore import Qt, pyqtSlot
|
30
|
-
from PyQt5.QtGui import QCloseEvent
|
31
30
|
from PyQt5.QtWidgets import (
|
32
|
-
QAbstractItemView,
|
33
|
-
|
31
|
+
QAbstractItemView, QDialogButtonBox, QGridLayout, QLabel, QListWidget,
|
32
|
+
QListWidgetItem, QVBoxLayout, QWidget
|
34
33
|
)
|
35
34
|
|
36
35
|
from novelwriter import CONFIG, SHARED
|
37
|
-
from novelwriter.extensions.switch import NSwitch
|
38
36
|
from novelwriter.extensions.configlayout import NColourLabel
|
39
|
-
from novelwriter.
|
37
|
+
from novelwriter.extensions.modified import NDialog
|
38
|
+
from novelwriter.extensions.switch import NSwitch
|
39
|
+
from novelwriter.types import QtAccepted, QtDialogCancel, QtDialogOk, QtDialogReset, QtUserRole
|
40
40
|
|
41
41
|
logger = logging.getLogger(__name__)
|
42
42
|
|
43
43
|
|
44
|
-
class GuiDocMerge(
|
44
|
+
class GuiDocMerge(NDialog):
|
45
45
|
|
46
46
|
D_HANDLE = QtUserRole
|
47
47
|
|
@@ -58,7 +58,7 @@ class GuiDocMerge(QDialog):
|
|
58
58
|
self.headLabel.setFont(SHARED.theme.guiFontB)
|
59
59
|
self.helpLabel = NColourLabel(
|
60
60
|
self.tr("Drag and drop items to change the order, or uncheck to exclude."),
|
61
|
-
SHARED.theme.helpText,
|
61
|
+
self, color=SHARED.theme.helpText, wrap=True
|
62
62
|
)
|
63
63
|
|
64
64
|
iPx = SHARED.theme.baseIconHeight
|
@@ -117,7 +117,7 @@ class GuiDocMerge(QDialog):
|
|
117
117
|
logger.debug("Delete: GuiDocMerge")
|
118
118
|
return
|
119
119
|
|
120
|
-
def
|
120
|
+
def data(self) -> dict:
|
121
121
|
"""Return the user's choices."""
|
122
122
|
finalItems = []
|
123
123
|
for i in range(self.listBox.count()):
|
@@ -130,15 +130,15 @@ class GuiDocMerge(QDialog):
|
|
130
130
|
|
131
131
|
return self._data
|
132
132
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
return
|
133
|
+
@classmethod
|
134
|
+
def getData(cls, parent: QWidget, handle: str, items: list[str]) -> tuple[dict, bool]:
|
135
|
+
"""Pop the dialog and return the result."""
|
136
|
+
cls = GuiDocMerge(parent, handle, items)
|
137
|
+
cls.exec()
|
138
|
+
data = cls.data()
|
139
|
+
accepted = cls.result() == QtAccepted
|
140
|
+
cls.softDelete()
|
141
|
+
return data, accepted
|
142
142
|
|
143
143
|
##
|
144
144
|
# Private Slots
|
@@ -182,5 +182,3 @@ class GuiDocMerge(QDialog):
|
|
182
182
|
self.listBox.addItem(newItem)
|
183
183
|
|
184
184
|
return
|
185
|
-
|
186
|
-
# END Class GuiDocMerge
|
novelwriter/dialogs/docsplit.py
CHANGED
@@ -27,21 +27,21 @@ from __future__ import annotations
|
|
27
27
|
import logging
|
28
28
|
|
29
29
|
from PyQt5.QtCore import pyqtSlot
|
30
|
-
from PyQt5.QtGui import QCloseEvent
|
31
30
|
from PyQt5.QtWidgets import (
|
32
|
-
QAbstractItemView, QComboBox,
|
33
|
-
|
31
|
+
QAbstractItemView, QComboBox, QDialogButtonBox, QGridLayout, QLabel,
|
32
|
+
QListWidget, QListWidgetItem, QVBoxLayout, QWidget
|
34
33
|
)
|
35
34
|
|
36
35
|
from novelwriter import CONFIG, SHARED
|
37
|
-
from novelwriter.extensions.switch import NSwitch
|
38
36
|
from novelwriter.extensions.configlayout import NColourLabel
|
39
|
-
from novelwriter.
|
37
|
+
from novelwriter.extensions.modified import NDialog
|
38
|
+
from novelwriter.extensions.switch import NSwitch
|
39
|
+
from novelwriter.types import QtAccepted, QtDialogCancel, QtDialogOk, QtUserRole
|
40
40
|
|
41
41
|
logger = logging.getLogger(__name__)
|
42
42
|
|
43
43
|
|
44
|
-
class GuiDocSplit(
|
44
|
+
class GuiDocSplit(NDialog):
|
45
45
|
|
46
46
|
LINE_ROLE = QtUserRole
|
47
47
|
LEVEL_ROLE = QtUserRole + 1
|
@@ -62,7 +62,7 @@ class GuiDocSplit(QDialog):
|
|
62
62
|
self.headLabel.setFont(SHARED.theme.guiFontB)
|
63
63
|
self.helpLabel = NColourLabel(
|
64
64
|
self.tr("Select the maximum level to split into files."),
|
65
|
-
SHARED.theme.helpText,
|
65
|
+
self, color=SHARED.theme.helpText, wrap=True
|
66
66
|
)
|
67
67
|
|
68
68
|
# Values
|
@@ -145,7 +145,7 @@ class GuiDocSplit(QDialog):
|
|
145
145
|
logger.debug("Delete: GuiDocSplit")
|
146
146
|
return
|
147
147
|
|
148
|
-
def
|
148
|
+
def data(self) -> tuple[dict, list[str]]:
|
149
149
|
"""Return the user's choices. Also save the users options for
|
150
150
|
the next time the dialog is used.
|
151
151
|
"""
|
@@ -178,15 +178,15 @@ class GuiDocSplit(QDialog):
|
|
178
178
|
|
179
179
|
return self._data, self._text
|
180
180
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
return
|
181
|
+
@classmethod
|
182
|
+
def getData(cls, parent: QWidget, handle: str) -> tuple[dict, list[str], bool]:
|
183
|
+
"""Pop the dialog and return the result."""
|
184
|
+
cls = GuiDocSplit(parent, handle)
|
185
|
+
cls.exec()
|
186
|
+
data, text = cls.data()
|
187
|
+
accepted = cls.result() == QtAccepted
|
188
|
+
cls.softDelete()
|
189
|
+
return data, text, accepted
|
190
190
|
|
191
191
|
##
|
192
192
|
# Private Slots
|
@@ -257,5 +257,3 @@ class GuiDocSplit(QDialog):
|
|
257
257
|
self.listBox.addItem(newItem)
|
258
258
|
|
259
259
|
return
|
260
|
-
|
261
|
-
# END Class GuiDocSplit
|