-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rendering several times from the same REPL process #10
Comments
Well, sure enough, there was a way to achieve my initial goal of being able to reload without restarting everything. Here's my take on it: (ns savages.art.gen-debug
(:require [tikkba.swing :as ts]
[tikkba.dom :as td]
[analemma.svg :as as]
[analemma.charts :as ac]
[analemma.xml :as ax])
(:import (javax.swing JFrame SwingUtilities)
(org.apache.batik.swing JSVGCanvas)))
; Hack to keep the same canvas across REPL reloads
(def canvas)
(when-not (bound? #'canvas)
(def ^JSVGCanvas canvas (ts/jsvgcanvas)))
(defn hw-svg []
(as/svg
(-> (as/line 2 10 50 10)
(ax/add-attrs :stroke "black" :stroke-width 4))
(-> (as/text "Hello world ZORRR")
(ax/add-attrs :x 2 :y 30)
(as/style :fill "#000066"
:font-family "Verdana"
:font-size "28px"
:alignment-baseline :middle))))
(defn create-frame []
(let [frame (JFrame.)]
(.setTitle frame "Tikkba!")
(.add frame canvas)
(.setSize frame 800 200)
;(.setDefaultCloseOperation frame JFrame/EXIT_ON_CLOSE)
(SwingUtilities/invokeAndWait
(fn []
(.setVisible frame true)))))
(defn reload! []
(let [doc (td/svg-doc (hw-svg))]
(ts/set-document canvas doc)
(.repaint canvas)))
(defn -main
[]
;; Converts the SVG representation to a XML Document
;; and displays the SVG in a JFrame
(reload!)
(create-frame)) I could boil that down and make it README-worthy if you're interested. I still believe that there is a glitch somewhere that prevents creating many JFrame/canvases in the same process. Regarding closing this issue, I'm not sure if tikkba.swing could provide a JFrame-level restart-able window. |
I cannot say where the problem is from. The best is to write a sample of your problem in Java and asks on the Batik mailing list but probably you do not want to do that. Maybe you can add a As for providing a helper function, if necessary, it could go in |
Actually attempting to reproduce this using only Java would clearly help pinpoint whether Batik or Tikkba is the origin. I can't commit to doing such a thing any time soon, however. If there is a Java/Batik workaround for the issue, making it available from Writing up a |
Yes, addition an example and a link is very fine. I misunderstood you, I though you wanted to have the whole code in the README.. |
Greetings!
I've been experimenting with tikkba exemples. I've stripped the first one down to just a text label.
I would like to be able to close the Swing window and start a new one by calling (-main) again from the REPL - arguably there are nicer ways to achieve reloading, but I was expecting this one to work.
What happens is that the first time (-main) is called from the REPL, the render succeeds (text appears in frame). After closing the frame, calling (-main) again results in an empty frame. Restarting the REPL allows for another render.
There are no exceptions as far as I can tell, and nothing to hint me off on stdout/stderr. How could I debug such an issue?
I'm on an up-to-date Archlinux system, with latest proprietary nvidia drivers.
Here is my test case:
Cheers!
The text was updated successfully, but these errors were encountered: