Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidy up enumerations, reset cursor on exception. #116

Merged
merged 2 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions src/mapclient/tools/pluginfinder/plugindata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json
from packaging import version

from PySide6 import QtCore, QtGui
from PySide6 import QtCore, QtGui, QtWidgets
from PySide6.QtWidgets import QApplication, QStyle, QStyleOptionButton, QInputDialog, QLineEdit, QMessageBox, QTreeView

from mapclient.core.workflow.workflowsteps import addStep
Expand Down Expand Up @@ -112,18 +112,18 @@ def paint(self, painter, option, index):
opt.icon = self._downloaded_icon
else:
opt.icon = self._loading_icon
painter.drawText(_get_label_pos(option), QtCore.Qt.AlignCenter | QtCore.Qt.AlignRight, installed_version)
painter.drawText(_get_label_pos(option), QtCore.Qt.AlignmentFlag.AlignCenter | QtCore.Qt.AlignmentFlag.AlignRight, installed_version)
else:
opt.icon = self._download_icon

opt.iconSize = QtCore.QSize(48, 48)
opt.rect = _get_button_rect(option.rect)

if self._pressed and self._pressed == (index.row(), index.column()):
opt.state = QStyle.State_Enabled | QStyle.State_Sunken
opt.state = QStyle.StateFlag.State_Enabled | QStyle.StateFlag.State_Sunken
else:
opt.state = QStyle.State_Enabled | QStyle.State_Raised
QApplication.style().drawControl(QStyle.CE_PushButton, opt, painter)
opt.state = QStyle.StateFlag.State_Enabled | QStyle.StateFlag.State_Raised
QApplication.style().drawControl(QStyle.ControlElement.CE_PushButton, opt, painter)

def editorEvent(self, event, model, option, index):
if index.parent().row() < 0:
Expand All @@ -133,15 +133,15 @@ def editorEvent(self, event, model, option, index):
if (name in self._installed_versions.keys()) and self._installed_versions[name] >= self._database_versions[name]:
return True

if event.type() == QtCore.QEvent.MouseButtonPress:
if event.type() == QtCore.QEvent.Type.MouseButtonPress:
if _get_button_rect(option.rect).contains(event.pos()):
self._pressed = (index.row(), index.column())
return True

elif event.type() == QtCore.QEvent.MouseButtonRelease:
elif event.type() == QtCore.QEvent.Type.MouseButtonRelease:
if self._pressed == (index.row(), index.column()):
if _get_button_rect(option.rect).contains(event.pos()):
plugin = model.data(index, QtCore.Qt.UserRole + 1)
plugin = model.data(index, QtCore.Qt.ItemDataRole.UserRole + 1)
self.buttonClicked.emit(name, plugin.get_url())
self._pressed = None
return True
Expand Down Expand Up @@ -187,7 +187,7 @@ def _authenticate_github_user():
while True:
try:
token, ok = QInputDialog().getText(None, "GitHub PAT", "GITHUB_PAT cannot be found or is invalid. "
"Please provide a Personal Access Token for GitHub:", QLineEdit.Password)
"Please provide a Personal Access Token for GitHub:", QLineEdit.EchoMode.Password)
if ok:
g = Github(token)
_ = g.get_user().name
Expand All @@ -196,7 +196,7 @@ def _authenticate_github_user():
else:
return None
except BadCredentialsException:
QMessageBox.information(None, 'Token Invalid', 'The Personal Access Token given is not valid.')
QMessageBox.information(QtWidgets.QWidget(), 'Token Invalid', 'The Personal Access Token given is not valid.')


# This method is used by the visualisation script to get an up-to-date version of the plugin database. DB in dictionary format.
Expand Down Expand Up @@ -263,9 +263,7 @@ def call_inner():
return call_inner()
except RateLimitExceededException:
g = _authenticate_github_user()
if not g:
return None
return call_inner()
return call_inner() if g else None


def from_json(json_dict):
Expand Down
4 changes: 3 additions & 1 deletion src/mapclient/view/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,11 @@ def do_runtime_error(self, *a, **kw):
try:
return f(self, *a, **kw)
except ClientRuntimeError as e:
QtWidgets.QApplication.restoreOverrideCursor()
QtWidgets.QApplication.setOverrideCursor(QtCore.Qt.CursorShape.ArrowCursor)
logger.error('{0}: {1}'.format(e.title, e.description))
ErrorDialog(e.title, e.description, self).exec()
QtWidgets.QApplication.restoreOverrideCursor()

return do_runtime_error


Expand Down