00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 from ost import gui
00022 from ost import gfx
00023 from PyQt4 import QtCore, QtGui
00024 from render_mode_widget import RenderModeWidget
00025
00026
00027 class CustomWidget(RenderModeWidget):
00028 def __init__(self, parent=None):
00029 RenderModeWidget.__init__(self, parent)
00030
00031
00032 self.text_ = "Ball & Stick"
00033
00034
00035 min_sphere_detail = 1
00036 max_sphere_detail = 12
00037
00038 min_arc_detail = 1
00039 max_arc_detail = 12
00040
00041 min_rad = 0.05
00042 max_bond_rad = 5.0
00043 max_sphere_rad = 5.0
00044
00045
00046
00047
00048 self.mode_ = gfx.RenderMode.CUSTOM
00049
00050
00051
00052 self.sphere_spinbox_ = QtGui.QSpinBox()
00053 self.sphere_spinbox_.setRange(min_sphere_detail, max_sphere_detail)
00054
00055 self.arc_spinbox_ = QtGui.QSpinBox()
00056 self.arc_spinbox_.setRange(min_arc_detail, max_arc_detail)
00057
00058
00059 radius_bond_label = QtGui.QLabel("Bond Radius")
00060
00061 self.radius_bond_spinbox_ = QtGui.QDoubleSpinBox()
00062 self.radius_bond_spinbox_.setRange(min_rad, max_bond_rad)
00063 self.radius_bond_spinbox_.setDecimals(2)
00064 self.radius_bond_spinbox_.setSingleStep(0.05)
00065
00066 self.radius_bond_slider_ = QtGui.QSlider(QtCore.Qt.Horizontal, self)
00067 self.radius_bond_slider_.setRange(min_rad*100.0, max_bond_rad*100.0)
00068 self.radius_bond_slider_.setTickPosition(QtGui.QSlider.NoTicks)
00069 self.radius_bond_slider_.setTickInterval(5)
00070
00071
00072
00073 radius_sphere_label = QtGui.QLabel("Sphere Radius")
00074
00075 self.radius_sphere_spinbox_ = QtGui.QDoubleSpinBox()
00076 self.radius_sphere_spinbox_.setRange(min_rad, max_sphere_rad)
00077 self.radius_sphere_spinbox_.setDecimals(2)
00078 self.radius_sphere_spinbox_.setSingleStep(0.05)
00079
00080 self.radius_sphere_slider_ = QtGui.QSlider(QtCore.Qt.Horizontal, self)
00081 self.radius_sphere_slider_.setRange(min_rad*100.0, max_sphere_rad*100.0)
00082 self.radius_sphere_slider_.setTickPosition(QtGui.QSlider.NoTicks)
00083 self.radius_sphere_slider_.setTickInterval(5)
00084
00085 custom_label = QtGui.QLabel(self.text_)
00086 font = custom_label.font()
00087 font.setBold(True)
00088
00089 sphere_label = QtGui.QLabel("Sphere Detail")
00090 arc_label = QtGui.QLabel("Arc Detail")
00091 grid = QtGui.QGridLayout()
00092 grid.addWidget(custom_label,0,0,1,1)
00093 grid.addWidget(sphere_label, 1, 0, 1, 3)
00094 grid.addWidget(self.sphere_spinbox_, 1, 2, 1, 1)
00095 grid.addWidget(arc_label,2,0,1,3)
00096 grid.addWidget(self.arc_spinbox_,2,2,1,1)
00097
00098 grid.addWidget(radius_bond_label, 3, 0, 1, 1)
00099 grid.addWidget(self.radius_bond_slider_, 3, 1, 1, 3)
00100 grid.addWidget(self.radius_bond_spinbox_, 3, 4, 1, 1)
00101
00102 grid.addWidget(radius_sphere_label, 4, 0, 1, 1)
00103 grid.addWidget(self.radius_sphere_slider_, 4, 1, 1, 3)
00104 grid.addWidget(self.radius_sphere_spinbox_, 4, 4, 1, 1)
00105
00106 grid.setRowStretch(3,1)
00107 self.setLayout(grid)
00108
00109 QtCore.QObject.connect(self.sphere_spinbox_, QtCore.SIGNAL("valueChanged(int)"), self.UpdateSphereDetail)
00110 QtCore.QObject.connect(self.arc_spinbox_, QtCore.SIGNAL("valueChanged(int)"), self.UpdateArcDetail)
00111
00112 QtCore.QObject.connect(self.radius_bond_spinbox_,
00113 QtCore.SIGNAL("valueChanged(double)"),
00114 self.UpdateBondRadius)
00115 QtCore.QObject.connect(self.radius_bond_slider_,
00116 QtCore.SIGNAL("valueChanged(int)"),
00117 self.UpdateSliderBondRadius)
00118
00119 QtCore.QObject.connect(self.radius_sphere_spinbox_,
00120 QtCore.SIGNAL("valueChanged(double)"),
00121 self.UpdateSphereRadius)
00122 QtCore.QObject.connect(self.radius_sphere_slider_,
00123 QtCore.SIGNAL("valueChanged(int)"),
00124 self.UpdateSliderSphereRadius)
00125
00126 self.setMinimumSize(250,150)
00127
00128 def UpdateSphereDetail(self, value):
00129 self.GetOptions().SetSphereDetail(value)
00130 self.ApplyOptions()
00131
00132 def UpdateArcDetail(self, value):
00133 self.GetOptions().SetArcDetail(value)
00134 self.ApplyOptions()
00135
00136 def UpdateBondRadius(self, value):
00137 self.GetOptions().SetBondRad(value)
00138 if(self.GetOptions().GetSphereRad()<self.GetOptions().GetBondRad()):
00139 self.GetOptions().SetSphereRad(value)
00140 self.ApplyOptions()
00141
00142 def UpdateSliderBondRadius(self, value):
00143 self.GetOptions().SetBondRad(value/100.0)
00144 self.ApplyOptions()
00145
00146 def UpdateSphereRadius(self, value):
00147 self.GetOptions().SetSphereRad(value)
00148 if(self.GetOptions().GetSphereRad()<self.GetOptions().GetBondRad()):
00149 self.GetOptions().SetBondRad(value)
00150 self.ApplyOptions()
00151
00152 def UpdateSliderSphereRadius(self, value):
00153 self.GetOptions().SetSphereRad(value/100.0)
00154 self.ApplyOptions()
00155
00156 def UpdateSphereRadiusGui(self,value):
00157 value = round(value, 2)
00158 if(abs(value*100.0 - self.radius_sphere_slider_.value())>=self.radius_sphere_slider_.singleStep()):
00159 self.radius_sphere_slider_.setValue(value*100.0)
00160 if (abs(value - self.radius_sphere_spinbox_.value())>=self.radius_sphere_spinbox_.singleStep()):
00161 self.radius_sphere_spinbox_.setValue(value)
00162
00163 def UpdateBondRadiusGui(self,value):
00164 value = round(value, 2)
00165 if(abs(value*100.0 - self.radius_bond_slider_.value())>=self.radius_bond_slider_.singleStep()):
00166 self.radius_bond_slider_.setValue(value*100.0)
00167 if (abs(value - self.radius_bond_spinbox_.value())>=self.radius_bond_spinbox_.singleStep()):
00168 self.radius_bond_spinbox_.setValue(value)
00169
00170 def UpdateGui(self,options):
00171 self.sphere_spinbox_.setValue(options.GetSphereDetail())
00172 self.arc_spinbox_.setValue(options.GetArcDetail())
00173
00174 self.UpdateBondRadiusGui(options.GetBondRad())
00175 self.UpdateSphereRadiusGui(options.GetSphereRad())
00176
00177 def GetText(self):
00178 return self.text_
00179
00180 def GetRenderMode(self):
00181 return self.mode_