Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ptsavol committed Oct 8, 2024
1 parent 205fd4d commit 17273a6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
28 changes: 14 additions & 14 deletions spinetoolbox/widgets/custom_qwidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def __init__(self, text, parent=None, compact=False):
parent.installEventFilter(self)

def eventFilter(self, obj, ev):
if ev.type() == QEvent.KeyPress:
if ev.type() == QEvent.Type.KeyPress:
self._parent_key_press_event = QKeyEvent(ev.type(), ev.key(), ev.modifiers())
return super().eventFilter(obj, ev)

Expand Down Expand Up @@ -342,7 +342,7 @@ def _align_buttons(self):
for i in range(layout.count()):
item = layout.itemAt(i)
if item.widget() in self._buttons:
item.setAlignment(Qt.AlignBottom)
item.setAlignment(Qt.AlignmentFlag.AlignBottom)

def add_frame(self, left, right, title):
"""Add frame around given actions, with given title.
Expand Down Expand Up @@ -394,16 +394,16 @@ def paintEvent(self, ev):
top_left = left.geometry().topLeft()
bottom_right = right.geometry().bottomRight()
rect = QRect(top_left, bottom_right).adjusted(-1, -fm.height() / 2, 1, 1)
painter.setPen(Qt.gray)
painter.setPen(Qt.GlobalColor.gray)
painter.drawRoundedRect(rect, 1, 1)
title_rect = fm.boundingRect(title).adjusted(-4, 0, 4, 0)
title_rect.moveCenter(rect.center())
title_rect.moveTop(rect.top() - fm.height() / 2)
painter.setBrush(Qt.white)
painter.setPen(Qt.NoPen)
painter.setBrush(Qt.GlobalColor.white)
painter.setPen(Qt.PenStyle.NoPen)
painter.drawRect(title_rect)
painter.setPen(Qt.black)
painter.drawText(title_rect, Qt.AlignHCenter | Qt.AlignTop, title)
painter.setPen(Qt.GlobalColor.black)
painter.drawText(title_rect, Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignTop, title)
painter.end()

def _setup_action_button(self, action):
Expand Down Expand Up @@ -438,29 +438,29 @@ def eventFilter(self, obj, ev):
"""Installed on each action's QToolButton.
Ignores Up and Down key press events, so they are handled by the toolbar for custom navigation.
"""
if ev.type() == QEvent.KeyPress:
if ev.key() in (Qt.Key_Left, Qt.Key_Right):
if ev.type() == QEvent.Type.KeyPress:
if ev.key() in (Qt.Key.Key_Left, Qt.Key.Key_Right):
ev.accept()
return True
if ev.key() in (Qt.Key_Up, Qt.Key_Down):
if ev.key() in (Qt.Key.Key_Up, Qt.Key.Key_Down):
ev.ignore()
return True
return super().eventFilter(obj, ev)

def keyPressEvent(self, ev):
"""Navigates over the tool bar buttons."""
if ev.key() in (Qt.Key_Left, Qt.Key_Right): # FIXME
if ev.key() in (Qt.Key.Key_Left, Qt.Key.Key_Right): # FIXME
ev.ignore()
return
if ev.key() in (Qt.Key_Up, Qt.Key_Down):
if ev.key() in (Qt.Key.Key_Up, Qt.Key.Key_Down):
widgets = [self.widgetForAction(a) for a in self.actions() if not a.isSeparator() and a.isEnabled()]
if self._focus_widget not in widgets:
self._focus_widget = None
if self._focus_widget is None:
next_index = 0 if ev.key() == Qt.Key_Down else len(widgets) - 1
next_index = 0 if ev.key() == Qt.Key.Key_Down else len(widgets) - 1
else:
index = widgets.index(self._focus_widget)
next_index = index + 1 if ev.key() == Qt.Key_Down else index - 1
next_index = index + 1 if ev.key() == Qt.Key.Key_Down else index - 1
if 0 <= next_index < len(widgets):
self._focus_widget = widgets[next_index]
self._focus_widget.setFocus()
Expand Down
15 changes: 8 additions & 7 deletions spinetoolbox/widgets/plugin_manager_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

class _InstallPluginModel(QStandardItemModel):
def data(self, index, role=None):
if role == Qt.SizeHintRole:
if role == Qt.ItemDataRole.SizeHintRole:
return QSize(0, 40)
return super().data(index, role)


class _ManagePluginsModel(_InstallPluginModel):
def flags(self, index):
return super().flags(index) & ~Qt.ItemIsSelectable
return super().flags(index) & ~Qt.ItemFlag.ItemIsSelectable


class InstallPluginDialog(QDialog):
Expand All @@ -44,7 +44,7 @@ def __init__(self, parent):
self._model = QSortFilterProxyModel(self)
self._source_model = _InstallPluginModel(self)
self._model.setSourceModel(self._source_model)
self._model.setFilterCaseSensitivity(Qt.CaseInsensitive)
self._model.setFilterCaseSensitivity(Qt.CaseSensitivity.CaseInsensitive)
self._list_view.setModel(self._model)
self._timer = QTimer(self)
self._timer.setInterval(200)
Expand All @@ -54,7 +54,7 @@ def __init__(self, parent):
self.layout().addWidget(self._line_edit)
self.layout().addWidget(self._list_view)
self.layout().addWidget(self._button_box)
self.setAttribute(Qt.WA_DeleteOnClose)
self.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose)
self.setMinimumWidth(400)
self._button_box.button(QDialogButtonBox.StandardButton.Cancel).clicked.connect(self.close)
self._button_box.button(QDialogButtonBox.StandardButton.Ok).clicked.connect(self._handle_ok_clicked)
Expand Down Expand Up @@ -109,13 +109,14 @@ def __init__(self, parent):
self._button_box.setStandardButtons(QDialogButtonBox.StandardButton.Close)
self.layout().addWidget(self._list_view)
self.layout().addWidget(self._button_box)
self.setAttribute(Qt.WA_DeleteOnClose)
self.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose)
self.setMinimumWidth(400)
self._button_box.button(QDialogButtonBox.StandardButton.Close).clicked.connect(self.close)

def populate_list(self, names):
for name, can_update in names:
item = QStandardItem(name)
item = QStandardItem() # Don't put name into DisplayRole or the plugin name is shown twice
item.setData(name, role=Qt.ItemDataRole.UserRole)
self._model.appendRow(item)
widget = self._create_plugin_widget(name, can_update)
index = self._model.indexFromItem(item)
Expand All @@ -131,7 +132,7 @@ def _create_plugin_widget(self, plugin_name, can_update):

def _emit_item_removed(self, plugin_name):
for row in range(self._model.rowCount()):
if self._model.index(row, 0).data(Qt.ItemDataRole.DisplayRole) == plugin_name:
if self._model.index(row, 0).data(Qt.ItemDataRole.UserRole) == plugin_name:
self._model.removeRow(row)
break
self.item_removed.emit(plugin_name)
Expand Down

0 comments on commit 17273a6

Please sign in to comment.