00001 from PyQt4.QtCore import *
00002 from PyQt4.QtGui import *
00003 from ost import *
00004 from ost import gui
00005 from ost.gui.init_splash import _InitSplash
00006 from ost.gui.dng import termuse
00007 from ost.gui.dng import superpositiondialog
00008
00009 import sys
00010 class FileMenu(QMenu):
00011 def __init__(self, parent=None):
00012 QMenu.__init__(self, parent)
00013 self.setTitle('File')
00014 gui.AddMenuAction(self, 'Open', self._Open, shortcut='Ctrl+O')
00015 gui.AddMenuAction(self, 'Save As...', self._SaveAs,
00016 shortcut='Ctrl+Shift+S',
00017 enabled=gui.OneOf(gfx.Entity))
00018 def _Open(self):
00019 filename=QFileDialog.getOpenFileName(None, 'Open file','')
00020 if(QFileInfo(filename).isFile()):
00021 gui.FileLoader.LoadObject(str(filename))
00022
00023 def _SaveAs(self):
00024 sel_node=gui.SceneSelection.Instance().GetActiveNode(0)
00025 filename=QFileDialog.getSaveFileName(None, 'Save As',
00026 '%s.pdb' % sel_node.name)
00027 io.SavePDB(sel_node.view, str(filename))
00028
00029 class ClipWidget(QWidget):
00030 def __init__(self, width=500, height=500):
00031 QWidget.__init__(self)
00032 self.setWindowFlags(Qt.Tool)
00033 l = QGridLayout(self)
00034 l.addWidget(QLabel("Near"), 0, 0)
00035 l.addWidget(QLabel("Far"), 1, 0)
00036 bounds_near = QLineEdit(str(0))
00037 bounds_near.setValidator(QIntValidator(0, 9999, bounds_near))
00038 bounds_near.setMaxLength(4)
00039 bounds_near.setMaximumWidth(50)
00040 bounds_far = QLineEdit(str(200))
00041 bounds_far.setValidator(QIntValidator(0, 9999, bounds_far))
00042 bounds_far.setMaxLength(4)
00043 bounds_far.setMaximumWidth(50)
00044 l.addWidget(bounds_near, 0, 1, 2, 1)
00045 l.addWidget(bounds_far, 0, 3, 2, 1)
00046 self.near_ = QSlider(Qt.Horizontal)
00047 self.near_.setMinimum(int(bounds_near.text()))
00048 self.near_.setMaximum(int(bounds_far.text()))
00049 self.near_.setValue(int(gfx.Scene().near))
00050 self.far_ = QSlider(Qt.Horizontal)
00051 self.far_.setMinimum(int(bounds_near.text()))
00052 self.far_.setMaximum(int(bounds_far.text()))
00053 far = int(gfx.Scene().far)
00054 if far>sys.maxint:
00055 far = sys.maxint
00056 self.far_.setValue(far)
00057 self.auto_ = QCheckBox("Continuous Automatic Clipping")
00058 self.auto_.setChecked(gfx.Scene().GetAutoAutoslab())
00059
00060 l.addWidget(self.near_, 0, 2)
00061 l.addWidget(self.far_, 1, 2)
00062 l.addWidget(self.auto_, 2, 0, 1, 4)
00063 self.connect(self.near_, SIGNAL('valueChanged(int)'), self.SetNear)
00064 self.connect(self.far_, SIGNAL('valueChanged(int)'), self.SetFar)
00065 self.connect(self.auto_, SIGNAL('stateChanged(int)'), self.SetAuto)
00066 self.connect(bounds_near, SIGNAL('textEdited(QString)'), self.SetNearBounds)
00067 self.connect(bounds_far, SIGNAL('textEdited(QString)'), self.SetFarBounds)
00068
00069 def SetNear(self, val):
00070 gfx.Scene().near = val
00071
00072 def SetFar(self, val):
00073 gfx.Scene().far = val
00074
00075 def SetAuto(self, val):
00076 gfx.Scene().AutoAutoslab(val)
00077 gfx.Scene().near = int(self.near_.value())
00078 gfx.Scene().far = int(self.far_.value())
00079
00080 def SetNearBounds(self, text):
00081 if text!='':
00082 self.near_.setMinimum(int(text))
00083 self.far_.setMinimum(int(text))
00084
00085 def SetFarBounds(self, text):
00086 if text!='':
00087 self.near_.setMaximum(int(text))
00088 self.far_.setMaximum(int(text))
00089
00090 class ExportSceneDialog(QDialog):
00091 def __init__(self, width=500, height=500):
00092 QDialog.__init__(self)
00093 l=QGridLayout(self)
00094 l.setColumnMinimumWidth(0, 100)
00095 l.addWidget(QLabel("Width (px)"), 0, 0)
00096 l.addWidget(QLabel("Height (px)"), 1, 0)
00097 self.width_=QLineEdit(str(width))
00098 self.height_=QLineEdit((str(height)))
00099 self.width_.setValidator(QIntValidator(50, 3000, self.width_))
00100 self.height_.setValidator(QIntValidator(50, 3000, self.height_))
00101 self.opaque_=QCheckBox("Force Opaque Background")
00102 l.addWidget(self.width_, 0, 1)
00103 l.addWidget(self.height_, 1, 1)
00104 l.addWidget(self.opaque_, 2, 1)
00105 hbox=QHBoxLayout()
00106 cancel=QPushButton("Cancel")
00107 QObject.connect(cancel, SIGNAL('clicked()'), self.reject)
00108 hbox.addWidget(cancel)
00109 export=QPushButton("Export")
00110 hbox.addWidget(export)
00111 export.setDefault(True)
00112 l.addLayout(hbox, 3, 1, 2, 1)
00113 QObject.connect(export, SIGNAL('clicked()'), self.accept)
00114 @property
00115 def transparent(self):
00116 return not self.opaque_.isChecked()
00117
00118 @property
00119 def width(self):
00120 return int(self.width_.text())
00121
00122 @property
00123 def height(self):
00124 return int(self.height_.text())
00125
00126 class SceneMenu(QMenu):
00127 def __init__(self, parent=None):
00128 QMenu.__init__(self, parent)
00129 self.setTitle('Scene')
00130 QObject.connect(self, SIGNAL('aboutToShow()'), self._AboutToShow)
00131 gui.AddMenuAction(self, 'Background Color', self._SetSceneBackground)
00132 self.fog_action=gui.AddMenuAction(self, 'Depth Cueing', self._ToggleFog,
00133 shortcut='Ctrl+Shift+F', checkable=True,
00134 checked=gfx.Scene().fog)
00135 gui.AddMenuAction(self, 'Center', self._Center,
00136 enabled=gui.ManyOf(gfx.GfxObj))
00137 gui.AddMenuAction(self, 'Fit To Screen', self._FitToScreen,
00138 enabled=gui.OneOf(gfx.Entity))
00139 gui.AddMenuAction(self, 'Superpose', self._SuperposeDialog,
00140 enabled=gui.TwoOf(gfx.Entity))
00141 gui.AddMenuAction(self, 'Save Snapshot', self._ExportScene)
00142 gui.AddMenuAction(self, 'Scene Clipping', self._ClipScene, shortcut='Ctrl+Shift+C')
00143
00144 def _ExportScene(self):
00145 qd=ExportSceneDialog()
00146 if not qd.exec_():
00147 return
00148 filename=QFileDialog.getSaveFileName(None, 'Save Snapshot',
00149 'snapshot.png')
00150 if filename:
00151 gfx.Scene().Export(str(filename), qd.width, qd.height, qd.transparent)
00152
00153 def _ClipScene(self):
00154 self.cw = ClipWidget()
00155 self.cw.show()
00156
00157 def _AboutToShow(self):
00158 self.fog_action.setChecked(gfx.Scene().fog)
00159
00160 def _Center(self):
00161 sel=gui.SceneSelection.Instance()
00162 gfx.Scene().center=sel.GetActiveNode(0).center
00163
00164 def _SetSceneBackground(self):
00165 new_color=gui.PickColor(gfx.Scene().bg)
00166 if new_color:
00167 gfx.Scene().bg=new_color
00168
00169 def _ToggleFog(self):
00170 gfx.Scene().fog=not gfx.Scene().fog
00171 self.fog_action.setChecked(gfx.Scene().fog)
00172
00173 def _FitToScreen(self):
00174 sel=gui.SceneSelection.Instance()
00175 gfx.FitToScreen(sel.GetActiveNode(0))
00176
00177 def _SuperposeDialog(self):
00178 sel=gui.SceneSelection.Instance()
00179 act_count=sel.GetActiveNodeCount()
00180
00181
00182 i = 0;
00183 gfx_ent_1 = sel.GetActiveNode(i)
00184 while not isinstance(gfx_ent_1, gfx.Entity):
00185 i += 1
00186 gfx_ent_1 = sel.GetActiveNode(i)
00187 i += 1
00188 gfx_ent_2 = sel.GetActiveNode(i)
00189 while not isinstance(gfx_ent_2, gfx.Entity):
00190 i += 1
00191 gfx_ent_2 = sel.GetActiveNode(i)
00192 sd = superpositiondialog.SuperpositionDialog(gfx_ent_1, gfx_ent_2)
00193 if sd.rmsd_superposed_atoms != None:
00194 if sd.reference == 0:
00195 gfx_ent_2.UpdatePositions()
00196 gfx.Scene().CenterOn(gfx_ent_1)
00197 else:
00198 gfx_ent_1.UpdatePositions()
00199 gfx.Scene().CenterOn(gfx_ent_2)
00200 LogScript('RMSD: %.3f'%sd.rmsd)
00201 LogScript('RMSD superposed atoms: %.3f'%sd.rmsd_superposed_atoms)
00202 LogScript('fraction superposed: %.3f'%sd.fraction_superposed)
00203 elif sd.rmsd != None:
00204 if sd.reference == 0:
00205 gfx_ent_2.UpdatePositions()
00206 gfx.Scene().CenterOn(gfx_ent_1)
00207 else:
00208 gfx_ent_1.UpdatePositions()
00209 gfx.Scene().CenterOn(gfx_ent_2)
00210 LogScript('RMSD: %.3f'%sd.rmsd)
00211
00212 class WindowMenu(QMenu):
00213 def __init__(self, parent=None):
00214 QMenu.__init__(self, parent)
00215 self.setTitle('Window')
00216 gosty=gui.GostyApp.Instance()
00217 QObject.connect(self, SIGNAL('aboutToShow()'), self._AboutToShow)
00218 inspector_visible=gosty.GetWidget('InspectorDialog').isVisible()
00219 self._gl_win_action=gui.AddMenuAction(self, 'GL Window',
00220 self._ToggleShowGLWindow, checkable=True,
00221 checked=gosty.gl_win.qobject.isVisible(),
00222 shortcut='Ctrl+G')
00223 self._inspector_action=gui.AddMenuAction(self, 'Inspector',
00224 self._ToggleShowInspector,
00225 checkable=True,
00226 checked=inspector_visible,
00227 shortcut='Ctrl+I')
00228 self.addSeparator()
00229 self.addMenu(gosty.perspective.panels.menu)
00230 gui.AddMenuAction(self, 'Reset View', self._ResetView)
00231 def _AboutToShow(self):
00232 gosty=gui.GostyApp.Instance()
00233 self._gl_win_action.setChecked(gosty.gl_win.qobject.isVisible())
00234 inspector_visible=gosty.GetWidget('InspectorDialog').isVisible()
00235 self._inspector_action.setChecked(inspector_visible)
00236
00237 def _ToggleShowGLWindow(self):
00238 gosty=gui.GostyApp.Instance()
00239 gl_win=gosty.GetGLWin()
00240 if gl_win and gl_win.qobject.isHidden():
00241 gl_win.Show()
00242 else:
00243 gl_win.Hide()
00244
00245 def _ToggleShowInspector(self):
00246 gosty=gui.GostyApp.Instance()
00247 inspector=gosty.GetWidget('InspectorDialog')
00248 if inspector and inspector.isHidden():
00249 inspector.show()
00250 else:
00251 inspector.hide()
00252
00253 def _ResetView(self):
00254 msg_box = QMessageBox()
00255 msg_box.setWindowTitle("Reset the Panels and Widget");
00256 msg_box.setIcon(QMessageBox.Question)
00257 msg_box.setText("Do you really want to reset the Panels and Widgets?");
00258 msg_box.setStandardButtons(QMessageBox.Yes |
00259 QMessageBox.Cancel);
00260 msg_box.setDefaultButton(QMessageBox.Cancel);
00261 ret = msg_box.exec_();
00262 if(ret == QMessageBox.Yes):
00263 settings = QSettings()
00264 settings.setValue("restore_settings",QVariant(False))
00265 info_box = QMessageBox()
00266 info_box.setStandardButtons(QMessageBox.Ok)
00267 info_box.setIcon(QMessageBox.Information)
00268 info_box.setWindowTitle("Restart OpenStructure")
00269 info_box.setText("You must restart OpenStructure for the changes to take effect!");
00270 info_box.exec_();
00271
00272 class HelpMenu(QMenu):
00273 def __init__(self, parent=None):
00274 QMenu.__init__(self, parent)
00275 self.setTitle('Help')
00276 gui.AddMenuAction(self, 'Documentation', self._VisitDocs)
00277 gui.AddMenuAction(self, 'About', self._ShowAboutDialog)
00278 if sys.platform=='darwin':
00279 gui.AddMenuAction(self, 'Install Command Line Tool',
00280 termuse.InstallTerminalPrograms)
00281 def _VisitDocs(self):
00282 QDesktopServices.openUrl(QUrl("http://www.openstructure.org/docs/"))
00283
00284 def _ShowAboutDialog(self):
00285 _InitSplash()
00286
00287 def _InitMenu():
00288 _InitMenu.mbar=gui.GostyApp.Instance().perspective.GetMenuBar()
00289 file_menu=FileMenu(_InitMenu.mbar)
00290 scene_menu=SceneMenu(_InitMenu.mbar)
00291 win_menu=WindowMenu(_InitMenu.mbar)
00292 help_menu=HelpMenu(_InitMenu.mbar)
00293 _InitMenu.mbar.addMenu(file_menu)
00294 _InitMenu.mbar.addMenu(scene_menu)
00295 _InitMenu.mbar.addMenu(win_menu)
00296 _InitMenu.mbar.addMenu(help_menu)