Skip to content

Commit 6b75499

Browse files
committed
Prevent GUI initialization in headless mode
1 parent c05504b commit 6b75499

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

src/main/PythonExtension.scala

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ import org.json4s.jackson.{ JsonMethods, Json4sScalaModule }
1212

1313
import org.nlogo.languagelibrary.Subprocess.path
1414
import org.nlogo.languagelibrary.Subprocess
15-
import org.nlogo.languagelibrary.config.{ Config, FileProperty, Menu, Platform }
15+
import org.nlogo.languagelibrary.config.{ Config, ConfigProperty, FileProperty, Menu, Platform }
1616

1717
import org.nlogo.api
1818
import org.nlogo.api._
1919
import org.nlogo.core.{ LogoList, Syntax }
20+
import org.nlogo.workspace.{ AbstractWorkspace, ExtensionManager => WorkspaceExtensionManager }
2021

2122
import scala.collection.immutable.ArraySeq
2223

@@ -69,9 +70,34 @@ class PythonExtension extends api.DefaultClassManager {
6970
override def runOnce(em: ExtensionManager): Unit = {
7071
super.runOnce(em)
7172

72-
val py2Message = s"It is recommended to use Python 3 if possible and enter its path above. If you must use Python 2, enter the path to its executable folder below."
73-
val py2Property = new FileProperty("python2", "python2", PythonExtension.config.get("python2").getOrElse(""), py2Message)
74-
PythonExtension.menu = Menu.create(em, PythonExtension.longName, PythonExtension.extLangBin, PythonExtension.config, Seq(py2Property))
73+
em.asInstanceOf[WorkspaceExtensionManager].workspace.asInstanceOf[AbstractWorkspace].isHeadless
74+
75+
val headless: Boolean = em match {
76+
case wem: WorkspaceExtensionManager =>
77+
wem.workspace match {
78+
case aw: AbstractWorkspace if aw.isHeadless =>
79+
true
80+
81+
case _ =>
82+
false
83+
}
84+
85+
case _ =>
86+
false
87+
}
88+
89+
val extraProperties: Seq[ConfigProperty] = {
90+
if (headless) {
91+
Seq()
92+
} else {
93+
val py2Message = s"It is recommended to use Python 3 if possible and enter its path above. If you must use Python 2, enter the path to its executable folder below."
94+
val py2Property = new FileProperty("python2", "python2", PythonExtension.config.get("python2").getOrElse(""), py2Message)
95+
96+
Seq(py2Property)
97+
}
98+
}
99+
100+
PythonExtension.menu = Menu.create(em, PythonExtension.longName, PythonExtension.extLangBin, PythonExtension.config, extraProperties)
75101
}
76102

77103
override def unload(em: ExtensionManager): Unit = {

0 commit comments

Comments
 (0)