Re: core.async + swing
Den måndagen den 29:e juli 2013 kl. 16:44:50 UTC+2 skrev eliass...@yahoo.com: Hi, I'm playing around with core.async a bit. Is it possible to put java.awt.Graphics object into a channel and do the drawing in a go loop consuming this channel. The problem I'm having is that when I consume the channel, core.async has switched to another thread. I'm not in the Swing thread anymore. Is there a way to stay in the Swing thread while doing this? This is how I setup the producer: (defn create-canvas [paint-channel] (proxy [JButton] [] (getPreferredSize [] (Dimension. 300 300)) (paintComponent [g] (go (proxy-super paintComponent g) (! paint-channel g) ;I've tried put! too Thanks! --anders -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: core.async + swing
Hi Tim, I did try invokeLater before unsuccessfully. I think the problem was that the Graphics I passed on the channel wasn't valid anymore. This time around I tried getting the graphics with Component.getGraphics instead, inside invokeLater. That worked! By the way, I think core.async is fantastic, what a relief to get rid of all the callbacks. Thanks so much for your help and for core.async! --anders Den måndagen den 29:e juli 2013 kl. 16:52:31 UTC+2 skrev tbc++: I recommend using invokeLater to send a fn to Swing to do the rendering. http://docs.oracle.com/javase/6/docs/api/javax/swing/SwingUtilities.html#invokeLater(java.lang.Runnable) If you need Swing to notify the go channel when the rendering is complete, you can do something like this: (go (let [c (chan)] (SwingUtilities/invokeLater (fn [] (do ...stuff ) (close! c))) (! c))) Wrap in a macro if you find yourself doing it a lot: (go (in-swing-and-wait ...stuff...)) Timothy On Mon, Jul 29, 2013 at 8:44 AM, eliass...@yahoo.com javascript:wrote: Hi, I'm playing around with core.async a bit. Is it possible to put java.awt.Graphics object into a channel and do the drawing in a go loop consuming this channel. The problem I'm having is that when I consume the channel, core.async has switched to another thread. I'm not in the Swing thread anymore. Is there a way to stay in the Swing thread while doing this? This is how I setup the producer: (defn create-canvas [paint-channel] (proxy [JButton] [] (getPreferredSize [] (Dimension. 300 300)) (paintComponent [g] (go (proxy-super paintComponent g) (! paint-channel g) ;I've tried put! too Thanks! --anders -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@googlegroups.comjavascript: Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+u...@googlegroups.com javascript: For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com javascript:. For more options, visit https://groups.google.com/groups/opt_out. -- “One of the main causes of the fall of the Roman Empire was that–lacking zero–they had no way to indicate successful termination of their C programs.” (Robert Firth) -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
core.async + swing
Hi, I'm playing around with core.async a bit. Is it possible to put java.awt.Graphics object into a channel and do the drawing in a go loop consuming this channel. The problem I'm having is that when I consume the channel, core.async has switched to another thread. I'm not in the Swing thread anymore. Is there a way to stay in the Swing thread while doing this? This is how I setup the producer: (defn create-canvas [paint-channel] (proxy [JButton] [] (getPreferredSize [] (Dimension. 300 300)) (paintComponent [g] (go (proxy-super paintComponent g) (! paint-channel g) ;I've tried put! too Thanks! --anders -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: core.async + swing
I recommend using invokeLater to send a fn to Swing to do the rendering. http://docs.oracle.com/javase/6/docs/api/javax/swing/SwingUtilities.html#invokeLater(java.lang.Runnable) If you need Swing to notify the go channel when the rendering is complete, you can do something like this: (go (let [c (chan)] (SwingUtilities/invokeLater (fn [] (do ...stuff ) (close! c))) (! c))) Wrap in a macro if you find yourself doing it a lot: (go (in-swing-and-wait ...stuff...)) Timothy On Mon, Jul 29, 2013 at 8:44 AM, eliassona...@yahoo.com wrote: Hi, I'm playing around with core.async a bit. Is it possible to put java.awt.Graphics object into a channel and do the drawing in a go loop consuming this channel. The problem I'm having is that when I consume the channel, core.async has switched to another thread. I'm not in the Swing thread anymore. Is there a way to stay in the Swing thread while doing this? This is how I setup the producer: (defn create-canvas [paint-channel] (proxy [JButton] [] (getPreferredSize [] (Dimension. 300 300)) (paintComponent [g] (go (proxy-super paintComponent g) (! paint-channel g) ;I've tried put! too Thanks! --anders -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- “One of the main causes of the fall of the Roman Empire was that–lacking zero–they had no way to indicate successful termination of their C programs.” (Robert Firth) -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.