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 from ost.gui.scene.preset import Preset
00026
00027
00028 class ImmutablePresetInfoHandler:
00029 PRESETS_GROUP_NAME = "Presets"
00030 PRESET_GROUP_NAME = "Preset"
00031 NAME_ATTRIBUTE_NAME = "Name"
00032
00033 def __init__(self, file_name):
00034 self.file_name_ = file_name
00035 self.handle_ = info.LoadOrCreateInfo(self.file_name_)
00036
00037 self.root_ = self.handle_.Root()
00038
00039 self.presets_ = self.root_.RetrieveGroup(ImmutablePresetInfoHandler.PRESETS_GROUP_NAME)
00040
00041
00042 def GetPreset(self, name):
00043 group_list = self.presets_.GetGroups(ImmutablePresetInfoHandler.PRESET_GROUP_NAME)
00044 for group in group_list:
00045 if group.HasAttribute(ImmutablePresetInfoHandler.NAME_ATTRIBUTE_NAME):
00046 groupname = group.GetAttribute(ImmutablePresetInfoHandler.NAME_ATTRIBUTE_NAME)
00047 if name == groupname:
00048 preset = Preset.FromInfo(group)
00049 return preset
00050 return None
00051
00052 def GetPresets(self):
00053 group_list = self.presets_.GetGroups(ImmutablePresetInfoHandler.PRESET_GROUP_NAME)
00054 presets = dict()
00055
00056 for group in group_list:
00057 if group.HasAttribute(ImmutablePresetInfoHandler.NAME_ATTRIBUTE_NAME):
00058 preset = Preset.FromInfo(group)
00059 presets[group.GetAttribute(self.NAME_ATTRIBUTE_NAME)] = preset
00060 return presets