=== added file 'TextFlow/core/DbusInterface.py' --- TextFlow/core/DbusInterface.py 1970-01-01 00:00:00 +0000 +++ TextFlow/core/DbusInterface.py 2008-06-20 18:53:40 +0000 @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- + +####################################################################### +# Copyright © 2007-2008 Waldecir Santos. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published +# the Free Software Foundation; version 2 only. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +####################################################################### + +import dbus +import dbus.service +import dbus.glib +import gtk +dbus.glib.threads_init() + + +class DaemonDBus(dbus.service.Object): + def __init__(self, bus_name, TextFlow_instance): + self.TextFlow = TextFlow_instance + object_path = '/DBusInterface' + super(DaemonDBus, self).__init__(bus_name, object_path) + + @dbus.service.method('org.gnome.TextFlow.DBusInterface') + def open_file_tab(self, path): + self.TextFlow.document_manager.open_file_tab(path) + self.TextFlow.main_window.deiconify() + +def TextFlow_dbus_init(TextFlow_instance): + try: + session_bus = dbus.SessionBus() + name = dbus.service.BusName('org.gnome.TextFlow.DBus', bus=session_bus) + return DaemonDBus(name, TextFlow_instance) + except dbus.DBusException: + import sys + sys.stderr.write(_('Could not connect to dbus session bus.' + ' dbus will be unavailable.\n')) + return None === modified file 'TextFlow/core/constants.py' --- TextFlow/core/constants.py 2008-06-17 22:17:35 +0000 +++ TextFlow/core/constants.py 2008-06-20 19:25:14 +0000 @@ -100,6 +100,7 @@ MESSAGE_0026 = _("Tab Size:") MESSAGE_0027 = _("Filter:") MESSAGE_0028 = _("Goto line:") +MESSAGE_0029 = _('Could not connect to dbus session bus. dbus will be unavailable.') # Application info APPNAME = _("TextFlow") === modified file 'textflow' --- textflow 2008-06-14 21:00:59 +0000 +++ textflow 2008-06-20 18:53:40 +0000 @@ -6,8 +6,10 @@ import os import gnomevfs import shutil +import dbus from TextFlow.ui.MainWindow import MainWindow from TextFlow.core import constants +from TextFlow.core.DbusInterface import TextFlow_dbus_init def get_paths(uris): paths = [] @@ -38,19 +40,34 @@ #gtk.glade.textdomain(APP) #End of internationalization stuff -# Verify snippets file -if not os.path.exists(constants.LANGUAGES_USER_DIR): - shutil.copytree(constants.LANGUAGES_DIR, constants.HOME + '/.textflow/languages') - -args = sys.argv - -if len(args) > 1: - paths = get_paths(args[1:]) - print paths - main_window = MainWindow(paths) + +if __name__ == '__main__': + # Verify snippets file + if not os.path.exists(constants.LANGUAGES_USER_DIR): + shutil.copytree(constants.LANGUAGES_DIR, constants.HOME + '/.textflow/languages') + + args = sys.argv + + if len(args) > 1: -else: - main_window = MainWindow() - -gtk.main() + bus = dbus.SessionBus() + + try: + remote_TextFlow = bus.get_object('org.gnome.TextFlow.DBus', '/DBusInterface') + print remote_TextFlow + paths = get_paths(args[1:]) + for path in paths: + remote_TextFlow.open_file_tab(path) + sys.exit(0) + except dbus.DBusException: + paths = get_paths(args[1:]) + main_window = MainWindow(paths) + TextFlow_dbus_init(main_window) + + + else: + main_window = MainWindow() + TextFlow_dbus_init(main_window) + + gtk.main()