Make paper sizes translatable
This commit is contained in:
@@ -235,6 +235,22 @@ class nwLabels:
|
|||||||
"cm": 10.0,
|
"cm": 10.0,
|
||||||
"in": 25.4,
|
"in": 25.4,
|
||||||
}
|
}
|
||||||
|
PAPER_NAME = {
|
||||||
|
"A4": QT_TRANSLATE_NOOP("Constant", "A4"),
|
||||||
|
"A5": QT_TRANSLATE_NOOP("Constant", "A5"),
|
||||||
|
"A6": QT_TRANSLATE_NOOP("Constant", "A6"),
|
||||||
|
"Legal": QT_TRANSLATE_NOOP("Constant", "US Legal"),
|
||||||
|
"Letter": QT_TRANSLATE_NOOP("Constant", "US Letter"),
|
||||||
|
"Custom": QT_TRANSLATE_NOOP("Constant", "Custom"),
|
||||||
|
}
|
||||||
|
PAPER_SIZE = {
|
||||||
|
"A4": (210.0, 297.0),
|
||||||
|
"A5": (148.0, 210.0),
|
||||||
|
"A6": (105.0, 148.0),
|
||||||
|
"Legal": (215.9, 355.6),
|
||||||
|
"Letter": (215.9, 279.4),
|
||||||
|
"Custom": (-1.0, -1.0),
|
||||||
|
}
|
||||||
|
|
||||||
# END Class nwLabels
|
# END Class nwLabels
|
||||||
|
|
||||||
|
|||||||
@@ -132,15 +132,6 @@ SETTINGS_LABELS = {
|
|||||||
"html.addStyles": QT_TRANSLATE_NOOP("Builds", "Add CSS Styles"),
|
"html.addStyles": QT_TRANSLATE_NOOP("Builds", "Add CSS Styles"),
|
||||||
}
|
}
|
||||||
|
|
||||||
PAGE_SIZES = {
|
|
||||||
"A4": (210.0, 297.0),
|
|
||||||
"A5": (148.0, 210.0),
|
|
||||||
"A6": (105.0, 148.0),
|
|
||||||
"Legal": (215.9, 355.6),
|
|
||||||
"Letter": (215.9, 279.4),
|
|
||||||
"Custom": (-1.0, -1.0),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class FilterMode(Enum):
|
class FilterMode(Enum):
|
||||||
"""The decision reason for an item in a filtered project."""
|
"""The decision reason for an item in a filtered project."""
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ from novelwriter.core.toodt import ToOdt
|
|||||||
from novelwriter.core.tohtml import ToHtml
|
from novelwriter.core.tohtml import ToHtml
|
||||||
from novelwriter.core.project import NWProject
|
from novelwriter.core.project import NWProject
|
||||||
from novelwriter.core.tokenizer import Tokenizer
|
from novelwriter.core.tokenizer import Tokenizer
|
||||||
from novelwriter.core.buildsettings import PAGE_SIZES, BuildSettings
|
from novelwriter.core.buildsettings import BuildSettings
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -292,10 +292,10 @@ class NWBuildDocument:
|
|||||||
bldObj.setLanguage(buildLang)
|
bldObj.setLanguage(buildLang)
|
||||||
|
|
||||||
scale = nwLabels.UNIT_SCALE.get(self._build.getStr("format.pageUnit"), 1.0)
|
scale = nwLabels.UNIT_SCALE.get(self._build.getStr("format.pageUnit"), 1.0)
|
||||||
width, height = PAGE_SIZES.get(self._build.getStr("format.pageSize"), (-1.0, -1.0))
|
pW, pH = nwLabels.PAPER_SIZE.get(self._build.getStr("format.pageSize"), (-1.0, -1.0))
|
||||||
bldObj.setPageLayout(
|
bldObj.setPageLayout(
|
||||||
width if width > 0.0 else scale*self._build.getFloat("format.pageWidth"),
|
pW if pW > 0.0 else scale*self._build.getFloat("format.pageWidth"),
|
||||||
height if height > 0.0 else scale*self._build.getFloat("format.pageHeight"),
|
pH if pH > 0.0 else scale*self._build.getFloat("format.pageHeight"),
|
||||||
scale*self._build.getFloat("format.topMargin"),
|
scale*self._build.getFloat("format.topMargin"),
|
||||||
scale*self._build.getFloat("format.bottomMargin"),
|
scale*self._build.getFloat("format.bottomMargin"),
|
||||||
scale*self._build.getFloat("format.leftMargin"),
|
scale*self._build.getFloat("format.leftMargin"),
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ from PyQt5.QtWidgets import (
|
|||||||
|
|
||||||
from novelwriter import CONFIG
|
from novelwriter import CONFIG
|
||||||
from novelwriter.constants import nwHeadFmt, nwLabels, trConst
|
from novelwriter.constants import nwHeadFmt, nwLabels, trConst
|
||||||
from novelwriter.core.buildsettings import PAGE_SIZES, BuildSettings, FilterMode
|
from novelwriter.core.buildsettings import BuildSettings, FilterMode
|
||||||
from novelwriter.extensions.switch import NSwitch
|
from novelwriter.extensions.switch import NSwitch
|
||||||
from novelwriter.extensions.switchbox import NSwitchBox
|
from novelwriter.extensions.switchbox import NSwitchBox
|
||||||
from novelwriter.extensions.configlayout import NConfigLayout, NSimpleLayout
|
from novelwriter.extensions.configlayout import NConfigLayout, NSimpleLayout
|
||||||
@@ -1024,8 +1024,8 @@ class _FormatTab(QWidget):
|
|||||||
self.pageUnit.addItem(trConst(name), key)
|
self.pageUnit.addItem(trConst(name), key)
|
||||||
|
|
||||||
self.pageSize = QComboBox(self)
|
self.pageSize = QComboBox(self)
|
||||||
for key, size in PAGE_SIZES.items():
|
for key, name in nwLabels.PAPER_NAME.items():
|
||||||
self.pageSize.addItem(key, size)
|
self.pageSize.addItem(trConst(name), key)
|
||||||
|
|
||||||
self.pageWidth = QDoubleSpinBox(self)
|
self.pageWidth = QDoubleSpinBox(self)
|
||||||
self.pageWidth.setFixedWidth(dbW)
|
self.pageWidth.setFixedWidth(dbW)
|
||||||
@@ -1115,7 +1115,7 @@ class _FormatTab(QWidget):
|
|||||||
self.rightMargin.setValue(self._build.getFloat("format.rightMargin"))
|
self.rightMargin.setValue(self._build.getFloat("format.rightMargin"))
|
||||||
|
|
||||||
pageSize = self._build.getStr("format.pageSize")
|
pageSize = self._build.getStr("format.pageSize")
|
||||||
index = self.pageSize.findText(pageSize)
|
index = self.pageSize.findData(pageSize)
|
||||||
if index >= 0:
|
if index >= 0:
|
||||||
self.pageSize.setCurrentIndex(index)
|
self.pageSize.setCurrentIndex(index)
|
||||||
self._changePageSize(index)
|
self._changePageSize(index)
|
||||||
@@ -1131,11 +1131,13 @@ class _FormatTab(QWidget):
|
|||||||
self._build.setValue("format.textFont", self.textFont.text())
|
self._build.setValue("format.textFont", self.textFont.text())
|
||||||
self._build.setValue("format.textSize", self.textSize.value())
|
self._build.setValue("format.textSize", self.textSize.value())
|
||||||
self._build.setValue("format.lineHeight", self.lineHeight.value())
|
self._build.setValue("format.lineHeight", self.lineHeight.value())
|
||||||
|
|
||||||
self._build.setValue("format.justifyText", self.justifyText.isChecked())
|
self._build.setValue("format.justifyText", self.justifyText.isChecked())
|
||||||
self._build.setValue("format.stripUnicode", self.stripUnicode.isChecked())
|
self._build.setValue("format.stripUnicode", self.stripUnicode.isChecked())
|
||||||
self._build.setValue("format.replaceTabs", self.replaceTabs.isChecked())
|
self._build.setValue("format.replaceTabs", self.replaceTabs.isChecked())
|
||||||
|
|
||||||
self._build.setValue("format.pageUnit", str(self.pageUnit.currentData()))
|
self._build.setValue("format.pageUnit", str(self.pageUnit.currentData()))
|
||||||
self._build.setValue("format.pageSize", str(self.pageSize.currentText()))
|
self._build.setValue("format.pageSize", str(self.pageSize.currentData()))
|
||||||
self._build.setValue("format.pageWidth", self.pageWidth.value())
|
self._build.setValue("format.pageWidth", self.pageWidth.value())
|
||||||
self._build.setValue("format.pageHeight", self.pageHeight.value())
|
self._build.setValue("format.pageHeight", self.pageHeight.value())
|
||||||
self._build.setValue("format.topMargin", self.topMargin.value())
|
self._build.setValue("format.topMargin", self.topMargin.value())
|
||||||
@@ -1220,12 +1222,12 @@ class _FormatTab(QWidget):
|
|||||||
self.pageWidth.setEnabled(True)
|
self.pageWidth.setEnabled(True)
|
||||||
self.pageHeight.setEnabled(True)
|
self.pageHeight.setEnabled(True)
|
||||||
|
|
||||||
width, height = self.pageSize.itemData(index) if index >= 0 else (-1.0, -1.0)
|
w, h = nwLabels.PAPER_SIZE[self.pageSize.itemData(index)] if index >= 0 else (-1.0, -1.0)
|
||||||
if width > 0.0 and height > 0.0:
|
if w > 0.0 and h > 0.0:
|
||||||
self.pageWidth.setEnabled(False)
|
self.pageWidth.setEnabled(False)
|
||||||
self.pageHeight.setEnabled(False)
|
self.pageHeight.setEnabled(False)
|
||||||
self.pageWidth.setValue(width/self._unitScale)
|
self.pageWidth.setValue(w/self._unitScale)
|
||||||
self.pageHeight.setValue(height/self._unitScale)
|
self.pageHeight.setValue(h/self._unitScale)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user