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.
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.
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)
Set the data saved of the current workspace.
If the file of the workspace does not exist, return an empty instance of sppasWorkspace.
IndexError
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
Return the number of workspaces.
def get_size(self):
"""Return the number of workspaces.
:returns: (int)
"""
return len(self.__wkps)
Return the name of the current workspace.
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]
Return the index of the given workspace name.
(ValueError)
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)
Return the index of the current workspace.
def get_wkp_current_index(self):
"""Return the index of the current workspace.
:returns: (int)
"""
return self.__current
Set the current workspace at the given index.
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()
Append a new empty workspace and set it the current one.
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)
Append a new imported workspace.
A ".wjson" extension is expected.
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)
Save the current workspace into an external file.
A ".wjson" extension is expected but not verified.
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)
Set a new name to the current workspace.
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 the given data to the active workspace or to the given one.
IndexError, IOError
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 a workspace of the list and delete the corresponding file.
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)