FreeCAD

Форк
0
/
StartMigrator.py 
118 строк · 6.3 Кб
1
# SPDX-License-Identifier: LGPL-2.1-or-later
2
# /**************************************************************************
3
#                                                                           *
4
#    Copyright (c) 2024 The FreeCAD Project Association AISBL               *
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
import FreeCAD
25

26

27
def _remove_from_list(prefs, pref_name):
28
    # Remove Start and Web from a preference that consists of a comma-separated list of workbenches
29
    mods = prefs.GetString(pref_name, "").split(",")
30
    if "StartWorkbench" in mods:
31
        mods.remove("StartWorkbench")
32
    if "WebWorkbench" in mods:
33
        mods.remove("WebWorkbench")
34
    prefs.SetString(pref_name, ",".join(mods))
35

36

37
class StartMigrator2024:
38
    """In April 2024 the old Start workbench was retired, and replaced with the current Start command. This function
39
    cleans up references to the old workbench, migrating the settings where appropriate, and deleting them where they
40
    are no longer relevant. Web was also removed, without replacement.
41
    TODO: Remove the 2024 migration code when enough time has passed that it is no longer useful"""
42

43
    def __init__(self):
44
        self.completion_indicator = "Migration2024Complete"
45
        self.start_prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Start")
46
        self.general_prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/General")
47
        self.migration_2024_complete = self.start_prefs.GetBool(self.completion_indicator, False)
48

49
    def run_migration(self):
50
        if self.migration_2024_complete:
51
            # Refuse to run if it's already been done
52
            return
53
        FreeCAD.Console.PrintMessage("Migrating Start Workbench to Start command... ")
54
        self._update_startup_flags()
55
        self._remove_wb_references()
56
        self._remove_commands()
57
        self._remove_toolbars()
58
        self._remove_deprecated_parameters()
59
        self._mark_complete()
60
        FreeCAD.Console.PrintMessage("done.\n")
61

62
    # If the old Start workbench was set as the Autoload Module, reconfigure it so the Start command is run at startup,
63
    # and set the Autoload module to "PartDesignWorkbench"
64
    def _update_startup_flags(self):
65
        autoload_module = self.general_prefs.GetString("AutoloadModule", "StartWorkbench")
66
        if autoload_module == "StartWorkbench":
67
            self.start_prefs.SetBool("ShowOnStartup", True)
68
            self.general_prefs.SetString("AutoloadModule", "PartDesignWorkbench")
69
        else:
70
            self.start_prefs.SetBool("ShowOnStartup", False)
71

72
    # Remove all references to the StartWorkbench in the various workbench lists
73
    def _remove_wb_references(self):
74
        general_prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/General")
75
        last_module = general_prefs.GetString("LastModule", "")
76
        if last_module in ["StartWorkbench", "WebWorkbench"]:
77
            general_prefs.RemString("LastModule")
78
        _remove_from_list(general_prefs, "BackgroundAutoloadModules")
79
        treeview_prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Workbenches")
80
        _remove_from_list(treeview_prefs, "Ordered")
81
        _remove_from_list(treeview_prefs, "Disabled")
82

83
    # Remove any commands that begin with "Start_" or "Web_" (except "Start_Start", the current command)
84
    def _remove_commands(self):
85
        command_prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Commands")
86
        commands = command_prefs.GetStrings()
87
        for command in commands:
88
            if command.startswith("Web_") or (
89
                command.startswith("Start_") and command != "Start_Start"
90
            ):
91
                command_prefs.RemString(command)
92

93
    # Remove any persistent toolbars
94
    def _remove_toolbars(self):
95
        tux_prefs = FreeCAD.ParamGet("User parameter:Tux/PersistentToolbars/User")
96
        groups = tux_prefs.GetGroups()
97
        if "StartWorkbench" in groups:
98
            tux_prefs.RemGroup("StartWorkbench")
99
        if "WebWorkbench" in groups:
100
            tux_prefs.RemGroup("WebWorkbench")
101

102
    # Delete old Start preferences
103
    def _remove_deprecated_parameters(self):
104
        show_on_startup = self.start_prefs.GetBool("ShowOnStartup", True)
105
        show_examples = self.start_prefs.GetBool("ShowExamples", True)
106
        close_start = self.start_prefs.GetBool("closeStart", False)
107
        custom_folder = self.start_prefs.GetString(
108
            "ShowCustomFolder", ""
109
        )  # Note: allow multiple locations separated by ";;"
110
        self.start_prefs.Clear()
111
        self.start_prefs.SetBool("ShowOnStartup", show_on_startup)
112
        self.start_prefs.SetBool("ShowExamples", show_examples)
113
        self.start_prefs.SetBool("CloseStart", close_start)
114
        self.start_prefs.SetString("ShowCustomFolder", custom_folder)
115

116
    # Indicate that this migration has been run
117
    def _mark_complete(self):
118
        self.start_prefs.SetBool(self.completion_indicator, True)
119

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

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

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

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