OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
preset_editor_widget.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 mol
24 from datetime import datetime
25 from datetime import datetime
26 from PyQt5 import QtCore, QtWidgets, QtGui
27 from .color_select_widget import ColorSelectWidget
28 from .gradient_preset_widget import GradientPresetWidget
29 from .gradient_editor_widget import GradientPreview
30 from .gradient_editor_widget import GradientEdit
31 from .preset_editor_list_model import PresetEditorListModel
32 from .immutable_gradient_info_handler import ImmutableGradientInfoHandler
33 from .query_editor import QueryEditorWidget
34 from ost.mol import Prop
35 from ost.gfx import ByElementColorOp
36 from ost.gfx import ByChainColorOp
37 from ost.gfx import GradientLevelColorOp
38 from ost.gfx import UniformColorOp
39 from .preset import Preset
40 from .render_op import RenderOp
41 from .visibility_op import VisibilityOp
42 
43 #Preset Editor
44 class PresetEditor(QtWidgets.QDialog):
45  def __init__(self, parent=None):
46  QtWidgets.QDialog.__init__(self, parent)
47 
48  self.setWindowTitle("Preset Editor")
49 
50  #Create Ui Elements
51  self.list_view_ = QtWidgets.QListView()
52 
53  self.combo_box_ = QtWidgets.QComboBox()
54 
59  self.row_=RenderOpWidget(self)
61  self.combo_box_.addItem("Uniform Color Operation", QtCore.QVariant(self.ufcow_))
62  self.combo_box_.addItem("Gradient Operation", QtCore.QVariant(self.glcow_))
63  self.combo_box_.addItem("By Element Operation", QtCore.QVariant(self.beow_))
64  self.combo_box_.addItem("By Chain Operation", QtCore.QVariant(self.bcow_))
65  self.combo_box_.addItem("RenderMode Operation", QtCore.QVariant(self.row_))
66  self.combo_box_.addItem("Visibility Operation", QtCore.QVariant(self.vow_))
67 
68  self.add_button_ = QtWidgets.QPushButton("Add")
69 
70  #Create Model
71  self.list_view_.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
72 
73  self.list_view_.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
74  self.list_view_.customContextMenuRequested.connect(self.contextMenuEvent)
75 
76  self.hbox_ = QtWidgets.QHBoxLayout()
77  self.ok_button_ = QtWidgets.QPushButton("OK")
78  self.cancel_button_ = QtWidgets.QPushButton("Cancel")
79  self.hbox_.addWidget(self.ok_button_)
80  self.hbox_.addStretch()
81  self.hbox_.addWidget(self.cancel_button_)
82 
83  grid = QtWidgets.QGridLayout()
84  grid.setContentsMargins(0,5,0,0)
85  grid.addWidget(self.combo_box_,0,0,1,1)
86  grid.addWidget(self.add_button_,0,1,1,1)
87  grid.addWidget(self.list_view_,1,0,3,3)
88  grid.addLayout(self.hbox_,5,0,1,3)
89  grid.setRowStretch(1, 1)
90  self.setLayout(grid)
91 
92  self.add_button_.clicked.connect(self.Add)
93  self.ok_button_.clicked.connect(self.Ok)
94  self.cancel_button_.clicked.connect(self.Cancel)
95 
96  self.CreateContextMenu()
97 
98  def SetPreset(self, preset):
99  self.list_model_ = PresetEditorListModel(preset, self)
100  self.list_view_.setModel(self.list_model_)
101 
102  def CreateContextMenu(self):
103  self.context_menu_ = QtWidgets.QMenu("Context menu", self)
104  self.edit_ = QtWidgets.QAction("Edit", self.list_view_)
105  self.remove_ = QtWidgets.QAction("Remove", self.list_view_)
106  self.moveup_ = QtWidgets.QAction("Move Up", self.list_view_)
107  self.movedown_ = QtWidgets.QAction("Move Down", self.list_view_)
108  self.context_menu_.addAction(self.edit_)
109  self.context_menu_.addAction(self.remove_)
110  self.context_menu_.addAction(self.moveup_)
111  self.context_menu_.addAction(self.movedown_)
112  #Connect Signals with Slots
113  self.edit_.triggered.connect(self.Edit)
114  self.remove_.triggered.connect(self.Remove)
115  self.moveup_.triggered.connect(self.MoveUp)
116  self.movedown_.triggered.connect(self.MoveDown)
117 
118  def contextMenuEvent(self, pos):
119  #ContextMenu
120  index = self.list_view_.indexAt(pos)
121  if index.isValid():
122  self.context_menu_.popup(QtWidgets.QCursor.pos())
123 
124  def Add(self):
125  dialog = self.combo_box_.itemData(self.combo_box_.currentIndex()).toPyObject()
126  if(dialog.exec_()):
127  row = self.list_model_.rowCount()
128  op = dialog.GetOp()
129  self.list_model_.AddItem(op, row)
130 
131  def Edit(self):
132  current_index = self.list_view_.currentIndex()
133  op = self.list_model_.GetOp(current_index)
134  if isinstance(op, gfx.UniformColorOp):
135  self.ufcow_.SetOp(op)
136  if self.ufcow_.exec_():
137  self.list_model_.SetItem(current_index, self.ufcow_.GetOp())
138  elif isinstance(op, gfx.GradientLevelColorOp):
139  self.glcow_.SetOp(op)
140  if self.glcow_.exec_():
141  self.list_model_.SetItem(current_index, self.glcow_.GetOp())
142  elif isinstance(op, gfx.ByElementColorOp):
143  self.beow_.SetOp(op)
144  if self.beow_.exec_():
145  self.list_model_.SetItem(current_index, self.beow_.GetOp())
146  elif isinstance(op, gfx.ByChainColorOp):
147  self.bcow_.SetOp(op)
148  if self.bcow_.exec_():
149  self.list_model_.SetItem(current_index, self.bcow_.GetOp())
150  elif isinstance(op, RenderOp):
151  self.row_.SetOp(op)
152  if self.row_.exec_():
153  self.list_model_.SetItem(current_index, self.row_.GetOp())
154  elif isinstance(op, VisibilityOp):
155  self.vow_.SetOp(op)
156  if self.vow_.exec_():
157  self.list_model_.SetItem(current_index, self.vow_.GetOp())
158 
159  def Remove(self):
160  current_index = self.list_view_.currentIndex()
161  self.list_model_.RemoveItem(current_index.row())
162 
163  def MoveDown(self):
164  current_index = self.list_view_.currentIndex()
165  if self.list_model_.GetLastRow != current_index.row():
166  op = self.list_model_.GetOp(current_index)
167  self.list_model_.RemoveItem(current_index.row())
168  self.list_model_.AddItem(op, current_index.row()+1)
169 
170  def MoveUp(self):
171  current_index = self.list_view_.currentIndex()
172  if self.list_model_.GetLastRow != 0:
173  op = self.list_model_.GetOp(current_index)
174  self.list_model_.RemoveItem(current_index.row())
175  self.list_model_.AddItem(op, current_index.row()-1)
176 
177  def Ok(self):
178  self.accept()
179 
180  def Cancel(self):
181  self.reject()
182 
183 class UniformColorOpWidget(QtWidgets.QDialog):
184  def __init__(self, parent=None):
185  QtWidgets.QDialog.__init__(self, parent)
186  self.query_editor_ = QueryEditorWidget(self)
187 
188  detail_label = QtWidgets.QLabel("Parts")
189  self.detail_selection_cb_ = QtWidgets.QComboBox()
190  self.detail_selection_cb_.addItem("Main and Detail",QtCore.QVariant(3))
191  self.detail_selection_cb_.addItem("Main",QtCore.QVariant(2))
192  self.detail_selection_cb_.addItem("Detail",QtCore.QVariant(1))
193 
194  color_label = QtWidgets.QLabel("Color")
195  self.color_select_widget_ = ColorSelectWidget(30,30,QtGui.QColor("White"))
196 
197  self.hbox_ = QtWidgets.QHBoxLayout()
198  self.ok_button_ = QtWidgets.QPushButton("OK")
199  self.cancel_button_ = QtWidgets.QPushButton("Cancel")
200  self.hbox_.addWidget(self.ok_button_)
201  self.hbox_.addStretch()
202  self.hbox_.addWidget(self.cancel_button_)
203 
204 
205  grid = QtWidgets.QGridLayout()
206  grid.setContentsMargins(0,5,0,0)
207  grid.addWidget(self.query_editor_, 0, 0, 1, 2)
208  grid.addWidget(detail_label, 1, 0, 1, 1)
209  grid.addWidget(self.detail_selection_cb_, 1, 1, 1, 1)
210  grid.addWidget(color_label, 2, 0, 1, 1)
211  grid.addWidget(self.color_select_widget_, 2, 1, 1, 1)
212  grid.addLayout(self.hbox_,3,0,1,2)
213  grid.setRowStretch(2, 1)
214  self.setLayout(grid)
215 
216  self.ok_button_.clicked.connect(self.Ok)
217  self.cancel_button_.clicked.connect(self.Cancel)
218 
219  def GetOp(self):
220  qv=mol.QueryViewWrapper(self.query_editor_.GetQuery(),self.query_editor_.GetQueryFlags())
221  ufco = UniformColorOp(qv,gfx.RGBA(1,1,1,1))
222 
223  detail = self.detail_selection_cb_.itemData(self.detail_selection_cb_.currentIndex()).toPyObject()
224  ufco.SetMask(detail)
225  qcolor = self.color_select_widget_.GetColor()
226  color=gfx.RGBAb(qcolor.red(),qcolor.green(),qcolor.blue(),qcolor.alpha())
227  ufco.SetColor(color)
228  return ufco
229 
230  def SetOp(self, ufco):
231  self.query_editor_.SetQuery(ufco.GetSelection())
232  self.query_editor_.SetQueryFlags(ufco.GetSelectionFlags())
233  found=False
234  for i in range(0,self.detail_selection_cb_.count()):
235  mask = self.detail_selection_cb_.itemData(i).toPyObject()
236  if mask == ufco.GetMask():
237  self.detail_selection_cb_.setCurrentIndex(i)
238  found = True
239  break
240  if not found:
241  self.detail_selection_cb_.setCurrentIndex(0)
242 
243  color = ufco.GetColor()
244  qcolor = QtGui.QColor(color.Red()*255, color.Green()*255, color.Blue()*255, color.Alpha()*255)
245  self.color_select_widget_.SetColor(qcolor)
246 
247  def Ok(self):
248  self.accept()
249 
250  def Cancel(self):
251  self.reject()
252 
253 class GradientLevelColorOpWidget(QtWidgets.QDialog):
254  def __init__(self, parent=None):
255  QtWidgets.QDialog.__init__(self, parent)
256 
257  self.query_editor_ = QueryEditorWidget(self)
258 
259  detail_label = QtWidgets.QLabel("Parts")
260  self.detail_selection_cb_ = QtWidgets.QComboBox()
261  self.detail_selection_cb_.addItem("Main and Detail",QtCore.QVariant(3))
262  self.detail_selection_cb_.addItem("Main",QtCore.QVariant(2))
263  self.detail_selection_cb_.addItem("Detail",QtCore.QVariant(1))
264 
265  property_label = QtWidgets.QLabel("Property")
266  self.property_edit_ = QtWidgets.QLineEdit()
267 
268  self.prop_combo_box_ = QtWidgets.QComboBox()
269  self.prop_combo_box_.addItem("atom B-factor",QtCore.QVariant("abfac"))
270  self.prop_combo_box_.addItem("average residue B-factor",QtCore.QVariant("rbfac"))
271  self.prop_combo_box_.addItem("X-Coordinate",QtCore.QVariant("x"))
272  self.prop_combo_box_.addItem("Y-Coordinate",QtCore.QVariant("y"))
273  self.prop_combo_box_.addItem("Z-Coordinate",QtCore.QVariant("z"))
274  self.prop_combo_box_.addItem("Residue Number",QtCore.QVariant("rnum"))
275  self.prop_combo_box_.addItem("Atom Charge",QtCore.QVariant("acharge"))
276  self.prop_combo_box_.addItem("Custom",QtCore.QVariant("custom"))
277 
278 
279  level_label = QtWidgets.QLabel("Level")
280  self.combo_box_ = QtWidgets.QComboBox(self);
281  self.combo_box_.addItem("Atom",QtCore.QVariant(Prop.Level.ATOM))
282  self.combo_box_.addItem("Residue",QtCore.QVariant(Prop.Level.RESIDUE))
283  self.combo_box_.addItem("Chain",QtCore.QVariant(Prop.Level.CHAIN))
284  self.combo_box_.addItem("Unspecified",QtCore.QVariant(Prop.Level.UNSPECIFIED))
285 
286  gradient_label = QtWidgets.QLabel("Gradient")
287  self.gradient_preview_ = GradientPreview()
288  self.gradient_edit_ = GradientEdit(self.gradient_preview_,self)
289 
290  self.minmax_label_ = QtWidgets.QLabel("Min Max")
291  self.auto_calc_ = QtWidgets.QCheckBox("Auto calculate")
292  self.auto_calc_.setChecked(True)
293 
294  self.minv_label_ = QtWidgets.QLabel("Min Value")
295  self.maxv_label_ = QtWidgets.QLabel("Max Value")
296 
297  self.minv_ = QtWidgets.QDoubleSpinBox(self)
298  self.minv_.setDecimals(2)
299  self.minv_.setMinimum(-9999.99)
300  self.minv_.setValue(0)
301  self.maxv_ = QtWidgets.QDoubleSpinBox(self)
302  self.maxv_.setDecimals(2)
303  self.maxv_.setValue(1)
304  self.maxv_.setMinimum(-9999.99)
305 
306  self.hbox_ = QtWidgets.QHBoxLayout()
307  self.ok_button_ = QtWidgets.QPushButton("OK")
308  self.cancel_button_ = QtWidgets.QPushButton("Cancel")
309  self.hbox_.addWidget(self.ok_button_)
310  self.hbox_.addStretch()
311  self.hbox_.addWidget(self.cancel_button_)
312 
313 
314  grid = QtWidgets.QGridLayout()
315  grid.setContentsMargins(0,5,0,0)
316  grid.addWidget(self.query_editor_, 0, 0, 1, 2)
317  grid.addWidget(detail_label, 1, 0, 1, 1)
318  grid.addWidget(self.detail_selection_cb_, 1, 1, 1, 1)
319  grid.addWidget(property_label, 2, 0, 1, 1)
320  grid.addWidget(self.prop_combo_box_, 2, 1, 1, 1)
321  grid.addWidget(self.property_edit_, 3, 1, 1, 1)
322  grid.addWidget(level_label, 4, 0, 1, 1)
323  grid.addWidget(self.combo_box_, 4, 1, 1, 1)
324  grid.addWidget(gradient_label, 5, 0, 1, 1)
325  grid.addWidget(self.gradient_preview_, 5, 1, 1, 1)
326  grid.addWidget(self.gradient_edit_, 6, 1, 1, 1)
327  grid.addWidget(self.gradient_edit_, 6, 1, 1, 1)
328  grid.addWidget(self.minmax_label_,7,0,1,1)
329  grid.addWidget(self.auto_calc_,7,1,1,1)
330  grid.addWidget(self.minv_label_,8,0,1,1)
331  grid.addWidget(self.minv_,8,1,1,1)
332  grid.addWidget(self.maxv_label_,9,0,1,1)
333  grid.addWidget(self.maxv_,9,1,1,1)
334  grid.addLayout(self.hbox_,10,0,1,2)
335  grid.setRowStretch(1, 1)
336  self.setLayout(grid)
337 
338  self.prop_combo_box_.currentIndexChanged.connect(self.UpdateGui)
339  self.ok_button_.clicked.connect(self.Ok)
340  self.cancel_button_.clicked.connect(self.Cancel)
341  self.auto_calc_.stateChanged.connect(self.UpdateGui)
342 
343  self.UpdateGui()
344 
345  def GetOp(self):
346  gradient = self.gradient_edit_.GetGfxGradient()
347 
348  detail = self.detail_selection_cb_.itemData(self.detail_selection_cb_.currentIndex()).toPyObject()
349  qv=mol.QueryViewWrapper(self.query_editor_.GetQuery(),self.query_editor_.GetQueryFlags())
350  prop = str()
351  level = Prop.Level()
352  if(self.property_edit_.isEnabled()):
353  prop = str(self.property_edit_.text())
354  level = Prop.Level(self.combo_box_.itemData(self.combo_box_.currentIndex()).toPyObject())
355  else:
356  prop = str(self.prop_combo_box_.itemData(self.prop_combo_box_.currentIndex()).toPyObject())
357 
358  if(self.auto_calc_.isChecked()):
359  return GradientLevelColorOp(qv, detail, prop, gradient, level)
360  else:
361  minv = self.minv_.value()
362  maxv = self.maxv_.value()
363  return GradientLevelColorOp(qv, detail, prop, gradient, minv, maxv, level)
364 
365 
366  def SetOp(self, glco):
367  self.query_editor_.SetQuery(glco.GetSelection())
368  self.query_editor_.SetQueryFlags(glco.GetSelectionFlags())
369  found=False
370  for i in range(0,self.detail_selection_cb_.count()):
371  mask = self.detail_selection_cb_.itemData(i).toPyObject()
372  if mask == glco.GetMask():
373  self.detail_selection_cb_.setCurrentIndex(i)
374  found = True
375  break
376  if not found:
377  self.detail_selection_cb_.setCurrentIndex(0)
378 
379  found = False
380  for i in range(0,self.prop_combo_box_.count()):
381  prop = str(self.prop_combo_box_.itemData(i).toPyObject())
382  if prop == glco.GetProperty():
383  self.prop_combo_box_.setCurrentIndex(i)
384  found = True
385  if not found:
386  self.prop_combo_box_.setCurrentIndex(self.prop_combo_box_.count()-1)
387  self.property_edit_.setText(glco.GetProperty())
388 
389  self.combo_box_.setCurrentIndex(glco.GetLevel())
390  self.gradient_edit_.LoadGradient(ImmutableGradientInfoHandler.ConvertToQGradient(glco.GetGradient()))
391  self.auto_calc_.setChecked(glco.GetCalculateMinMax());
392  if(not glco.GetCalculateMinMax()):
393  self.minv_.setValue(glco.GetMinV())
394  self.maxv_.setValue(glco.GetMaxV())
395  self.UpdateGui()
396 
397  def UpdateGui(self):
398  prop = str(self.prop_combo_box_.itemData(self.prop_combo_box_.currentIndex()))
399  if(prop == "custom"):
400  self.combo_box_.setEnabled(True)
401  self.property_edit_.setEnabled(True)
402  else:
403  self.combo_box_.setEnabled(False)
404  self.property_edit_.setEnabled(False)
405 
406  if(self.auto_calc_.isChecked()):
407  self.minv_.setEnabled(False)
408  self.maxv_.setEnabled(False)
409  else:
410  self.minv_.setEnabled(True)
411  self.maxv_.setEnabled(True)
412 
413  def Ok(self):
414  self.accept()
415 
416  def Cancel(self):
417  self.reject()
418 
419  def Update(self):
420  pass #Do Nothing
421 
422 class ByElementColorOpWidget(QtWidgets.QDialog):
423  def __init__(self, parent=None):
424  QtWidgets.QDialog.__init__(self, parent)
425  self.query_editor_ = QueryEditorWidget(self)
426 
427  detail_label = QtWidgets.QLabel("Parts")
428  self.detail_selection_cb_ = QtWidgets.QComboBox()
429  self.detail_selection_cb_.addItem("Main and Detail",QtCore.QVariant(3))
430  self.detail_selection_cb_.addItem("Main",QtCore.QVariant(2))
431  self.detail_selection_cb_.addItem("Detail",QtCore.QVariant(1))
432 
433  self.hbox_ = QtWidgets.QHBoxLayout()
434  self.ok_button_ = QtWidgets.QPushButton("OK")
435  self.cancel_button_ = QtWidgets.QPushButton("Cancel")
436  self.hbox_.addWidget(self.ok_button_)
437  self.hbox_.addStretch()
438  self.hbox_.addWidget(self.cancel_button_)
439 
440  grid = QtWidgets.QGridLayout()
441  grid.setContentsMargins(0,5,0,0)
442  grid.addWidget(self.query_editor_, 0, 0, 1, 2)
443  grid.addWidget(detail_label, 1, 0, 1, 1)
444  grid.addWidget(self.detail_selection_cb_, 1, 1, 1, 1)
445  grid.addLayout(self.hbox_,2,0,1,2)
446  grid.setRowStretch(1, 1)
447  self.setLayout(grid)
448 
449  self.ok_button_.clicked.connect(self.Ok)
450  self.cancel_button_.clicked.connect(self.Cancel)
451 
452  def GetOp(self):
453  detail = self.detail_selection_cb_.itemData(self.detail_selection_cb_.currentIndex()).toPyObject()
454  qv=mol.QueryViewWrapper(self.query_editor_.GetQuery(),self.query_editor_.GetQueryFlags())
455  beco = ByElementColorOp(qv, detail)
456  return beco
457 
458  def SetOp(self, beco):
459  self.query_editor_.SetQuery(beco.GetSelection())
460  self.query_editor_.SetQueryFlags(beco.GetSelectionFlags())
461  found=False
462  for i in range(0,self.detail_selection_cb_.count()):
463  mask = self.detail_selection_cb_.itemData(i).toPyObject()
464  if mask == beco.GetMask():
465  self.detail_selection_cb_.setCurrentIndex(i)
466  found = True
467  break
468  if not found:
469  self.detail_selection_cb_.setCurrentIndex(0)
470 
471  def Ok(self):
472  self.accept()
473 
474  def Cancel(self):
475  self.reject()
476 
477 
478 class ByChainColorOpWidget(QtWidgets.QDialog):
479  def __init__(self, parent=None):
480  QtWidgets.QDialog.__init__(self, parent)
481  self.query_editor_ = QueryEditorWidget(self)
482 
483  detail_label = QtWidgets.QLabel("Parts")
484  self.detail_selection_cb_ = QtWidgets.QComboBox()
485  self.detail_selection_cb_.addItem("Main and Detail",QtCore.QVariant(3))
486  self.detail_selection_cb_.addItem("Main",QtCore.QVariant(2))
487  self.detail_selection_cb_.addItem("Detail",QtCore.QVariant(1))
488 
489  self.hbox_ = QtWidgets.QHBoxLayout()
490  self.ok_button_ = QtWidgets.QPushButton("OK")
491  self.cancel_button_ = QtWidgets.QPushButton("Cancel")
492  self.hbox_.addWidget(self.ok_button_)
493  self.hbox_.addStretch()
494  self.hbox_.addWidget(self.cancel_button_)
495 
496  grid = QtWidgets.QGridLayout()
497  grid.setContentsMargins(0,5,0,0)
498  grid.addWidget(self.query_editor_, 0, 0, 1, 2)
499  grid.addWidget(detail_label, 1, 0, 1, 1)
500  grid.addWidget(self.detail_selection_cb_, 1, 1, 1, 1)
501  grid.addLayout(self.hbox_,2,0,1,2)
502  grid.setRowStretch(1, 1)
503  self.setLayout(grid)
504 
505  self.ok_button_.clicked.connect(self.Ok)
506  self.cancel_button_.clicked.connect(self.Cancel)
507 
508  def GetOp(self):
509  detail = self.detail_selection_cb_.itemData(self.detail_selection_cb_.currentIndex()).toPyObject()
510  qv=mol.QueryViewWrapper(self.query_editor_.GetQuery(),self.query_editor_.GetQueryFlags())
511  bcco = ByChainColorOp(qv, detail)
512  return bcco
513 
514  def SetOp(self, bcco):
515  self.query_editor_.SetQuery(bcco.GetSelection())
516  self.query_editor_.SetQueryFlags(bcco.GetSelectionFlags())
517  found=False
518  for i in range(0,self.detail_selection_cb_.count()):
519  mask = self.detail_selection_cb_.itemData(i).toPyObject()
520  if mask == bcco.GetMask():
521  self.detail_selection_cb_.setCurrentIndex(i)
522  found = True
523  break
524  if not found:
525  self.detail_selection_cb_.setCurrentIndex(0)
526 
527  def Ok(self):
528  self.accept()
529 
530  def Cancel(self):
531  self.reject()
532 
533 
534 class RenderOpWidget(QtWidgets.QDialog):
535  def __init__(self, parent=None):
536  QtWidgets.QDialog.__init__(self, parent)
537  self.query_editor_ = QueryEditorWidget(self)
538 
539  self.keep_ = QtWidgets.QCheckBox("Keep")
540  self.keep_.setChecked(False)
541 
542  render_label = QtWidgets.QLabel("Rendermode")
543  self.render_modes_ = QtWidgets.QComboBox()
544  self.render_modes_.addItem("Fast Bonds")
545  self.render_modes_.addItem("Ball & Stick")
546  self.render_modes_.addItem("Spheres")
547  self.render_modes_.addItem("Fast Trace")
548  self.render_modes_.addItem("Trace")
549  self.render_modes_.addItem("Fast Spline")
550  self.render_modes_.addItem("Smooth Tube")
551  self.render_modes_.addItem("Helix & Strand Cartoon")
552 
553  self.render_modes_list_ = [gfx.RenderMode.SIMPLE,
554  gfx.RenderMode.CUSTOM,
555  gfx.RenderMode.CPK,
556  gfx.RenderMode.LINE_TRACE,
557  gfx.RenderMode.TRACE,
558  gfx.RenderMode.SLINE,
559  gfx.RenderMode.TUBE,
560  gfx.RenderMode.HSC]
561 
562  self.hbox_ = QtWidgets.QHBoxLayout()
563  self.ok_button_ = QtWidgets.QPushButton("OK")
564  self.cancel_button_ = QtWidgets.QPushButton("Cancel")
565  self.hbox_.addWidget(self.ok_button_)
566  self.hbox_.addStretch()
567  self.hbox_.addWidget(self.cancel_button_)
568 
569  grid = QtWidgets.QGridLayout()
570  grid.setContentsMargins(0,5,0,0)
571  grid.addWidget(self.query_editor_, 0, 0, 1, 2)
572  grid.addWidget(self.keep_, 1, 1, 1, 1)
573  grid.addWidget(render_label,2,0,1,1)
574  grid.addWidget(self.render_modes_,2,1,1,1)
575  grid.addLayout(self.hbox_,3,0,1,2)
576  grid.setRowStretch(1, 1)
577  self.setLayout(grid)
578 
579  self.ok_button_.clicked.connect(self.Ok)
580  self.cancel_button_.clicked.connect(self.Cancel)
581 
582  def GetOp(self):
583  selection = self.query_editor_.GetQueryText()
584  flags = self.query_editor_.GetQueryFlags()
585  render_mode = self.render_modes_list_[self.render_modes_.currentIndex()]
586  ro = RenderOp(render_mode, selection, flags, self.keep_.isChecked())
587  return ro
588 
589  def SetOp(self, ro):
590  self.query_editor_.SetQuery(ro.GetSelection())
591  self.query_editor_.SetQueryFlags(ro.GetSelectionFlags())
592  found=False
593  for i in range(0,self.render_modes_.count()):
594  render_mode = self.render_modes_list_[i]
595  if render_mode == ro.GetRenderMode():
596  self.render_modes_.setCurrentIndex(i)
597  found = True
598  break
599  if not found:
600  self.render_modes_.setCurrentIndex(0)
601  self.keep_.setChecked(ro.IsKept())
602 
603  def Ok(self):
604  self.accept()
605 
606  def Cancel(self):
607  self.reject()
608 
609 class VisibilityOpWidget(QtWidgets.QDialog):
610  def __init__(self, parent=None):
611  QtWidgets.QDialog.__init__(self, parent)
612  self.query_editor_ = QueryEditorWidget(self)
613 
614  self.visible_ = QtWidgets.QCheckBox("Visible")
615  self.visible_.setChecked(True)
616 
617  self.hbox_ = QtWidgets.QHBoxLayout()
618  self.ok_button_ = QtWidgets.QPushButton("OK")
619  self.cancel_button_ = QtWidgets.QPushButton("Cancel")
620  self.hbox_.addWidget(self.ok_button_)
621  self.hbox_.addStretch()
622  self.hbox_.addWidget(self.cancel_button_)
623 
624  grid = QtWidgets.QGridLayout()
625  grid.setContentsMargins(0,5,0,0)
626  grid.addWidget(self.query_editor_, 0, 0, 1, 2)
627  grid.addWidget(self.visible_, 1, 1, 1, 1)
628  grid.addLayout(self.hbox_,2,0,1,2)
629  grid.setRowStretch(1, 1)
630  self.setLayout(grid)
631 
632  self.ok_button_.clicked.connect(self.Ok)
633  self.cancel_button_.clicked.connect(self.Cancel)
634 
635  def GetOp(self):
636  selection = self.query_editor_.GetQueryText()
637  flags = self.query_editor_.GetQueryFlags()
638  vo = VisibilityOp(selection, flags, self.visible_.isChecked())
639  return vo
640 
641  def SetOp(self, vo):
642  self.query_editor_.SetQuery(vo.GetSelection())
643  self.query_editor_.SetQueryFlags(vo.GetSelectionFlags())
644  self.visible_.setChecked(vo.IsVisible())
645 
646  def Ok(self):
647  self.accept()
648 
649  def Cancel(self):
650  self.reject()