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 mol
00024 from datetime import datetime
00025 from datetime import datetime
00026 from PyQt4 import QtCore, QtGui
00027 from color_select_widget import ColorSelectWidget
00028 from gradient_preset_widget import GradientPresetWidget
00029 from gradient_editor_widget import GradientPreview
00030 from gradient_editor_widget import GradientEdit
00031 from preset_editor_list_model import PresetEditorListModel
00032 from immutable_gradient_info_handler import ImmutableGradientInfoHandler
00033 from query_editor import QueryEditorWidget
00034 from ost.mol import Prop
00035 from ost.gfx import ByElementColorOp
00036 from ost.gfx import ByChainColorOp
00037 from ost.gfx import GradientLevelColorOp
00038 from ost.gfx import UniformColorOp
00039 from preset import Preset
00040 from render_op import RenderOp
00041 from visibility_op import VisibilityOp
00042
00043
00044 class PresetEditor(QtGui.QDialog):
00045 def __init__(self, parent=None):
00046 QtGui.QDialog.__init__(self, parent)
00047
00048 self.setWindowTitle("Preset Editor")
00049
00050
00051 self.list_view_ = QtGui.QListView()
00052
00053 self.combo_box_ = QtGui.QComboBox()
00054
00055 self.ufcow_=UniformColorOpWidget(self)
00056 self.glcow_=GradientLevelColorOpWidget(self)
00057 self.beow_=ByElementColorOpWidget(self)
00058 self.bcow_=ByChainColorOpWidget(self)
00059 self.row_=RenderOpWidget(self)
00060 self.vow_=VisibilityOpWidget(self)
00061 self.combo_box_.addItem("Uniform Color Operation", QtCore.QVariant(self.ufcow_))
00062 self.combo_box_.addItem("Gradient Operation", QtCore.QVariant(self.glcow_))
00063 self.combo_box_.addItem("By Element Operation", QtCore.QVariant(self.beow_))
00064 self.combo_box_.addItem("By Chain Operation", QtCore.QVariant(self.bcow_))
00065 self.combo_box_.addItem("RenderMode Operation", QtCore.QVariant(self.row_))
00066 self.combo_box_.addItem("Visibility Operation", QtCore.QVariant(self.vow_))
00067
00068 self.add_button_ = QtGui.QPushButton("Add")
00069
00070
00071 self.list_view_.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
00072
00073 self.list_view_.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
00074 QtCore.QObject.connect(self.list_view_, QtCore.SIGNAL("customContextMenuRequested(const QPoint)"), self.contextMenuEvent)
00075
00076 self.hbox_ = QtGui.QHBoxLayout()
00077 self.ok_button_ = QtGui.QPushButton("OK")
00078 self.cancel_button_ = QtGui.QPushButton("Cancel")
00079 self.hbox_.addWidget(self.ok_button_)
00080 self.hbox_.addStretch()
00081 self.hbox_.addWidget(self.cancel_button_)
00082
00083 grid = QtGui.QGridLayout()
00084 grid.setContentsMargins(0,5,0,0)
00085 grid.addWidget(self.combo_box_,0,0,1,1)
00086 grid.addWidget(self.add_button_,0,1,1,1)
00087 grid.addWidget(self.list_view_,1,0,3,3)
00088 grid.addLayout(self.hbox_,5,0,1,3)
00089 grid.setRowStretch(1, 1)
00090 self.setLayout(grid)
00091
00092 QtCore.QObject.connect(self.add_button_, QtCore.SIGNAL("clicked()"), self.Add)
00093 QtCore.QObject.connect(self.ok_button_, QtCore.SIGNAL("clicked()"), self.Ok)
00094 QtCore.QObject.connect(self.cancel_button_, QtCore.SIGNAL("clicked()"), self.Cancel)
00095
00096 self.CreateContextMenu()
00097
00098 def SetPreset(self, preset):
00099 self.list_model_ = PresetEditorListModel(preset, self)
00100 self.list_view_.setModel(self.list_model_)
00101
00102 def CreateContextMenu(self):
00103 self.context_menu_ = QtGui.QMenu("Context menu", self)
00104 self.edit_ = QtGui.QAction("Edit", self.list_view_)
00105 self.remove_ = QtGui.QAction("Remove", self.list_view_)
00106 self.moveup_ = QtGui.QAction("Move Up", self.list_view_)
00107 self.movedown_ = QtGui.QAction("Move Down", self.list_view_)
00108 self.context_menu_.addAction(self.edit_)
00109 self.context_menu_.addAction(self.remove_)
00110 self.context_menu_.addAction(self.moveup_)
00111 self.context_menu_.addAction(self.movedown_)
00112
00113 QtCore.QObject.connect(self.edit_, QtCore.SIGNAL("triggered()"), self.Edit)
00114 QtCore.QObject.connect(self.remove_, QtCore.SIGNAL("triggered()"), self.Remove)
00115 QtCore.QObject.connect(self.moveup_, QtCore.SIGNAL("triggered()"), self.MoveUp)
00116 QtCore.QObject.connect(self.movedown_, QtCore.SIGNAL("triggered()"), self.MoveDown)
00117
00118 def contextMenuEvent(self, pos):
00119
00120 index = self.list_view_.indexAt(pos)
00121 if index.isValid():
00122 self.context_menu_.popup(QtGui.QCursor.pos())
00123
00124 def Add(self):
00125 dialog = self.combo_box_.itemData(self.combo_box_.currentIndex()).toPyObject()
00126 if(dialog.exec_()):
00127 row = self.list_model_.rowCount()
00128 op = dialog.GetOp()
00129 self.list_model_.AddItem(op, row)
00130
00131 def Edit(self):
00132 current_index = self.list_view_.currentIndex()
00133 op = self.list_model_.GetOp(current_index)
00134 if isinstance(op, gfx.UniformColorOp):
00135 self.ufcow_.SetOp(op)
00136 if self.ufcow_.exec_():
00137 self.list_model_.SetItem(current_index, self.ufcow_.GetOp())
00138 elif isinstance(op, gfx.GradientLevelColorOp):
00139 self.glcow_.SetOp(op)
00140 if self.glcow_.exec_():
00141 self.list_model_.SetItem(current_index, self.glcow_.GetOp())
00142 elif isinstance(op, gfx.ByElementColorOp):
00143 self.beow_.SetOp(op)
00144 if self.beow_.exec_():
00145 self.list_model_.SetItem(current_index, self.beow_.GetOp())
00146 elif isinstance(op, gfx.ByChainColorOp):
00147 self.bcow_.SetOp(op)
00148 if self.bcow_.exec_():
00149 self.list_model_.SetItem(current_index, self.bcow_.GetOp())
00150 elif isinstance(op, RenderOp):
00151 self.row_.SetOp(op)
00152 if self.row_.exec_():
00153 self.list_model_.SetItem(current_index, self.row_.GetOp())
00154 elif isinstance(op, VisibilityOp):
00155 self.vow_.SetOp(op)
00156 if self.vow_.exec_():
00157 self.list_model_.SetItem(current_index, self.vow_.GetOp())
00158
00159 def Remove(self):
00160 current_index = self.list_view_.currentIndex()
00161 self.list_model_.RemoveItem(current_index.row())
00162
00163 def MoveDown(self):
00164 current_index = self.list_view_.currentIndex()
00165 if self.list_model_.GetLastRow != current_index.row():
00166 op = self.list_model_.GetOp(current_index)
00167 self.list_model_.RemoveItem(current_index.row())
00168 self.list_model_.AddItem(op, current_index.row()+1)
00169
00170 def MoveUp(self):
00171 current_index = self.list_view_.currentIndex()
00172 if self.list_model_.GetLastRow != 0:
00173 op = self.list_model_.GetOp(current_index)
00174 self.list_model_.RemoveItem(current_index.row())
00175 self.list_model_.AddItem(op, current_index.row()-1)
00176
00177 def Ok(self):
00178 self.accept()
00179
00180 def Cancel(self):
00181 self.reject()
00182
00183 class UniformColorOpWidget(QtGui.QDialog):
00184 def __init__(self, parent=None):
00185 QtGui.QDialog.__init__(self, parent)
00186 self.query_editor_ = QueryEditorWidget(self)
00187
00188 detail_label = QtGui.QLabel("Parts")
00189 self.detail_selection_cb_ = QtGui.QComboBox()
00190 self.detail_selection_cb_.addItem("Main and Detail",QtCore.QVariant(3))
00191 self.detail_selection_cb_.addItem("Main",QtCore.QVariant(2))
00192 self.detail_selection_cb_.addItem("Detail",QtCore.QVariant(1))
00193
00194 color_label = QtGui.QLabel("Color")
00195 self.color_select_widget_ = ColorSelectWidget(30,30,QtGui.QColor("White"))
00196
00197 self.hbox_ = QtGui.QHBoxLayout()
00198 self.ok_button_ = QtGui.QPushButton("OK")
00199 self.cancel_button_ = QtGui.QPushButton("Cancel")
00200 self.hbox_.addWidget(self.ok_button_)
00201 self.hbox_.addStretch()
00202 self.hbox_.addWidget(self.cancel_button_)
00203
00204
00205 grid = QtGui.QGridLayout()
00206 grid.setContentsMargins(0,5,0,0)
00207 grid.addWidget(self.query_editor_, 0, 0, 1, 2)
00208 grid.addWidget(detail_label, 1, 0, 1, 1)
00209 grid.addWidget(self.detail_selection_cb_, 1, 1, 1, 1)
00210 grid.addWidget(color_label, 2, 0, 1, 1)
00211 grid.addWidget(self.color_select_widget_, 2, 1, 1, 1)
00212 grid.addLayout(self.hbox_,3,0,1,2)
00213 grid.setRowStretch(2, 1)
00214 self.setLayout(grid)
00215
00216 QtCore.QObject.connect(self.ok_button_, QtCore.SIGNAL("clicked()"), self.Ok)
00217 QtCore.QObject.connect(self.cancel_button_, QtCore.SIGNAL("clicked()"), self.Cancel)
00218
00219 def GetOp(self):
00220 qv=mol.QueryViewWrapper(self.query_editor_.GetQuery(),self.query_editor_.GetQueryFlags())
00221 ufco = UniformColorOp(qv,gfx.RGBA(1,1,1,1))
00222
00223 detail = self.detail_selection_cb_.itemData(self.detail_selection_cb_.currentIndex()).toPyObject()
00224 ufco.SetMask(detail)
00225 qcolor = self.color_select_widget_.GetColor()
00226 color=gfx.RGBAb(qcolor.red(),qcolor.green(),qcolor.blue(),qcolor.alpha())
00227 ufco.SetColor(color)
00228 return ufco
00229
00230 def SetOp(self, ufco):
00231 self.query_editor_.SetQuery(ufco.GetSelection())
00232 self.query_editor_.SetQueryFlags(ufco.GetSelectionFlags())
00233 found=False
00234 for i in range(0,self.detail_selection_cb_.count()):
00235 mask = self.detail_selection_cb_.itemData(i).toPyObject()
00236 if mask == ufco.GetMask():
00237 self.detail_selection_cb_.setCurrentIndex(i)
00238 found = True
00239 break
00240 if not found:
00241 self.detail_selection_cb_.setCurrentIndex(0)
00242
00243 color = ufco.GetColor()
00244 qcolor = QtGui.QColor(color.Red()*255, color.Green()*255, color.Blue()*255, color.Alpha()*255)
00245 self.color_select_widget_.SetColor(qcolor)
00246
00247 def Ok(self):
00248 self.accept()
00249
00250 def Cancel(self):
00251 self.reject()
00252
00253 class GradientLevelColorOpWidget(QtGui.QDialog):
00254 def __init__(self, parent=None):
00255 QtGui.QDialog.__init__(self, parent)
00256
00257 self.query_editor_ = QueryEditorWidget(self)
00258
00259 detail_label = QtGui.QLabel("Parts")
00260 self.detail_selection_cb_ = QtGui.QComboBox()
00261 self.detail_selection_cb_.addItem("Main and Detail",QtCore.QVariant(3))
00262 self.detail_selection_cb_.addItem("Main",QtCore.QVariant(2))
00263 self.detail_selection_cb_.addItem("Detail",QtCore.QVariant(1))
00264
00265 property_label = QtGui.QLabel("Property")
00266 self.property_edit_ = QtGui.QLineEdit()
00267
00268 self.prop_combo_box_ = QtGui.QComboBox()
00269 self.prop_combo_box_.addItem("atom B-factor",QtCore.QVariant("abfac"))
00270 self.prop_combo_box_.addItem("average residue B-factor",QtCore.QVariant("rbfac"))
00271 self.prop_combo_box_.addItem("X-Coordinate",QtCore.QVariant("x"))
00272 self.prop_combo_box_.addItem("Y-Coordinate",QtCore.QVariant("y"))
00273 self.prop_combo_box_.addItem("Z-Coordinate",QtCore.QVariant("z"))
00274 self.prop_combo_box_.addItem("Residue Number",QtCore.QVariant("rnum"))
00275 self.prop_combo_box_.addItem("Atom Charge",QtCore.QVariant("acharge"))
00276 self.prop_combo_box_.addItem("Custom",QtCore.QVariant("custom"))
00277
00278
00279 level_label = QtGui.QLabel("Level")
00280 self.combo_box_ = QtGui.QComboBox(self);
00281 self.combo_box_.addItem("Atom",QtCore.QVariant(Prop.Level.ATOM))
00282 self.combo_box_.addItem("Residue",QtCore.QVariant(Prop.Level.RESIDUE))
00283 self.combo_box_.addItem("Chain",QtCore.QVariant(Prop.Level.CHAIN))
00284 self.combo_box_.addItem("Unspecified",QtCore.QVariant(Prop.Level.UNSPECIFIED))
00285
00286 gradient_label = QtGui.QLabel("Gradient")
00287 self.gradient_preview_ = GradientPreview()
00288 self.gradient_edit_ = GradientEdit(self.gradient_preview_,self)
00289
00290 self.minmax_label_ = QtGui.QLabel("Min Max")
00291 self.auto_calc_ = QtGui.QCheckBox("Auto calculate")
00292 self.auto_calc_.setChecked(True)
00293
00294 self.minv_label_ = QtGui.QLabel("Min Value")
00295 self.maxv_label_ = QtGui.QLabel("Max Value")
00296
00297 self.minv_ = QtGui.QDoubleSpinBox(self)
00298 self.minv_.setDecimals(2)
00299 self.minv_.setMinimum(-9999.99)
00300 self.minv_.setValue(0)
00301 self.maxv_ = QtGui.QDoubleSpinBox(self)
00302 self.maxv_.setDecimals(2)
00303 self.maxv_.setValue(1)
00304 self.maxv_.setMinimum(-9999.99)
00305
00306 self.hbox_ = QtGui.QHBoxLayout()
00307 self.ok_button_ = QtGui.QPushButton("OK")
00308 self.cancel_button_ = QtGui.QPushButton("Cancel")
00309 self.hbox_.addWidget(self.ok_button_)
00310 self.hbox_.addStretch()
00311 self.hbox_.addWidget(self.cancel_button_)
00312
00313
00314 grid = QtGui.QGridLayout()
00315 grid.setContentsMargins(0,5,0,0)
00316 grid.addWidget(self.query_editor_, 0, 0, 1, 2)
00317 grid.addWidget(detail_label, 1, 0, 1, 1)
00318 grid.addWidget(self.detail_selection_cb_, 1, 1, 1, 1)
00319 grid.addWidget(property_label, 2, 0, 1, 1)
00320 grid.addWidget(self.prop_combo_box_, 2, 1, 1, 1)
00321 grid.addWidget(self.property_edit_, 3, 1, 1, 1)
00322 grid.addWidget(level_label, 4, 0, 1, 1)
00323 grid.addWidget(self.combo_box_, 4, 1, 1, 1)
00324 grid.addWidget(gradient_label, 5, 0, 1, 1)
00325 grid.addWidget(self.gradient_preview_, 5, 1, 1, 1)
00326 grid.addWidget(self.gradient_edit_, 6, 1, 1, 1)
00327 grid.addWidget(self.gradient_edit_, 6, 1, 1, 1)
00328 grid.addWidget(self.minmax_label_,7,0,1,1)
00329 grid.addWidget(self.auto_calc_,7,1,1,1)
00330 grid.addWidget(self.minv_label_,8,0,1,1)
00331 grid.addWidget(self.minv_,8,1,1,1)
00332 grid.addWidget(self.maxv_label_,9,0,1,1)
00333 grid.addWidget(self.maxv_,9,1,1,1)
00334 grid.addLayout(self.hbox_,10,0,1,2)
00335 grid.setRowStretch(1, 1)
00336 self.setLayout(grid)
00337
00338 QtCore.QObject.connect(self.prop_combo_box_, QtCore.SIGNAL("currentIndexChanged(int)"), self.UpdateGui)
00339 QtCore.QObject.connect(self.ok_button_, QtCore.SIGNAL("clicked()"), self.Ok)
00340 QtCore.QObject.connect(self.cancel_button_, QtCore.SIGNAL("clicked()"), self.Cancel)
00341 QtCore.QObject.connect(self.auto_calc_, QtCore.SIGNAL("stateChanged (int)"), self.UpdateGui)
00342
00343 self.UpdateGui()
00344
00345 def GetOp(self):
00346 gradient = self.gradient_edit_.GetGfxGradient()
00347
00348 detail = self.detail_selection_cb_.itemData(self.detail_selection_cb_.currentIndex()).toPyObject()
00349 qv=mol.QueryViewWrapper(self.query_editor_.GetQuery(),self.query_editor_.GetQueryFlags())
00350 prop = str()
00351 level = Prop.Level()
00352 if(self.property_edit_.isEnabled()):
00353 prop = str(self.property_edit_.text())
00354 level = Prop.Level(self.combo_box_.itemData(self.combo_box_.currentIndex()).toPyObject())
00355 else:
00356 prop = str(self.prop_combo_box_.itemData(self.prop_combo_box_.currentIndex()).toPyObject())
00357
00358 if(self.auto_calc_.isChecked()):
00359 return GradientLevelColorOp(qv, detail, prop, gradient, level)
00360 else:
00361 minv = self.minv_.value()
00362 maxv = self.maxv_.value()
00363 return GradientLevelColorOp(qv, detail, prop, gradient, minv, maxv, level)
00364
00365
00366 def SetOp(self, glco):
00367 self.query_editor_.SetQuery(glco.GetSelection())
00368 self.query_editor_.SetQueryFlags(glco.GetSelectionFlags())
00369 found=False
00370 for i in range(0,self.detail_selection_cb_.count()):
00371 mask = self.detail_selection_cb_.itemData(i).toPyObject()
00372 if mask == glco.GetMask():
00373 self.detail_selection_cb_.setCurrentIndex(i)
00374 found = True
00375 break
00376 if not found:
00377 self.detail_selection_cb_.setCurrentIndex(0)
00378
00379 found = False
00380 for i in range(0,self.prop_combo_box_.count()):
00381 prop = str(self.prop_combo_box_.itemData(i).toPyObject())
00382 if prop == glco.GetProperty():
00383 self.prop_combo_box_.setCurrentIndex(i)
00384 found = True
00385 if not found:
00386 self.prop_combo_box_.setCurrentIndex(self.prop_combo_box_.count()-1)
00387 self.property_edit_.setText(glco.GetProperty())
00388
00389 self.combo_box_.setCurrentIndex(glco.GetLevel())
00390 self.gradient_edit_.LoadGradient(ImmutableGradientInfoHandler.ConvertToQGradient(glco.GetGradient()))
00391 self.auto_calc_.setChecked(glco.GetCalculateMinMax());
00392 if(not glco.GetCalculateMinMax()):
00393 self.minv_.setValue(glco.GetMinV())
00394 self.maxv_.setValue(glco.GetMaxV())
00395 self.UpdateGui()
00396
00397 def UpdateGui(self):
00398 prop = self.prop_combo_box_.itemData(self.prop_combo_box_.currentIndex()).toPyObject()
00399 if(prop == "custom"):
00400 self.combo_box_.setEnabled(True)
00401 self.property_edit_.setEnabled(True)
00402 else:
00403 self.combo_box_.setEnabled(False)
00404 self.property_edit_.setEnabled(False)
00405
00406 if(self.auto_calc_.isChecked()):
00407 self.minv_.setEnabled(False)
00408 self.maxv_.setEnabled(False)
00409 else:
00410 self.minv_.setEnabled(True)
00411 self.maxv_.setEnabled(True)
00412
00413 def Ok(self):
00414 self.accept()
00415
00416 def Cancel(self):
00417 self.reject()
00418
00419 def Update(self):
00420 pass
00421
00422 class ByElementColorOpWidget(QtGui.QDialog):
00423 def __init__(self, parent=None):
00424 QtGui.QDialog.__init__(self, parent)
00425 self.query_editor_ = QueryEditorWidget(self)
00426
00427 detail_label = QtGui.QLabel("Parts")
00428 self.detail_selection_cb_ = QtGui.QComboBox()
00429 self.detail_selection_cb_.addItem("Main and Detail",QtCore.QVariant(3))
00430 self.detail_selection_cb_.addItem("Main",QtCore.QVariant(2))
00431 self.detail_selection_cb_.addItem("Detail",QtCore.QVariant(1))
00432
00433 self.hbox_ = QtGui.QHBoxLayout()
00434 self.ok_button_ = QtGui.QPushButton("OK")
00435 self.cancel_button_ = QtGui.QPushButton("Cancel")
00436 self.hbox_.addWidget(self.ok_button_)
00437 self.hbox_.addStretch()
00438 self.hbox_.addWidget(self.cancel_button_)
00439
00440 grid = QtGui.QGridLayout()
00441 grid.setContentsMargins(0,5,0,0)
00442 grid.addWidget(self.query_editor_, 0, 0, 1, 2)
00443 grid.addWidget(detail_label, 1, 0, 1, 1)
00444 grid.addWidget(self.detail_selection_cb_, 1, 1, 1, 1)
00445 grid.addLayout(self.hbox_,2,0,1,2)
00446 grid.setRowStretch(1, 1)
00447 self.setLayout(grid)
00448
00449 QtCore.QObject.connect(self.ok_button_, QtCore.SIGNAL("clicked()"), self.Ok)
00450 QtCore.QObject.connect(self.cancel_button_, QtCore.SIGNAL("clicked()"), self.Cancel)
00451
00452 def GetOp(self):
00453 detail = self.detail_selection_cb_.itemData(self.detail_selection_cb_.currentIndex()).toPyObject()
00454 qv=mol.QueryViewWrapper(self.query_editor_.GetQuery(),self.query_editor_.GetQueryFlags())
00455 beco = ByElementColorOp(qv, detail)
00456 return beco
00457
00458 def SetOp(self, beco):
00459 self.query_editor_.SetQuery(beco.GetSelection())
00460 self.query_editor_.SetQueryFlags(beco.GetSelectionFlags())
00461 found=False
00462 for i in range(0,self.detail_selection_cb_.count()):
00463 mask = self.detail_selection_cb_.itemData(i).toPyObject()
00464 if mask == beco.GetMask():
00465 self.detail_selection_cb_.setCurrentIndex(i)
00466 found = True
00467 break
00468 if not found:
00469 self.detail_selection_cb_.setCurrentIndex(0)
00470
00471 def Ok(self):
00472 self.accept()
00473
00474 def Cancel(self):
00475 self.reject()
00476
00477
00478 class ByChainColorOpWidget(QtGui.QDialog):
00479 def __init__(self, parent=None):
00480 QtGui.QDialog.__init__(self, parent)
00481 self.query_editor_ = QueryEditorWidget(self)
00482
00483 detail_label = QtGui.QLabel("Parts")
00484 self.detail_selection_cb_ = QtGui.QComboBox()
00485 self.detail_selection_cb_.addItem("Main and Detail",QtCore.QVariant(3))
00486 self.detail_selection_cb_.addItem("Main",QtCore.QVariant(2))
00487 self.detail_selection_cb_.addItem("Detail",QtCore.QVariant(1))
00488
00489 self.hbox_ = QtGui.QHBoxLayout()
00490 self.ok_button_ = QtGui.QPushButton("OK")
00491 self.cancel_button_ = QtGui.QPushButton("Cancel")
00492 self.hbox_.addWidget(self.ok_button_)
00493 self.hbox_.addStretch()
00494 self.hbox_.addWidget(self.cancel_button_)
00495
00496 grid = QtGui.QGridLayout()
00497 grid.setContentsMargins(0,5,0,0)
00498 grid.addWidget(self.query_editor_, 0, 0, 1, 2)
00499 grid.addWidget(detail_label, 1, 0, 1, 1)
00500 grid.addWidget(self.detail_selection_cb_, 1, 1, 1, 1)
00501 grid.addLayout(self.hbox_,2,0,1,2)
00502 grid.setRowStretch(1, 1)
00503 self.setLayout(grid)
00504
00505 QtCore.QObject.connect(self.ok_button_, QtCore.SIGNAL("clicked()"), self.Ok)
00506 QtCore.QObject.connect(self.cancel_button_, QtCore.SIGNAL("clicked()"), self.Cancel)
00507
00508 def GetOp(self):
00509 detail = self.detail_selection_cb_.itemData(self.detail_selection_cb_.currentIndex()).toPyObject()
00510 qv=mol.QueryViewWrapper(self.query_editor_.GetQuery(),self.query_editor_.GetQueryFlags())
00511 bcco = ByChainColorOp(qv, detail)
00512 return bcco
00513
00514 def SetOp(self, bcco):
00515 self.query_editor_.SetQuery(bcco.GetSelection())
00516 self.query_editor_.SetQueryFlags(bcco.GetSelectionFlags())
00517 found=False
00518 for i in range(0,self.detail_selection_cb_.count()):
00519 mask = self.detail_selection_cb_.itemData(i).toPyObject()
00520 if mask == bcco.GetMask():
00521 self.detail_selection_cb_.setCurrentIndex(i)
00522 found = True
00523 break
00524 if not found:
00525 self.detail_selection_cb_.setCurrentIndex(0)
00526
00527 def Ok(self):
00528 self.accept()
00529
00530 def Cancel(self):
00531 self.reject()
00532
00533
00534 class RenderOpWidget(QtGui.QDialog):
00535 def __init__(self, parent=None):
00536 QtGui.QDialog.__init__(self, parent)
00537 self.query_editor_ = QueryEditorWidget(self)
00538
00539 self.keep_ = QtGui.QCheckBox("Keep")
00540 self.keep_.setChecked(False)
00541
00542 render_label = QtGui.QLabel("Rendermode")
00543 self.render_modes_ = QtGui.QComboBox()
00544 self.render_modes_.addItem("Fast Bonds")
00545 self.render_modes_.addItem("Ball & Stick")
00546 self.render_modes_.addItem("Spheres")
00547 self.render_modes_.addItem("Fast Trace")
00548 self.render_modes_.addItem("Trace")
00549 self.render_modes_.addItem("Fast Spline")
00550 self.render_modes_.addItem("Smooth Tube")
00551 self.render_modes_.addItem("Helix & Strand Cartoon")
00552
00553 self.render_modes_list_ = [gfx.RenderMode.SIMPLE,
00554 gfx.RenderMode.CUSTOM,
00555 gfx.RenderMode.CPK,
00556 gfx.RenderMode.LINE_TRACE,
00557 gfx.RenderMode.TRACE,
00558 gfx.RenderMode.SLINE,
00559 gfx.RenderMode.TUBE,
00560 gfx.RenderMode.HSC]
00561
00562 self.hbox_ = QtGui.QHBoxLayout()
00563 self.ok_button_ = QtGui.QPushButton("OK")
00564 self.cancel_button_ = QtGui.QPushButton("Cancel")
00565 self.hbox_.addWidget(self.ok_button_)
00566 self.hbox_.addStretch()
00567 self.hbox_.addWidget(self.cancel_button_)
00568
00569 grid = QtGui.QGridLayout()
00570 grid.setContentsMargins(0,5,0,0)
00571 grid.addWidget(self.query_editor_, 0, 0, 1, 2)
00572 grid.addWidget(self.keep_, 1, 1, 1, 1)
00573 grid.addWidget(render_label,2,0,1,1)
00574 grid.addWidget(self.render_modes_,2,1,1,1)
00575 grid.addLayout(self.hbox_,3,0,1,2)
00576 grid.setRowStretch(1, 1)
00577 self.setLayout(grid)
00578
00579 QtCore.QObject.connect(self.ok_button_, QtCore.SIGNAL("clicked()"), self.Ok)
00580 QtCore.QObject.connect(self.cancel_button_, QtCore.SIGNAL("clicked()"), self.Cancel)
00581
00582 def GetOp(self):
00583 selection = self.query_editor_.GetQueryText()
00584 flags = self.query_editor_.GetQueryFlags()
00585 render_mode = self.render_modes_list_[self.render_modes_.currentIndex()]
00586 ro = RenderOp(render_mode, selection, flags, self.keep_.isChecked())
00587 return ro
00588
00589 def SetOp(self, ro):
00590 self.query_editor_.SetQuery(ro.GetSelection())
00591 self.query_editor_.SetQueryFlags(ro.GetSelectionFlags())
00592 found=False
00593 for i in range(0,self.render_modes_.count()):
00594 render_mode = self.render_modes_list_[i]
00595 if render_mode == ro.GetRenderMode():
00596 self.render_modes_.setCurrentIndex(i)
00597 found = True
00598 break
00599 if not found:
00600 self.render_modes_.setCurrentIndex(0)
00601 self.keep_.setChecked(ro.IsKept())
00602
00603 def Ok(self):
00604 self.accept()
00605
00606 def Cancel(self):
00607 self.reject()
00608
00609 class VisibilityOpWidget(QtGui.QDialog):
00610 def __init__(self, parent=None):
00611 QtGui.QDialog.__init__(self, parent)
00612 self.query_editor_ = QueryEditorWidget(self)
00613
00614 self.visible_ = QtGui.QCheckBox("Visible")
00615 self.visible_.setChecked(True)
00616
00617 self.hbox_ = QtGui.QHBoxLayout()
00618 self.ok_button_ = QtGui.QPushButton("OK")
00619 self.cancel_button_ = QtGui.QPushButton("Cancel")
00620 self.hbox_.addWidget(self.ok_button_)
00621 self.hbox_.addStretch()
00622 self.hbox_.addWidget(self.cancel_button_)
00623
00624 grid = QtGui.QGridLayout()
00625 grid.setContentsMargins(0,5,0,0)
00626 grid.addWidget(self.query_editor_, 0, 0, 1, 2)
00627 grid.addWidget(self.visible_, 1, 1, 1, 1)
00628 grid.addLayout(self.hbox_,2,0,1,2)
00629 grid.setRowStretch(1, 1)
00630 self.setLayout(grid)
00631
00632 QtCore.QObject.connect(self.ok_button_, QtCore.SIGNAL("clicked()"), self.Ok)
00633 QtCore.QObject.connect(self.cancel_button_, QtCore.SIGNAL("clicked()"), self.Cancel)
00634
00635 def GetOp(self):
00636 selection = self.query_editor_.GetQueryText()
00637 flags = self.query_editor_.GetQueryFlags()
00638 vo = VisibilityOp(selection, flags, self.visible_.isChecked())
00639 return vo
00640
00641 def SetOp(self, vo):
00642 self.query_editor_.SetQuery(vo.GetSelection())
00643 self.query_editor_.SetQueryFlags(vo.GetSelectionFlags())
00644 self.visible_.setChecked(vo.IsVisible())
00645
00646 def Ok(self):
00647 self.accept()
00648
00649 def Cancel(self):
00650 self.reject()