Skip to content

Instantly share code, notes, and snippets.

@ryanlerch
Created October 24, 2014 16:21
Show Gist options
  • Save ryanlerch/0f275bfacd91d666cb19 to your computer and use it in GitHub Desktop.
Save ryanlerch/0f275bfacd91d666cb19 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""
DBus Scripting API: Python Demo 1 (testShapes)
"""
import dbus
def testShapes (doc):
doc.rectangle (0, 0, 100, 100)
doc.ellipse (100, 100, 100, 100)
doc.star (250, 250, 50, 25, 5, False, .9, 1.4)
doc.polygon (350, 350, 50, 0, 5)
doc.line (400,400,500,500)
doc.spiral (550,550,50,3)
# Connect to bus
bus = dbus.SessionBus()
# Get interface for default document
inkscapeobject = bus.get_object('org.inkscape', '/org/inkscape/application')
inkscapeinterface = dbus.Interface(inkscapeobject, dbus_interface="org.inkscape.application")
currentdocument = inkscapeinterface.get_active_document()
inkdoc1 = bus.get_object('org.inkscape', currentdocument)
# Interfaces provide a namespacing mechanism for methods.
doc1 = dbus.Interface(inkdoc1, dbus_interface="org.inkscape.document")
# Call desired test functions
testShapes(doc1)
# eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment