How to Create External Tools
External tools are an convenient way to create custom applications to add new features like file converters, code generators, node editors, Git support, and other useful features to Titania.
Find it: Click on the External Tools > Manage External Tools menu item in the menu bar.
Manage External Tools Dialog
The name of the current tool can be edited directly using the list on the left side of the dialog. The list item can be rearranged using drag & drop to create a custom menu layout including submenus.
Here is a short description of the editable properties for a given tool:
- Edit: the actual commands to be ran
- Save: saving or not (current document or all documents) before running the tool.
- Input: what content to give to the commands (as stdin).
- Encoding: what type of encoding (XML, VRML, or JSON) should have the input.
- Output: what to do with the commands output (from stdout).
- Applicability: what documents can be affected by that tool? Criteria are: saved or not, local or remote.
If a script is run TITANIA_* environment variables are available.
D-Bus Interface
Titania can be controlled using it's D-Bus interface. The D-Bus interface name is »de.create3000.titania«. Useful methods and signals are available. The D-Bus Interface can be inspected using D-Feet.
Methods
void GetCurrentScene (encoding : String)
Returns the current scene as X3D file in the desired format specified by encoding. Encoding can be of type 'XML', 'VRML', or 'JSON'.
String GetSelection (encoding : String)
Returns the current selection as X3D file in the desired format specified by encoding. Encoding can be of type 'XML', 'VRML', or 'JSON'.
void ReplaceSelection (pluginName : String, x3dSyntax : String, assign : Boolean)
Replaces or assigns the current selection by the first node found in x3dSyntax. To create a useful undo description, the pluginName must be provided and shall reflect the use of the plug-in. x3dSyntax must be a valid X3D scene string in XML, Classic VRML. or JSOM encoding. If assign is false the current selection is replaced by the first node found in x3dSyntax. If assign is true and this will be in most cases the desired option, it will be tried to assign the output to the selection, if this is not possible the selection will be replaced.
Signals
CurrentSceneChanged : void on_current_scene_changed ()
The signal is send when the current scene changes.
SelectionChanged : void on_selection_changed ()
The signal is send when the current selection changes.
Python D-Bus Example
The script below shows a minimal Python D-Bus example that can be run as
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
#!/usr/bin/python import gi gi .require_version ('Gtk', '3.0') from gi .repository import Gtk import dbus from dbus .mainloop .glib import DBusGMainLoop import random import sys """ Plug-in example with D-Bus function call and signal handling. """ class MyWindow (Gtk .Window): def __init__ (self): Gtk .Window .__init__ (self, title = "D-Bus Example") titania .connect_to_signal ("SelectionChanged", self .set_selection, dbus_interface = "de.create3000.titania") self .button = Gtk .Button (label = "Click Here") self .button .connect ("clicked", self .on_button_clicked) self .add (self .button) def set_selection (self): print ("set_selection") print (titania .GetSelection ("XML", dbus_interface = "de.create3000.titania")) sys .stdout .flush () def on_button_clicked (self, widget): print ("Button clicked.") sys .stdout .flush () x3dSyntax = """#X3D V3.3 utf8 Comment DEF Cone Transform { children Shape { appearance Appearance { material Material { diffuseColor %f %f %f } } geometry Cone { } } } """ % (random .random (), random .random (), random .random ()) titania .Open (x3dSyntax, dbus_interface = "de.create3000.titania") #titania .ReplaceSelection ("DBus Example", x3dSyntax, True, dbus_interface = "de.create3000.titania") if __name__ == '__main__': sessionBus = dbus. SessionBus (mainloop = DBusGMainLoop ()) titania = sessionBus .get_object ("de.create3000.titania", "/de/create3000/titania") win = MyWindow () win .connect ("delete-event", Gtk.main_quit) win .show_all () Gtk .main () |
Because Titania is running in a sandbox when using the flatpak, Python modules must be installed using pip, the Python Package Manager. To install Gtk3 and DBus copy and paste the following lines into a terminal:
1 2 |
pip install PyGObject pip install dbus-python |
This will install the required Python modules within your home directory. More Python packages can be found at PyPI.