Пример #1
0
def switch_language(lang_key=None):
    global _current_translator

    if not lang_key:
        lang_key = settings.get_value("global/language")
    if not lang_key:
        lang_key = get_locale_language()
        logger.info(
            "No language in settings, trying local language '{}'".format(
                lang_key))
    if lang_key not in LANGUAGES.values():
        lang_key = "en"
        logger.warning(
            "Language '{}' unavailable, defaulting to English".format(
                lang_key))
    translator = QTranslator()
    path = ":/translations/translations/parsec_{}.qm".format(lang_key)
    if not translator.load(path):
        logger.warning(
            "Unable to load the translations for language '{}'".format(
                lang_key))
        return False
    if not QCoreApplication.installTranslator(translator):
        logger.warning(
            "Failed to install the translator for language '{}'".format(
                lang_key))
        return False

    QCoreApplication.removeTranslator(_current_translator)
    settings.set_value("global/language", lang_key)
    _current_translator = translator
    QCoreApplication.processEvents()
    return True
Пример #2
0
    def init(self):
        mountpoint = self.core_config.mountpoint_base_dir
        settings.set_value("global/mountpoint", str(mountpoint))
        self.line_edit_mountpoint.setText(str(mountpoint))
        mountpoint_enabled = settings.get_value("global/mountpoint_enabled",
                                                None)
        if os.name == "nt":
            settings.set_value("global/mountpoint_enabled", False)
            mountpoint_enabled = False
            self.checkbox_enable_mountpoint.setDisabled(True)
        elif mountpoint_enabled is None:
            settings.set_value("global/mountpoint_enabled", True)
            mountpoint_enabled = True

        self.button_choose_mountpoint.setDisabled(not mountpoint_enabled)
        self.checkbox_enable_mountpoint.setChecked(
            Qt.Checked if mountpoint_enabled else Qt.Unchecked)
        tray_enabled = settings.get_value("global/tray_enabled", None)
        if tray_enabled is None:
            settings.set_value("global/tray_enabled", True)
            tray_enabled = True
        self.checkbox_tray.setChecked(
            Qt.Checked if tray_enabled else Qt.Unchecked)
        current = None
        for lg, key in lang.LANGUAGES.items():
            self.combo_languages.addItem(lg, key)
            if key == settings.get_value("global/language"):
                current = lg
        if current:
            self.combo_languages.setCurrentText(current)
Пример #3
0
 def save(self):
     settings.set_value("global/tray_enabled",
                        self.checkbox_tray.checkState() == Qt.Checked)
     settings.set_value("global/language",
                        self.combo_languages.currentData())
     settings.set_value("global/mountpoint",
                        self.line_edit_mountpoint.text())
     settings.set_value(
         "global/mountpoint_enabled",
         self.checkbox_enable_mountpoint.checkState() == Qt.Checked)
Пример #4
0
    def start_core(self):
        def _run_core():
            async def _run():
                try:
                    portal = trio.BlockingTrioPortal()
                    self.core_queue.put(portal)
                    with trio.open_cancel_scope() as cancel_scope:
                        self.core_queue.put(cancel_scope)
                        async with logged_core_factory(
                            self.core_config, self.current_device
                        ) as core:
                            self.core_queue.put(core)
                            await trio.sleep_forever()
                # If we have an exception, we never put the core object in the queue. Since the
                # main thread except something to be there, we put the exception.
                except Exception as exc:
                    self.core_queue.put(exc)

            trio.run(_run)

        self.core_config = self.core_config.evolve(mountpoint_enabled=True)
        self.core_thread = threading.Thread(target=_run_core)
        self.core_thread.start()
        self.portal = self.core_queue.get()
        self.cancel_scope = self.core_queue.get()
        self.core = self.core_queue.get()
        # Core object can be an exception if one occured with the logged_core_factory.
        # We join the thread by calling stop_core(), then re-raise the exception.
        if isinstance(self.core, Exception):
            exc = self.core
            self.portal = None
            self.cancel_scope = None
            self.stop_core()
            raise exc
        self.central_widget.set_core_attributes(core=self.core, portal=self.portal)
        settings.set_value(
            "last_device",
            "{}:{}".format(
                self.core.device.organization_addr.organization_id, self.core.device.device_id
            ),
        )
 def save(self):
     if self.combo_proxy_type.currentIndex() == 0:
         settings.set_value("network/proxy_type", "")
     if self.combo_proxy_type.currentIndex() != 0:
         settings.set_value("network/proxy_type",
                            self.combo_proxy_type.currentText())
     settings.set_value("network/proxy_host",
                        self.line_edit_proxy_host.text())
     if self.line_edit_proxy_port.text():
         settings.set_value("network/proxy_port",
                            int(self.line_edit_proxy_port.text()))
     settings.set_value("network/proxy_username",
                        self.line_edit_proxy_username.text())
     settings.set_value("network/simultaneous_connections",
                        int(self.spin_sim_connections.value()))
     if self.radio_upload_no_limit.isChecked():
         settings.set_value("network/upload_limit", -1)
     else:
         settings.set_value("network/upload_limit",
                            int(self.line_edit_upload_limit.text()))
     if self.radio_download_no_limit.isChecked():
         settings.set_value("network/download_limit", -1)
     else:
         settings.set_value("network/download_limit",
                            int(self.line_edit_download_limit.text()))