FreeCAD

Форк
0
/
AppStartGui.cpp 
115 строк · 4.0 Кб
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()
37
void CreateStartCommands();
38

39
void loadStartResource()
40
{
41
    // add resources and reloads the translators
42
    Q_INIT_RESOURCE(Start);
43
    Q_INIT_RESOURCE(Start_translation);
44
    Gui::Translator::instance()->refresh();
45
}
46

47
namespace StartGui
48
{
49
class Module: public Py::ExtensionModule<Module>
50
{
51
public:
52
    Module()
53
        : Py::ExtensionModule<Module>("StartGui")
54
    {
55
        initialize("This module is the StartGui module.");  // register with Python
56
    }
57

58
private:
59
};
60

61
PyObject* initModule()
62
{
63
    return Base::Interpreter().addModule(new Module);
64
}
65

66
}  // namespace StartGui
67

68

69
/* Python entry */
70
PyMOD_INIT_FUNC(StartGui)
71
{
72
    if (!Gui::Application::Instance) {
73
        PyErr_SetString(PyExc_ImportError, "Cannot load Gui module in console application.");
74
        PyMOD_Return(nullptr);
75
    }
76

77
    // load dependent module
78
    try {
79
        Base::Interpreter().runString("import WebGui");
80
    }
81
    catch (const Base::Exception& e) {
82
        PyErr_SetString(PyExc_ImportError, e.what());
83
        PyMOD_Return(nullptr);
84
    }
85
    catch (Py::Exception& e) {
86
        Py::Object o = Py::type(e);
87
        if (o.isString()) {
88
            Py::String s(o);
89
            Base::Console().Error("%s\n", s.as_std_string("utf-8").c_str());
90
        }
91
        else {
92
            Py::String s(o.repr());
93
            Base::Console().Error("%s\n", s.as_std_string("utf-8").c_str());
94
        }
95
        // Prints message to console window if we are in interactive mode
96
        PyErr_Print();
97
    }
98

99
    PyObject* mod = StartGui::initModule();
100
    Base::Console().Log("Loading GUI of Start module... done\n");
101

102
    // clang-format off
103
    // register preferences pages
104
    new Gui::PrefPageProducer<StartGui::DlgStartPreferencesImp> (QT_TRANSLATE_NOOP("QObject", "Start"));
105
    new Gui::PrefPageProducer<StartGui::DlgStartPreferencesAdvancedImp> (QT_TRANSLATE_NOOP("QObject", "Start"));
106
    // clang-format on
107

108
    // instantiating the commands
109
    CreateStartCommands();
110
    StartGui::Workbench::init();
111

112
    // add resources and reloads the translators
113
    loadStartResource();
114
    PyMOD_Return(mod);
115
}
116

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

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

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

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