OpenStructure
Loading...
Searching...
No Matches
build-2.11
stage
lib
python3.11
site-packages
ost
gui
scene
immutable_gradient_info_handler.py
Go to the documentation of this file.
1
#------------------------------------------------------------------------------
2
# This file is part of the OpenStructure project <www.openstructure.org>
3
#
4
# Copyright (C) 2008-2020 by the OpenStructure authors
5
#
6
# This library is free software; you can redistribute it and/or modify it under
7
# the terms of the GNU Lesser General Public License as published by the Free
8
# Software Foundation; either version 3.0 of the License, or (at your option)
9
# any later version.
10
# This library is distributed in the hope that it will be useful, but WITHOUT
11
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13
# details.
14
#
15
# You should have received a copy of the GNU Lesser General Public License
16
# along with this library; if not, write to the Free Software Foundation, Inc.,
17
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
#------------------------------------------------------------------------------
19
# -*- coding: utf-8 -*-
20
21
from
ost
import
gui
22
from
ost
import
gfx
23
from
ost
import
info
24
from
PyQt5
import
QtCore, QtWidgets, QtGui
25
26
#Gradient Editor
27
class
ImmutableGradientInfoHandler
:
28
def
__init__
(self, fileName):
29
30
self.
FILE_NAME
= fileName
31
self.
GRADIENTS_GROUP_NAME
=
"Gradients"
32
self.
GRADIENT_GROUP_NAME
=
"Gradient"
33
self.
NAME_ATTRIBUTE_NAME
=
"Name"
34
35
self.
handle_
= info.LoadOrCreateInfo(self.
FILE_NAME
)
36
37
self.
root_
= self.
handle_
.Root()
38
39
self.
gradients_
= self.
root_
.RetrieveGroup(self.
GRADIENTS_GROUP_NAME
)
40
41
42
def
GetGfxGradient
(self, name):
43
group = self.
gradients_
.GetGroup(name)
44
gfx_gradient = gfx.Gradient.GradientFromInfo(group)
45
return
gfx_gradient
46
47
def
GetQGradient
(self, name):
48
gfx_gradient = self.
GetGfxGradient
(name)
49
return
ImmutableGradientInfoHandler.ConvertToQGradient(gfx_gradient)
50
51
def
GetQGradients
(self):
52
group_list = self.
gradients_
.GetGroups(self.
GRADIENT_GROUP_NAME
)
53
q_gradients = dict()
54
55
for
group
in
group_list:
56
if
group.HasAttribute(self.
NAME_ATTRIBUTE_NAME
):
57
gfx_gradient = gfx.Gradient.GradientFromInfo(group)
58
q_gradients[group.GetAttribute(self.
NAME_ATTRIBUTE_NAME
)] = (ImmutableGradientInfoHandler.ConvertToQGradient(gfx_gradient))
59
60
return
q_gradients
61
62
@staticmethod
63
def
ConvertToQGradient
(gfx_gradient):
64
stops = gfx_gradient.GetStops()
65
qgrad = QtGui.QLinearGradient()
66
for
stop
in
stops:
67
color = stop.GetColor()
68
qcolor = QtGui.QColor(int(color.Red()*255),
69
int(color.Green()*255),
70
int(color.Blue()*255),
71
int(color.Alpha()*255))
72
qgrad.setColorAt(stop.GetRel(), qcolor)
73
return
qgrad
74
75
@staticmethod
76
def
ConvertToGfxGradient
(gradient):
77
gfx_gradient =
gfx.Gradient
()
78
for
s
in
gradient.stops():
79
rel=s[0]
80
color=s[1]
81
gfx_gradient.SetColorAt(s[0], gfx.RGB(s[1].redF(), s[1].greenF(), s[1].blueF()));
82
return
gfx_gradient;
ost::gfx::Gradient
color gradient
Definition
gradient.hh:59
ost::gui.scene.immutable_gradient_info_handler.ImmutableGradientInfoHandler
Definition
immutable_gradient_info_handler.py:27
ost::gui.scene.immutable_gradient_info_handler.ImmutableGradientInfoHandler.ConvertToGfxGradient
ConvertToGfxGradient(gradient)
Definition
immutable_gradient_info_handler.py:76
ost::gui.scene.immutable_gradient_info_handler.ImmutableGradientInfoHandler.__init__
__init__(self, fileName)
Definition
immutable_gradient_info_handler.py:28
ost::gui.scene.immutable_gradient_info_handler.ImmutableGradientInfoHandler.root_
root_
Definition
immutable_gradient_info_handler.py:37
ost::gui.scene.immutable_gradient_info_handler.ImmutableGradientInfoHandler.GetGfxGradient
GetGfxGradient(self, name)
Definition
immutable_gradient_info_handler.py:42
ost::gui.scene.immutable_gradient_info_handler.ImmutableGradientInfoHandler.handle_
handle_
Definition
immutable_gradient_info_handler.py:35
ost::gui.scene.immutable_gradient_info_handler.ImmutableGradientInfoHandler.ConvertToQGradient
ConvertToQGradient(gfx_gradient)
Definition
immutable_gradient_info_handler.py:63
ost::gui.scene.immutable_gradient_info_handler.ImmutableGradientInfoHandler.GetQGradients
GetQGradients(self)
Definition
immutable_gradient_info_handler.py:51
ost::gui.scene.immutable_gradient_info_handler.ImmutableGradientInfoHandler.FILE_NAME
FILE_NAME
Definition
immutable_gradient_info_handler.py:30
ost::gui.scene.immutable_gradient_info_handler.ImmutableGradientInfoHandler.GRADIENTS_GROUP_NAME
GRADIENTS_GROUP_NAME
Definition
immutable_gradient_info_handler.py:31
ost::gui.scene.immutable_gradient_info_handler.ImmutableGradientInfoHandler.GetQGradient
GetQGradient(self, name)
Definition
immutable_gradient_info_handler.py:47
ost::gui.scene.immutable_gradient_info_handler.ImmutableGradientInfoHandler.gradients_
gradients_
Definition
immutable_gradient_info_handler.py:39
ost::gui.scene.immutable_gradient_info_handler.ImmutableGradientInfoHandler.NAME_ATTRIBUTE_NAME
NAME_ATTRIBUTE_NAME
Definition
immutable_gradient_info_handler.py:33
ost::gui.scene.immutable_gradient_info_handler.ImmutableGradientInfoHandler.GRADIENT_GROUP_NAME
GRADIENT_GROUP_NAME
Definition
immutable_gradient_info_handler.py:32
Generated by
1.9.8