scala - How can you get ScalaFX to play nice in the SBT console? -
i'm writing image library intro programming students play with. (i stole idea , patterns image library drracket.)
https://github.com/dupontmanualhs/dm-image
it's written in swing (that's master branch), i'm trying convert scalafx (see scalafx branch), , there issues. ideally, student should able like:
scala> import org.dupontmanual.image._ scala> trainengine.display() and have dialog box train engine show up. i've tried using code at
https://github.com/scalafx/scalafx-tutorials
in stand-alone-dialog project, if include system.exit(0) after dialog.showandwait(), error:
not interrupting system thread thread[process reaper,10,system] exception while removing reference: java.lang.interruptedexception java.lang.interruptedexception @ java.lang.object.wait(native method) @ java.lang.ref.referencequeue.remove(referencequeue.java:135) @ java.lang.ref.referencequeue.remove(referencequeue.java:151) @ com.sun.glass.utils.disposer.run(disposer.java:69) @ java.lang.thread.run(thread.java:744) not interrupting system thread thread[prism font disposer,10,system] exception in runnable exception in thread "javafx application thread" (note same error if try run app stand-alone-dialog in console, i'm guessing calling system.exit(0) not great idea in sbt console.)
if leave system.exit(0) line out, things seem work fine--mostly. after first time display dialog, doesn't bring dialog focus, have click dismiss dialog. real problem when :q exit console, sbt hangs , have ctrl-c able type again. (and, yes, ctrl-c exits sbt completely, not console.)
i think may need create thread scalafx stuff. example, have method stack 1 image on top of another, , got illegalstateexception when tried call function, though doesn't display anything, creates new group 2 previous nodes stacked appropriately. unfortunately, i'm not sure how create new thread , make sure image-related runs through that.
i've set fork := true in build.sbt, doesn't seem make difference console.
== update ==
i found initialcommands , cleanupcommands in sbt documentation , tried clean after when console starts , ends. values are:
initialcommands in console := """import org.dupontmanual.image._; org.dupontmanual.image.initialize()""" cleanupcommands in console := """org.dupontmanual.image.cleanup()""" which defined thusly:
package object image { var masterframe: jframe = _ def initialize() { masterframe = new jframe() masterframe.add(new jfxpanel()) masterframe.setdefaultcloseoperation(jframe.exit_on_close) } def cleanup() { println("exiting platform") platform.exit() println("disposing of frames") frame.getframes().foreach { _.dispose() } println("frames disposed") system.exit(0); } here's result of running console , trying quit:
> console [info] compiling 1 scala source /home/sysadmin/dm-workspace/dm-image/target/scala-2.10/classes... [info] starting scala interpreter... [info] import org.dupontmanual.image._ welcome scala version 2.10.3 (java hotspot(tm) 64-bit server vm, java 1.7.0_51). type in expressions have them evaluated. type :help more information. scala> hacker.display() scala> :q exiting platform disposing of frames frames disposed not interrupting system thread thread[xtoolkt-shutdown-thread,5,system] not interrupting system thread thread[awt-xawt,6,system] not interrupting system thread thread[prism font disposer,10,system] not interrupting system thread thread[java2d disposer,10,system] exception while removing reference: java.lang.interruptedexception java.lang.interruptedexception @ java.lang.object.wait(native method) @ java.lang.ref.referencequeue.remove(referencequeue.java:135) @ java.lang.ref.referencequeue.remove(referencequeue.java:151) @ com.sun.glass.utils.disposer.run(disposer.java:69) @ java.lang.thread.run(thread.java:744) exception: sbt.trapexitsecurityexception thrown uncaughtexceptionhandler in thread "run-main-0" and doesn't exit console. still have use ctrl-c, exits out of sbt completely.
something still running, can't figure out is. grrr.
i think problem somehow need fork console, perhaps it's issue: https://github.com/sbt/sbt/issues/1918
the following idea seems work: instead of sbt console embed repl, such ammonite. still sbt run doesn't work, fork in run := true. packaging fat jar , running seem work:
build.sbt
name := "foo" version := "0.1.0" scalaversion := "2.11.7" librarydependencies ++= seq( "org.scala-lang.modules" %% "scala-swing" % "1.0.2", "com.lihaoyi" % "ammonite-repl" % "0.5.1" cross crossversion.full ) project/build.properties
sbt.version=0.13.9 project/plugins.sbt
addsbtplugin("com.eed3si9n" % "sbt-assembly" % "0.14.1") src/main/scala/foo/main.scala
package foo import scala.swing._ object main extends app { def test(): unit = swing.onedt { new mainframe { contents = new label("app exits if close window") } .open() } ammonite.repl.main.run("") } then
$ sbt assembly ... $ java -jar target/scala-2.11/foo-assembly-0.1.0.jar loading... welcome ammonite repl 0.5.1 (scala 2.11.7 java 1.8.0_66) @ foo.main.test() the oddity after application exists, shell character echoing broken, perhaps that's issue of ammonite, might want try default scala repl.
Comments
Post a Comment