def __init__(self,
                 parent,
                 title="Language selection",
                 name="Language codes",
                 instruction="Click button when you are done"):
        super(LanguageSelector, self).__init__(
            None, QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint)
        self.qm_files_choices = {}
        self.parent = parent
        qm_files = utils.find_qm_files()

        # ========= check boxes ==============
        group_box = QtGui.QGroupBox(name)
        group_box_layout = QtGui.QGridLayout()
        for i, locale in enumerate(qm_files):
            check_box = QtGui.QCheckBox(locale)
            check_box.setAutoExclusive(True)
            self.qm_files_choices[check_box] = locale
            check_box.toggled.connect(self.check_box_toggled)
            group_box_layout.addWidget(check_box, i / 4, i % 4)
        # adding default language option. When using the PyQt distribution
        # no "en" files were found and yet "en" was the obvious default.
        # We need this option in case we want to revert a change.
        check_box = QtGui.QCheckBox("default")
        check_box.setAutoExclusive(True)
        self.qm_files_choices[check_box] = "default"
        check_box.toggled.connect(self.check_box_toggled)
        i = len(qm_files)
        group_box_layout.addWidget(check_box, i / 4, i % 4)
        group_box.setLayout(group_box_layout)

        # ========= buttons ==============
        button_box = QtGui.QDialogButtonBox()
        confirm_button = button_box.addButton(QtGui.QDialogButtonBox.Ok)
        confirm_button.clicked.connect(self.confirm)

        # ========= finalizing layout ====
        main_layout = QtGui.QVBoxLayout()
        main_layout.addWidget(group_box)
        main_layout.addWidget(QtGui.QLabel(instruction))
        main_layout.addWidget(button_box)
        self.setLayout(main_layout)
        self.setWindowTitle(title)
        self.show()
        self.raise_()
    def __init__(self, parent, title="Language selection",
                 name="Language codes",
                 instruction="Click button when you are done"):
        super(LanguageSelector, self).__init__(None,
                         QtCore.Qt.WindowSystemMenuHint |
                         QtCore.Qt.WindowTitleHint)
        self.qm_files_choices = {}
        self.parent = parent
        qm_files = utils.find_qm_files()

        # ========= check boxes ==============
        group_box = QtGui.QGroupBox(name)
        group_box_layout = QtGui.QGridLayout()
        for i, locale in enumerate(qm_files):
            check_box = QtGui.QCheckBox(locale)
            check_box.setAutoExclusive(True)
            self.qm_files_choices[check_box] = locale
            check_box.toggled.connect(self.check_box_toggled)
            group_box_layout.addWidget(check_box, i / 4, i % 4)
        # adding default language option. When using the PyQt distribution
        # no "en" files were found and yet "en" was the obvious default.
        # We need this option in case we want to revert a change.
        check_box = QtGui.QCheckBox("default")
        check_box.setAutoExclusive(True)
        self.qm_files_choices[check_box] = "default"
        check_box.toggled.connect(self.check_box_toggled)
        i = len(qm_files)
        group_box_layout.addWidget(check_box, i / 4, i % 4)
        group_box.setLayout(group_box_layout)

        # ========= buttons ==============
        button_box = QtGui.QDialogButtonBox()
        confirm_button = button_box.addButton(QtGui.QDialogButtonBox.Ok)
        confirm_button.clicked.connect(self.confirm)

        # ========= finalizing layout ====
        main_layout = QtGui.QVBoxLayout()
        main_layout.addWidget(group_box)
        main_layout.addWidget(QtGui.QLabel(instruction))
        main_layout.addWidget(button_box)
        self.setLayout(main_layout)
        self.setWindowTitle(title)
        self.show()
        self.raise_()
Beispiel #3
0
 def set_locale(self, locale, save=True):
     """Sets the language of the basic controls for PyQt
        from a locale - provided that the corresponding qm files
        are present in the PyQt distribution.
     """
     global QM_FILES
     if QM_FILES is None:
         QM_FILES = utils.find_qm_files()
     if locale in QM_FILES:
         if self.translator.load("qt_" + locale, QM_FILES[locale]):
             self.installTranslator(self.translator)
             self.config['locale'] = locale
         else:
             print("language not available")
     elif locale == "default" and self.config['locale'] != 'default':
         self.removeTranslator(self.translator)
         self.translator = QtCore.QTranslator()
         self.config['locale'] = 'default'
     elif self.config['locale'] in QM_FILES:
         if self.translator.load("qt_" + self.config['locale'],
                                 QM_FILES[self.config['locale']]):
             self.installTranslator(self.translator)
     if save:
         self.save_config()
Beispiel #4
0
 def set_locale(self, locale, save=True):
     """Sets the language of the basic controls for PyQt
        from a locale - provided that the corresponding qm files
        are present in the PyQt distribution.
     """
     global QM_FILES
     if QM_FILES is None:
         QM_FILES = utils.find_qm_files()
     if locale in QM_FILES:
         if self.translator.load("qt_" + locale, QM_FILES[locale]):
             self.installTranslator(self.translator)
             self.config['locale'] = locale
         else:
             print("language not available")
     elif locale == "default" and self.config['locale'] != 'default':
         self.removeTranslator(self.translator)
         self.translator = QtCore.QTranslator()
         self.config['locale'] = 'default'
     elif self.config['locale'] in QM_FILES:
         if self.translator.load("qt_" + self.config['locale'],
                                      QM_FILES[self.config['locale']]):
             self.installTranslator(self.translator)
     if save:
         self.save_config()