ognon package¶
Ognon is a local-only web application for the creation of 2D animation. Run python -m ognon to start the server. Then browse http://localhost:40460
ognon.model¶
This module define the Ognon model
It describes every data that can be write on the disk. they are nested python classes. With no method description.
-
class
ognon.model.
Anim
(layers=None)[source]¶ Bases:
object
This class describe Anims.
An anim contain Layers in a ‘layers’ list.
-
class
ognon.model.
AnimRef
(name, tags=None)[source]¶ Bases:
ognon.model.Element
This class describe AnimRefs.
An animref is a reference to another animation in the same project. It allow to include animations in other animations. It has a name attribute, the name of the animation it referes to.
-
class
ognon.model.
BrokenElement
(name, tags=None)[source]¶ Bases:
ognon.model.Element
This class describe a BrokenElement.
It should not be inside an animation but it’s returned by some functions if the asked element is broken (e.g. unexisting animref)
-
class
ognon.model.
Cell
(lines=None, tags=None)[source]¶ Bases:
ognon.model.Element
This class describe Cells.
A cell is the ellement made for draw on it. It has a list of lines.
-
class
ognon.model.
Element
(tags=None)[source]¶ Bases:
object
This class is the super class for all elements.
An element is an object that can be placed into a layer’s elements list
-
class
ognon.model.
Layer
(elements=None)[source]¶ Bases:
object
This class describe Layers.
A layer contain Elements in an ‘elements’ list.
-
class
ognon.model.
Line
(coords)[source]¶ Bases:
object
This class describe Lines.
A line has a list of coords that should look like :
[x1, y1, x2, y2, x3, y3, ...]
-
class
ognon.model.
Project
(name, anims=None, config=None)[source]¶ Bases:
object
This class describe Projects.
A project contain Anims in an ‘anims’ dict where keys are anims names. A Project also has a name, config dict and two states id that should be incremented each time the project changes. ‘state_id’ should be incremented when the project organisation changes. ‘draw_state_id’ should be incremented when the content of the elements changes.
ognon.cursor¶
This module defines the Cursor class. The cursor is the most importants object of the ognon’s structure. It is a required argument for every control and view functions.
-
class
ognon.cursor.
Cursor
(proj=None)[source]¶ Bases:
object
A Cursor is a point of view on an ognon project, a tape head.
It store informations about his position and his state and a reference to the project. It provides a bunch of getters and setters to move the cursor, know where it is and access to the ellements under it.
Attributes:
proj : a model.Project instance.
- _posa dict that store the cursor position.
_pos[‘anim’] : The name of an animation in the project anims dict.
_pos[‘layer’] : The index of a layer in the animation layers list.
_pos[‘frm’] : A specific instant of the animation.
playing : The cursor state (playing or not playing)
-
constrain_frm
(frm)[source]¶ Return a frm position constrained in the current anim length.
Result will be different depending on whether the loop mode is on or off.
-
get_element
(anim=None, layer=None, frm=None)[source]¶ Return the current element or the element on the specified frm in the specified layer in the specified anim
-
get_element_pos
(anim=None, layer=None, frm=None)[source]¶ Return a tuple with the index of the element in the layer, the element object and the position of the cursor inside the element Return None if no element.
-
get_layer
(anim=None, layer=None)[source]¶ Return the current layer or the specified layer in the specified anim Return None if no layer
-
get_pos
(key=None)[source]¶ Get the cursor position.
If a key is passed, return the specified position (‘anim’, ‘layer’ or ‘frm’). This method first call set_pos without arguments to ensure that the position is valid (e.g. not pointing an inexisting layer)
-
is_animref
(element)¶
-
is_self_ref
(elmt)¶
-
is_unexisting_ref
(elmt)¶
-
property
proj
¶
-
set_pos
(anim=None, layer=None, frm=None)[source]¶ Set the cursor position. (anim, layer and frm)
Positions are constrained to valid values : frm is constained using the constrain_frm method, anim is set to ‘masster’ if current value refer to an unexisting animation and layer is set to 0 if the current value is an out of range index.
If the anim argument is passed but layer or frm are not, set them to 0.
If no arguments are passed, just constain the three values.
If no project, raise a UndefinedProjectError
ognon.projects¶
This module is the project loader. His role is to load projects from files and also to keep in memory all loaded projects by names to provide preloaded projects.
-
ognon.projects.
get
(name)[source]¶ return a project from the project dict. If the project does not exist, load it from the projects directory, if it does not exists there neither, create it.
-
ognon.projects.
get_saved_projects_list
()[source]¶ Return a list of all saved projects name.
Return a list of dirs in the projects directory. ignore dirs starting with a dot or an underscore.
-
ognon.projects.
load
(name)[source]¶ Load the project in the default projects directory, store it in the projects dict and return it.
-
ognon.projects.
load_from_path
(path)[source]¶ Load the ognon project at the specified path. store it in the projects dict and return it.
ognon.server¶
This module defines dictionaries, functions and classes to run the ognon servers.
-
class
ognon.server.
OgnonHTTPHandler
(*args, directory=None, **kwargs)[source]¶ Bases:
http.server.SimpleHTTPRequestHandler
This class is used to handle the HTTP requests that arrive at the server.
We wait two kinds of requests :
GET requests to provide client pages.
POST requests to call functions from ognon.
-
do_POST
()[source]¶ Handler for POST request.
The path tell which function to call. Args are given in the post body. Convert the function to json and send it as a response. If calling the function raise an exception, send an error message
-
log_message
(format, *args)[source]¶ Log an arbitrary message.
This is used by all other logging functions. Override it if you have specific logging wishes.
The first argument, FORMAT, is a format string for the message to be logged. If the format string contains any % escapes requiring parameters, they should be specified as subsequent arguments (it’s just like printf!).
The client ip and current date/time are prefixed to every message.
-
class
ognon.server.
OgnonOSCDispatcher
[source]¶ Bases:
pythonosc.dispatcher.Dispatcher
This is the class of the OSC dispatcher.
-
ognon.server.
call_function
(path, *args, **kwargs)[source]¶ Get a function with get_function, call it with passed args/kwargs and return the result.
-
ognon.server.
get_cursor
(name='default')[source]¶ Return a cursor from the cursors dict.
If the asked cursor does not exists, store a new cursor in the dict and return it.
-
ognon.server.
get_function
(path)[source]¶ Return a function from the functions dict.
If the asked function does not exists in the dict, import it, store it in the dict and return it.
ognon.view¶
This module contain bunch of stateless functions. They all takes a
Cursor
object as first argument and return a JSON serializable value.
-
ognon.view.
get_cursor_infos
(cursor)[source]¶ Return a dict containing informations about the cursor state
keys are : ‘project_name’, ‘playing’, ‘clipboard’, ‘anim’, ‘frm’, ‘layer’
-
ognon.view.
get_element_infos
(cursor, anim=None, layer=None, frm=None, element=None)[source]¶ Return a dict containing informations about the current element keys are : ‘type’, ‘len’, ‘tags’, ‘name’
Alternatives frm index and anim name can be passed. If an element is passed, return element infos and ignore position args.
-
ognon.view.
get_lines
(cursor, anim=None, frm=None, playing=None)[source]¶ Return all current visible lines as a list of dict.
Each dict has ‘coords’ and specials lines dict also has a ‘line_type’ key.
Alternatives frm index, anim name and playing value can be passed.
-
ognon.view.
get_path
(cursor, file='')[source]¶ Return path to the project (or path to a file in the project).
-
ognon.view.
get_project_defined
(cursor)[source]¶ Return True or False if the cursor has a project defined.
-
ognon.view.
get_projects_tree
(cursor)[source]¶ Return a dict withs all projects in the projects dir as keys and a list of the projects’ anims as values
-
ognon.view.
get_timeline
(cursor)[source]¶ Return a dict with informations about organization of the anim.
The ‘len’ field contain the animation length. The ‘layers’ field contain a list of layers as lists of elements. Each element is describe as a dict with elements infos from get_element_infos.
So the output may look like this :
{ 'len':4, 'layers':[ [{...}], [{...}, {...}], [{...}, {...}] ] }
ognon.control¶
This package contain bunch of stateless functions. organized into modules.
They all takes a Cursor
object as first argument and does not return
any value.
-
ognon.control.
change_cursor_state
(fun)[source]¶ This decorator is for control function that change the cursor state. It make the function increment the cursor’s state_id before doing stuff.
-
ognon.control.
change_project_draw_state
(fun)[source]¶ This decorator is for control function that change the project draw state. It make the function increment the project’s draw_state_id before doing stuff.
-
ognon.control.
change_project_state
(fun)[source]¶ This decorator is for control function that change the project state. It make the function increment the project’s state_id before doing stuff.
ognon.control.animsmanager¶
This module provide control functions to manage project’s anims
ognon.control.drawer¶
This module provide control functions to draw on cells
ognon.control.exporter¶
This module provide control functions to export frms and anims
-
exception
ognon.control.exporter.
ExportDestNotFoundError
[source]¶ Bases:
FileNotFoundError
This error is raised when the destination directory for exporting is not found.
-
ognon.control.exporter.
anim_to_avi
(cursor)[source]¶ Save the animation on the disk as an avi video.
Location is given by export>avi_name in the config file.
-
ognon.control.exporter.
anim_to_gif
(cursor)[source]¶ Save the animation on the disk as a animated gif.
Location is given by export>gif_name in the config file.
-
ognon.control.exporter.
anim_to_pngs
(cursor)[source]¶ Save all animation frms on the disk as a png images.
-
ognon.control.exporter.
anim_to_tgas
(cursor)[source]¶ Save all animation frms on the disk as a tgas images.
ognon.control.layersorganizer¶
This module provide control functions to create, delete layers into animation.
ognon.control.elementsorganizer¶
This module provide control functions to create, delete and move elements into layers and layers into animation
ognon.control.projectmanager¶
This module provide control functions to manage projects
ognon.control.tagger¶
This module provide control functions to tags elements
ognon.utils¶
This module define utils function.
-
class
ognon.utils.
SetEncoder
(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]¶ Bases:
json.encoder.JSONEncoder
-
default
(obj)[source]¶ Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
-
ognon.tags¶
This module define tags function.
Tags defined here :
loop n
loopfor n
pendulum n
pendulum2 n
random n
startafter n
endafter n
draft
mask
Return the lines description modified by the tag.
Call the calculate_lines function of the tag.
Return the inside position modified by the tag.
Call the calculate_inside_pos function of the tag.
Return the length modified by the tag.
Call the calculate_len function of the tag.
Return the lines description modified by the tag.
Call the calculate_lines function of the tag.
Return a two elements tuple with tag name and tag args.