Browse files

cleanup, add helper function for getting widgets via glade

darcs-hash:20060809065643-4b390-9de011a9283d3efbe211531a81da4e519fb3cd7f.gz
  • Loading branch information...
1 parent a8e6544 commit a685595badf1772254cc6590fd71f65f4a595f63 @kfish committed Aug 9, 2006
Showing with 18 additions and 11 deletions.
  1. +1 −1 cairo-appbase.cabal
  2. +17 −10 src/cairo-appbase.hs
View
2 cairo-appbase.cabal
@@ -6,7 +6,7 @@ License: BSD3
License-file: LICENSE
Author: Conrad Parker
Maintainer: conradp@cse.unsw.edu.au
-Build-Depends: base, gtk, glade, cairo
+Build-Depends: base, glib, gtk, glade, cairo
Data-Files: data/main.glade
Executable: cairo-appbase
View
27 src/cairo-appbase.hs
@@ -5,6 +5,7 @@
-- This code is in the public domain.
--
+import qualified System.Glib.Types as GTypes
import qualified Graphics.UI.Gtk as G
import qualified Graphics.UI.Gtk.Glade as Glade
import qualified Graphics.Rendering.Cairo as C
@@ -31,37 +32,43 @@ main = do
-- load up the glade file
filename <- My.getDataFileName "data/main.glade"
- dialogXmlM <- Glade.xmlNew filename
- let dialogXml = case dialogXmlM of
- (Just dX) -> dX
+ windowXmlM <- Glade.xmlNew filename
+ let windowXml = case windowXmlM of
+ (Just wX) -> wX
Nothing -> error ("can't find the glade file " ++ filename)
+ get :: (G.WidgetClass widget) => (GTypes.GObject -> widget) -> String -> IO widget
+ get = Glade.xmlGetWidget windowXml
-- get a handle on widgets from the glade file
- window <- Glade.xmlGetWidget dialogXml G.castToWindow "window1"
- canvas <- Glade.xmlGetWidget dialogXml G.castToDrawingArea "drawingarea1"
- quit1 <- Glade.xmlGetWidget dialogXml G.castToMenuItem "quit1"
+ window <- get G.castToWindow "window1"
- open1 <- Glade.xmlGetWidget dialogXml G.castToMenuItem "open1"
- openDialog <- Glade.xmlGetWidget dialogXml G.castToFileChooserDialog "opendialog"
+ -- set up the File->Open dialog
+ open1 <- get G.castToMenuItem "open1"
+ openDialog <- get G.castToFileChooserDialog "opendialog"
G.onActivateLeaf open1 $ G.widgetShow openDialog
G.onResponse openDialog $ myFileOpen openDialog
- about1 <- Glade.xmlGetWidget dialogXml G.castToMenuItem "about1"
- aboutdialog1 <- Glade.xmlGetWidget dialogXml G.castToAboutDialog "aboutdialog1"
+ -- set up the Help->About dialog
+ about1 <- get G.castToMenuItem "about1"
+ aboutdialog1 <- get G.castToAboutDialog "aboutdialog1"
G.onActivateLeaf about1 $ G.widgetShow aboutdialog1
-- fix size
-- G.windowSetResizable window False
G.widgetSetSizeRequest window windowWidth windowHeight
-- quit on File->Quit menu selection
+ quit1 <- get G.castToMenuItem "quit1"
G.onActivateLeaf quit1 $ G.widgetDestroy window
G.onDestroy window G.mainQuit
+ -- set up the canvas
+ canvas <- get G.castToDrawingArea "drawingarea1"
G.onExpose canvas $ const (updateCanvas canvas)
G.widgetShowAll window
G.mainGUI
+myFileOpen :: G.FileChooserDialog -> G.ResponseId -> IO ()
myFileOpen fcdialog response = do
case response of
G.ResponseOk -> do Just filename <- G.fileChooserGetFilename fcdialog

0 comments on commit a685595

Please sign in to comment.