2 from PyQt5
import QtCore, QtWidgets, QtGui
6 QtWidgets.QWidget.__init__(self, parent)
8 self.default_font_.setForeground(QtGui.QBrush(QtGui.QColor(0,0,0)))
10 self.error_font_.setForeground(QtGui.QBrush(QtGui.QColor(255,0,0)))
12 self.selection_edit_.setFixedHeight(40)
13 self.selection_edit_.updateGeometry()
15 self.status_.setWordWrap(
True)
16 self.status_.setMargin(0)
17 self.status_.setAlignment(QtCore.Qt.AlignRight)
18 self.status_.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum,
19 QtWidgets.QSizePolicy.Expanding))
20 vl=QtWidgets.QVBoxLayout()
25 self.in_bonds_.setChecked(
True)
28 vl.setContentsMargins(0,0,0,0)
32 hl=QtWidgets.QHBoxLayout()
33 l=QtWidgets.QLabel(
"bonds:")
45 self.selection_edit_.textChanged.connect(self.
_StartTimer)
51 if self.no_bonds_.isChecked():
53 if self.ex_bonds_.isChecked():
54 flags|=mol.EXCLUSIVE_BONDS
55 if self.match_res_.isChecked():
56 flags|=mol.MATCH_RESIDUES
60 return mol.Query(str(self.selection_edit_.toPlainText()))
63 return str(self.selection_edit_.toPlainText())
66 self.no_bonds_.setChecked(flags & mol.NO_BONDS)
67 self.ex_bonds_.setChecked(flags & mol.EXCLUSIVE_BONDS)
68 self.in_bonds_.setChecked(
not (flags & mol.NO_BONDS|mol.EXCLUSIVE_BONDS))
69 self.match_res_.setChecked(flags & mol.MATCH_RESIDUES)
72 self.selection_edit_.setText(query)
74 def _StartTimer(self):
76 self.timer_.start(500)
78 def _UpdateMessage(self):
84 cursor=self.selection_edit_.textCursor()
85 cursor.select(QtGui.QTextCursor.Document)
89 self.status_.setText(
"")
91 d=query.GetErrorDescription()
92 self.status_.setText(
"<font color='red'>%s</font>"%d.msg.strip())
94 cursor.movePosition(QtGui.QTextCursor.Start)
95 if d.range.Loc<len(query.string):
97 cursor.movePosition(QtGui.QTextCursor.NextCharacter,
98 QtGui.QTextCursor.MoveAnchor, d.range.Loc)
99 cursor.movePosition(QtGui.QTextCursor.NextCharacter,
100 QtGui.QTextCursor.KeepAnchor, d.range.Length)
106 QtWidgets.QDialog.__init__(self, parent)
107 l=QtWidgets.QVBoxLayout(self)
108 self.setWindowTitle(title)
112 l3=QtWidgets.QHBoxLayout()
113 ab=QtWidgets.QPushButton(
'OK')
115 cb=QtWidgets.QPushButton(
'Cancel')
120 cb.clicked.connect(self.reject)
121 ab.clicked.connect(self.accept)
122 self.editor.selection_edit_.textChanged.connect(self.
_CheckNewline)
126 return self.editor.GetQueryFlags()
129 return self.editor.GetQueryText()
132 if e.type() == QtCore.QEvent.KeyPress
and (e.key () == QtCore.Qt.Key_Return
or e.key () == QtCore.Qt.Key_Enter):
136 return QtWidgets.QDialog.event(self, e)
138 def _CheckNewline(self):
139 if self.editor.GetQueryText().endswith(
"\n"):