FreeCAD

Форк
0
/
AppStartGui.cpp 
128 строк · 4.4 Кб
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
#include "PreCompiled.h"
25
#ifndef _PreComp_
26
#include <QString>
27
#include <QTimer>
28
#endif
29

30
#include <Base/Console.h>
31
#include <Base/Interpreter.h>
32
#include <Base/PyObjectBase.h>
33
#include <Gui/Language/Translator.h>
34
#include <Gui/Command.h>
35
#include <Gui/MainWindow.h>
36

37

38
#include <gsl/pointers>
39

40
#include "Manipulator.h"
41
#include "StartView.h"
42

43
void loadStartResource()
44
{
45
    // add resources and reloads the translators
46
    Q_INIT_RESOURCE(Start);
47
    Q_INIT_RESOURCE(Start_translation);
48
    Gui::Translator::instance()->refresh();
49
}
50

51
namespace StartGui
52
{
53
extern PyObject* initModule();
54
}
55

56

57
namespace StartGui
58
{
59
class Module: public Py::ExtensionModule<Module>
60
{
61
public:
62
    Module()
63
        : Py::ExtensionModule<Module>("StartGui")
64
    {
65
        initialize("This module is the StartGui module.");  // register with Python
66
    }
67
};
68

69
class StartLauncher
70
{
71
public:
72
    StartLauncher()
73
    {
74
        // QTimers don't fire until the event loop starts, which is our signal that the GUI is up
75
        QTimer::singleShot(100, [this] {
76
            Launch();
77
        });
78
    }
79

80
    void Launch()
81
    {
82
        auto hGrp = App::GetApplication().GetParameterGroupByPath(
83
            "User parameter:BaseApp/Preferences/Mod/Start");
84
        bool showOnStartup = hGrp->GetBool("ShowOnStartup", true);
85
        if (showOnStartup) {
86
            Gui::Application::Instance->commandManager().runCommandByName("Start_Start");
87
            QTimer::singleShot(100, [this] {
88
                EnsureLaunched();
89
            });
90
        }
91
    }
92

93
    void EnsureLaunched()
94
    {
95
        // It's possible that "Start_Start" didn't result in the creation of an MDI window, if it
96
        // was called to early. This polls the views to make sure the view was created, and if it
97
        // was not, re-calls the command.
98
        auto mw = Gui::getMainWindow();
99
        auto existingView = mw->findChild<StartGui::StartView*>(QLatin1String("StartView"));
100
        if (!existingView) {
101
            Launch();
102
        }
103
    }
104
};
105

106
PyObject* initModule()
107
{
108
    auto newModule = gsl::owner<Module*>(new Module);
109
    return Base::Interpreter().addModule(newModule);  // Transfer ownership
110
}
111

112
}  // namespace StartGui
113

114
/* Python entry */
115
PyMOD_INIT_FUNC(StartGui)
116
{
117
    static StartGui::StartLauncher* launcher = new StartGui::StartLauncher();
118
    Q_UNUSED(launcher)
119

120
    Base::Console().Log("Loading GUI of Start module... ");
121
    PyObject* mod = StartGui::initModule();
122
    auto manipulator = std::make_shared<StartGui::Manipulator>();
123
    Gui::WorkbenchManipulator::installManipulator(manipulator);
124
    loadStartResource();
125
    Base::Console().Log("done\n");
126

127
    PyMOD_Return(mod);
128
}
129

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

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

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

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