33 from dbus.server
import Server
34 from python_qt_binding
import QT_BINDING
35 from python_qt_binding.QtCore
import (QByteArray, QDataStream, qDebug, QIODevice,
36 QProcess, QSignalMapper, Qt, qWarning)
37 from python_qt_binding.QtGui
import QIcon, QToolBar, QX11EmbedContainer
47 Server part of the `PluginHandlerXEmbed`. 49 Starts the plugin in a subprocess and provides the `PluginHandlerDBusService` through a 50 peer-to-peer DBus connection. 55 def __init__(self, parent, main_window, instance_id,
56 application_context, container_manager, argv, dbus_object_path):
57 super(PluginHandlerXEmbedContainer, self).
__init__(
58 parent, main_window, instance_id, application_context, container_manager, argv)
59 self.setObjectName(
'PluginHandlerXEmbedContainer')
77 if not Main.main_filename:
79 'PluginHandlerXEmbedContainer._load() ' 80 'filename of initially started script is unknown')
91 self._process.setProcessChannelMode(QProcess.SeparateChannels)
96 cmd = sys.executable +
' -u' 97 cmd +=
' %s' % Main.main_filename
98 cmd +=
' --qt-binding=%s' % QT_BINDING
99 cmd +=
' --embed-plugin=%s --embed-plugin-serial=%s --embed-plugin-address=%s' % (
101 self._dbus_server.address)
103 cmd +=
' --args %s' %
' '.join(self.
argv())
105 self._process.start(cmd)
106 started = self._process.waitForStarted(3000)
108 self._dbus_container_service.remove_from_connection()
109 self._dbus_plugin_settings_service.remove_from_connection()
110 self._dbus_instance_settings_service.remove_from_connection()
112 'PluginHandlerXEmbedContainer._load() could not start ' 113 'subprocess in reasonable time')
116 self.
_pid = self._process.pid()
122 qDebug(
'PluginHandlerXEmbedContainer._load() started subprocess (#%s) for plugin "%s"' %
129 self._dbus_plugin_settings_service.add_to_connection(
131 self._dbus_instance_settings_service.add_to_connection(
135 self.
_print_process(self._process.readAllStandardOutput(), qDebug)
138 self.
_print_process(self._process.readAllStandardError(), qWarning)
142 lines = str(data).split(
'\n')
146 method(
' %d %s' % (self.
_pid, line))
150 exception =
None if loaded
else True 156 qDebug(
'PluginHandlerXEmbedContainer._shutdown_plugin()')
158 self._dbus_container_service.shutdown_plugin()
161 self._dbus_container_service.remove_from_connection()
162 self._dbus_plugin_settings_service.remove_from_connection()
163 self._dbus_instance_settings_service.remove_from_connection()
165 self._process.close()
166 self._process.waitForFinished(5000)
167 if self._process.state() != QProcess.NotRunning:
174 qDebug(
'PluginHandlerXEmbedContainer._unload()')
178 qDebug(
'PluginHandlerXEmbedContainer._save_settings()')
179 self._dbus_plugin_settings_service.set_settings(plugin_settings)
180 self._dbus_instance_settings_service.set_settings(instance_settings)
181 self._dbus_container_service.save_settings()
184 self._dbus_plugin_settings_service.set_settings(
None)
185 self._dbus_instance_settings_service.set_settings(
None)
189 qDebug(
'PluginHandlerXEmbedContainer._restore_settings()')
190 self._dbus_plugin_settings_service.set_settings(plugin_settings)
191 self._dbus_instance_settings_service.set_settings(instance_settings)
192 self._dbus_container_service.restore_settings()
195 self._dbus_plugin_settings_service.set_settings(
None)
196 self._dbus_instance_settings_service.set_settings(
None)
200 self._dbus_container_service.trigger_configuration()
204 embed_container = QX11EmbedContainer(dock_widget)
209 return embed_container.winId()
214 ba = QByteArray.fromBase64(icon_str)
215 s = QDataStream(ba, QIODevice.ReadOnly)
218 embed_container.setWindowIcon(icon)
222 embed_container.setWindowTitle(title)
231 toolbar.setObjectName(toolbar_object_name)
232 embed_container = QX11EmbedContainer(toolbar)
233 toolbar.addWidget(embed_container)
239 self._signal_mapper_toolbars.setMapping(toolbar, toolbar_object_name)
240 toolbar.orientationChanged.connect(self._signal_mapper_toolbars.map)
241 return embed_container.winId()
246 self._dbus_container_service.toolbar_orientation_changed(
247 embed_container.winId(), toolbar.orientation() == Qt.Horizontal)
254 embed_container.close()
def _trigger_configuration(self)
def remove_widget(self, widget)
def load_completed(self, loaded, has_configuration)
def embed_widget(self, pid, widget_object_name)
def update_embedded_widget_title(self, widget_object_name, title)
def remove_toolbar(self, toolbar)
def unembed_toolbar(self, toolbar_object_name)
def emit_save_settings_completed(self)
def _emit_close_plugin(self)
def _add_toolbar(self, toolbar)
def embed_toolbar(self, pid, toolbar_object_name)
def update_embedded_widget_icon(self, widget_object_name, icon_str)
_plugin_has_configuration
def _print_process_error(self)
def _print_process(self, data, method)
def unembed_widget(self, widget_object_name)
def _emit_load_completed(self, exception=None)
_dbus_instance_settings_service
def _on_toolbar_orientation_changed(self, toolbar_object_name)
def _emit_unload_completed(self)
def _update_title_bars(self)
def emit_shutdown_plugin_completed(self)
def _add_dbus_connection(self, conn)
def emit_restore_settings_completed(self)
def _create_dock_widget(self)
def _add_dock_widget(self, dock_widget, widget)
_dbus_plugin_settings_service
def __init__(self, parent, main_window, instance_id, application_context, container_manager, argv, dbus_object_path)
def _shutdown_plugin(self)
def _restore_settings(self, plugin_settings, instance_settings)
def _print_process_output(self)
def _save_settings(self, plugin_settings, instance_settings)