SPPAS 4.22

https://sppas.org/

Module sppas.src.wkps

Class sppasWkpsManager

Description

Manager of the data of the currently enabled workspace.

Among the list of available workspaces in the software, this class allows to manage this list and to enable any of them.

Constructor

View Source
def __init__(self, wkp_index=0):
    self.__wkps = sppasWkps()
    if len(self.__wkps) == 0:
        self.__wkps.new('Blank')
    self.data = None
    self.__current = self.load_data(wkp_index)

Public functions

load_data

Set the data saved of the current workspace.

If the file of the workspace does not exist, return an empty instance of sppasWorkspace.

Parameters
  • index: (int) Index of the workspace to get data
Returns
  • (int) Index of the loaded workspace
Raises

IndexError

View Source
def load_data(self, index=None):
    """Set the data saved of the current workspace.

        If the file of the workspace does not exist, return an empty
        instance of sppasWorkspace.

        :param index: (int) Index of the workspace to get data
        :returns: (int) Index of the loaded workspace
        :raises: IndexError

        """
    if index is None:
        index = self.__current
    self.data = self.__wkps.load_data(index)
    return index

get_size

Return the number of workspaces.

Returns
  • (int)
View Source
def get_size(self):
    """Return the number of workspaces.

        :returns: (int)

        """
    return len(self.__wkps)

get_wkp_name

Return the name of the current workspace.

Parameters
  • index: (int) Index of the workspace to get name
Returns
  • (str)
View Source
def get_wkp_name(self, index=None):
    """Return the name of the current workspace.

        :param index: (int) Index of the workspace to get name
        :returns: (str)

        """
    if index is None:
        index = self.__current
    return self.__wkps[index]

get_wkp_index

Return the index of the given workspace name.

Parameters
  • name: (str) Workspace name
Returns
  • (int)
Raises

(ValueError)

View Source
def get_wkp_index(self, name):
    """Return the index of the given workspace name.

        :param name: (str) Workspace name
        :returns: (int)
        :raises: (ValueError)

        """
    return self.__wkps.index(name)

get_wkp_current_index

Return the index of the current workspace.

Returns
  • (int)
View Source
def get_wkp_current_index(self):
    """Return the index of the current workspace.

        :returns: (int)

        """
    return self.__current

switch_to

Set the current workspace at the given index.

Parameters
  • index: (int) Index of the workspace to switch on
View Source
def switch_to(self, index):
    """Set the current workspace at the given index.

        :param index: (int) Index of the workspace to switch on

        """
    wkp_name = self.__wkps[index]
    self.__current = index
    self.load_data()

pin

Append a new empty workspace and set it the current one.

Parameters
  • new_name: (str) Name of the new workspace.
View Source
def pin(self, new_name):
    """Append a new empty workspace and set it the current one.

        :param new_name: (str) Name of the new workspace.

        """
    new_name = self.__wkps.new(new_name)
    index = self.__wkps.index(new_name)
    self.switch_to(index)

import_from

Append a new imported workspace.

A ".wjson" extension is expected.

Parameters
  • filename: (str) Name of the file to import.
View Source
def import_from(self, filename):
    """Append a new imported workspace.

        A ".wjson" extension is expected.

        :param filename: (str) Name of the file to import.

        """
    try:
        with open(filename, 'r'):
            pass
    except IOError:
        raise
    wkp_name = self.__wkps.import_from_file(filename)

export_to

Save the current workspace into an external file.

A ".wjson" extension is expected but not verified.

Parameters
  • filename: (str) Name of the exported file.
View Source
def export_to(self, filename):
    """Save the current workspace into an external file.

        A ".wjson" extension is expected but not verified.

        :param filename: (str) Name of the exported file.

        """
    self.__wkps.export_to_file(self.__current, filename)

rename

Set a new name to the current workspace.

Parameters
  • new_name: (str) New name to assign to the workspace.
View Source
def rename(self, new_name):
    """Set a new name to the current workspace.

        :param new_name: (str) New name to assign to the workspace.

        """
    u_name = self.__wkps.rename(self.__current, new_name)

save

Save the given data to the active workspace or to the given one.

Parameters
  • data: (sppasWorkspace)
  • index: (int) Save data to the workspace with this index
Raises

IndexError, IOError

View Source
def save(self, data, index=None):
    """Save the given data to the active workspace or to the given one.

        :param data: (sppasWorkspace)
        :param index: (int) Save data to the workspace with this index
        :raises: IndexError, IOError

        """
    if index is None:
        index = self.__current
    self.__wkps.save_data(data, index)

remove

Remove a workspace of the list and delete the corresponding file.

Parameters
  • index: (int)
View Source
def remove(self, index):
    """Remove a workspace of the list and delete the corresponding file.

        :param index: (int)

        """
    if index == self.__current:
        raise IndexError("The currently displayed workspace can't be removed")
    if index == 0:
        raise IndexError("The 'Blank' workspace can't be removed")
    self.__wkps.delete(index)