[Haskell-beginners] gtk2hs not rendering drawingArea

Norbert Wojtowicz wojtowicz.norbert at gmail.com
Thu Dec 4 07:07:06 EST 2008


I'm having problems getting a drawingArea to render, I've narrowed the
program down to the following skeleton. Any suggestions on what I'm
doing wrong? The label gets updated correctly, but the drawingArea
just remains gray as if it was never rendered. I'm including an entire
compilable skeleton in case someone wants to help me debug it. (I have
a feeling I'm just missing something very obvious...)

Thanks in advance,


module Main where
import Graphics.UI.Gtk -- hiding (fill)
import Graphics.UI.Gtk.Glade
import Graphics.Rendering.Cairo.SVG
import Graphics.Rendering.Cairo
import Control.Monad

main = do
  let gFile = "brainSpin.glade"
  windowXmlM <- xmlNew gFile
  let windowXml = case windowXmlM of
                    (Just windowXml) -> windowXml
                    Nothing -> error "Can't find the glade file
\"brainSpin.glade\" in the current directory"
  window <- xmlGetWidget windowXml castToWindow "brainSpinMain"
  onDestroy window mainQuit
  label <- xmlGetWidget windowXml castToLabel "label1"
  drawArea <- xmlGetWidget windowXml castToDrawingArea "drawArea"
  widgetShowAll window
  labelSetText label "foo"

  -- THIS is the offending code. Originally I was working with SVGs,
but I simplified
  -- it to this, just to track down the problem. It seems any Render () does not
  -- get updated in the drawArea
  let r = do setSourceRGB 0 0 0
  drawin <- widgetGetDrawWindow drawArea
  renderWithDrawable drawin r



<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.4.5 on Thu Dec  4 12:50:25 2008 -->
  <widget class="GtkWindow" id="brainSpinMain">
      <widget class="GtkVBox" id="vbox1">
        <property name="visible">True</property>
          <widget class="GtkLabel" id="label1">
            <property name="visible">True</property>
            <property name="label" translatable="yes">label</property>
          <widget class="GtkDrawingArea" id="drawArea">
            <property name="visible">True</property>
            <property name="position">1</property>

More information about the Beginners mailing list