The format is auto-detected using the extension and in some case the content of the file. If the format is not detected a casetta.errors.FormatNotFound will be raised. In some case, a file format can only write file, and a casetta.errors.FormatCantOpen will be raised. You can catch it with:

Saving a file will save all the content of file in the disk in a file format. Export will save only some data selected (see the “Select to export” part bellow).
Because file formats are very heterogeneous, some of them cannot save data (read only), and some of them cannot manage any kind of data.

# Save the my_file:
my_file.save("/path/of/the/saved/file.ext")# You can also specify a format, like in open or import:
my_file.save("/path/of/the/saved/file.ext", format)# Error management:try:
my_file.save("/path/of/the/saved/file.ext")except casetta.errors.FormatNotFound:
# Casetta cannot auto-detect the right format:print"The format cannot be detected"except casetta.errors.FormatCantSave, error:
# The format of the file cannot write dataprint"The format %s can only read files"% error.format.nameexcept casetta.errors.DataNoManaged, not_managed:
# This exception is raised when some data are not managed by the file format# not_managed.data_type_list is a list of data classes (see the data part for informations about data classes)# not_managed.data_type_list may also be ['all'] if all data type are not managedif not_managed.data_type_list = ['all']:
print"The format cannot manage any data - abort."else:
print"The format cannot manage this data: %s."%",".join([data.dTypefor data in not_managed.data_type_list])# In this case, if you want, you can save all supported data using:
my_file.save("/path/of/the/saved/file.ext", ignore_warnings=True)

The export is like the save, you just must to set the export flag at True, like:

You can create data in two way: alone or inside a file. In most of cases, data will be create inside a file.

# Make a data alone
my_data = casetta.data.Data()# The casetta.data.Data is a generic class.# If you know the type of your data, it's better to use the corresponding class:
my_prgm = casetta.data.Program()
my_backup = casetta.data.Backup()
my_picture = casetta.data.Picture()# To know more about data classes, see the data-kind specific part bellow.# Make a data inside a file (recommended)# This method use as argument a data class to specify the kind of data
my_new_data = my_file.new_record(casetta.data.Program)# You can also pass initialization parameters for the class (see this parameters in the data-kind specific part):
my_new_data = my_file.new_record(casetta.data.Program, ['name of my program'], {'password': 'tux', 'use_base': True})

If you initialize you data with a name, you should check the name of the data.

The list of data to be exported is used when you set to True the export flag when saving or sending data.
To select some data to be exported, add the index of those data in the FileData.export list (and remove it to deselect the data).

The name of a data is always contain in the Data.name string. But this string is in the casio raw format, so some characters may not be ASCII characters. If you want to get or set a name in an human readable format (newcat syntax), use:

print"Raw name", my_data.nameprint"Human-readable name", my_data.get_name()# Set the name from an human-readable format:
my_data.set_name("New name")

my_prgm = my_file.new_record(casetta.data.Program)
my_prgm.set_name("New name")if my_file.check_name(my_prgm) == 1:
print"OK, good name"elif my_file.check_name(my_prgm) == 0:
print'Bad syntax (ie program name with more than 8 characters, or picture name which not follow "Picture[1-6]").'elif my_file.check_name(my_prgm) == -1:
print"Name already used by another data."

Each data have a date property, which represent the data of the receiving of the data. It's very useful for backups. If the data is unknown (almost all file format cannot save this data), its value is None. In other case, it's a datetime.data object.

# Get the raw program
raw_prgm = my_program.raw_data# Set the raw program
my_program.raw_data = raw_prgm
# Get the program in a human readable format (newcat syntax)
prgm = my_program.get_text()# Set the program from a human readable format
my_program.set_text(prgm)

If you want to extract programs from a backup, you can use a code like this:

prgm_list = my_backup.find_program_list()# prgm_list = [ ["Name1", use_base1, "offset1", "password1"], ["Name2", use_base2, "offset2", "password2"], ...]# use_base1 is a boolean (True if the program use base calculation, False else)# Get the first program
name = prgm_list[0][0]
my_program = my_backup.get_program_by_name(name)# my_program is a Program object

pallet is a list like ['b', 'g', 'o', 'w'] (b for blue, g for green, o for orange, w for white). This list explain the role of each sheet of the picture, and depend of the format of the picture.
color_byte specify the index of the first byte of each sheet. In most case, color_byte = 0.

Each data type is a data class from the casetta.data module.
To know what are the available data in your casetta version, you can use:

for data_type in casetta.data.data_type_list:
# Data.dType is the name of the data typeprint data_type, "is the class of", data_type.dTypeprint"Available types:", casetta.data.data_type_dic.keys()for name in casetta.data.data_type_dic:
print casetta.data.data_type_dic[name], "is the class of", name

Each file format is a class. You can get the list of formats available in casetta using:

# Print the list of formats:print casetta.formats.format_list# Each format has a string identifier, its name:for format in casetta.formats.format_list:
print format.name# There is also a dictionary with names:for format_name in casetta.formats.format_dic:
print casetta.formats.format_dic[format_name], "is the class of", format_name

Some file formats don't manage all data type, so each file format has a list of managed data types. Almost all file format manage the same data types in read and write, but this list is only the list of managed data types for writing.

# Print the list of data classes managed by a_format for writing:print a_format.managed_data

Each transfer tool is a class. You can get the list of available transfer tools in casetta with:

for tool in casetta.devices.tool_list:
# The name property is a string identifierprint tool.name# You can also use a dictionary of tools with names as keys:for tool_name in casetta.devices.tool_dic:
print tool_name, "is the name of", casetta.devices.tool_dic[tool_name]

The serial transfer tool is an internal transfer tool for Casio Graph 35/65. It work with the Fx-Interface link, and maybe with others. This tool is recommended by the casetta project.
This tool need two interface functions, a status function which display the state of the transfer, and an overwrite function which ask the user to overwrite a data if needed. If you omit those functions, the status will be printed on the standard output.

To initialize this tool, use a code like this:

# Get the Serial class:
Serial = casetta.devices.tool_dic['serial']# Build settings for serial:
port = 0# port may be a integer (from 0), or the path of a serial port (example: "/dev/ttyS0" or "COM1")def status_fun(data_name, current_size, total_size, is_header = False):
"""This function is called each time the status change"""# data_name is the name of the current transferred data# current_size is the number of bytes already transferred# total_size is the number total of bytes# is_header indicate if the current data is an header (in this case,# the data_name variable hasn't really sense.passdef overwrite_fun(data_name):
"""This function is called each time a data already exist. It must return True or False"""# Return always True: the data will always be replaced.returnTrue# Initialize the serial tool:
tool = Serial(port, status_fun, overwrite_fun)

Cafix is the old software used for transfer in casetta 0.1 and 0.2. This tool has some bugs, didn't manage all data types, and work only on GNU/Linux systems.

The port of the serial link must be choice by making a symbolic link from your port to /dev/casio. You can use (as root) the cafix-setup program, or a command like ln -s /dev/ttyS0 /dev/casio.

You can initialize Cafix without any parameter, casetta will use default interface using the standard input/output.

# Get the Cafix class:
Cafix = casetta.devices.tool_dic['cafix']# Build settings for cafix:def send_interface(tmp_dir):
"""This function must send all data in tmp_dir using cafix"""# You must run this command:
command = "cd " + tmp_dir + " && cafix -s *"# But you can run this command in several ways: in a terminal,# by getting the output of cafix, etc.# Example (using the standard output):importosos.system(command)def receive_interface(tmp_dir):
"""This function must receive all data in tmp_dir using cafix"""# You must run this command:
command = "cd " + tmp_dir + " && cafix -r"# But as for the send_interface function, you can run it as you want.# Example:importosos.system(command)# Initialize the cafix transfer tool:
tool = Cafix(receive_interface, send_interface)

The other tool is a generic wrapper for an external program. The other tool will save data in a file and run a command to send the content of this file, or open the result of a command an import all data in casetta.

You can omit receive_interface and send_interface, default functions will be used.

# Get the Other class:
Other = casetta.devices.tool_dic['other']# Build settings:
format = a_format # Set the format class which will be used to save/open temporary files
port = '/dev/ttyS0'# The syntax of the port depend of the custom program.
receive_command = "my_prgm --receive %port %file"# Set the command which will be run to receive data
send_command = "my_prgm --send %port %file"# Set the command which will be run to send data# In this command, you can use %port, which will be replaced by the port setting,# and %file, which is the temporary file in the wanted format.def receive_interface(cmd_line):
"""This function must run cmd_line."""# Here you can code how you want cmd_line be run to receive data# Example:importosos.system(cmd_line)def send_interface(cmd_line):
"""This function must run cmd_line."""# Here you can code how you want cmd_line be run to send data# Example:importosos.system(cmd_line)
tool = Other(format, receive_command, send_command, port, receive_interface, send_interface)

# We assume that tool is an initialized transfer tool.# How to receive data from a transfer tool:
received_data = tool.receive()# If you want to add it to an existing FileData:
new_data_list = older_file.add_records(received_data)#After that, you should check the name of each data in new_data_list. # How to send data to a device:# Send all data in my_file:
my_file.send(tool)# Send only selected-to-be-exported data:
my_file.send(tool, export=True)