FreeCAD
1/***************************************************************************
2* Copyright (c) 2008 Jürgen Riegel <juergen.riegel@web.de> *
3* *
4* This file is part of the FreeCAD CAx development system. *
5* *
6* This library is free software; you can redistribute it and/or *
7* modify it under the terms of the GNU Library General Public *
8* License as published by the Free Software Foundation; either *
9* version 2 of the License, or (at your option) any later version. *
10* *
11* This library is distributed in the hope that it will be useful, *
12* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14* GNU Library General Public License for more details. *
15* *
16* You should have received a copy of the GNU Library General Public *
17* License along with this library; see the file COPYING.LIB. If not, *
18* write to the Free Software Foundation, Inc., 59 Temple Place, *
19* Suite 330, Boston, MA 02111-1307, USA *
20* *
21***************************************************************************/
22
23#include "PreCompiled.h"24
25#include <Base/Console.h>26#include <Base/Interpreter.h>27#include <Base/PyObjectBase.h>28#include <Gui/Application.h>29#include <Gui/Language/Translator.h>30#include <Gui/WidgetFactory.h>31
32#include "DlgStartPreferencesImp.h"33#include "Workbench.h"34
35
36// use a different name to CreateCommand()
37void CreateStartCommands();38
39void loadStartResource()40{
41// add resources and reloads the translators42Q_INIT_RESOURCE(Start);43Q_INIT_RESOURCE(Start_translation);44Gui::Translator::instance()->refresh();45}
46
47namespace StartGui48{
49class Module: public Py::ExtensionModule<Module>50{
51public:52Module()53: Py::ExtensionModule<Module>("StartGui")54{55initialize("This module is the StartGui module."); // register with Python56}57
58private:59};60
61PyObject* initModule()62{
63return Base::Interpreter().addModule(new Module);64}
65
66} // namespace StartGui67
68
69/* Python entry */
70PyMOD_INIT_FUNC(StartGui)71{
72if (!Gui::Application::Instance) {73PyErr_SetString(PyExc_ImportError, "Cannot load Gui module in console application.");74PyMOD_Return(nullptr);75}76
77// load dependent module78try {79Base::Interpreter().runString("import WebGui");80}81catch (const Base::Exception& e) {82PyErr_SetString(PyExc_ImportError, e.what());83PyMOD_Return(nullptr);84}85catch (Py::Exception& e) {86Py::Object o = Py::type(e);87if (o.isString()) {88Py::String s(o);89Base::Console().Error("%s\n", s.as_std_string("utf-8").c_str());90}91else {92Py::String s(o.repr());93Base::Console().Error("%s\n", s.as_std_string("utf-8").c_str());94}95// Prints message to console window if we are in interactive mode96PyErr_Print();97}98
99PyObject* mod = StartGui::initModule();100Base::Console().Log("Loading GUI of Start module... done\n");101
102// clang-format off103// register preferences pages104new Gui::PrefPageProducer<StartGui::DlgStartPreferencesImp> (QT_TRANSLATE_NOOP("QObject", "Start"));105new Gui::PrefPageProducer<StartGui::DlgStartPreferencesAdvancedImp> (QT_TRANSLATE_NOOP("QObject", "Start"));106// clang-format on107
108// instantiating the commands109CreateStartCommands();110StartGui::Workbench::init();111
112// add resources and reloads the translators113loadStartResource();114PyMOD_Return(mod);115}
116