Source code for schrodinger.application.desmond.cwidget
"""
Widgets used mainly in Desmond and MCPRO+ panels.
Copyright Schrodinger, LLC. All rights reserved.
"""
import schrodinger.ui.qt.filedialog as filedialog
from schrodinger.Qt import QtWidgets
try:
import schrodinger.maestro as maestro
except:
maestro = None
[docs]class AdvLabel(QtWidgets.QLabel):
"""
A mutli-line label with small, bold text.
"""
[docs] def __init__(self, text, parent, max_height=None):
# FIXME max_height
QtWidgets.QLabel.__init__(self, "<b><small>%s</small></b>" % text,
parent)
self.setWordWrap(True)
[docs]class EntryField(QtWidgets.QWidget):
"""
A special composite widget which contains a labeled line edit field.
"""
[docs] def __init__(self, parent, label_text, initial_text=""):
"""
Create a labeled text entry area with text 'label_text', set the
initial text value to 'initial_text' and if 'units_text' is defined
then add a label after the editable text to display the lable
"""
QtWidgets.QWidget.__init__(self, parent)
layout = QtWidgets.QHBoxLayout(self)
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(3)
self.label = QtWidgets.QLabel(label_text, self)
layout.addWidget(self.label)
self.line_edit = QtWidgets.QLineEdit(self)
self.line_edit.setText(initial_text)
layout.addWidget(self.line_edit, 10) # Make entry field stretchable
[docs] def setText(self, text):
"""
Set the text for the QLineEdit part of the entry field
"""
self.line_edit.setText(text)
[docs] def text(self):
"""
Returns the text for the QLineEdit part of the entry field
"""
return str(self.line_edit.text())
[docs] def setValidator(self, validator):
self.line_edit.setValidator(validator)
[docs] def hasAcceptableInput(self):
return self.line_edit.hasAcceptableInput()
[docs]class FileEntry(QtWidgets.QWidget):
"""
Class combining a QLabel, QLineEdit, and a QPushButton (Browse...).
"""
[docs] def __init__(self,
parent,
label_text,
fdlg_title,
fdlg_ftypes,
initial_dir="",
command=None):
self._fdlg_title = fdlg_title
self._fdlg_ftypes = fdlg_ftypes
self.initial_dir = initial_dir
self._command = command
QtWidgets.QWidget.__init__(self, parent)
layout = QtWidgets.QHBoxLayout(self)
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(3)
self._label = QtWidgets.QLabel(label_text, self)
layout.addWidget(self._label)
self.entry = QtWidgets.QLineEdit(self)
self.entry.setText("")
layout.addWidget(self.entry, 10) # Make entry field stretchable
self.browse_btn = QtWidgets.QPushButton("Browse...", self)
layout.addWidget(self.browse_btn)
self.browse_btn.clicked.connect(self.browse)
[docs] def pathModified(self):
"""
Called when the selected file path is modified.
"""
val = str(self.entry.text()).strip()
self.entry.setText(val)
#self.entry.xview_moveto( 1 )
if self._command:
self._command(val)
[docs] def browse(self):
"""
Called when the user clicks on the Browse button
"""
fname = filedialog.get_open_file_name(self, self._fdlg_title,
self.initial_dir,
self._fdlg_ftypes)
if fname:
self.entry.setText(fname)
self.pathModified()
[docs] def text(self):
"""
Get the value of the entry field.
"""
return str(self.entry.text())
[docs] def setText(self, value):
"""
Set the value of the entry field.
"""
self.entry.setText(value)