This repository has been archived on 2024-12-11. You can view files and clone it, but cannot push or open issues or pull requests.
PyBitmessage-2024-12-11/src/bitmessageqt/retranslateui.py
Dmitri Bogomolov 8dca39e902
Initial support for PyQt5 (main window shown) using QtPy package.
QtPy is a compatibility layer which allows to use the code written for
PyQt5 with any python Qt binding: PyQt4, PyQt5, pyside or pyside2.

Main differences in PyQt5:

  - all widget classes are now in QtWidgets package, not QtGui;
  - QString obsoleted by unicode (sip API 2);
  - changed the way of signals connection.

Closes: #1191
2021-12-15 19:07:34 +02:00

21 lines
917 B
Python

from PyQt5 import QtWidgets
import widgets
class RetranslateMixin(object):
def retranslateUi(self):
defaults = QtWidgets.QWidget()
widgets.load(self.__class__.__name__.lower() + '.ui', defaults)
for attr, value in defaults.__dict__.iteritems():
setTextMethod = getattr(value, "setText", None)
if callable(setTextMethod):
getattr(self, attr).setText(getattr(defaults, attr).text())
elif isinstance(value, QtWidgets.QTableWidget):
for i in range(value.columnCount()):
getattr(self, attr).horizontalHeaderItem(i).setText(
getattr(defaults, attr).horizontalHeaderItem(i).text())
for i in range(value.rowCount()):
getattr(self, attr).verticalHeaderItem(i).setText(
getattr(defaults, attr).verticalHeaderItem(i).text())