OpenStructure
render_mode_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 PyQt5 import QtCore, QtWidgets
24 
25 
26 #Tube Render Options
27 class RenderModeWidget(QtWidgets.QWidget):
28  def __init__(self, parent=None):
29  QtWidgets.QWidget.__init__(self, parent)
30  self.options_options_ = None
31  self.entities_entities_ = set()
32 
33  def GetText(self):
34  raise NotImplementedError("Subclasses must define GetText()")
35 
36  def GetRenderMode(self):
37  raise NotImplementedError("Subclasses must define GetRenderMode()")
38 
39  def UpdateGui(self, options):
40  pass
41 
42  def Update(self):
43  self.entities_.clear()
44 
45  scene_selection = gui.SceneSelection.Instance()
46  if scene_selection.GetActiveNodeCount() == 0 and scene_selection.GetActiveViewCount() == 0:
47  self.setEnabled(False)
48  return
49 
50  if scene_selection.GetActiveNodeCount() > 0 :
51  for i in range(0,scene_selection.GetActiveNodeCount()):
52  entity = scene_selection.GetActiveNode(i)
53  if isinstance(entity, gfx.Entity):
54  self.entities_.add(entity)
55  else:
56  self.setEnabled(False)
57  return
58 
59  if scene_selection.GetActiveViewCount() > 0 :
60  entity = scene_selection.GetViewEntity()
61  self.entities_.add(entity)
62 
63  if len(self.entities_)>0:
64  entity = self.entities_.pop()
65  self.options_=entity.GetOptions(self.GetRenderMode())
66  self.UpdateGui(self.options_)
67  QtWidgets.QWidget.setEnabled(self,True)
68  else:
69  QtWidgets.QWidget.setEnabled(self,False)
70 
71  def ApplyOptions(self):
72  for entity in self.entities_entities_:
73  entity.ApplyOptions(self.GetRenderModeGetRenderMode(), self.GetOptionsGetOptions())
74 
75  def GetOptions(self):
76  return self.options_options_
graphical rendering of mol::EntityHandle entites
Definition: entity.hh:60