Difference between revisions of "D-Bus examples"
Jump to navigation
Jump to search
(→Python) |
|||
Line 14: | Line 14: | ||
pair_name = 'en-af'; |
pair_name = 'en-af'; |
||
dbus_pair_name = |
dbus_pair_name = '/' + '_'.join(pair_name.split('-')); |
||
bus = dbus.SessionBus(); |
bus = dbus.SessionBus(); |
||
translator = dbus.Interface(bus.get_object( |
translator = dbus.Interface(bus.get_object('org.apertium.mode', dbus_pair_name), 'org.apertium.Mode') |
||
input = sys.stdin.read(); |
input = sys.stdin.read(); |
||
print translator.translate({}, input) |
print translator.translate({}, input); |
||
</pre> |
</pre> |
Revision as of 17:59, 18 December 2007
Here are some code snippets for various programming languages showing how you can interface with Apertium by means of D-Bus.
Python
#!/usr/bin/python # coding=utf-8 # -*- encoding: utf-8 -*- import dbus, sys, codecs; sys.stdin = codecs.getwriter('utf-8')(sys.stdin); sys.stdout = codecs.getwriter('utf-8')(sys.stdout); pair_name = 'en-af'; dbus_pair_name = '/' + '_'.join(pair_name.split('-')); bus = dbus.SessionBus(); translator = dbus.Interface(bus.get_object('org.apertium.mode', dbus_pair_name), 'org.apertium.Mode') input = sys.stdin.read(); print translator.translate({}, input);