FreeCAD

Форк
0
72 строки · 3.4 Кб
1
# ***************************************************************************
2
# *   (c) 2009 Yorik van Havre <yorik@uncreated.net>                        *
3
# *   (c) 2010 Ken Cline <cline@frii.com>                                   *
4
# *   (c) 2020 Eliud Cabrera Castillo <e.cabrera-castillo@tum.de>           *
5
# *                                                                         *
6
# *   This file is part of the FreeCAD CAx development system.              *
7
# *                                                                         *
8
# *   This program is free software; you can redistribute it and/or modify  *
9
# *   it under the terms of the GNU Lesser General Public License (LGPL)    *
10
# *   as published by the Free Software Foundation; either version 2 of     *
11
# *   the License, or (at your option) any later version.                   *
12
# *   for detail see the LICENCE text file.                                 *
13
# *                                                                         *
14
# *   FreeCAD is distributed in the hope that it will be useful,            *
15
# *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
16
# *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
17
# *   GNU Library General Public License for more details.                  *
18
# *                                                                         *
19
# *   You should have received a copy of the GNU Library General Public     *
20
# *   License along with FreeCAD; if not, write to the Free Software        *
21
# *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
22
# *   USA                                                                   *
23
# *                                                                         *
24
# ***************************************************************************
25
"""Provides GUI tools to apply styles to objects."""
26
## @package gui_styles
27
# \ingroup draftguitools
28
# \brief Provides GUI tools to apply styles to objects.
29

30
## \addtogroup draftguitools
31
# @{
32
from PySide.QtCore import QT_TRANSLATE_NOOP
33

34
import FreeCADGui as Gui
35

36
from draftguitools import gui_base_original
37
from draftutils.translate import translate
38
from draftutils import groups
39

40
class ApplyStyle(gui_base_original.Modifier):
41
    """Gui Command for the ApplyStyle tool."""
42

43
    def GetResources(self):
44
        """Set icon, menu and tooltip."""
45
        return {
46
            "Pixmap": "Draft_Apply",
47
            "MenuText": QT_TRANSLATE_NOOP("Draft_ApplyStyle", "Apply current style"),
48
            "ToolTip": QT_TRANSLATE_NOOP("Draft_ApplyStyle", "Applies the current style defined in the toolbar (line width and colors) to the selected objects and groups.")
49
        }
50

51
    def IsActive(self):
52
        return bool(Gui.ActiveDocument and Gui.Selection.getSelection())
53

54
    def Activated(self):
55
        """Execute when the command is called."""
56
        super().Activated(name="Apply style")
57
        objs = Gui.Selection.getSelection()
58
        if objs:
59
            objs = groups.get_group_contents(objs, addgroups=True, spaces=True, noarchchild=True)
60
            Gui.addModule("Draft")
61
            cmd_list = [
62
                "doc = FreeCAD.ActiveDocument",
63
                "Draft.apply_current_style([" + ", ".join(["doc." + obj.Name for obj in objs]) + "])",
64
                "doc.recompute()"
65
            ]
66
            self.commit(translate("draft", "Change Style"), cmd_list)
67
        self.finish()
68

69

70
Gui.addCommand("Draft_ApplyStyle", ApplyStyle())
71

72
## @}
73

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

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

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

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