Merge branch 'dev' into hard_scene
This commit is contained in:
+19
-2
@@ -30,6 +30,7 @@ import logging
|
||||
|
||||
from time import time
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
|
||||
from PyQt5.QtGui import QFontDatabase
|
||||
from PyQt5.QtCore import (
|
||||
@@ -84,8 +85,11 @@ class Config:
|
||||
self._nwLangPath = self._appPath / "assets" / "i18n"
|
||||
self._qtLangPath = QLibraryInfo.location(QLibraryInfo.TranslationsPath)
|
||||
|
||||
wantedLocale = self._nwLangPath / f"nw_{QLocale.system().name()}.qm"
|
||||
self._qLocale = QLocale.system() if wantedLocale.exists() else QLocale("en_GB")
|
||||
hasLocale = (self._nwLangPath / f"nw_{QLocale.system().name()}.qm").exists()
|
||||
self._qLocale = QLocale.system() if hasLocale else QLocale("en_GB")
|
||||
self._dLocale = QLocale.system()
|
||||
self._dShortDate = self._dLocale.dateFormat(QLocale.FormatType.ShortFormat)
|
||||
self._dShortDateTime = self._dLocale.dateTimeFormat(QLocale.FormatType.ShortFormat)
|
||||
self._qtTrans = {}
|
||||
|
||||
# PDF Manual
|
||||
@@ -414,6 +418,14 @@ class Config:
|
||||
self._errData = []
|
||||
return message
|
||||
|
||||
def localDate(self, value: datetime) -> str:
|
||||
"""Return a localised date format."""
|
||||
return self._dLocale.toString(value, self._dShortDate)
|
||||
|
||||
def localDateTime(self, value: datetime) -> str:
|
||||
"""Return a localised datetime format."""
|
||||
return self._dLocale.toString(value, self._dShortDateTime)
|
||||
|
||||
def listLanguages(self, lngSet: int) -> list[tuple[str, str]]:
|
||||
"""List localisation files in the i18n folder. The default GUI
|
||||
language is British English (en_GB).
|
||||
@@ -496,6 +508,11 @@ class Config:
|
||||
QLocale.setDefault(self._qLocale)
|
||||
self._qtTrans = {}
|
||||
|
||||
hasLocale = (self._nwLangPath / f"nw_{self._qLocale.name()}.qm").exists()
|
||||
self._dLocale = self._qLocale if hasLocale else QLocale.system()
|
||||
self._dShortDate = self._dLocale.dateFormat(QLocale.FormatType.ShortFormat)
|
||||
self._dShortDateTime = self._dLocale.dateTimeFormat(QLocale.FormatType.ShortFormat)
|
||||
|
||||
langList = [
|
||||
(self._qtLangPath, "qtbase"), # Qt 5.x
|
||||
(str(self._nwLangPath), "nw"), # novelWriter
|
||||
|
||||
@@ -151,8 +151,7 @@ class GuiPreferences(QDialog):
|
||||
self.guiLocale.setMinimumWidth(minWidth)
|
||||
for lang, name in CONFIG.listLanguages(CONFIG.LANG_NW):
|
||||
self.guiLocale.addItem(name, lang)
|
||||
if (idx := self.guiLocale.findData(CONFIG.guiLocale)) != -1:
|
||||
self.guiLocale.setCurrentIndex(idx)
|
||||
self.guiLocale.setCurrentData(CONFIG.guiLocale, "en_GB")
|
||||
|
||||
self.mainForm.addRow(
|
||||
self.tr("Display language"), self.guiLocale,
|
||||
@@ -164,8 +163,7 @@ class GuiPreferences(QDialog):
|
||||
self.guiTheme.setMinimumWidth(minWidth)
|
||||
for theme, name in SHARED.theme.listThemes():
|
||||
self.guiTheme.addItem(name, theme)
|
||||
if (idx := self.guiTheme.findData(CONFIG.guiTheme)) != -1:
|
||||
self.guiTheme.setCurrentIndex(idx)
|
||||
self.guiTheme.setCurrentData(CONFIG.guiTheme, "default")
|
||||
|
||||
self.mainForm.addRow(
|
||||
self.tr("Colour theme"), self.guiTheme,
|
||||
@@ -226,8 +224,7 @@ class GuiPreferences(QDialog):
|
||||
self.guiSyntax.setMinimumWidth(CONFIG.pxInt(200))
|
||||
for syntax, name in SHARED.theme.listSyntax():
|
||||
self.guiSyntax.addItem(name, syntax)
|
||||
if (idx := self.guiSyntax.findData(CONFIG.guiSyntax)) != -1:
|
||||
self.guiSyntax.setCurrentIndex(idx)
|
||||
self.guiSyntax.setCurrentData(CONFIG.guiSyntax, "default_light")
|
||||
|
||||
self.mainForm.addRow(
|
||||
self.tr("Document colour theme"), self.guiSyntax,
|
||||
|
||||
@@ -7,6 +7,7 @@ Created: 2020-05-03 [0.4.5] NColourLabel
|
||||
Created: 2024-01-08 [2.3b1] NScrollableForm
|
||||
Created: 2024-01-26 [2.3b1] NScrollablePage
|
||||
Created: 2024-01-26 [2.3b1] NFixedPage
|
||||
Created: 2024-03-12 [2.4b1] NWrappedWidgetBox
|
||||
|
||||
This file is a part of novelWriter
|
||||
Copyright 2018–2024, Veronica Berglyd Olsen
|
||||
@@ -269,3 +270,24 @@ class NColourLabel(QLabel):
|
||||
return
|
||||
|
||||
# END Class NColourLabel
|
||||
|
||||
|
||||
class NWrappedWidgetBox(QHBoxLayout):
|
||||
"""Extension: A Text-Wrapped Widget Box
|
||||
|
||||
A custom layout box where a widget is wrapped in text labels on
|
||||
either side within a layout box. The widget is inserted at the {0}
|
||||
position so that it can be used for translation strings.
|
||||
"""
|
||||
|
||||
def __init__(self, text: str, widget: QWidget) -> None:
|
||||
super().__init__()
|
||||
before, _, after = text.partition(r"{0}")
|
||||
if before:
|
||||
self.addWidget(QLabel(before.rstrip()))
|
||||
self.addWidget(widget)
|
||||
if after:
|
||||
self.addWidget(QLabel(after.lstrip()))
|
||||
return
|
||||
|
||||
# END Class NWrappedWidgetBox
|
||||
|
||||
@@ -44,6 +44,12 @@ class NComboBox(QComboBox):
|
||||
event.ignore()
|
||||
return
|
||||
|
||||
def setCurrentData(self, data: str, default: str) -> None:
|
||||
"""Set the current index from data, with a fallback."""
|
||||
idx = self.findData(data)
|
||||
self.setCurrentIndex(self.findData(default) if idx < 0 else idx)
|
||||
return
|
||||
|
||||
# END Class NComboBox
|
||||
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ class VersionInfoWidget(QWidget):
|
||||
# Labels
|
||||
self._lblInfo = QLabel("{0} {1} \u2013 {2} {3} \u2013 {4}".format(
|
||||
self.tr("Version"), formatVersion(__version__),
|
||||
self.tr("Released on"), datetime.strptime(__date__, "%Y-%m-%d").strftime("%x"),
|
||||
self.tr("Released on"), CONFIG.localDate(datetime.strptime(__date__, "%Y-%m-%d")),
|
||||
"<a href='#notes'>{0}</a>".format(self.tr("Release Notes")),
|
||||
), self)
|
||||
self._lblInfo.linkActivated.connect(self._processLink)
|
||||
|
||||
@@ -355,8 +355,8 @@ class GuiMain(QMainWindow):
|
||||
if hexToInt(CONFIG.lastNotes) < hexToInt(__hexversion__):
|
||||
CONFIG.lastNotes = __hexversion__
|
||||
trVersion = self.tr(
|
||||
"You are now running novelWriter version {0}.".format(formatVersion(__version__))
|
||||
)
|
||||
"You are now running novelWriter version {0}."
|
||||
).format(formatVersion(__version__))
|
||||
trRelease = self.tr(
|
||||
"Please check the {0}release notes{1} for further details."
|
||||
).format(f"<a href='{nwConst.URL_RELEASES}'>", "</a>")
|
||||
@@ -457,7 +457,7 @@ class GuiMain(QMainWindow):
|
||||
"'{0}' ({1} {2}), last active on {3}."
|
||||
).format(
|
||||
lockStatus[0], lockStatus[1], lockStatus[2],
|
||||
datetime.fromtimestamp(int(lockStatus[3])).strftime("%x %X")
|
||||
CONFIG.localDateTime(datetime.fromtimestamp(int(lockStatus[3])))
|
||||
)
|
||||
except Exception:
|
||||
lockDetails = ""
|
||||
|
||||
@@ -827,7 +827,7 @@ class _PreviewWidget(QTextBrowser):
|
||||
"""Update the build time and the fuzzy age."""
|
||||
if self._docTime > 0:
|
||||
strBuildTime = "%s (%s)" % (
|
||||
datetime.fromtimestamp(self._docTime).strftime("%x %X"),
|
||||
CONFIG.localDateTime(datetime.fromtimestamp(self._docTime)),
|
||||
fuzzyTime(int(time()) - self._docTime)
|
||||
)
|
||||
else:
|
||||
|
||||
@@ -45,6 +45,7 @@ from novelwriter.enum import nwItemClass
|
||||
from novelwriter.common import formatInt, makeFileNameSafe
|
||||
from novelwriter.constants import nwFiles
|
||||
from novelwriter.core.coretools import ProjectBuilder
|
||||
from novelwriter.extensions.configlayout import NWrappedWidgetBox
|
||||
from novelwriter.extensions.switch import NSwitch
|
||||
from novelwriter.extensions.modified import NSpinBox
|
||||
from novelwriter.extensions.versioninfo import VersionInfoWidget
|
||||
@@ -455,7 +456,7 @@ class _ProjectListModel(QAbstractListModel):
|
||||
opened = self.tr("Last Opened")
|
||||
records = sorted(CONFIG.recentProjects.listEntries(), key=lambda x: x[3], reverse=True)
|
||||
for path, title, count, time in records:
|
||||
when = datetime.fromtimestamp(time).strftime("%x")
|
||||
when = CONFIG.localDate(datetime.fromtimestamp(time))
|
||||
data.append((title, path, f"{opened}: {when}, {words}: {formatInt(count)}"))
|
||||
self._data = data
|
||||
return
|
||||
@@ -630,20 +631,18 @@ class _NewProjectForm(QWidget):
|
||||
self.numChapters.setValue(5)
|
||||
self.numChapters.setToolTip(self.tr("Set to 0 to only add scenes"))
|
||||
|
||||
self.chapterBox = QHBoxLayout()
|
||||
self.chapterBox.addWidget(QLabel(self.tr("Add")))
|
||||
self.chapterBox.addWidget(self.numChapters)
|
||||
self.chapterBox.addWidget(QLabel(self.tr("chapter documents")))
|
||||
self.chapterBox = NWrappedWidgetBox(
|
||||
self.tr("Add {0} chapter documents"), self.numChapters
|
||||
)
|
||||
self.chapterBox.addStretch(1)
|
||||
|
||||
self.numScenes = NSpinBox(self)
|
||||
self.numScenes.setRange(0, 200)
|
||||
self.numScenes.setValue(5)
|
||||
|
||||
self.sceneBox = QHBoxLayout()
|
||||
self.sceneBox.addWidget(QLabel(self.tr("Add")))
|
||||
self.sceneBox.addWidget(self.numScenes)
|
||||
self.sceneBox.addWidget(QLabel(self.tr("scene documents (to each chapter)")))
|
||||
self.sceneBox = NWrappedWidgetBox(
|
||||
self.tr("Add {0} scene documents (to each chapter)"), self.numScenes
|
||||
)
|
||||
self.sceneBox.addStretch(1)
|
||||
|
||||
self.novelForm = QVBoxLayout()
|
||||
|
||||
Reference in New Issue
Block a user