OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
custom_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-2011 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 #Custom Render Options
27 class CustomWidget(RenderModeWidget):
28  def __init__(self, parent=None):
29  RenderModeWidget.__init__(self, parent)
30 
31  #Title
32  self.text_ = "Ball & Stick"
33 
34  #Defaults
35  min_sphere_detail = 1
36  max_sphere_detail = 12
37 
38  min_arc_detail = 1
39  max_arc_detail = 12
40 
41  min_rad = 0.05
42  max_bond_rad = 5.0
43  max_sphere_rad = 5.0
44 
45 
46 
47  #Set Render Mode
48  self.mode_ = gfx.RenderMode.CUSTOM
49 
50  #Create Ui elements
51 
52  self.sphere_spinbox_ = QtWidgets.QSpinBox()
53  self.sphere_spinbox_.setRange(min_sphere_detail, max_sphere_detail)
54 
55  self.arc_spinbox_ = QtWidgets.QSpinBox()
56  self.arc_spinbox_.setRange(min_arc_detail, max_arc_detail)
57 
58  #Bond Radius
59  radius_bond_label = QtWidgets.QLabel("Bond Radius")
60 
61  self.radius_bond_spinbox_ = QtWidgets.QDoubleSpinBox()
62  self.radius_bond_spinbox_.setRange(min_rad, max_bond_rad)
63  self.radius_bond_spinbox_.setDecimals(2)
64  self.radius_bond_spinbox_.setSingleStep(0.05)
65 
66  self.radius_bond_slider_ = QtWidgets.QSlider(QtCore.Qt.Horizontal, self)
67  self.radius_bond_slider_.setRange(min_rad*100.0, max_bond_rad*100.0)
68  self.radius_bond_slider_.setTickPosition(QtWidgets.QSlider.NoTicks)
69  self.radius_bond_slider_.setTickInterval(5)
70 
71 
72  #Sphere Radius
73  radius_sphere_label = QtWidgets.QLabel("Sphere Radius")
74 
75  self.radius_sphere_spinbox_ = QtWidgets.QDoubleSpinBox()
76  self.radius_sphere_spinbox_.setRange(min_rad, max_sphere_rad)
77  self.radius_sphere_spinbox_.setDecimals(2)
78  self.radius_sphere_spinbox_.setSingleStep(0.05)
79 
80  self.radius_sphere_slider_ = QtWidgets.QSlider(QtCore.Qt.Horizontal, self)
81  self.radius_sphere_slider_.setRange(min_rad*100.0, max_sphere_rad*100.0)
82  self.radius_sphere_slider_.setTickPosition(QtWidgets.QSlider.NoTicks)
83  self.radius_sphere_slider_.setTickInterval(5)
84 
85  custom_label = QtWidgets.QLabel(self.text_)
86  font = custom_label.font()
87  font.setBold(True)
88 
89  sphere_label = QtWidgets.QLabel("Sphere Detail")
90  arc_label = QtWidgets.QLabel("Arc Detail")
91  grid = QtWidgets.QGridLayout()
92  grid.addWidget(custom_label,0,0,1,1)
93  grid.addWidget(sphere_label, 1, 0, 1, 3)
94  grid.addWidget(self.sphere_spinbox_, 1, 2, 1, 1)
95  grid.addWidget(arc_label,2,0,1,3)
96  grid.addWidget(self.arc_spinbox_,2,2,1,1)
97 
98  grid.addWidget(radius_bond_label, 3, 0, 1, 1)
99  grid.addWidget(self.radius_bond_slider_, 3, 1, 1, 3)
100  grid.addWidget(self.radius_bond_spinbox_, 3, 4, 1, 1)
101 
102  grid.addWidget(radius_sphere_label, 4, 0, 1, 1)
103  grid.addWidget(self.radius_sphere_slider_, 4, 1, 1, 3)
104  grid.addWidget(self.radius_sphere_spinbox_, 4, 4, 1, 1)
105 
106  grid.setRowStretch(3,1)
107  self.setLayout(grid)
108 
109  self.sphere_spinbox_.valueChanged.connect(self.UpdateSphereDetail)
110  self.arc_spinbox_.valueChanged.connect(self.UpdateArcDetail)
111 
112  self.radius_bond_spinbox_.valueChanged.connect(self.UpdateBondRadius)
113  self.radius_bond_slider_.valueChanged.connect(self.UpdateSliderBondRadius)
114 
115  self.radius_sphere_spinbox_.valueChanged.connect(self.UpdateSphereRadius)
116  self.radius_sphere_slider_.valueChanged.connect(self.UpdateSliderSphereRadius)
117 
118  self.setMinimumSize(250,150)
119 
120  def UpdateSphereDetail(self, value):
121  self.GetOptions().SetSphereDetail(value)
122  self.ApplyOptions()
123 
124  def UpdateArcDetail(self, value):
125  self.GetOptions().SetArcDetail(value)
126  self.ApplyOptions()
127 
128  def UpdateBondRadius(self, value):
129  self.GetOptions().SetBondRad(value)
130  if(self.GetOptions().GetSphereRad()<self.GetOptions().GetBondRad()):
131  self.GetOptions().SetSphereRad(value)
132  self.ApplyOptions()
133 
134  def UpdateSliderBondRadius(self, value):
135  self.GetOptions().SetBondRad(value/100.0)
136  self.ApplyOptions()
137 
138  def UpdateSphereRadius(self, value):
139  self.GetOptions().SetSphereRad(value)
140  if(self.GetOptions().GetSphereRad()<self.GetOptions().GetBondRad()):
141  self.GetOptions().SetBondRad(value)
142  self.ApplyOptions()
143 
144  def UpdateSliderSphereRadius(self, value):
145  self.GetOptions().SetSphereRad(value/100.0)
146  self.ApplyOptions()
147 
148  def UpdateSphereRadiusGui(self,value):
149  value = round(value, 2)
150  if(abs(value*100.0 - self.radius_sphere_slider_.value())>=self.radius_sphere_slider_.singleStep()):
151  self.radius_sphere_slider_.setValue(value*100.0)
152  if (abs(value - self.radius_sphere_spinbox_.value())>=self.radius_sphere_spinbox_.singleStep()):
153  self.radius_sphere_spinbox_.setValue(value)
154 
155  def UpdateBondRadiusGui(self,value):
156  value = round(value, 2)
157  if(abs(value*100.0 - self.radius_bond_slider_.value())>=self.radius_bond_slider_.singleStep()):
158  self.radius_bond_slider_.setValue(value*100.0)
159  if (abs(value - self.radius_bond_spinbox_.value())>=self.radius_bond_spinbox_.singleStep()):
160  self.radius_bond_spinbox_.setValue(value)
161 
162  def UpdateGui(self,options):
163  self.sphere_spinbox_.setValue(options.GetSphereDetail())
164  self.arc_spinbox_.setValue(options.GetArcDetail())
165 
166  self.UpdateBondRadiusGui(options.GetBondRad())
167  self.UpdateSphereRadiusGui(options.GetSphereRad())
168 
169  def GetText(self):
170  return self.text_
171 
172  def GetRenderMode(self):
173  return self.mode_