00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 import sys
00022 from ost import mol
00023 from ost import gui
00024 from ost import gfx
00025 try:
00026 from ost import img
00027 _img_present=True
00028 except ImportError:
00029 _img_present=False
00030 pass
00031
00032 from PyQt4 import QtCore, QtGui
00033 from scene_selection_helper import SelHelper
00034 from gradient_editor_widget import GradientEditor
00035 from uniform_color_widget import UniformColorWidget
00036 from combo_options_widget import ComboOptionsWidget
00037
00038 class ColorOptionsWidget(ComboOptionsWidget):
00039 def __init__(self, parent=None):
00040 ComboOptionsWidget.__init__(self, parent)
00041
00042
00043 self.text_ = "Color Options"
00044 conly_label_ = QtGui.QLabel('carbons only')
00045 self.conly_box_ = QtGui.QCheckBox()
00046
00047
00048 self.entity_widgets_ = list()
00049 self.entity_widgets_.append(["Color by Element", ByElementWidget("Color by Element", self)])
00050 self.entity_widgets_.append(["Color by Chain", ByChainWidget("Color by Chain", self)])
00051 self.entity_widgets_.append(["Color by Entity", ByEntityWidget("Color by Entity", self)])
00052 self.entity_widgets_.append(["Color by Property", GradientEditor(self)])
00053 self.entity_widgets_.append(["Uniform",UniformColorWidget(self)])
00054
00055 self.img_widgets_ = list()
00056 self.img_widgets_.append(["Uniform",UniformColorWidget()])
00057
00058 qw = QtGui.QWidget(self)
00059 gl = QtGui.QGridLayout(qw)
00060 gl.addWidget(self.conly_box_, 0, 0, 1, 1)
00061 gl.addWidget(conly_label_, 0, 1, 1, 4)
00062 self.grid_layout_.addWidget(qw, 2, 0, 1, 1)
00063
00064 self.setMinimumSize(250,200)
00065
00066 def OnComboChange(self, item):
00067 scene_selection = gui.SceneSelection.Instance()
00068 if hasattr(item,"PrepareColoring"):
00069 item.PrepareColoring()
00070 for i in range(0,scene_selection.GetActiveNodeCount()):
00071 node = scene_selection.GetActiveNode(i)
00072 item.ChangeColor(node)
00073
00074 if(scene_selection.GetActiveViewCount() > 0):
00075 entity = scene_selection.GetViewEntity()
00076 view = scene_selection.GetViewUnion()
00077 item.ChangeViewColor(entity,view)
00078
00079 self.DoResize()
00080
00081
00082 def Update(self):
00083
00084 ComboOptionsWidget.setEnabled(self,True)
00085
00086 if SelHelper().CheckAllFlags(SelHelper.NO_SELECTION):
00087 ComboOptionsWidget.setEnabled(self,False)
00088 return
00089
00090 for w in self.entity_widgets_:
00091 self.RemoveWidget(w[0])
00092 for w in self.img_widgets_:
00093 self.RemoveWidget(w[0])
00094
00095
00096 if SelHelper().CheckFlags(SelHelper.HAS_IMG | SelHelper.IS_ONE_TYPE):
00097 for w in self.img_widgets_:
00098 self.AddWidget(w[0], w[1])
00099 elif SelHelper().CheckMinOneFlag(SelHelper.HAS_ENTITY| SelHelper.HAS_VIEW| SelHelper.HAS_SURFACE) and SelHelper().CheckNotFlags(SelHelper.HAS_IMG):
00100 for w in self.entity_widgets_:
00101 self.AddWidget(w[0], w[1])
00102 else:
00103 ComboOptionsWidget.setEnabled(self,False)
00104 return
00105
00106 self.GetCurrentWidget().Update()
00107
00108 def GetText(self):
00109 return self.text_
00110
00111 def GetCarbonsOnly(self):
00112 return self.conly_box_.isChecked()
00113
00114
00115 class ByElementWidget(QtGui.QWidget):
00116 def __init__(self, text, parent=None):
00117 QtGui.QWidget.__init__(self, parent)
00118 self.parent_ = parent
00119
00120
00121
00122 self.text_ = text
00123
00124
00125 text_label = QtGui.QLabel(text)
00126 font = text_label.font()
00127 font.setBold(True)
00128
00129 grid = QtGui.QGridLayout()
00130 grid.addWidget(text_label,0,0,1,1)
00131 grid.addWidget(QtGui.QLabel("No Settings available"), 1, 0, 1, 3)
00132 grid.setRowStretch(2,1)
00133 self.setLayout(grid)
00134 self.setMinimumSize(250,60)
00135
00136 def Update(self):
00137 pass
00138
00139 def ChangeColor(self, node):
00140 if isinstance(node, gfx.Entity):
00141 node.CleanColorOps()
00142 if self.parent_.GetCarbonsOnly():
00143 node.ColorByElement("ele=C")
00144 else:
00145 node.ColorByElement()
00146
00147 def ChangeViewColor(self, entity, view):
00148 if isinstance(entity, gfx.Entity) and isinstance(view, mol.EntityView):
00149 if self.parent_.GetCarbonsOnly():
00150 beco=gfx.ByElementColorOp(mol.QueryViewWrapper(mol.Query("ele=C"), view))
00151 else:
00152 beco=gfx.ByElementColorOp(mol.QueryViewWrapper(view))
00153 entity.Apply(beco)
00154
00155 def GetText(self):
00156 return self.text_
00157
00158
00159 class ByChainWidget(QtGui.QWidget):
00160 def __init__(self, text, parent=None):
00161 QtGui.QWidget.__init__(self, parent)
00162 self.parent_ = parent
00163
00164
00165 self.text_ = text
00166
00167
00168 text_label = QtGui.QLabel(text)
00169 font = text_label.font()
00170 font.setBold(True)
00171
00172 grid = QtGui.QGridLayout()
00173 grid.addWidget(text_label,0,0,1,1)
00174 grid.setRowStretch(2,1)
00175 self.setLayout(grid)
00176 self.setMinimumSize(250,60)
00177
00178 def Update(self):
00179 pass
00180
00181 def ChangeColor(self, node):
00182 if isinstance(node, gfx.Entity):
00183 node.CleanColorOps()
00184 if self.parent_.GetCarbonsOnly():
00185 node.ColorByChain('ele=C')
00186 else:
00187 node.ColorByChain()
00188
00189 def ChangeViewColor(self, entity, view):
00190 if isinstance(entity, gfx.Entity) and isinstance(view, mol.EntityView):
00191 if self.parent_.GetCarbonsOnly():
00192 bco=gfx.ByChainColorOp(mol.QueryViewWrapper(mol.Query("ele=C"),view))
00193 else:
00194 bco=gfx.ByChainColorOp(mol.QueryViewWrapper(view))
00195 entity.Apply(bco)
00196
00197 def GetText(self):
00198 return self.text_
00199
00200 class ByEntityWidget(QtGui.QWidget):
00201 def __init__(self, text, parent=None):
00202 QtGui.QWidget.__init__(self, parent)
00203 self.parent_ = parent
00204
00205
00206 self.text_ = text
00207
00208
00209 text_label = QtGui.QLabel(text)
00210 font = text_label.font()
00211 font.setBold(True)
00212
00213 grid = QtGui.QGridLayout()
00214 grid.addWidget(text_label,0,0,1,1)
00215 grid.setRowStretch(2,1)
00216 self.setLayout(grid)
00217 self.setMinimumSize(250,60)
00218
00219 self.gradient_ = gfx.Gradient("RAINBOW")
00220
00221 def Update(self):
00222 pass
00223
00224 def PrepareColoring(self):
00225 scene_selection = gui.SceneSelection.Instance()
00226 entity_count = scene_selection.GetActiveNodeCount()
00227 for i in range(0,scene_selection.GetActiveNodeCount()):
00228 if i<=0:
00229 color=self.gradient_.GetColorAt(0.0)
00230 else:
00231 color=self.gradient_.GetColorAt(float(i) / entity_count)
00232 node = scene_selection.GetActiveNode(i)
00233 if self.parent_.GetCarbonsOnly():
00234 node.SetColor(color, 'ele=C')
00235 else:
00236 node.SetColor(color)
00237
00238 def ChangeColor(self, node):
00239 pass
00240
00241 def ChangeViewColor(self, entity, view):
00242 if isinstance(entity, gfx.Entity) and isinstance(view, mol.EntityView):
00243 if self.parent_.GetCarbonsOnly():
00244 bco=gfx.ByChainColorOp(mol.QueryViewWrapper(mol.Query("ele=C"),view))
00245 else:
00246 bco=gfx.ByChainColorOp(mol.QueryViewWrapper(view))
00247 entity.Apply(bco)
00248
00249 def GetText(self):
00250 return self.text_