FreeCAD

Форк
0
/
addonmanager_firstrun.py 
106 строк · 5.3 Кб
1
# SPDX-License-Identifier: LGPL-2.1-or-later
2
# ***************************************************************************
3
# *                                                                         *
4
# *   Copyright (c) 2022 FreeCAD Project Association                        *
5
# *                                                                         *
6
# *   This file is part of FreeCAD.                                         *
7
# *                                                                         *
8
# *   FreeCAD is free software: you can redistribute it and/or modify it    *
9
# *   under the terms of the GNU Lesser General Public License as           *
10
# *   published by the Free Software Foundation, either version 2.1 of the  *
11
# *   License, or (at your option) any later version.                       *
12
# *                                                                         *
13
# *   FreeCAD is distributed in the hope that it will be useful, but        *
14
# *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
15
# *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      *
16
# *   Lesser General Public License for more details.                       *
17
# *                                                                         *
18
# *   You should have received a copy of the GNU Lesser General Public      *
19
# *   License along with FreeCAD. If not, see                               *
20
# *   <https://www.gnu.org/licenses/>.                                      *
21
# *                                                                         *
22
# ***************************************************************************
23

24
""" Class to display a first-run dialog for the Addon Manager """
25

26
import os
27

28
from PySide import QtCore, QtWidgets
29

30
import FreeCAD
31
import FreeCADGui
32

33
import addonmanager_utilities as utils
34

35
# pylint: disable=too-few-public-methods
36

37

38
class FirstRunDialog:
39
    """Manage the display of the Addon Manager's first-run dialog, setting up some user
40
    preferences and making sure they are aware that this connects to the internet, downloads
41
    data, and possibly installs things that run code not affiliated with FreeCAD itself."""
42

43
    def __init__(self):
44
        self.pref = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Addons")
45
        self.readWarning = self.pref.GetBool("readWarning2022", False)
46

47
    def exec(self) -> bool:
48
        """Display a first-run dialog if needed, and return True to indicate the Addon Manager
49
        should continue loading, or False if the user cancelled the dialog and wants to exit."""
50
        if not self.readWarning:
51
            warning_dialog = FreeCADGui.PySideUic.loadUi(
52
                os.path.join(os.path.dirname(__file__), "first_run.ui")
53
            )
54
            warning_dialog.setWindowFlag(QtCore.Qt.WindowStaysOnTopHint, True)
55
            autocheck = self.pref.GetBool("AutoCheck", False)
56
            download_macros = self.pref.GetBool("DownloadMacros", False)
57
            proxy_string = self.pref.GetString("ProxyUrl", "")
58
            if self.pref.GetBool("NoProxyCheck", True):
59
                proxy_option = 0
60
            elif self.pref.GetBool("SystemProxyCheck", False):
61
                proxy_option = 1
62
            elif self.pref.GetBool("UserProxyCheck", False):
63
                proxy_option = 2
64

65
            def toggle_proxy_list(option: int):
66
                if option == 2:
67
                    warning_dialog.lineEditProxy.show()
68
                else:
69
                    warning_dialog.lineEditProxy.hide()
70

71
            warning_dialog.checkBoxAutoCheck.setChecked(autocheck)
72
            warning_dialog.checkBoxDownloadMacroMetadata.setChecked(download_macros)
73
            warning_dialog.comboBoxProxy.setCurrentIndex(proxy_option)
74
            toggle_proxy_list(proxy_option)
75
            if proxy_option == 2:
76
                warning_dialog.lineEditProxy.setText(proxy_string)
77

78
            warning_dialog.comboBoxProxy.currentIndexChanged.connect(toggle_proxy_list)
79

80
            warning_dialog.labelWarning.setStyleSheet(
81
                f"color:{utils.warning_color_string()};font-weight:bold;"
82
            )
83

84
            if warning_dialog.exec() == QtWidgets.QDialog.Accepted:
85
                self.readWarning = True
86
                self.pref.SetBool("readWarning2022", True)
87
                self.pref.SetBool("AutoCheck", warning_dialog.checkBoxAutoCheck.isChecked())
88
                self.pref.SetBool(
89
                    "DownloadMacros",
90
                    warning_dialog.checkBoxDownloadMacroMetadata.isChecked(),
91
                )
92
                selected_proxy_option = warning_dialog.comboBoxProxy.currentIndex()
93
                if selected_proxy_option == 0:
94
                    self.pref.SetBool("NoProxyCheck", True)
95
                    self.pref.SetBool("SystemProxyCheck", False)
96
                    self.pref.SetBool("UserProxyCheck", False)
97
                elif selected_proxy_option == 1:
98
                    self.pref.SetBool("NoProxyCheck", False)
99
                    self.pref.SetBool("SystemProxyCheck", True)
100
                    self.pref.SetBool("UserProxyCheck", False)
101
                else:
102
                    self.pref.SetBool("NoProxyCheck", False)
103
                    self.pref.SetBool("SystemProxyCheck", False)
104
                    self.pref.SetBool("UserProxyCheck", True)
105
                    self.pref.SetString("ProxyUrl", warning_dialog.lineEditProxy.text())
106
        return self.readWarning
107

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.