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 PyQt4 import QtCore, QtGui
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_ = QtGui.QSpinBox()
53  self.sphere_spinbox_.setRange(min_sphere_detail, max_sphere_detail)
54 
55  self.arc_spinbox_ = QtGui.QSpinBox()
56  self.arc_spinbox_.setRange(min_arc_detail, max_arc_detail)
57 
58  #Bond Radius
59  radius_bond_label = QtGui.QLabel("Bond Radius")
60 
61  self.radius_bond_spinbox_ = QtGui.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_ = QtGui.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(QtGui.QSlider.NoTicks)
69  self.radius_bond_slider_.setTickInterval(5)
70 
71 
72  #Sphere Radius
73  radius_sphere_label = QtGui.QLabel("Sphere Radius")
74 
75  self.radius_sphere_spinbox_ = QtGui.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_ = QtGui.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(QtGui.QSlider.NoTicks)
83  self.radius_sphere_slider_.setTickInterval(5)
84 
85  custom_label = QtGui.QLabel(self.text_)
86  font = custom_label.font()
87  font.setBold(True)
88 
89  sphere_label = QtGui.QLabel("Sphere Detail")
90  arc_label = QtGui.QLabel("Arc Detail")
91  grid = QtGui.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  QtCore.QObject.connect(self.sphere_spinbox_, QtCore.SIGNAL("valueChanged(int)"), self.UpdateSphereDetail)
110  QtCore.QObject.connect(self.arc_spinbox_, QtCore.SIGNAL("valueChanged(int)"), self.UpdateArcDetail)
111 
112  QtCore.QObject.connect(self.radius_bond_spinbox_,
113  QtCore.SIGNAL("valueChanged(double)"),
114  self.UpdateBondRadius)
115  QtCore.QObject.connect(self.radius_bond_slider_,
116  QtCore.SIGNAL("valueChanged(int)"),
118 
119  QtCore.QObject.connect(self.radius_sphere_spinbox_,
120  QtCore.SIGNAL("valueChanged(double)"),
121  self.UpdateSphereRadius)
122  QtCore.QObject.connect(self.radius_sphere_slider_,
123  QtCore.SIGNAL("valueChanged(int)"),
125 
126  self.setMinimumSize(250,150)
127 
128  def UpdateSphereDetail(self, value):
129  self.GetOptions().SetSphereDetail(value)
130  self.ApplyOptions()
131 
132  def UpdateArcDetail(self, value):
133  self.GetOptions().SetArcDetail(value)
134  self.ApplyOptions()
135 
136  def UpdateBondRadius(self, value):
137  self.GetOptions().SetBondRad(value)
138  if(self.GetOptions().GetSphereRad()<self.GetOptions().GetBondRad()):
139  self.GetOptions().SetSphereRad(value)
140  self.ApplyOptions()
141 
142  def UpdateSliderBondRadius(self, value):
143  self.GetOptions().SetBondRad(value/100.0)
144  self.ApplyOptions()
145 
146  def UpdateSphereRadius(self, value):
147  self.GetOptions().SetSphereRad(value)
148  if(self.GetOptions().GetSphereRad()<self.GetOptions().GetBondRad()):
149  self.GetOptions().SetBondRad(value)
150  self.ApplyOptions()
151 
152  def UpdateSliderSphereRadius(self, value):
153  self.GetOptions().SetSphereRad(value/100.0)
154  self.ApplyOptions()
155 
156  def UpdateSphereRadiusGui(self,value):
157  value = round(value, 2)
158  if(abs(value*100.0 - self.radius_sphere_slider_.value())>=self.radius_sphere_slider_.singleStep()):
159  self.radius_sphere_slider_.setValue(value*100.0)
160  if (abs(value - self.radius_sphere_spinbox_.value())>=self.radius_sphere_spinbox_.singleStep()):
161  self.radius_sphere_spinbox_.setValue(value)
162 
163  def UpdateBondRadiusGui(self,value):
164  value = round(value, 2)
165  if(abs(value*100.0 - self.radius_bond_slider_.value())>=self.radius_bond_slider_.singleStep()):
166  self.radius_bond_slider_.setValue(value*100.0)
167  if (abs(value - self.radius_bond_spinbox_.value())>=self.radius_bond_spinbox_.singleStep()):
168  self.radius_bond_spinbox_.setValue(value)
169 
170  def UpdateGui(self,options):
171  self.sphere_spinbox_.setValue(options.GetSphereDetail())
172  self.arc_spinbox_.setValue(options.GetArcDetail())
173 
174  self.UpdateBondRadiusGui(options.GetBondRad())
175  self.UpdateSphereRadiusGui(options.GetSphereRad())
176 
177  def GetText(self):
178  return self.text_
179 
180  def GetRenderMode(self):
181  return self.mode_