mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-05-15 10:22:26 +12:00
Adds: GUI settings to change translation
This commit is contained in:
parent
146a3fc6c1
commit
824f15e54c
|
@ -1,13 +1,14 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import faulthandler
|
||||
import os
|
||||
import sys
|
||||
|
||||
from PyQt5.QtCore import QLocale, QTranslator, QSettings
|
||||
from PyQt5.QtGui import QIcon
|
||||
from PyQt5.QtWidgets import QApplication, qApp
|
||||
|
||||
from manuskript.functions import appPath
|
||||
from manuskript.functions import appPath, writablePath
|
||||
|
||||
_version = "0.2.0"
|
||||
|
||||
|
@ -28,27 +29,33 @@ def run():
|
|||
|
||||
app.setStyle("Fusion")
|
||||
|
||||
# Translation process
|
||||
locale = QLocale.system().name()
|
||||
# locale = "fr_CH"
|
||||
|
||||
appTranslator = QTranslator()
|
||||
if appTranslator.load(appPath("i18n/manuskript_{}.qm").format(locale)):
|
||||
app.installTranslator(appTranslator)
|
||||
print(app.tr("Loaded transation: {}.").format(locale))
|
||||
else:
|
||||
print(app.tr("Failed to load translator for {}...").format(locale))
|
||||
|
||||
# Load style from QSettings
|
||||
settings = QSettings(app.organizationName(), app.applicationName())
|
||||
if settings.contains("applicationStyle"):
|
||||
style = settings.value("applicationStyle")
|
||||
app.setStyle(style)
|
||||
|
||||
# Translation process
|
||||
locale = QLocale.system().name()
|
||||
|
||||
appTranslator = QTranslator()
|
||||
# By default: locale
|
||||
translation = appPath(os.path.join("i18n", "manuskript_{}.qm".format(locale)))
|
||||
|
||||
# Load translation from settings
|
||||
if settings.contains("applicationTranslation"):
|
||||
translation = appPath(os.path.join("i18n", settings.value("applicationTranslation")))
|
||||
print("Found translation in settings:", translation)
|
||||
|
||||
if appTranslator.load(translation):
|
||||
app.installTranslator(appTranslator)
|
||||
print(app.tr("Loaded translation: {}.").format(translation))
|
||||
|
||||
else:
|
||||
print(app.tr("Warning: failed to load translator for locale {}...").format(locale))
|
||||
|
||||
QIcon.setThemeSearchPaths(QIcon.themeSearchPaths() + [appPath("icons")])
|
||||
QIcon.setThemeName("NumixMsk")
|
||||
print(QIcon.hasThemeIcon("dialog-no"))
|
||||
print(QIcon.themeSearchPaths())
|
||||
# qApp.setWindowIcon(QIcon.fromTheme("im-aim"))
|
||||
|
||||
# Seperating launch to avoid segfault, so it seem.
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
#!/usr/bin/env python
|
||||
# --!-- coding: utf8 --!--
|
||||
import os
|
||||
from collections import OrderedDict
|
||||
|
||||
from PyQt5.QtCore import QSize, QSettings, QRegExp
|
||||
from PyQt5.QtCore import QSize, QSettings, QRegExp, QTranslator, QObject
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtGui import QIntValidator, QIcon, QFont, QColor, QPixmap, QStandardItem, QPainter
|
||||
from PyQt5.QtWidgets import QStyleFactory, QWidget, QStyle, QColorDialog, QListWidgetItem
|
||||
from PyQt5.QtWidgets import QStyleFactory, QWidget, QStyle, QColorDialog, QListWidgetItem, QMessageBox
|
||||
from PyQt5.QtWidgets import qApp
|
||||
|
||||
# Spell checker support
|
||||
|
@ -45,6 +46,21 @@ class settingsWindow(QWidget, Ui_Settings):
|
|||
self.cmbStyle.setCurrentIndex([i.lower() for i in list(QStyleFactory.keys())].index(qApp.style().objectName()))
|
||||
self.cmbStyle.currentIndexChanged[str].connect(self.setStyle)
|
||||
|
||||
self.cmbTranslation.clear()
|
||||
tr = OrderedDict()
|
||||
tr["English"] = ""
|
||||
tr["Français"] = "manuskript_fr.qm"
|
||||
tr["Español"] = "manuskript_es.qm"
|
||||
|
||||
for name in tr:
|
||||
self.cmbTranslation.addItem(name, tr[name])
|
||||
|
||||
sttgs = QSettings(qApp.organizationName(), qApp.applicationName())
|
||||
if sttgs.contains("applicationTranslation") and sttgs.value("applicationTranslation") in tr.values():
|
||||
self.cmbTranslation.setCurrentText([i for i in tr if tr[i] == sttgs.value("applicationTranslation")][0])
|
||||
|
||||
self.cmbTranslation.currentIndexChanged.connect(self.setTranslation)
|
||||
|
||||
self.txtAutoSave.setValidator(QIntValidator(0, 999, self))
|
||||
self.txtAutoSaveNoChanges.setValidator(QIntValidator(0, 999, self))
|
||||
self.chkAutoSave.setChecked(settings.autoSave)
|
||||
|
@ -209,6 +225,14 @@ class settingsWindow(QWidget, Ui_Settings):
|
|||
sttgs.setValue("applicationStyle", style)
|
||||
qApp.setStyle(style)
|
||||
|
||||
def setTranslation(self, index):
|
||||
path = self.cmbTranslation.currentData()
|
||||
# Save settings
|
||||
sttgs = QSettings(qApp.organizationName(), qApp.applicationName())
|
||||
sttgs.setValue("applicationTranslation", path)
|
||||
|
||||
# QMessageBox.information(self, "Warning", "You'll have to restart manuskript.")
|
||||
|
||||
def saveSettingsChanged(self):
|
||||
if self.txtAutoSave.text() in ["", "0"]:
|
||||
self.txtAutoSave.setText("1")
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
# Form implementation generated from reading ui file 'manuskript/ui/settings_ui.ui'
|
||||
#
|
||||
# Created: Wed Mar 2 00:30:17 2016
|
||||
# by: PyQt5 UI code generator 5.2.1
|
||||
# Created by: PyQt5 UI code generator 5.4.2
|
||||
#
|
||||
# WARNING! All changes made in this file will be lost!
|
||||
|
||||
|
@ -12,7 +11,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets
|
|||
class Ui_Settings(object):
|
||||
def setupUi(self, Settings):
|
||||
Settings.setObjectName("Settings")
|
||||
Settings.resize(658, 491)
|
||||
Settings.resize(658, 561)
|
||||
self.horizontalLayout_8 = QtWidgets.QHBoxLayout(Settings)
|
||||
self.horizontalLayout_8.setObjectName("horizontalLayout_8")
|
||||
self.lstMenu = QtWidgets.QListWidget(Settings)
|
||||
|
@ -77,6 +76,30 @@ class Ui_Settings(object):
|
|||
self.cmbStyle.setObjectName("cmbStyle")
|
||||
self.verticalLayout_5.addWidget(self.cmbStyle)
|
||||
self.verticalLayout_7.addWidget(self.groupBox_2)
|
||||
self.groupBox_14 = QtWidgets.QGroupBox(self.stackedWidgetPage1)
|
||||
font = QtGui.QFont()
|
||||
font.setBold(True)
|
||||
font.setWeight(75)
|
||||
self.groupBox_14.setFont(font)
|
||||
self.groupBox_14.setObjectName("groupBox_14")
|
||||
self.verticalLayout_20 = QtWidgets.QVBoxLayout(self.groupBox_14)
|
||||
self.verticalLayout_20.setObjectName("verticalLayout_20")
|
||||
self.label_52 = QtWidgets.QLabel(self.groupBox_14)
|
||||
font = QtGui.QFont()
|
||||
font.setBold(False)
|
||||
font.setWeight(50)
|
||||
self.label_52.setFont(font)
|
||||
self.label_52.setWordWrap(True)
|
||||
self.label_52.setObjectName("label_52")
|
||||
self.verticalLayout_20.addWidget(self.label_52)
|
||||
self.cmbTranslation = QtWidgets.QComboBox(self.groupBox_14)
|
||||
font = QtGui.QFont()
|
||||
font.setBold(False)
|
||||
font.setWeight(50)
|
||||
self.cmbTranslation.setFont(font)
|
||||
self.cmbTranslation.setObjectName("cmbTranslation")
|
||||
self.verticalLayout_20.addWidget(self.cmbTranslation)
|
||||
self.verticalLayout_7.addWidget(self.groupBox_14)
|
||||
self.groupBox_10 = QtWidgets.QGroupBox(self.stackedWidgetPage1)
|
||||
font = QtGui.QFont()
|
||||
font.setBold(True)
|
||||
|
@ -1321,7 +1344,6 @@ class Ui_Settings(object):
|
|||
self.layoutWidget = QtWidgets.QWidget(self.splitter)
|
||||
self.layoutWidget.setObjectName("layoutWidget")
|
||||
self.verticalLayout_14 = QtWidgets.QVBoxLayout(self.layoutWidget)
|
||||
self.verticalLayout_14.setContentsMargins(0, 0, 0, 0)
|
||||
self.verticalLayout_14.setObjectName("verticalLayout_14")
|
||||
self.cmbThemeEdit = QtWidgets.QComboBox(self.layoutWidget)
|
||||
self.cmbThemeEdit.setObjectName("cmbThemeEdit")
|
||||
|
@ -1601,7 +1623,7 @@ class Ui_Settings(object):
|
|||
self.horizontalLayout_8.addWidget(self.stack)
|
||||
|
||||
self.retranslateUi(Settings)
|
||||
self.stack.setCurrentIndex(2)
|
||||
self.stack.setCurrentIndex(0)
|
||||
self.tabViews.setCurrentIndex(0)
|
||||
self.themeStack.setCurrentIndex(1)
|
||||
self.themeEditStack.setCurrentIndex(0)
|
||||
|
@ -1630,6 +1652,8 @@ class Ui_Settings(object):
|
|||
self.lblTitleGeneral.setText(_translate("Settings", "General settings"))
|
||||
self.groupBox_2.setTitle(_translate("Settings", "Application style"))
|
||||
self.label_2.setText(_translate("Settings", "You might need to restart manuskript in order to avoid some visual issues."))
|
||||
self.groupBox_14.setTitle(_translate("Settings", "Application language"))
|
||||
self.label_52.setText(_translate("Settings", "You will need to restart manuskript for the translation to take effect."))
|
||||
self.groupBox_10.setTitle(_translate("Settings", "Loading"))
|
||||
self.chkAutoLoad.setText(_translate("Settings", "Automatically load last project on startup"))
|
||||
self.groupBox.setTitle(_translate("Settings", "Saving"))
|
||||
|
@ -1676,7 +1700,7 @@ class Ui_Settings(object):
|
|||
self.rdoTreeWC.setText(_translate("Settings", "Show wordcount"))
|
||||
self.rdoTreeProgress.setText(_translate("Settings", "Show progress"))
|
||||
self.rdoTreeSummary.setText(_translate("Settings", "Show summary"))
|
||||
self.rdoTreeNothing.setText(_translate("Settings", "Nothing"))
|
||||
self.rdoTreeNothing.setText(_translate("Settings", "&Nothing"))
|
||||
self.groupBox_9.setTitle(_translate("Settings", "Text"))
|
||||
self.rdoTreeTextWC.setText(_translate("Settings", "Show wordcount"))
|
||||
self.rdoTreeTextProgress.setText(_translate("Settings", "Show progress"))
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>658</width>
|
||||
<height>491</height>
|
||||
<height>561</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -51,7 +51,7 @@
|
|||
<item>
|
||||
<widget class="QStackedWidget" name="stack">
|
||||
<property name="currentIndex">
|
||||
<number>2</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="stackedWidgetPage1">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_7">
|
||||
|
@ -133,6 +133,47 @@ text-align:center;</string>
|
|||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_14">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Application language</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_20">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_52">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>50</weight>
|
||||
<bold>false</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>You will need to restart manuskript for the translation to take effect.</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="cmbTranslation">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>50</weight>
|
||||
<bold>false</bold>
|
||||
</font>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_10">
|
||||
<property name="font">
|
||||
|
@ -1032,7 +1073,7 @@ text-align:center;</string>
|
|||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Nothing</string>
|
||||
<string>&Nothing</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
|
|
Loading…
Reference in a new issue