Skip to content

Commit 5c6bf34

Browse files
committed
Small changes
- Change some icons and function names - Handle logout errors correctly - Put login window on top when activated - Print warnings of OSF token to console instead of using notifications
1 parent 702bff4 commit 5c6bf34

File tree

3 files changed

+37
-28
lines changed

3 files changed

+37
-28
lines changed

QOpenScienceFramework/manager.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ def show_login_window(self):
141141

142142
self.browser.load(browser_url)
143143
self.browser.show()
144+
self.browser.raise_()
145+
self.browser.activateWindow()
144146

145147
def logout(self):
146148
""" Logs out from OSF """
@@ -149,13 +151,18 @@ def logout(self):
149151
osf.logout_url,
150152
self.__logout_succeeded,
151153
{'token':osf.session.access_token},
154+
errorCallback=self.__logout_failed
152155
)
153156

154-
def __logout_succeeded(self,data,*args):
155-
""" Callback for logout(). Called when logout has succeeded. This function
157+
def __logout_succeeded(self, data, *args):
158+
""" Callback for logout(). Called when logout has failed. This function
156159
will then dispatch the logout signal to all other connected elements. """
157160
self.dispatcher.dispatch_logout()
158161

162+
def __logout_failed(self, data, *args):
163+
""" Callback for logout(). Called when logout has failed. """
164+
self.dispatcher.dispatch_login()
165+
159166
def check_for_stored_token(self, tokenfile):
160167
""" Checks if valid token information is stored in a token.json file at
161168
the supplied location. If not, or if the oken is invalid/expired, it returns
@@ -321,8 +328,7 @@ def get(self, url, callback, *args, **kwargs):
321328

322329
# Add OAuth2 token
323330
if not self.add_token(request):
324-
self.warning_message.emit('Warning',
325-
_(u"Token could not be added to the request"))
331+
warnings.warn(_(u"Token could not be added to the request"))
326332

327333
# Check if this is a redirect and keep a count to prevent endless
328334
# redirects. If redirect_count is not set, init it to 0
@@ -466,8 +472,7 @@ def put(self, url, callback, *args, **kwargs):
466472

467473
# Add OAuth2 token
468474
if not self.add_token(request):
469-
self.warning_message.emit('Warning',
470-
_(u"Token could not be added to the request"))
475+
warnings.warn(_(u"Token could not be added to the request"))
471476

472477
reply = super(ConnectionManager, self).put(request, data_to_send)
473478
reply.finished.connect(lambda: self.__reply_finished(callback, *args, **kwargs))
@@ -521,8 +526,7 @@ def delete(self, url, callback, *args, **kwargs):
521526

522527
# Add OAuth2 token
523528
if not self.add_token(request):
524-
self.warning_message.emit('Warning',
525-
_(u"Token could not be added to the request"))
529+
warnings.warn(_(u"Token could not be added to the request"))
526530

527531
# Check if this is a redirect and keep a count to prevent endless
528532
# redirects. If redirect_count is not set, init it to 0

QOpenScienceFramework/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"base_url" : "https://accounts.osf.io/",
33
"api_base_url" : "https://api.osf.io/v2/",
4-
"website_url" : "http://osf.io",
4+
"website_url" : "https://osf.io",
55
"scope" : ["osf.full_read", "osf.full_write"]
66
}

QOpenScienceFramework/widgets.py

+24-19
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ def __init__(self, manager, icon_size=None):
163163

164164
self.login_button.setContentsMargins(0, 0, 0, 0)
165165
self.user_button.setContentsMargins(0, 0, 0, 0)
166-
self.setContentsMargins(0, 0, 0, 0)
167166
self.layout().setContentsMargins(0, 0, 0, 0)
167+
self.layout().setSpacing(0)
168168

169169
def current_user(self):
170170
""" Checks the current status of the user.
@@ -439,7 +439,7 @@ def __create_buttonbar(self):
439439
self.new_folder_button.setDisabled(True)
440440

441441
self.delete_icon = QtGui.QIcon.fromTheme(
442-
'user-trash-symbolic',
442+
'edit-delete',
443443
qta.icon('fa.trash')
444444
)
445445
self.delete_button = QtWidgets.QPushButton(self.delete_icon, _('Delete'))
@@ -737,7 +737,7 @@ def set_file_properties(self, data):
737737
else:
738738
# Get the ID part of the filter parameter and generate the url
739739
web_id = target.split("=")[1]
740-
web_url = u"https://osf.io/{}".format(web_id)
740+
web_url = u"{}/{}".format(osf.settings['website_url'], web_id)
741741
a = u"<a href=\"{0}\">{0}</a>".format(web_url)
742742
# Set the URL in the field
743743
self.properties["Link"][1].setText(a)
@@ -1357,8 +1357,10 @@ def __set_collapsed_icon(self,item):
13571357
item.setIcon(0,self.get_icon('folder',data['attributes']['name']))
13581358
self.expanded_items.discard(data['id'])
13591359

1360-
def __populate_error(self, reply):
1361-
""" Callback for when an error occured while populating the tree. """
1360+
def __cleanup_reply(self, reply):
1361+
""" Callback for when an error occured while populating the tree, or when
1362+
populate_tree finished successfully. Removes the QNetworkReply
1363+
from the list of active HTTP operations. """
13621364
# Reset active requests after error
13631365
try:
13641366
self.active_requests.remove(reply)
@@ -1611,7 +1613,7 @@ def refresh_children_of_node(self, node):
16111613
content_url,
16121614
self.populate_tree,
16131615
node,
1614-
errorCallback=self.__populate_error
1616+
errorCallback=self.__cleanup_reply
16151617
)
16161618

16171619
# If something went wrong, req should be None
@@ -1641,7 +1643,7 @@ def refresh_contents(self):
16411643
# If not, query the osf for the user data, and pass get_repo_contents
16421644
# ass the callback to which the received data should be sent.
16431645
self.manager.get_logged_in_user(
1644-
self.process_repo_contents, errorCallback=self.__populate_error)
1646+
self.process_repo_contents, errorCallback=self.__cleanup_reply)
16451647

16461648
def add_item(self, parent, data):
16471649
if data['type'] == 'nodes':
@@ -1700,8 +1702,17 @@ def populate_tree(self, reply, parent=None):
17001702
parent = self.invisibleRootItem()
17011703

17021704
for entry in osf_response["data"]:
1703-
# Add item to the tree
1704-
item, kind = self.add_item(parent, entry)
1705+
# Add item to the tree. Check if object hasn't been deleted in the
1706+
# meantime
1707+
try:
1708+
item, kind = self.add_item(parent, entry)
1709+
except RuntimeError as e:
1710+
# If a runtime error occured the tree was probably reset or
1711+
# another event deleted treeWidgetItems. Not much that can be
1712+
# done here, so do some cleanup and quit
1713+
warnings.warn(e)
1714+
self.__cleanup_reply(reply)
1715+
return
17051716

17061717
if kind in ["project","folder"]:
17071718
try:
@@ -1717,7 +1728,7 @@ def populate_tree(self, reply, parent=None):
17171728
next_entrypoint,
17181729
self.populate_tree,
17191730
item,
1720-
errorCallback=self.__populate_error
1731+
errorCallback=self.__cleanup_reply
17211732
)
17221733
# If something went wrong, req should be None
17231734
if req:
@@ -1736,20 +1747,14 @@ def populate_tree(self, reply, parent=None):
17361747
next_page_url,
17371748
self.populate_tree,
17381749
parent,
1739-
errorCallback=self.__populate_error
1750+
errorCallback=self.__cleanup_reply
17401751
)
17411752
# If something went wrong, req should be None
17421753
if req:
17431754
self.active_requests.append(req)
17441755

17451756
# Remove current reply from list of active requests (assuming it finished)
1746-
try:
1747-
self.active_requests.remove(reply)
1748-
except ValueError:
1749-
logging.info("Reply not found in active requests")
1750-
1751-
if not self.active_requests:
1752-
self.refreshFinished.emit()
1757+
self.__cleanup_reply(reply)
17531758

17541759
def process_repo_contents(self, logged_in_user):
17551760
""" Processes contents for the logged in user. Starts by listing
@@ -1776,7 +1781,7 @@ def process_repo_contents(self, logged_in_user):
17761781
req = self.manager.get(
17771782
user_nodes_api_call,
17781783
self.populate_tree,
1779-
errorCallback=self.__populate_error,
1784+
errorCallback=self.__cleanup_reply,
17801785
)
17811786
# If something went wrong, req should be None
17821787
if req:

0 commit comments

Comments
 (0)