FreeCAD
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
26import os27
28from PySide import QtCore, QtWidgets29
30import FreeCAD31import FreeCADGui32
33import addonmanager_utilities as utils34
35# pylint: disable=too-few-public-methods
36
37
38class FirstRunDialog:39"""Manage the display of the Addon Manager's first-run dialog, setting up some user40preferences and making sure they are aware that this connects to the internet, downloads
41data, and possibly installs things that run code not affiliated with FreeCAD itself."""
42
43def __init__(self):44self.pref = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Addons")45self.readWarning = self.pref.GetBool("readWarning2022", False)46
47def exec(self) -> bool:48"""Display a first-run dialog if needed, and return True to indicate the Addon Manager49should continue loading, or False if the user cancelled the dialog and wants to exit."""
50if not self.readWarning:51warning_dialog = FreeCADGui.PySideUic.loadUi(52os.path.join(os.path.dirname(__file__), "first_run.ui")53)54warning_dialog.setWindowFlag(QtCore.Qt.WindowStaysOnTopHint, True)55autocheck = self.pref.GetBool("AutoCheck", False)56download_macros = self.pref.GetBool("DownloadMacros", False)57proxy_string = self.pref.GetString("ProxyUrl", "")58if self.pref.GetBool("NoProxyCheck", True):59proxy_option = 060elif self.pref.GetBool("SystemProxyCheck", False):61proxy_option = 162elif self.pref.GetBool("UserProxyCheck", False):63proxy_option = 264
65def toggle_proxy_list(option: int):66if option == 2:67warning_dialog.lineEditProxy.show()68else:69warning_dialog.lineEditProxy.hide()70
71warning_dialog.checkBoxAutoCheck.setChecked(autocheck)72warning_dialog.checkBoxDownloadMacroMetadata.setChecked(download_macros)73warning_dialog.comboBoxProxy.setCurrentIndex(proxy_option)74toggle_proxy_list(proxy_option)75if proxy_option == 2:76warning_dialog.lineEditProxy.setText(proxy_string)77
78warning_dialog.comboBoxProxy.currentIndexChanged.connect(toggle_proxy_list)79
80warning_dialog.labelWarning.setStyleSheet(81f"color:{utils.warning_color_string()};font-weight:bold;"82)83
84if warning_dialog.exec() == QtWidgets.QDialog.Accepted:85self.readWarning = True86self.pref.SetBool("readWarning2022", True)87self.pref.SetBool("AutoCheck", warning_dialog.checkBoxAutoCheck.isChecked())88self.pref.SetBool(89"DownloadMacros",90warning_dialog.checkBoxDownloadMacroMetadata.isChecked(),91)92selected_proxy_option = warning_dialog.comboBoxProxy.currentIndex()93if selected_proxy_option == 0:94self.pref.SetBool("NoProxyCheck", True)95self.pref.SetBool("SystemProxyCheck", False)96self.pref.SetBool("UserProxyCheck", False)97elif selected_proxy_option == 1:98self.pref.SetBool("NoProxyCheck", False)99self.pref.SetBool("SystemProxyCheck", True)100self.pref.SetBool("UserProxyCheck", False)101else:102self.pref.SetBool("NoProxyCheck", False)103self.pref.SetBool("SystemProxyCheck", False)104self.pref.SetBool("UserProxyCheck", True)105self.pref.SetString("ProxyUrl", warning_dialog.lineEditProxy.text())106return self.readWarning107