OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
cpk_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 from .render_mode_widget import RenderModeWidget
25 
26 #CPK Render Options
27 class CPKWidget(RenderModeWidget):
28  def __init__(self, parent=None):
29  RenderModeWidget.__init__(self, parent)
30 
31  #Title
32  self.text_ = "Spheres"
33 
34  #Defaults
35  min_sphere_detail = 1
36  max_sphere_detail = 20
37 
38  #Set Render Mode
39  self.mode_ = gfx.RenderMode.CPK
40 
41  #Create Ui elements
42 
43  self.sphere_spinbox_ = QtWidgets.QSpinBox()
44  self.sphere_spinbox_.setRange(min_sphere_detail, max_sphere_detail)
45  cpk_mode_label = QtWidgets.QLabel("Rendering Mode")
46  self.cpk_mode_ = QtWidgets.QComboBox()
47  self.cpk_mode_.addItem("Triangles")
48  self.cpk_mode_.addItem("3D Sprites")
49  cpk_label = QtWidgets.QLabel(self.text_)
50  font = cpk_label.font()
51  font.setBold(True)
52 
53  sphere_label = QtWidgets.QLabel("Sphere Detail")
54  grid = QtWidgets.QGridLayout()
55  grid.addWidget(cpk_label,0,0,1,1)
56  grid.addWidget(sphere_label, 1, 0, 1, 3)
57  grid.addWidget(self.sphere_spinbox_, 1, 2, 1, 1)
58  grid.setRowStretch(2,1)
59  self.setLayout(grid)
60 
61  self.sphere_spinbox_.valueChanged.connect(self.UpdateSphereDetail)
62  self.cpk_mode_.currentIndexChanged.connect(self.UpdateSphereMode)
63 
64  self.setMinimumSize(250,60)
65 
66  def UpdateSphereDetail(self, value):
67  self.GetOptions().SetSphereDetail(value)
68  self.ApplyOptions()
69 
70  def UpdateSphereMode(self, value):
71  self.GetOptions().SetSphereMode(value)
72  self.ApplyOptions()
73 
74  def UpdateGui(self,options):
75  self.sphere_spinbox_.setValue(options.GetSphereDetail())
76  self.cpk_mode_.setCurrentIndex(options.GetSphereMode())
77 
78  def GetText(self):
79  return self.text_
80 
81  def GetRenderMode(self):
82  return self.mode_