Addon Manager: Add preference to control macro download

This commit is contained in:
Chris Hennes
2021-12-31 20:02:03 -06:00
parent 8ef9f257be
commit 50336440dc
5 changed files with 230 additions and 29 deletions

View File

@@ -111,32 +111,64 @@ class CommandAddonManager:
def Activated(self) -> None:
# display first use dialog if needed
readWarningParameter = FreeCAD.ParamGet(
"User parameter:BaseApp/Preferences/Addons"
)
readWarning = readWarningParameter.GetBool("readWarning", False)
newReadWarningParameter = FreeCAD.ParamGet(
"User parameter:Plugins/addonsRepository"
)
readWarning |= newReadWarningParameter.GetBool("readWarning", False)
pref = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Addons")
readWarning = pref.GetBool("readWarning2022", False)
if not readWarning:
if (
QtWidgets.QMessageBox.warning(
None,
"FreeCAD",
translate(
"AddonsInstaller",
"The addons that can be installed here are not "
"officially part of FreeCAD, and are not reviewed "
"by the FreeCAD team. Make sure you know what you "
"are installing!",
),
QtWidgets.QMessageBox.Cancel | QtWidgets.QMessageBox.Ok,
)
!= QtWidgets.QMessageBox.StandardButton.Cancel
):
readWarningParameter.SetBool("readWarning", True)
warning_dialog = FreeCADGui.PySideUic.loadUi(
os.path.join(os.path.dirname(__file__), "first_run.ui")
)
autocheck = pref.GetBool("AutoCheck", False)
download_macros = pref.GetBool("DownloadMacros", False)
proxy_string = pref.GetString("ProxyUrl", "")
if pref.GetBool("NoProxyCheck", True):
proxy_option = 0
elif pref.GetBool("SystemProxyCheck", False):
proxy_option = 1
elif pref.GetBool("UserProxyCheck", False):
proxy_option = 2
def toggle_proxy_list(option: int):
if option == 2:
warning_dialog.lineEditProxy.show()
else:
warning_dialog.lineEditProxy.hide()
warning_dialog.checkBoxAutoCheck.setChecked(autocheck)
warning_dialog.checkBoxDownloadMacroMetadata.setChecked(download_macros)
warning_dialog.comboBoxProxy.setCurrentIndex(proxy_option)
toggle_proxy_list(proxy_option)
if proxy_option == 2:
warning_dialog.lineEditProxy.setText(proxy_string)
warning_dialog.comboBoxProxy.currentIndexChanged.connect(toggle_proxy_list)
warning_dialog.labelWarning.setStyleSheet(
f"color:{utils.warning_color_string()};font-weight:bold;"
)
if warning_dialog.exec() == QtWidgets.QDialog.Accepted:
readWarning = True
pref.SetBool("readWarning2022", True)
pref.SetBool("AutoCheck", warning_dialog.checkBoxAutoCheck.isChecked())
pref.SetBool(
"DownloadMacros",
warning_dialog.checkBoxDownloadMacroMetadata.isChecked(),
)
selected_proxy_option = warning_dialog.comboBoxProxy.currentIndex()
if selected_proxy_option == 0:
pref.SetBool("NoProxyCheck", True)
pref.SetBool("SystemProxyCheck", False)
pref.SetBool("UserProxyCheck", False)
elif selected_proxy_option == 1:
pref.SetBool("NoProxyCheck", False)
pref.SetBool("SystemProxyCheck", True)
pref.SetBool("UserProxyCheck", False)
else:
pref.SetBool("NoProxyCheck", False)
pref.SetBool("SystemProxyCheck", False)
pref.SetBool("UserProxyCheck", True)
pref.SetString("ProxyUrl", warning_dialog.lineEditProxy.text())
if readWarning:
self.launch()
@@ -384,9 +416,11 @@ class CommandAddonManager:
self.activate_table_widgets,
self.populate_macros,
self.update_metadata_cache,
self.load_macro_metadata,
self.check_updates,
]
pref = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Addons")
if pref.GetBool("DownloadMacros", False):
self.startup_sequence.append(self.load_macro_metadata)
self.current_progress_region = 0
self.number_of_progress_regions = len(self.startup_sequence)
self.do_next_startup_phase()
@@ -870,7 +904,6 @@ class CommandAddonManager:
self.dialog.labelStatusInfo.hide()
self.dialog.progressBar.hide()
self.dialog.buttonPauseUpdate.hide()
self.dialog.labelUpdateInProgress.hide()
self.packageList.ui.lineEditFilter.setFocus()
def show_progress_widgets(self) -> None:
@@ -878,7 +911,6 @@ class CommandAddonManager:
self.dialog.progressBar.show()
self.dialog.buttonPauseUpdate.show()
self.dialog.labelStatusInfo.show()
self.dialog.labelUpdateInProgress.show()
def update_progress_bar(self, current_value: int, max_value: int) -> None:
"""Update the progress bar, showing it if it's hidden"""

View File

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>390</width>
<height>628</height>
<width>388</width>
<height>621</height>
</rect>
</property>
<property name="windowTitle">
@@ -35,6 +35,19 @@ installed addons will be checked for available updates
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefCheckBox" name="guiprefcheckboxdownloadmacros">
<property name="text">
<string>Download Macro metadata (approximately 10MB)</string>
</property>
<property name="prefEntry" stdset="0">
<string>DownloadMacros</string>
</property>
<property name="prefPath" stdset="0">
<string>Addons</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>

View File

@@ -13,6 +13,7 @@ SET(AddonManager_SRCS
addonmanager_workers.py
AddonManager.ui
AddonManagerOptions.ui
first_run.ui
compact_view.py
expanded_view.py
package_list.py

View File

@@ -300,4 +300,15 @@ def fix_relative_links(text, base_url):
return new_text
def warning_color_string() -> str:
warningColorString = "rgb(255,0,0)"
if hasattr(QtWidgets.QApplication.instance(), "styleSheet"):
# Qt 5.9 doesn't give a QApplication instance, so can't give the stylesheet info
if "dark" in QtWidgets.QApplication.instance().styleSheet().lower():
warningColorString = "rgb(255,50,50)"
else:
warningColorString = "rgb(200,0,0)"
return warningColorString
# @}

View File

@@ -0,0 +1,144 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="windowModality">
<enum>Qt::WindowModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>398</width>
<height>237</height>
</rect>
</property>
<property name="windowTitle">
<string>Welcome to the Addon Manager</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="labelWarning">
<property name="text">
<string>The addons that can be installed here are not officially part of FreeCAD, and are not reviewed by the FreeCAD team. Make sure you know what you are installing!</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Download Settings</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxAutoCheck">
<property name="text">
<string>Automatically check installed Addons for updates</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxDownloadMacroMetadata">
<property name="text">
<string>Download Macro metadata (approximately 10MB)</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QComboBox" name="comboBoxProxy">
<item>
<property name="text">
<string>No proxy</string>
</property>
</item>
<item>
<property name="text">
<string>System proxy</string>
</property>
</item>
<item>
<property name="text">
<string>User-defined proxy:</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEditProxy"/>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>These and other settings are available in the FreeCAD Preferences window.</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>