Removing RetranslateMixin from MainWindow

This commit is contained in:
Dmitri Bogomolov 2018-11-20 14:11:18 +02:00
parent fe9b2d7188
commit 25e362c338
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13
4 changed files with 76 additions and 9 deletions

View File

@ -308,7 +308,6 @@ class MainWindow(Window):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.qmytranslator = self.qsystranslator = None
self.indicatorUpdate = None
self.actionStatus = None
@ -1269,8 +1268,8 @@ class MainWindow(Window):
def changeEvent(self, event):
if event.type() == QtCore.QEvent.LanguageChange:
self.retranslateUi(self)
self.init_inbox_popup_menu(False)
# FIXME: it's called very often
self.retranslateUi()
self.init_identities_popup_menu(False)
self.blackwhitelist.init_blacklist_popup_menu()
if event.type() == QtCore.QEvent.WindowStateChange:

View File

@ -1,7 +1,7 @@
"""
Dialogs that work with BM address.
"""
# pylint: disable=attribute-defined-outside-init,too-few-public-methods,relative-import
# pylint: disable=attribute-defined-outside-init,too-few-public-methods
import hashlib
@ -9,8 +9,11 @@ from PyQt4 import QtCore, QtGui
import queues
import widgets
from account import AccountMixin, GatewayAccount, MailchuckAccount, accountClass, getSortedAccounts
from addresses import addBMIfNotPresent, decodeAddress, encodeVarint
from account import (
GatewayAccount, MailchuckAccount, AccountMixin, accountClass,
getSortedAccounts
)
from addresses import decodeAddress, encodeVarint, addBMIfNotPresent
from inventory import Inventory
from tr import _translate

View File

@ -1,20 +1,26 @@
import locale
import os
import sys
from PyQt4 import QtCore, QtGui
import l10n
import paths
import settingsmixin
import widgets
from bmconfigparser import BMConfigParser
from debug import logger
from foldertree import AddressBookCompleter
from retranslateui import RetranslateMixin
from tr import _translate
class Window(settingsmixin.SMainWindow, RetranslateMixin):
class Window(settingsmixin.SMainWindow):
"""The main PyBitmessage's window"""
def __init__(self, parent=None):
super(Window, self).__init__(parent)
widgets.load('main.ui', self)
self.qmytranslator = self.qsystranslator = None
self.blackwhitelist.rerenderBlackWhiteList()
addressBookCompleter = AddressBookCompleter()
@ -82,3 +88,62 @@ class Window(settingsmixin.SMainWindow, RetranslateMixin):
if dontconnect else
_translate("MainWindow", "Go offline", None)
)
def retranslateUi(self):
"""Update widgets' texts which is not taken from ui-file"""
self.updateHumanFriendlyTTLDescription(int(
self.horizontalSliderTTL.tickPosition() ** 3.199 + 3600))
self.networkstatus.retranslateUi()
# FIXME: this is not best place for this func
def change_translation(self, newlocale=None):
"""Change translation language for the application"""
if newlocale is None:
newlocale = l10n.getTranslationLanguage()
try:
if not self.qmytranslator.isEmpty():
QtGui.QApplication.removeTranslator(self.qmytranslator)
except:
pass
try:
if not self.qsystranslator.isEmpty():
QtGui.QApplication.removeTranslator(self.qsystranslator)
except:
pass
self.qmytranslator = QtCore.QTranslator()
translationpath = os.path.join(
paths.codePath(), 'translations', 'bitmessage_' + newlocale)
self.qmytranslator.load(translationpath)
QtGui.QApplication.installTranslator(self.qmytranslator)
self.qsystranslator = QtCore.QTranslator()
if paths.frozen:
translationpath = os.path.join(
paths.codePath(), 'translations', 'qt_' + newlocale)
else:
translationpath = os.path.join(
str(QtCore.QLibraryInfo.location(
QtCore.QLibraryInfo.TranslationsPath)), 'qt_' + newlocale)
self.qsystranslator.load(translationpath)
QtGui.QApplication.installTranslator(self.qsystranslator)
lang = locale.normalize(l10n.getTranslationLanguage())
langs = [
lang.split(".")[0] + "." + l10n.encoding,
lang.split(".")[0] + "." + 'UTF-8',
lang
]
if 'win32' in sys.platform or 'win64' in sys.platform:
langs = [l10n.getWindowsLocale(lang)]
for lang in langs:
try:
l10n.setlocale(locale.LC_ALL, lang)
if 'win32' not in sys.platform and 'win64' not in sys.platform:
l10n.encoding = locale.nl_langinfo(locale.CODESET)
else:
l10n.encoding = locale.getlocale()[1]
logger.info("Successfully set locale to %s", lang)
break
except:
logger.error("Failed to set locale to %s", lang, exc_info=True)

View File

@ -240,7 +240,7 @@ class NetworkStatus(QtGui.QWidget, RetranslateMixin):
self.labelTotalConnections.setText(
_translate(
"networkstatus", "Total Connections: %1").arg(
str(self.tableWidgetConnectionCount.rowCount())))
self.tableWidgetConnectionCount.rowCount()))
self.labelStartupTime.setText(_translate(
"networkstatus", "Since startup on %1"
).arg(l10n.formatTimestamp(self.startup)))