OpenStructure
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-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 #Custom Render Options
28  def __init__(self, parent=None):
29  RenderModeWidget.__init__(self, parent)
30 
31  #Title
32  self.text_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_mode_ = gfx.RenderMode.CUSTOM
49 
50  #Create Ui elements
51 
52  self.sphere_spinbox_sphere_spinbox_ = QtWidgets.QSpinBox()
53  self.sphere_spinbox_sphere_spinbox_.setRange(min_sphere_detail, max_sphere_detail)
54 
55  self.arc_spinbox_arc_spinbox_ = QtWidgets.QSpinBox()
56  self.arc_spinbox_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_radius_bond_spinbox_ = QtWidgets.QDoubleSpinBox()
62  self.radius_bond_spinbox_radius_bond_spinbox_.setRange(min_rad, max_bond_rad)
63  self.radius_bond_spinbox_radius_bond_spinbox_.setDecimals(2)
64  self.radius_bond_spinbox_radius_bond_spinbox_.setSingleStep(0.05)
65 
66  self.radius_bond_slider_radius_bond_slider_ = QtWidgets.QSlider(QtCore.Qt.Horizontal, self)
67  self.radius_bond_slider_radius_bond_slider_.setRange(int(min_rad*100.0), int(max_bond_rad*100.0))
68  self.radius_bond_slider_radius_bond_slider_.setTickPosition(QtWidgets.QSlider.NoTicks)
69  self.radius_bond_slider_radius_bond_slider_.setTickInterval(5)
70 
71 
72  #Sphere Radius
73  radius_sphere_label = QtWidgets.QLabel("Sphere Radius")
74 
75  self.radius_sphere_spinbox_radius_sphere_spinbox_ = QtWidgets.QDoubleSpinBox()
76  self.radius_sphere_spinbox_radius_sphere_spinbox_.setRange(min_rad, max_sphere_rad)
77  self.radius_sphere_spinbox_radius_sphere_spinbox_.setDecimals(2)
78  self.radius_sphere_spinbox_radius_sphere_spinbox_.setSingleStep(0.05)
79 
80  self.radius_sphere_slider_radius_sphere_slider_ = QtWidgets.QSlider(QtCore.Qt.Horizontal, self)
81  self.radius_sphere_slider_radius_sphere_slider_.setRange(int(min_rad*100.0), int(max_sphere_rad*100.0))
82  self.radius_sphere_slider_radius_sphere_slider_.setTickPosition(QtWidgets.QSlider.NoTicks)
83  self.radius_sphere_slider_radius_sphere_slider_.setTickInterval(5)
84 
85  custom_label = QtWidgets.QLabel(self.text_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_sphere_spinbox_, 1, 2, 1, 1)
95  grid.addWidget(arc_label,2,0,1,3)
96  grid.addWidget(self.arc_spinbox_arc_spinbox_,2,2,1,1)
97 
98  grid.addWidget(radius_bond_label, 3, 0, 1, 1)
99  grid.addWidget(self.radius_bond_slider_radius_bond_slider_, 3, 1, 1, 3)
100  grid.addWidget(self.radius_bond_spinbox_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_radius_sphere_slider_, 4, 1, 1, 3)
104  grid.addWidget(self.radius_sphere_spinbox_radius_sphere_spinbox_, 4, 4, 1, 1)
105 
106  grid.setRowStretch(3,1)
107  self.setLayout(grid)
108 
109  self.sphere_spinbox_sphere_spinbox_.valueChanged.connect(self.UpdateSphereDetailUpdateSphereDetail)
110  self.arc_spinbox_arc_spinbox_.valueChanged.connect(self.UpdateArcDetailUpdateArcDetail)
111 
112  self.radius_bond_spinbox_radius_bond_spinbox_.valueChanged.connect(self.UpdateBondRadiusUpdateBondRadius)
113  self.radius_bond_slider_radius_bond_slider_.valueChanged.connect(self.UpdateSliderBondRadiusUpdateSliderBondRadius)
114 
115  self.radius_sphere_spinbox_radius_sphere_spinbox_.valueChanged.connect(self.UpdateSphereRadiusUpdateSphereRadius)
116  self.radius_sphere_slider_radius_sphere_slider_.valueChanged.connect(self.UpdateSliderSphereRadiusUpdateSliderSphereRadius)
117 
118  self.setMinimumSize(250,150)
119 
120  def UpdateSphereDetail(self, value):
121  self.GetOptionsGetOptions().SetSphereDetail(value)
122  self.ApplyOptionsApplyOptions()
123 
124  def UpdateArcDetail(self, value):
125  self.GetOptionsGetOptions().SetArcDetail(value)
126  self.ApplyOptionsApplyOptions()
127 
128  def UpdateBondRadius(self, value):
129  self.GetOptionsGetOptions().SetBondRad(value)
130  if(self.GetOptionsGetOptions().GetSphereRad()<self.GetOptionsGetOptions().GetBondRad()):
131  self.GetOptionsGetOptions().SetSphereRad(value)
132  self.ApplyOptionsApplyOptions()
133 
134  def UpdateSliderBondRadius(self, value):
135  self.GetOptionsGetOptions().SetBondRad(value/100.0)
136  self.ApplyOptionsApplyOptions()
137 
138  def UpdateSphereRadius(self, value):
139  self.GetOptionsGetOptions().SetSphereRad(value)
140  if(self.GetOptionsGetOptions().GetSphereRad()<self.GetOptionsGetOptions().GetBondRad()):
141  self.GetOptionsGetOptions().SetBondRad(value)
142  self.ApplyOptionsApplyOptions()
143 
144  def UpdateSliderSphereRadius(self, value):
145  self.GetOptionsGetOptions().SetSphereRad(value/100.0)
146  self.ApplyOptionsApplyOptions()
147 
148  def UpdateSphereRadiusGui(self,value):
149  value = round(value, 2)
150  if(abs(value*100.0 - self.radius_sphere_slider_radius_sphere_slider_.value())>=self.radius_sphere_slider_radius_sphere_slider_.singleStep()):
151  self.radius_sphere_slider_radius_sphere_slider_.setValue(int(value*100.0))
152  if (abs(value - self.radius_sphere_spinbox_radius_sphere_spinbox_.value())>=self.radius_sphere_spinbox_radius_sphere_spinbox_.singleStep()):
153  self.radius_sphere_spinbox_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_radius_bond_slider_.value())>=self.radius_bond_slider_radius_bond_slider_.singleStep()):
158  self.radius_bond_slider_radius_bond_slider_.setValue(int(value*100.0))
159  if (abs(value - self.radius_bond_spinbox_radius_bond_spinbox_.value())>=self.radius_bond_spinbox_radius_bond_spinbox_.singleStep()):
160  self.radius_bond_spinbox_radius_bond_spinbox_.setValue(value)
161 
162  def UpdateGui(self,options):
163  self.sphere_spinbox_sphere_spinbox_.setValue(options.GetSphereDetail())
164  self.arc_spinbox_arc_spinbox_.setValue(options.GetArcDetail())
165 
166  self.UpdateBondRadiusGuiUpdateBondRadiusGui(options.GetBondRad())
167  self.UpdateSphereRadiusGuiUpdateSphereRadiusGui(options.GetSphereRad())
168 
169  def GetText(self):
170  return self.text_text_
171 
172  def GetRenderMode(self):
173  return self.mode_mode_