@@ -163,8 +163,8 @@ def __init__(self, manager, icon_size=None):
163
163
164
164
self .login_button .setContentsMargins (0 , 0 , 0 , 0 )
165
165
self .user_button .setContentsMargins (0 , 0 , 0 , 0 )
166
- self .setContentsMargins (0 , 0 , 0 , 0 )
167
166
self .layout ().setContentsMargins (0 , 0 , 0 , 0 )
167
+ self .layout ().setSpacing (0 )
168
168
169
169
def current_user (self ):
170
170
""" Checks the current status of the user.
@@ -439,7 +439,7 @@ def __create_buttonbar(self):
439
439
self .new_folder_button .setDisabled (True )
440
440
441
441
self .delete_icon = QtGui .QIcon .fromTheme (
442
- 'user-trash-symbolic ' ,
442
+ 'edit-delete ' ,
443
443
qta .icon ('fa.trash' )
444
444
)
445
445
self .delete_button = QtWidgets .QPushButton (self .delete_icon , _ ('Delete' ))
@@ -737,7 +737,7 @@ def set_file_properties(self, data):
737
737
else :
738
738
# Get the ID part of the filter parameter and generate the url
739
739
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 )
741
741
a = u"<a href=\" {0}\" >{0}</a>" .format (web_url )
742
742
# Set the URL in the field
743
743
self .properties ["Link" ][1 ].setText (a )
@@ -1357,8 +1357,10 @@ def __set_collapsed_icon(self,item):
1357
1357
item .setIcon (0 ,self .get_icon ('folder' ,data ['attributes' ]['name' ]))
1358
1358
self .expanded_items .discard (data ['id' ])
1359
1359
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. """
1362
1364
# Reset active requests after error
1363
1365
try :
1364
1366
self .active_requests .remove (reply )
@@ -1611,7 +1613,7 @@ def refresh_children_of_node(self, node):
1611
1613
content_url ,
1612
1614
self .populate_tree ,
1613
1615
node ,
1614
- errorCallback = self .__populate_error
1616
+ errorCallback = self .__cleanup_reply
1615
1617
)
1616
1618
1617
1619
# If something went wrong, req should be None
@@ -1641,7 +1643,7 @@ def refresh_contents(self):
1641
1643
# If not, query the osf for the user data, and pass get_repo_contents
1642
1644
# ass the callback to which the received data should be sent.
1643
1645
self .manager .get_logged_in_user (
1644
- self .process_repo_contents , errorCallback = self .__populate_error )
1646
+ self .process_repo_contents , errorCallback = self .__cleanup_reply )
1645
1647
1646
1648
def add_item (self , parent , data ):
1647
1649
if data ['type' ] == 'nodes' :
@@ -1700,8 +1702,17 @@ def populate_tree(self, reply, parent=None):
1700
1702
parent = self .invisibleRootItem ()
1701
1703
1702
1704
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
1705
1716
1706
1717
if kind in ["project" ,"folder" ]:
1707
1718
try :
@@ -1717,7 +1728,7 @@ def populate_tree(self, reply, parent=None):
1717
1728
next_entrypoint ,
1718
1729
self .populate_tree ,
1719
1730
item ,
1720
- errorCallback = self .__populate_error
1731
+ errorCallback = self .__cleanup_reply
1721
1732
)
1722
1733
# If something went wrong, req should be None
1723
1734
if req :
@@ -1736,20 +1747,14 @@ def populate_tree(self, reply, parent=None):
1736
1747
next_page_url ,
1737
1748
self .populate_tree ,
1738
1749
parent ,
1739
- errorCallback = self .__populate_error
1750
+ errorCallback = self .__cleanup_reply
1740
1751
)
1741
1752
# If something went wrong, req should be None
1742
1753
if req :
1743
1754
self .active_requests .append (req )
1744
1755
1745
1756
# 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 )
1753
1758
1754
1759
def process_repo_contents (self , logged_in_user ):
1755
1760
""" Processes contents for the logged in user. Starts by listing
@@ -1776,7 +1781,7 @@ def process_repo_contents(self, logged_in_user):
1776
1781
req = self .manager .get (
1777
1782
user_nodes_api_call ,
1778
1783
self .populate_tree ,
1779
- errorCallback = self .__populate_error ,
1784
+ errorCallback = self .__cleanup_reply ,
1780
1785
)
1781
1786
# If something went wrong, req should be None
1782
1787
if req :
0 commit comments