Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _create_control(self, window, enable_range, value):
qt_orientation = dict(
horizontal=QtCore.Qt.Horizontal,
vertical=QtCore.Qt.Vertical,
)[self.orientation]
self._control = QResizableScrollBar(qt_orientation, window.control)
self._update_control(enable_range, value)
self._control.valueChanged.connect(self._update_enable_pos)
self._control.sliderPressed.connect(self._on_slider_pressed)
self._control.sliderReleased.connect(self._on_slider_released)
self._control.resized.connect(self._control_resized)
self._control.destroyed.connect(self._on_destroyed)
self._control.setVisible(True)
def mousePressEvent(self, event):
if event.button() == QtCore.Qt.LeftButton:
self.cur_drag = self.find_control_point(event.x(), event.y())
super(QFunctionControl, self).mousePressEvent(event)
def keyPressEvent(self, e):
""" This method is overridden to prevent the 's'/'w'/'e'/'q' keys from
doing the default thing which is generally useless. It also handles
the 'p' and 'l' keys so the picker and light manager are called.
"""
key = e.key()
modifiers = e.modifiers()
scene = self._scene
camera = scene.camera
if key in [QtCore.Qt.Key_Minus]:
camera.zoom(0.8)
scene.render()
scene._record_methods('camera.zoom(0.8)\nrender()')
return
if key in [QtCore.Qt.Key_Equal, QtCore.Qt.Key_Plus]:
camera.zoom(1.25)
scene.render()
scene._record_methods('camera.zoom(1.25)\nrender()')
return
if key in [QtCore.Qt.Key_E, QtCore.Qt.Key_Q, QtCore.Qt.Key_Escape]:
scene._disable_fullscreen()
return
if key in [QtCore.Qt.Key_W]:
self._connections_to_remove.append(
(control.undoAvailable, self.undo_available)
)
# Hijack the document size change signal to prevent Qt from adjusting
# the viewport's scrollbar. We are relying on an implementation detail
# of Q(Plain)TextEdit here, which is potentially dangerous, but without
# this functionality we cannot create a nice terminal interface.
layout = control.document().documentLayout()
layout.documentSizeChanged.disconnect()
layout.documentSizeChanged.connect(self._adjust_scrollbars)
# The document layout doesn't stay the same therefore its signal is
# not explicitly disconnected on destruction
# Configure the control.
control.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
control.setReadOnly(True)
control.setUndoRedoEnabled(False)
control.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
return control
editor.model.removeRow(row)
elif editor.selected_index != -1:
# Deleting the selected item will reset cause the ListView's
# selection model to select the next item before removing the
# originally selected rows. Visually, this looks fine because
# the next item is then placed where the deleted item used to
# be. However, some internal state is kept which makes the
# selected item seem off by one. So we'll reset it manually
# here.
row = editor.selected_index
editor.model.removeRow(row)
# Handle the case of deleting the last item in the list.
editor.selected_index = min(
row, editor.adapter.len(editor.object, editor.name) - 1)
elif (event.key() == QtCore.Qt.Key_Insert and
factory.editable and 'insert' in factory.operations):
event.accept()
if factory.multi_select:
indices = sorted(editor.multi_selected_indices)
row = indices[0] if len(indices) else -1
else:
row = editor.selected_index
if row == -1:
row = editor.adapter.len(editor.object, editor.name)
editor.model.insertRow(row)
self.setCurrentIndex(editor.model.index(row))
else:
QtGui.QListView.keyPressEvent(self, event)
def __init__(self, commit,
notifier,
selectable=QGraphicsItem.ItemIsSelectable,
cursor=Qt.PointingHandCursor,
xpos=commit_radius / 2.0 + 1.0,
cached_commit_color=commit_color,
cached_merge_color=merge_color):
QGraphicsItem.__init__(self)
self.commit = commit
self.notifier = notifier
self.selected = False
self.setZValue(0)
self.setFlag(selectable)
self.setCursor(cursor)
self.setToolTip(commit.oid[:12] + ': ' + commit.summary + ':' + commit.authdate)
if commit.tags:
def _event_filter_console_keypress(self, event):
""" Reimplemented for smart backspace.
"""
if (
event.key() == QtCore.Qt.Key_Backspace
and not event.modifiers() & QtCore.Qt.AltModifier
):
# Smart backspace: remove four characters in one backspace if:
# 1) everything left of the cursor is whitespace
# 2) the four characters immediately left of the cursor are spaces
col = self._get_input_buffer_cursor_column()
cursor = self._control.textCursor()
if col > 3 and not cursor.hasSelection():
text = self._get_input_buffer_cursor_line()[:col]
if text.endswith(" ") and not text.strip():
cursor.movePosition(
QtGui.QTextCursor.Left, QtGui.QTextCursor.KeepAnchor, 4
)
cursor.removeSelectedText()
return True
return super(PythonWidget, self)._event_filter_console_keypress(event)
elif key == QtCore.Qt.Key_Less:
self._page_control.moveCursor(QtGui.QTextCursor.Start)
return True
elif key in (QtCore.Qt.Key_Q, QtCore.Qt.Key_Escape):
if self._splitter:
self._page_control.hide()
else:
self.layout().setCurrentWidget(self._control)
return True
elif key in (QtCore.Qt.Key_Enter, QtCore.Qt.Key_Return):
new_event = QtGui.QKeyEvent(
QtCore.QEvent.KeyPress,
QtCore.Qt.Key_PageDown,
QtCore.Qt.NoModifier,
)
QtGui.QApplication.sendEvent(self._page_control, new_event)
return True
elif key == QtCore.Qt.Key_Backspace:
new_event = QtGui.QKeyEvent(
QtCore.QEvent.KeyPress,
QtCore.Qt.Key_PageUp,
QtCore.Qt.NoModifier,
)
QtGui.QApplication.sendEvent(self._page_control, new_event)
return True
return False
chars_before = self._chars_before_cursor(cursor, 2)
if chars_before == '| ' or chars_before == '+ ':
cursor.insertText(' ')
elif chars_before[1] == '|' or chars_before[1] == '+':
cursor.insertText(' ')
elif self._chars_at_cursor(cursor, 1) == '|':
cursor.movePosition(QtGui.QTextCursor.Left, QtGui.QTextCursor.MoveAnchor)
self.code_widget.code.setTextCursor(cursor)
cursor.insertText(' ')
else:
old_pos = self._move_end_of_cell(cursor)
cursor.insertText(' ')
cursor.setPosition(old_pos)
elif key == QtCore.Qt.Key_Delete:
if self._chars_at_cursor(cursor, 1) == '|':
cursor.movePosition(QtGui.QTextCursor.Right, QtGui.QTextCursor.MoveAnchor)
cursor.insertText('|')
cursor.movePosition(QtGui.QTextCursor.Left, QtGui.QTextCursor.MoveAnchor)
elif self._chars_at_cursor(cursor, 1) == '+':
cursor.movePosition(QtGui.QTextCursor.Right, QtGui.QTextCursor.MoveAnchor)
cursor.insertText('+')
cursor.movePosition(QtGui.QTextCursor.Left, QtGui.QTextCursor.MoveAnchor)
elif self._chars_at_cursor(cursor, 1) == ' ' and self._chars_before_cursor(cursor, 1) == '|':
cursor.insertText(' ')
else:
old_pos = self._move_end_of_cell(cursor)
cursor.insertText(' ')
cursor.setPosition(old_pos)
elif key == QtCore.Qt.Key_Return:
self.atom_table_buttons_layout = QtGui.QHBoxLayout(self.atom_table_buttons_widget)
self.atom_table_buttons_layout.setAlignment(QtCore.Qt.AlignLeft)
self.add_atom_button = QtGui.QPushButton('Add atom', self)
self.add_atom_button.setFixedWidth(150)
self.add_atom_button.clicked.connect(self.add_atom)
self.atom_table_buttons_layout.addWidget(self.add_atom_button)
self.remove_atom_button = QtGui.QPushButton('Remove atoms', self)
self.remove_atom_button.setFixedWidth(150)
self.remove_atom_button.clicked.connect(self.remove_atoms)
self.atom_table_buttons_layout.addWidget(self.remove_atom_button)
self.buttonBox = QtGui.QDialogButtonBox(self)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(
QtGui.QDialogButtonBox.Cancel | QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Apply)
self.verticalLayout.addWidget(self.buttonBox)
self.buttonBox.accepted.connect(self.accept)
self.buttonBox.rejected.connect(self.reject)
self.buttonBox.button(QtGui.QDialogButtonBox.Apply).clicked.connect(self.apply)
header = self.atom_table.horizontalHeader()
header.setResizeMode(0, QtGui.QHeaderView.ResizeToContents)
header.setResizeMode(1, QtGui.QHeaderView.Stretch)
header.setResizeMode(2, QtGui.QHeaderView.Stretch)
header.setResizeMode(3, QtGui.QHeaderView.Stretch)
self.unit_cell_table.horizontalHeader().setResizeMode(QtGui.QHeaderView.Stretch)
self.unit_cell_table.verticalHeader().setResizeMode(QtGui.QHeaderView.Stretch)