1
// SPDX-License-Identifier: LGPL-2.1-or-later
2
/****************************************************************************
4
* Copyright (c) 2024 The FreeCAD Project Association AISBL *
6
* This file is part of FreeCAD. *
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. *
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. *
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/>. *
22
***************************************************************************/
24
#include "PreCompiled.h"
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>
38
#include <gsl/pointers>
40
#include "Manipulator.h"
43
void loadStartResource()
45
// add resources and reloads the translators
46
Q_INIT_RESOURCE(Start);
47
Q_INIT_RESOURCE(Start_translation);
48
Gui::Translator::instance()->refresh();
53
extern PyObject* initModule();
59
class Module: public Py::ExtensionModule<Module>
63
: Py::ExtensionModule<Module>("StartGui")
65
initialize("This module is the StartGui module."); // register with Python
74
// QTimers don't fire until the event loop starts, which is our signal that the GUI is up
75
QTimer::singleShot(100, [this] {
82
auto hGrp = App::GetApplication().GetParameterGroupByPath(
83
"User parameter:BaseApp/Preferences/Mod/Start");
84
bool showOnStartup = hGrp->GetBool("ShowOnStartup", true);
86
Gui::Application::Instance->commandManager().runCommandByName("Start_Start");
87
QTimer::singleShot(100, [this] {
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"));
106
PyObject* initModule()
108
auto newModule = gsl::owner<Module*>(new Module);
109
return Base::Interpreter().addModule(newModule); // Transfer ownership
112
} // namespace StartGui
115
PyMOD_INIT_FUNC(StartGui)
117
static StartGui::StartLauncher* launcher = new StartGui::StartLauncher();
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);
125
Base::Console().Log("done\n");