00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 from ost import gui
00022 from ost import gfx
00023 from ost import info
00024 from PyQt4 import QtCore, QtGui
00025
00026
00027 class ImmutableGradientInfoHandler:
00028 def __init__(self, fileName):
00029
00030 self.FILE_NAME = fileName
00031 self.GRADIENTS_GROUP_NAME = "Gradients"
00032 self.GRADIENT_GROUP_NAME = "Gradient"
00033 self.NAME_ATTRIBUTE_NAME = "Name"
00034
00035 self.handle_ = info.LoadOrCreateInfo(self.FILE_NAME)
00036
00037 self.root_ = self.handle_.Root()
00038
00039 self.gradients_ = self.root_.RetrieveGroup(self.GRADIENTS_GROUP_NAME)
00040
00041
00042 def GetGfxGradient(self, name):
00043 group = self.gradients_.GetGroup(name)
00044 gfx_gradient = gfx.Gradient.GradientFromInfo(group)
00045 return gfx_gradient
00046
00047 def GetQGradient(self, name):
00048 gfx_gradient = self.GetGfxGradient(name)
00049 return ImmutableGradientInfoHandler.ConvertToQGradient(gfx_gradient)
00050
00051 def GetQGradients(self):
00052 group_list = self.gradients_.GetGroups(self.GRADIENT_GROUP_NAME)
00053 q_gradients = dict()
00054
00055 for group in group_list:
00056 if group.HasAttribute(self.NAME_ATTRIBUTE_NAME):
00057 gfx_gradient = gfx.Gradient.GradientFromInfo(group)
00058 q_gradients[group.GetAttribute(self.NAME_ATTRIBUTE_NAME)] = (ImmutableGradientInfoHandler.ConvertToQGradient(gfx_gradient))
00059
00060 return q_gradients
00061
00062 @staticmethod
00063 def ConvertToQGradient(gfx_gradient):
00064 stops = gfx_gradient.GetStops()
00065 qgrad = QtGui.QLinearGradient()
00066 for stop in stops:
00067 color = stop.GetColor()
00068 qcolor = QtGui.QColor(color.Red()*255,
00069 color.Green()*255,
00070 color.Blue()*255,
00071 color.Alpha()*255)
00072 qgrad.setColorAt(stop.GetRel(), qcolor)
00073 return qgrad
00074
00075 @staticmethod
00076 def ConvertToGfxGradient(gradient):
00077 gfx_gradient = gfx.Gradient()
00078 for s in gradient.stops():
00079 rel=s[0]
00080 color=s[1]
00081 gfx_gradient.SetColorAt(s[0], gfx.RGB(s[1].redF(), s[1].greenF(), s[1].blueF()));
00082 return gfx_gradient;