]> saetta.ns0.it Git - solipa/libsolipa/commitdiff
OOO pubblicizzata la funzione per l'inizializzazione del python.
authorAndrea Zagli <azagli@libero.it>
Mon, 2 Jul 2018 18:29:14 +0000 (20:29 +0200)
committerAndrea Zagli <azagli@libero.it>
Mon, 2 Jul 2018 18:29:14 +0000 (20:29 +0200)
src/ooo.c
src/ooo.h

index 56c93194b3d66cae2e5d2fb97d023f1cce985b4e..5a86fae157943f00d1e7b130424134e7dd7be6c1 100644 (file)
--- a/src/ooo.c
+++ b/src/ooo.c
@@ -191,6 +191,23 @@ SolipaOOO
        return solipa_ooo;
 }
 
+/**
+ * solipa_ooo_python_init:
+ * @ooo:
+ *
+ */
+void
+solipa_ooo_python_init (SolipaOOO* ooo)
+{
+       SolipaOOOPrivate *priv = SOLIPA_OOO_GET_PRIVATE (ooo);
+
+       Py_Initialize ();
+       priv->m_main = PyImport_AddModule ("__main__");
+       priv->dict = PyModule_GetDict (priv->m_main);
+
+       PyRun_SimpleString (ENCODING);
+}
+
 /**
  * solipa_ooo_set_transient:
  * @ooo:
@@ -428,11 +445,34 @@ solipa_ooo_exec (SolipaOOO *ooo, const gchar *statement)
 gchar
 *solipa_ooo_pycmd_header (SolipaOOO *ooo)
 {
+       GString *str;
        gchar *ret;
 
        SolipaOOOPrivate *priv = SOLIPA_OOO_GET_PRIVATE (ooo);
 
-       ret = g_strdup_printf (ENCODING "\n"
+       str = g_string_new ("");
+
+#ifdef G_OS_WIN32
+
+       gchar *ooo_path;
+
+       ooo_path = g_strjoinv ("\\\\", g_strsplit (priv->ooo_path, "\\", -1));
+       g_string_printf (str, "import os\n"
+                        "import sys\n"
+                        "os.environ['PATH'] = os.getenv('PATH') + ';%s\\\\URE\\\\bin'\n"
+                        "os.environ['PYTHONPATH'] = '%s\\\\Basis\\\\Program'\n"
+                        "sys.path.append('%s\\\\Basis\\\\Program')\n"
+                        "os.environ['URE_BOOTSTRAP'] = 'file:///%s/program/fundamental.ini'\n",
+                        ooo_path,
+                        ooo_path,
+                        ooo_path,
+                        g_strjoinv ("%20", g_strsplit (g_strjoinv ("/", g_strsplit (priv->ooo_path, "\\", -1)), " ", -1)));
+
+       g_free (ooo_path);
+
+#endif
+
+       g_string_append_printf (str,
                               "import uno\n"
                               "import string\n"
                               "from com.sun.star.beans import PropertyValue\n"
@@ -442,6 +482,9 @@ gchar
                                "desktop = context.ServiceManager.createInstanceWithContext(\"com.sun.star.frame.Desktop\", context)\n",
                                priv->ooo_port);
 
+       ret = g_strdup (str->str);
+       g_string_free (str, TRUE);
+
        return ret;
 }
 
@@ -781,12 +824,7 @@ solipa_ooo_apri_openoffice (SolipaOOO *ooo)
 
        SolipaOOOPrivate *priv = SOLIPA_OOO_GET_PRIVATE (ooo);
 
-       /* apro python */
-       Py_Initialize ();
-       priv->m_main = PyImport_AddModule ("__main__");
-       priv->dict = PyModule_GetDict (priv->m_main);
-
-       PyRun_SimpleString (ENCODING);
+       solipa_ooo_python_init (ooo);
 
 #ifdef G_OS_WIN32
 
index 0c3d0b168b1d2106899a3732373ebc8a0a0d86d9..31cabf229f077dda64c4afde61ebebb51bfe9039 100644 (file)
--- a/src/ooo.h
+++ b/src/ooo.h
@@ -63,6 +63,8 @@ SolipaOOO *solipa_ooo_new (GtkWindow *transient,
                            guint ooo_port,
                            gboolean visible);
 
+void solipa_ooo_python_init (SolipaOOO *ooo);
+
 void solipa_ooo_set_transient (SolipaOOO *ooo, GtkWindow *transient);
 GtkWindow *solipa_ooo_get_transient (SolipaOOO *ooo);