@@ -13,26 +13,26 @@ import org.json4s.jackson.{ JsonMethods, Json4sScalaModule }
1313
1414import org .nlogo .languagelibrary .Subprocess .path
1515import org .nlogo .languagelibrary .Subprocess
16- import org .nlogo .languagelibrary .config .{ Config , ConfigProperty , FileProperty , Menu , Platform }
16+ import org .nlogo .languagelibrary .config .{ Config , ConfigProperty , FileProperty , Menu }
1717
1818import org .nlogo .api
1919import org .nlogo .api ._
2020import org .nlogo .core .{ LogoList , Syntax }
21- import org .nlogo .workspace .{ AbstractWorkspace , ExtensionManager => WorkspaceExtensionManager }
21+ import org .nlogo .workspace .AbstractWorkspace
2222
2323import scala .collection .immutable .ArraySeq
2424
2525object PythonExtension {
2626 val codeName = " py"
2727 val longName = " Python"
28- val extLangBin = if (Platform .isWindows ) { " python" } else { " python3" }
28+ val extLangBin = if (System .getProperty( " os.name " ).toLowerCase.startsWith( " win " ) ) { " python" } else { " python3" }
2929
3030 private var _pythonProcess : Option [Subprocess ] = None
3131
3232 var menu : Option [Menu ] = None
3333 val config : Config = Config .createForPropertyFile(classOf [PythonExtension ], PythonExtension .codeName)
3434
35- var headless = GraphicsEnvironment . isHeadless || System .getProperty( " org.nlogo.preferHeadless " ) == " true"
35+ var isHeadless = true
3636
3737 def pythonProcess : Subprocess = {
3838 _pythonProcess.getOrElse(throw new ExtensionException (
@@ -72,21 +72,9 @@ class PythonExtension extends api.DefaultClassManager {
7272 override def runOnce (em : ExtensionManager ): Unit = {
7373 super .runOnce(em)
7474
75- PythonExtension .headless = PythonExtension .headless | (em match {
76- case wem : WorkspaceExtensionManager =>
77- wem.workspace match {
78- case aw : AbstractWorkspace if aw.isHeadless =>
79- true
75+ PythonExtension .isHeadless = ! em.workspaceContext.workspaceGUI
8076
81- case _ =>
82- false
83- }
84-
85- case _ =>
86- false
87- })
88-
89- if (! PythonExtension .headless) {
77+ if (! PythonExtension .isHeadless) {
9078 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. "
9179 val py2Property = new FileProperty (" python2" , " python2" , PythonExtension .config.get(" python2" ).getOrElse(" " ), py2Message)
9280 PythonExtension .menu = Menu .create(em, PythonExtension .longName, PythonExtension .extLangBin, PythonExtension .config, Seq (py2Property))
@@ -97,7 +85,7 @@ class PythonExtension extends api.DefaultClassManager {
9785 super .unload(em)
9886 PythonExtension .killPython()
9987
100- if (! PythonExtension .headless )
88+ if (! PythonExtension .isHeadless )
10189 PythonExtension .menu.foreach(_.unload())
10290 }
10391
@@ -114,7 +102,7 @@ object Using {
114102object PythonSubprocess {
115103 def python2 : Option [File ] = {
116104 val maybePy2File = PythonExtension .config.get(" python2" ).map( (dir) => {
117- val bin = if (Platform .isWindows ) { " python.exe" } else { " python2" }
105+ val bin = if (System .getProperty( " os.name " ).toLowerCase.startsWith( " win " ) ) { " python.exe" } else { " python2" }
118106 val path = Paths .get(dir, bin)
119107 new File (path.toString)
120108 })
@@ -158,7 +146,7 @@ object SetupPython extends api.Command {
158146 PythonExtension .codeName, PythonExtension .longName,
159147 customMapper = Option (mapper))
160148
161- if (! PythonExtension .headless )
149+ if (! PythonExtension .isHeadless )
162150 PythonExtension .menu.foreach(_.setup(PythonExtension .pythonProcess.evalStringified))
163151 } catch {
164152 case e : Exception =>
0 commit comments