API Reference

Connection

This module handles the OAuth2 authentication process and maintains the session (/token) information that is required to communicate with the OSF API

It is also responsible for constructing the correct API calls/uris as specified by the OSF for the various types of information that can be requested.

Note

A lot of the functions that are available here have equivalents in the ConnectionManager class. It is recommended to use those functions instead as they are executed asynchronously and are used throughout the rest of the application.

QOpenScienceFramework.connection.api_call(command, *args)[source]

generates and api endpoint. If arguments are required to build the endpoint , they can be specified as extra arguments.

Parameters:

command : {‘logged_in_user’, ‘projects’, ‘project_repos’, ‘repo_files’, ‘file_info’}

The key of the endpoint to look up in the api_calls dictionary

Extra arguments passed to this function will be integrated into the API call at specified positions (marked by {}). The formats of the calls are as follows:

logged_in_user: "users/me/"

projects: "users/me/nodes/"

project_repos: "nodes/{}/files/"

repo_files: "nodes/{}/files/{}/"

file_info: "files/{}/"

*args : various (optional)

Optional extra data which is needed to construct the correct api endpoint uri. Check the OSF API documentation for a list of variables that each type of call expects.

Returns:

string : The complete uri for the api endpoint.

QOpenScienceFramework.connection.check_for_active_session()[source]

Checks if a session object has been created and raises a RuntimeError otherwise.

QOpenScienceFramework.connection.create_session()[source]

Creates/resets and OAuth 2 session, with the specified data.

QOpenScienceFramework.connection.direct_api_call(*args, **kwargs)[source]

Performs a direct api call. Can be used as the api call is already constructed.

Parameters:

api_call: str

The api call to perform

Returns:

dict

The dict containing the returned JSON data

QOpenScienceFramework.connection.get_authorization_url()[source]

Generate the URL at which an OAuth2 token for the OSF can be requested with which OpenSesame can be allowed access to the user’s account.

Returns:

str

The complete uri for the api endpoint.

Raises:

RuntimeError

When there is no active OAuth2 session.

QOpenScienceFramework.connection.get_logged_in_user(*args, **kwargs)[source]

Gets the currently logged in user’s data

Returns:

dict

The dict containing the returned JSON data

QOpenScienceFramework.connection.get_project_repos(*args, **kwargs)[source]

Gets the data of the specified project

Parameters:

project_id : str

Reference to the project node on the OSF

Returns:

dict

The dict containing the returned JSON data

QOpenScienceFramework.connection.get_repo_files(*args, **kwargs)[source]

Gets the data of the specified repository of the specified project.

Parameters:

project_id : str

Reference to the project node on the OSF

repo_name : {‘osfstorage’,’dropbox’,’github’,’figshare’,’s3’,’googledrive’}

The repository to return the data of.

Returns:

dict

The dict containing the returned JSON data

QOpenScienceFramework.connection.get_user_projects(*args, **kwargs)[source]

Gets the currently logged in user’s projects

Returns:

dict

The dict containing the returned JSON data

QOpenScienceFramework.connection.is_authorized()[source]

Convenience function simply returning OAuth2Session.authorized.

Returns:

bool

True is the user is authorized, False if not

QOpenScienceFramework.connection.logout()[source]

Logs out the user, and resets the global session object.

Returns:

bool

True if logout was succesful, False if not.

QOpenScienceFramework.connection.parse_token_from_url(url)[source]

Parses token from url fragment

Parameters:

url : str

The url to parse. Should have a hass fragment (#) after which the token information is found.

Returns:

str

The currently used OAuth2 access token.

Raises:

RuntimeError

When there is no active OAuth2 session.

QOpenScienceFramework.connection.requires_authentication(func)[source]

Decorator function which checks if a user is authenticated before he performs the desired action. It furthermore checks if the response has been received without errors.

QOpenScienceFramework.connection.token_valid()[source]

Checks if OAuth token is present, and if so, if it has not expired yet.

Returns:

bool

True if the token is present and is valid, False otherwise

ConnectionManager

class QOpenScienceFramework.manager.ConnectionManager(*args, **kwargs)[source]

Bases: PyQt5.QtNetwork.QNetworkAccessManager

The connection manager does most of the heavy lifting in communicating with the OSF. It is responsible for all the HTTP requests and the correct treatment of responses from the OSF.

Attributes

progress_icon

Methods

add_token(request) Adds the OAuth2 token to a HTTP request.
buffer_network_request(func) Decorator function, not to be called directly.
check_for_stored_token(tokenfile) Checks for stored token information.
delete(inst, *args, **kwargs) Perform a HTTP DELETE request.
download_file(url, destination, *args, **kwargs) Downloads a file by a using HTTP GET request.
error_message PyQt signal to send an error message.
get(inst, *args, **kwargs) Performs a HTTP GET request.
get_file_info(file_id, callback, *args, **kwargs) Gets information about the specified file.
get_logged_in_user(callback, *args, **kwargs) Get logged in user information.
get_project_repos(project_id, callback, ...) Get repos for the specified project.
get_repo_files(project_id, repo_name, ...) Retrieves files contained in a repository.
get_user_projects(callback, *args, **kwargs) Gets current user’s projects.
handle_login() Handles the login event received after login.
handle_logout() Handles the logout event received after a logout.
info_message PyQt signal to send an info message.
login() Logs in a user.
logout() Logs the current user out from OSF.
post(inst, *args, **kwargs) Perform a HTTP POST request.
put(inst, *args, **kwargs) Perform a HTTP PUT request.
set_logged_in_user(user_data) Callback function, not to be called directly.
show_login_window() Shows the login page on OSF.
success_message PyQt signal to send a success message.
upload_file(url, source_file, *args, **kwargs) Uploads a file.
warning_message PyQt signal to send a warning message.
__init__(*args, **kwargs)[source]

Constructor

Parameters:

tokenfile : str (default: ‘token.json’)

The path to the file in which the token information should be stored.

notifier : QtCore.QObject (default: None)

The object containing pyqt slots / callables to which this object’s message signals can be connected. The object should contain the following slots / functions: info, error, success, warning. Each of these should expect two strings. This object is then repsonsible for displaying the messages, or passing them on to another object responsible for the display.

If None is passed, then a events.Notifier object is created which simply displays all messages in QDialog boxes

add_token(request)[source]

Adds the OAuth2 token to a HTTP request.

Parameters:

request : QtNetwork.QNetworkRequest

The network request item in whose header to add the OAuth2 token

Returns:

bool

True if token could successfully be added to the request, False if not

buffer_network_request(func)[source]

Decorator function, not to be called directly. Checks if network is accessible and buffers the network request so that it can be sent again if it fails the first time, for instance due to an invalidated OAuth2 token. In this case the user will be presented with the login screen again. If the same user successfully logs in again, the request will be resent.

check_for_stored_token(tokenfile)[source]

Checks for stored token information. Checks if a token.json file can be found at the supplied location and inspects if it is not expired.

Parameters:

tokenfile : str

Path to the token file

Returns:

bool

True if a valid token was found at tokenfile’s location, False otherwise

delete(inst, *args, **kwargs)[source]

Perform a HTTP DELETE request.

The OAuth2 token is automatically added to the header if the request is going to an OSF server.

Parameters:

url : string / QtCore.QUrl

The target url/endpoint to perform the GET request on

callback : function

The function to call once the request is finished successfully.

errorCallback : function (default: None)

function to call whenever an error occurs. Should be able to accept the reply object as an argument. This function is also called if the operation is aborted by the user him/herself.

abortSignal : QtCore.pyqtSignal

This signal will be attached to the reply objects abort() slot, so that the operation can be aborted from outside if necessary.

*args (optional)

Any other arguments that you want to have passed to the callback

**kwargs (optional)

Any other keywoard arguments that you want to have passed to the callback

download_file(url, destination, *args, **kwargs)[source]

Downloads a file by a using HTTP GET request. The OAuth2 token is automatically added to the header if the request is going to an OSF server.

Parameters:

url : string / QtCore.QUrl

The target url that points to the file to download

destination : string

The path and filename with which the file should be saved.

finished_callback : function (default: None)

The function to call once the download is finished.

downloadProgress : function (default: None)

The slot (callback function) for the downloadProgress signal of the reply object. This signal is emitted after a certain amount of bytes is received, and can be used for instance to update a download progress dialog box. The callback function should have two parameters to which the transfered and total bytes can be assigned.

errorCallback : function (default: None)

function to call whenever an error occurs. Should be able to accept the reply object as an argument.

progressDialog : dict (default

A dictionary containing data about the file to be transferred. It should have two entries: filename: The name of the file filesize: the size of the file in bytes

*args (optional)

Any other arguments that you want to have passed to the callback

**kwargs (optional)

Any other keywoard arguments that you want to have passed to the callback

error_message

PyQt signal to send an error message.

get(inst, *args, **kwargs)[source]

Performs a HTTP GET request.

The OAuth2 token is automatically added to the header if the request is going to an OSF server.

Parameters:

url : string / QtCore.QUrl

The target url/endpoint to perform the GET request on

callback : callable

The function to call once the request is finished successfully.

downloadProgess : function (defualt: None)

The slot (callback function) for the downloadProgress signal of the reply object. This signal is emitted after a certain amount of bytes is received, and can be used for instance to update a download progress dialog box. The callback function should have two parameters to which the transfered and total bytes can be assigned.

readyRead : function (default

The slot (callback function) for the readyRead signal of the reply object.

errorCallback : function (default: None)

function to call whenever an error occurs. Should be able to accept the reply object as an argument. This function is also called if the operation is aborted by the user him/herself.

progressDialog : QtWidgets.QProgressDialog (default: None)

The dialog to send the progress indication to. Will be included in the reply object so that it is accessible in the downloadProgress slot, by calling self.sender().property(‘progressDialog’)

abortSignal : QtCore.pyqtSignal

This signal will be attached to the reply objects abort() slot, so that the operation can be aborted from outside if necessary.

*args (optional)

Any other arguments that you want to have passed to the callback

**kwargs (optional)

Any other keywoard arguments that you want to have passed to the callback

Returns:

QtNetwork.QNetworkReply

The reply object for the current request. Note that if a 301 or 302 redirect has occurred, a new reply object has been made for the redirect and the one returned here is no longer valid.

get_file_info(file_id, callback, *args, **kwargs)[source]

Gets information about the specified file.

Parameters:

file_id : string

The OSF file identifier (e.g. the node id).

callback : function

The callback function to which the data should be delivered once the request is finished.

Returns:

QtNetwork.QNetworkReply or None if something went wrong.

get_logged_in_user(callback, *args, **kwargs)[source]

Get logged in user information. Contacts the OSF to request data of the currently logged in user

Parameters:

callback : function

The callback function to which the data should be delivered once the request is finished

Returns:

QtNetwork.QNetworkReply or None if something went wrong

get_project_repos(project_id, callback, *args, **kwargs)[source]

Get repos for the specified project. Retrieves a list of repositories from the OSF that belong to the passed project id.

Parameters:

project_id : string

The project id that OSF uses for this project (e.g. the node id)

callback : function

The callback function to which the data should be delivered once the request is finished

Returns:

QtNetwork.QNetworkReply or None if something went wrong

get_repo_files(project_id, repo_name, callback, *args, **kwargs)[source]

Retrieves files contained in a repository. Retrieves a list of files from the OSF that belong to the indicated repository of the passed project id.

Parameters:

project_id : string

The project id that OSF uses for this project (e.g. the node id)

repo_name : string

The repository to get the files from. Should be something along the lines of osfstorage, github, dropbox, etc. Check OSF documentation for a full list of specifications.

callback : function

The callback function to which the data should be delivered once the request is finished

Returns:

QtNetwork.QNetworkReply or None if something went wrong

get_user_projects(callback, *args, **kwargs)[source]

Gets current user’s projects. Retrieves a list of projects owned by the currently logged in user from OSF

Parameters:

callback : function

The callback function to which the data should be delivered once the request is finished

Returns:

QtNetwork.QNetworkReply or None if something went wrong

handle_login()[source]

Handles the login event received after login.

handle_logout()[source]

Handles the logout event received after a logout.

info_message

PyQt signal to send an info message.

login()[source]

Logs in a user. Checks if a token file is stored which can be used to login a user. If not or the token file is invalid, it opens a browser window through which a user can log in. After a successful login, the browser widget fires the ‘logged_in’ event.

logout()[source]

Logs the current user out from OSF.

post(inst, *args, **kwargs)[source]

Perform a HTTP POST request.

The OAuth2 token is automatically added to the header if the request is going to an OSF server. This request is mainly used to send small amounts of data to the OSF framework (use PUT for larger files, as this is also required by the WaterButler service used by the OSF)

Parameters:

url : string / QtCore.QUrl

The target url/endpoint to perform the POST request on.

callback : function

The function to call once the request is finished.

data_to_send : dict

The data to send with the POST request. keys will be used as variable names and values will be used as the variable values.

*args (optional)

Any other arguments that you want to have passed to callable.

**kwargs (optional)

Any other keywoard arguments that you want to have passed to the callback

put(inst, *args, **kwargs)[source]

Perform a HTTP PUT request.

The OAuth2 token is automatically added to the header if the request is going to an OSF server. This method should be used to upload larger sets of data such as files.

Parameters:

url : string / QtCore.QUrl

The target url/endpoint to perform the PUT request on.

callback : function

The function to call once the request is finished.

data_to_send : QIODevice (default

The file to upload (QFile or other QIODevice type)

uploadProgess : callable (defualt: None)

The slot (callback function) for the downloadProgress signal of the reply object. This signal is emitted after a certain amount of bytes is received, and can be used for instance to update a download progress dialog box. The callback function should have two parameters to which the transfered and total bytes can be assigned.

errorCallback : callable (default: None)

function to call whenever an error occurs. Should be able to accept the reply object as an argument. This function is also called if the operation is aborted by the user him/herself.

progressDialog : QtWidgets.QProgressDialog (default: None)

The dialog to send the progress indication to. Will be included in the reply object so that it is accessible in the downloadProgress slot, by calling self.sender().property(‘progressDialog’)

abortSignal : QtCore.pyqtSignal

This signal will be attached to the reply objects abort() slot, so that the operation can be aborted from outside if necessary.

*args (optional)

Any other arguments that you want to have passed to the callback

**kwargs (optional)

Any other keywoard arguments that you want to have passed to the callback

set_logged_in_user(user_data)[source]

Callback function, not to be called directly.

Locally saves the data of the currently logged_in user

show_login_window()[source]

Shows the login page on OSF.

success_message

PyQt signal to send a success message.

upload_file(url, source_file, *args, **kwargs)[source]

Uploads a file. The file will be stored at the specified destination on the OSF.

Parameters:

url : string / QtCore.QUrl

The target url that points to endpoint handling the upload

source_file : string / QtCore.QtFile

The path to the file which should be uploaded.

finishedCallback : function (default: None)

The function to call once the upload is finished.

uploadProgress : function (default: None)

The slot (callback function) for the uploadProgress signal of the reply object. This signal is emitted after a certain amount of bytes is received, and can be used for instance to update a upload progress dialog box. The callback function should have two parameters to which the transfered and total bytes can be assigned.

errorCallback : function (default: None)

function to call whenever an error occurs. Should be able to accept the reply object as an argument.

progressDialog : dict (default

A dictionary containing data about the file to be transferred. It should have two entries: filename: The name of the file filesize: the size of the file in bytes

*args (optional)

Any other arguments that you want to have passed to the callback

**kwargs (optional)

Any other keywoard arguments that you want to have passed to the callback

warning_message

PyQt signal to send a warning message.

Events

class QOpenScienceFramework.events.EventDispatcher(*args, **kwargs)[source]

This class fires events to connected classes, which are henceforth referenced to as ‘listeners’. Basically EventDispatcher’s purpose is to propagate login and logout events to the QWidget subclasses that require authorization at the OSF to function correctly, but of course this can be extended with other events that are relevant for all listeners.

The only requirement for listener classes is that they implement a handling function for each event that should be named “handle_<event_name>”. For example, to catch a login event, a listener should have the function handle_login.

Methods

add_listener(item) Add a new object to listen for the events.
add_listeners(obj_list) Add one or more object(s) to the list of listeners.
dispatch_login() Convenience function to dispatch the login event.
dispatch_logout() Convenience function to dispatch the logout event.
logged_in PyQt Signal emitted when a user just logged in.
logged_out PyQt Signal emitted when a user just logged out.
remove_listener(item) Remove a listener.
add_listener(item)[source]

Add a new object to listen for the events.

Parameters:

obj : object

the listener to add. Should implement handling functions which are called when certain events occur. The list of functions that the listener should implement is currently:

  • handle_login
  • handle_logout
add_listeners(obj_list)[source]

Add one or more object(s) to the list of listeners.

Parameters:

obj : object

the list of listeners to add. Listeners should implement handling functions which are called when certain events occur. The list of functions that listeners should implement is currently:

  • handle_login
  • handle_logout
dispatch_login()[source]

Convenience function to dispatch the login event.

dispatch_logout()[source]

Convenience function to dispatch the logout event.

logged_in

PyQt Signal emitted when a user just logged in.

logged_out

PyQt Signal emitted when a user just logged out.

remove_listener(item)[source]

Remove a listener.

obj
: object
The object that is to be disconnected
Returns:A reference to the current instance of this object (self).
class QOpenScienceFramework.events.Notifier[source]

This object receives error or info messages and displays them in a QMessageBox notification box. It works with Qts signal slot architecture, as in all functions are slots to which Qt signals should be connected.

Methods

error(title, message) Show an error message in a ‘critical’ QMessageBox.
info(title, message) Show an info message in an ‘information’ QMessageBox.
success(title, message) Show a success message in a ‘success’ QMessageBox.
warning(title, message) Show a warning message in a ‘warning’ QMessageBox.
error(title, message)[source]

Show an error message in a ‘critical’ QMessageBox.

Parameters:

title : str

The title of the box

message : str

The message to display

info(title, message)[source]

Show an info message in an ‘information’ QMessageBox.

Parameters:

title : str

The title of the box

message : str

The message to display

success(title, message)[source]

Show a success message in a ‘success’ QMessageBox.

Parameters:

title : str

The title of the box

message : str

The message to display

warning(title, message)[source]

Show a warning message in a ‘warning’ QMessageBox.

Parameters:

title : str

The title of the box

message : str

The message to display

class QOpenScienceFramework.events.TokenFileListener(tokenfile)[source]

This listener stores the OAuth2 token after login and destroys it after logout.

Methods

handle_login() Handles the login event.
handle_logout() Handles the logout event.
handle_login()[source]

Handles the login event.

Stores the OAuth2 token in a file.

handle_logout()[source]

Handles the logout event.

Deletes the file containing the OAuth2 token.

Widgets

LoginWindow

class QOpenScienceFramework.widgets.loginwindow.LoginWindow(*args, **kwargs)[source]

Bases: PyQt5.QtWebEngineWidgets.QWebEngineView

A Login window for the OSF

Methods

checkResponse(reply) Callback function.
check_URL(url) Callback function.
logged_in Event fired when user successfully logged in.
checkResponse(reply)[source]

Callback function. Do not use directly.

Callback for NetworkRequestManager.finished event used to check if OAuth2 is redirecting to a link containing the token string. This is necessary for the QtWebKit module, because it drops fragments after being redirect to a different URL. QWebEngine uses the check_URL function to check for the token fragment

Parameters:

reply : QtNetwork.QNetworkReply

The response object provided by NetworkRequestManager

check_URL(url)[source]

Callback function. Do not use directly.

Calback for urlChanged event.

Parameters:

command : url

New url, provided by the urlChanged event

logged_in

Event fired when user successfully logged in.

OSFExplorer

class QOpenScienceFramework.widgets.osfexplorer.OSFExplorer(manager, tree_widget=None, locale=u'en_us')[source]

Bases: PyQt5.QtWidgets.QWidget

An explorer of the current user’s OSF account

Attributes

config The current configuration of the project explorer.

Methods

abort_preview PyQt signal emitted when an image preview is to be aborted.
add_buttonset(title, buttons) Adds a set of buttons that can be referenced by ‘title’.
closeEvent(event) Reimplementation of closeEvent.
create_context_menu(item) Creates a context menu for the currently selected TreeWidgetItem.
handle_login() Callback function for a login event is detected.
handle_logout() Callback function for when a logout event is detected.
set_config(config) Function that sets the current config.
set_file_properties(data) Fills the contents of the properties panel for files.
set_folder_properties(data) Fills the contents of the properties pane for folders.
show_buttonset(title) Sets the buttonset to show and hides all others.
__init__(manager, tree_widget=None, locale=u'en_us')[source]

Constructor

Can be passed a reference to an already existing ProjectTree if desired, otherwise it creates a new instance of this object.

Parameters:

manager : manger.ConnectionManager

The object taking care of all the communication with the OSF

tree_widget : ProjectTree (default: None)

The kind of object, which can be project, folder or file

locale : string (default: en-us)

The language in which the time information should be presented. Should consist of lowercase characters only (e.g. nl_nl)

abort_preview

PyQt signal emitted when an image preview is to be aborted.

add_buttonset(title, buttons)[source]

Adds a set of buttons that can be referenced by ‘title’. With set_buttonset(title) the buttons can be switched to this set.

Parameters:

title : str

The label of the buttonset

buttons : list

A list of objects that inherit from QWidgets.QAbstractButton and which should be included in the buttonset designated by title

Raises:

TypeError

If an item in the buttons list is not an instance of QAbstractButton.

closeEvent(event)[source]

Reimplementation of closeEvent. Makes sure the login window also closes if the explorer closes.

config

The current configuration of the project explorer. Contains information about the current filter that is set for the project tree and the buttonset that is shown.

create_context_menu(item)[source]

Creates a context menu for the currently selected TreeWidgetItem. Menu contents differ depending on if the selected item is a file or a folder, and if the folder is the root of a repo or a subfolder thereof.

handle_login()[source]

Callback function for a login event is detected.

handle_logout()[source]

Callback function for when a logout event is detected.

set_config(config)[source]

Function that sets the current config.

The OSF explorer can be configured to show specific button sets at the bottom (e.g. show other buttons than the default download, upload, etc.) and to hide items in the tree by setting a filter. To only show items with a .txt extension, one can set the filter by passing the dict:

config = {'filter':'.txt'}

Multiple filetypes can be filtered by passing a list of extensions:

config = {'filter':['.txt','.py']}

To clear a previously set filter, set its value to None

config = {'filter': None}       

If you have created extra button sets by using the add_buttonset function, you can specify which buttonset should be shown by adding a ‘buttonset’ entry to the config dict, which contains the name of the buttonset to show

config = {'buttonset': 'my_buttonset'}

to switch back to the default buttonset, pass ‘default’ as the value

config = {'buttonset': 'default'}

Note

Calling this function is equal to setting the config variable directly by using OSFExplorer.config = <config dict>

Parameters:

config : dict

The dictionary containing new configuration parameters. It can contain directives to set a filter (with the filter key) and/or which buttonset to show (with the buttonset key)

set_file_properties(data)[source]

Fills the contents of the properties panel for files. Makes sure the extra fields concerning files are shown.

Parameters:

attributes : dict

A dictionary containing the information retrieved from the OSF, stored at the data/attributes path of the json response.

set_folder_properties(data)[source]

Fills the contents of the properties pane for folders. Make sure the fields only concerning files are hidden.

Parameters:

attributes : dict

A dictionary containing the information retrieved from the OSF, stored at the data/attributes path of the json response

show_buttonset(title)[source]

Sets the buttonset to show and hides all others.

Parameters:

title : str

The label of the buttonset that should be shown. To show the default buttonset, pass ‘default’.

Raises:

KeyError

If there is no buttonset known by that label.

ProjectTree

class QOpenScienceFramework.widgets.projecttree.ProjectTree(manager, use_theme=None, theme_path=u'./resources/iconthemes')[source]

Bases: PyQt5.QtWidgets.QTreeWidget

A tree representation of projects and files on the OSF for the current user in a treeview widget.

Attributes

filter The currently set filter parameters.

Methods

add_item(parent, data) Adds a new item to the tree.
clear_filter() Clears the filter.
find_item(item, index, value) Finds an item in the tree.
get_icon(datatype, name) Returns a QIcon for the passed datatype.
handle_login() Callback function for EventDispatcher when a login event is detected.
handle_logout() Callback function for EventDispatcher when a logout event is detected.
populate_tree(reply[, parent]) Populates the tree with content.
process_repo_contents(logged_in_user) Processes contents for the logged in user.
refreshFinished PyQt signal that emits when the tree is completely refreshed.
refresh_children_of_node(node) Refreshes the children of the specified node.
refresh_contents() Refreshes all contents in the tree.
set_filter(filetypes) Sets an extension based filter for items in the tree.
__init__(manager, use_theme=None, theme_path=u'./resources/iconthemes')[source]

Constructor. Creates a tree showing the contents of the user’s OSF repositories. Can be passed a theme to use for the icons, but if this doesn’t happen it will use the default qtawesome (FontAwesome) icons for the buttons.

Parameters:

manager : manger.ConnectionManager

The object taking care of all the communication with the OSF.

use_theme : string (default: None)

The name of the icon theme to use.

theme_path : The path to the folder at which the icon theme is located

Relevant only on Windows and OSX as the location of icon themes on Linux is standardized.

add_item(parent, data)[source]

Adds a new item to the tree. The data that is passed should be the dictionary containing the information that is found under the ‘data’ key in an OSF API responses.

Parameters:

parent : QtWidgets.QTreeWidgetItem

The parent node to place the new item under.

data : dict

The ‘data’ segment from the osf data.

Returns:

item : QtWidgets.QTreeWidgetItem

The newly created tree widget item

kind : str

The type of the new item (folder, file, project, etc.)

clear_filter()[source]

Clears the filter.

filter

The currently set filter parameters.

find_item(item, index, value)[source]

Finds an item in the tree. Checks if there is already a tree item with the same name as value. This function does not recurse over the tree items, it only checks the direct descendants of the given item.

Parameters:

item : QtWidgets.QTreeWidgetItem

The tree widget item of which to search the direct descendents.

index : int

The column index of the tree widget item.

value : str

The value to search for

Returns:

int

The index position at which the item is found or None .

get_icon(datatype, name)[source]

Returns a QIcon for the passed datatype. Retrieves the curren theme icon for a certain object (project, folder) or filetype. Uses the file extension to determine the file type.

Parameters:

datatype : string

The kind of object, which can be project, folder or file

name : string

The name of the object, which is the project’s, folder’s or file’s name

Returns:

QtGui.QIcon

The icon for the current file/object type

handle_login()[source]

Callback function for EventDispatcher when a login event is detected.

handle_logout()[source]

Callback function for EventDispatcher when a logout event is detected.

populate_tree(reply, parent=None)[source]

Populates the tree with content. The entry point should be a project, repository or folder inside a repository. The JSON representation that the api endpoint returns for such a node is used to build the tree contents. This function is called recursively, for each new subfolder that is encountered from the entry point on.

Parameters:

reply : QtNetwork.QNetworkReply

The data of the entrypoint from the OSF to create the node in the tree for.

parent : QtWidgets.QTreeWidgetItem (default: None)

The parent item to which the generated tree should be attached. Is mainly used for the recursiveness that this function implements. If not specified the invisibleRootItem() is used as a parent.

Returns:

list

The list of tree items that have just been generated

process_repo_contents(logged_in_user)[source]

Processes contents for the logged in user. Starts by listing the projects and then recurses through all their repositories, folders and files.

refreshFinished

PyQt signal that emits when the tree is completely refreshed.

refresh_children_of_node(node)[source]

Refreshes the children of the specified node. In contrast to refresh_contents, which refreshes the whole tree from the root, this function only refreshes the children of the passed node.

Parameters:

node : QtWidgets.QTreeWidgetItem

The tree item of which the children need to be refreshed.

refresh_contents()[source]

Refreshes all contents in the tree. This operation might take a long time depending on the number of projects that the user has, so it is recommended to use a partial refresh (refresh_children_of_node), wherever you can.

set_filter(filetypes)[source]

Sets an extension based filter for items in the tree.

Note

Can be used instead of using ProjectTree.filter = <value> directly.

Parameters:

filetypes : str or list

A filetype or list of filetypes that should be shown while other file types are hidden. For example, passing ‘.txt’ to this function will only show files which have the .txt extension

UserBadge

class QOpenScienceFramework.widgets.userbadge.UserBadge(manager, icon_size=None)[source]

Bases: PyQt5.QtWidgets.QWidget

A Widget showing the logged in user

Methods

current_user() Checks the current status of the user.
handle_login() Callback function for EventDispatcher when a login event is detected.
handle_logout(*args) Callback function for EventDispatcher when a logout event is detected.
login_request PyQt signal to send a login request.
logout_request PyQt signal to send a logout request.
__init__(manager, icon_size=None)[source]

Constructor

Parameters:

manager : manager.ConnectionManager

The object taking care of all the communication with the OSF

iconsize : QtCore.QSize (default: None)

The size of the icon to use for the osf logo and user photo, if not passed a size of 40x40 is used.

current_user()[source]

Checks the current status of the user.

Returns:

dict : contains the information of the logged in user, or is empty if no

user is currently logged in.

handle_login()[source]

Callback function for EventDispatcher when a login event is detected.

handle_logout(*args)[source]

Callback function for EventDispatcher when a logout event is detected.

login_request

PyQt signal to send a login request.

logout_request

PyQt signal to send a logout request.