You can subscribe to this list here.
2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(4) |
Jun
|
Jul
(68) |
Aug
(4) |
Sep
|
Oct
(23) |
Nov
(95) |
Dec
(9) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2004 |
Jan
(3) |
Feb
|
Mar
|
Apr
(51) |
May
(81) |
Jun
(2) |
Jul
(86) |
Aug
(143) |
Sep
(3) |
Oct
(31) |
Nov
(63) |
Dec
(90) |
2005 |
Jan
(277) |
Feb
(157) |
Mar
(99) |
Apr
(195) |
May
(151) |
Jun
(148) |
Jul
(98) |
Aug
(123) |
Sep
(20) |
Oct
(174) |
Nov
(155) |
Dec
(26) |
2006 |
Jan
(51) |
Feb
(19) |
Mar
(16) |
Apr
(12) |
May
(5) |
Jun
|
Jul
(11) |
Aug
(7) |
Sep
(10) |
Oct
(31) |
Nov
(174) |
Dec
(56) |
2007 |
Jan
(45) |
Feb
(52) |
Mar
(10) |
Apr
(5) |
May
(47) |
Jun
(16) |
Jul
(80) |
Aug
(29) |
Sep
(14) |
Oct
(59) |
Nov
(46) |
Dec
(16) |
2008 |
Jan
(10) |
Feb
(1) |
Mar
|
Apr
|
May
(49) |
Jun
(26) |
Jul
(8) |
Aug
(4) |
Sep
(25) |
Oct
(53) |
Nov
(9) |
Dec
(1) |
2009 |
Jan
(66) |
Feb
(11) |
Mar
(1) |
Apr
(14) |
May
(8) |
Jun
(1) |
Jul
(2) |
Aug
(2) |
Sep
(9) |
Oct
(23) |
Nov
(35) |
Dec
|
2010 |
Jan
(7) |
Feb
(2) |
Mar
(39) |
Apr
(19) |
May
(161) |
Jun
(19) |
Jul
(32) |
Aug
(65) |
Sep
(113) |
Oct
(120) |
Nov
(2) |
Dec
|
2012 |
Jan
|
Feb
(5) |
Mar
(4) |
Apr
(7) |
May
(9) |
Jun
(14) |
Jul
(1) |
Aug
|
Sep
(1) |
Oct
(1) |
Nov
(12) |
Dec
(2) |
2013 |
Jan
(1) |
Feb
(17) |
Mar
(4) |
Apr
(4) |
May
(9) |
Jun
|
Jul
(8) |
Aug
|
Sep
(2) |
Oct
|
Nov
|
Dec
|
From: Duncan C. <dun...@wo...> - 2007-10-15 14:44:27
|
Thu Aug 30 11:41:07 PDT 2007 Duncan Coutts <du...@ha...> * Undo accidentally-comitted debugging change to soe hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 87 -define USE_CAIRO +#define USE_CAIRO |
From: Duncan C. <dun...@wo...> - 2007-10-15 14:44:26
|
Thu Aug 30 06:16:22 PDT 2007 Duncan Coutts <du...@ha...> * Remove a bit of soe debug cruft. hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 435 -instance Show Region where show (Region _ x y w h) = show (x,y,w,h) - hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 450 - Cairo.translate (fromIntegral (x) + fromIntegral width / 2) - (fromIntegral (y) + fromIntegral height / 2) + Cairo.translate (fromIntegral x + fromIntegral width / 2) + (fromIntegral y + fromIntegral height / 2) |
From: Duncan C. <dun...@wo...> - 2007-10-15 14:44:25
|
Thu Aug 30 05:44:27 PDT 2007 Duncan Coutts <du...@ha...> * Update Graphics.SOE.Gtk to new api and fix many bugs hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 2 --- SOE implementation based on Gtk and cairo or Gdk. +-- SOE implementation based on Gtk and cairo (or Gdk). +-- Some code borrowed from SOE implementation based on OpenGL and GLFW by +-- Paul Liu, http://www.haskell.org/soe/ hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 10 --- Copyright (C) 2005 Duncan Coutts +-- Copyright (C) 2005-2007 Duncan Coutts +-- Copyright (C) 2007 Paul Liu hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 82 - getWindowTick, hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 87 -#define USE_CAIRO +define USE_CAIRO hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 90 +import Data.List (foldl') hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 109 +------------------- +-- Window Functions +------------------- + hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 140 - eventsChan :: Chan Event, - timerVar :: MVar [MVar ()] + eventsChan :: Chan Event hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 145 - openWindowEx title Nothing (Just size) drawBufferedGraphic Nothing + openWindowEx title Nothing (Just size) drawBufferedGraphic hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 147 -openWindowEx :: - Title - -> Maybe Point - -> Maybe Size - -> RedrawMode - -> Maybe Word32 - -> IO Window -openWindowEx title position size (RedrawMode useDoubleBuffer) timer = +openWindowEx :: Title -> Maybe Point -> Maybe Size -> RedrawMode -> IO Window +openWindowEx title position size (RedrawMode useDoubleBuffer) = hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 167 - [_$_] + hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 170 - timerVar <- newMVar [] hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 198 - Cairo.setLineWidth 1 + Cairo.setLineWidth 1.5 hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 246 - [_$_] - case timer of - Nothing -> return () - Just delay -> do - let tick = do - ps <- takeMVar timerVar - mapM_ (\p -> putMVar p ()) ps - putMVar timerVar [] - return True - Gtk.timeoutAddFull tick Gtk.priorityDefaultIdle (fromIntegral delay) - return () hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 251 - eventsChan = eventsChan, - timerVar = timerVar + eventsChan = eventsChan hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 276 +-------------------- +-- Drawing Functions +-------------------- + hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 298 -type Angle = Double +type Angle = Float hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 382 -polygon (p@(x,y):ps) = Graphic $ \pc -> do +polygon ((x,y):ps) = Graphic $ \pc -> do hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 390 -polyline (p@(x,y):ps) = Graphic $ \pc -> do +polyline ((x,y):ps) = Graphic $ \pc -> do hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 401 - Cairo.curveTo (fromIntegral x1) (fromIntegral y2) + Cairo.curveTo (fromIntegral x1) (fromIntegral y1) hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 410 -arc pt1 pt2 start extent = Graphic $ \pc -> case normaliseBounds pt1 pt2 of +arc pt1 pt2 start_ extent_ = Graphic $ \pc -> case normaliseBounds pt1 pt2 of hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 420 + where start = realToFrac start_ + extent = realToFrac extent_ + +------------------- +-- Region Functions +------------------- hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 435 +instance Show Region where show (Region _ x y w h) = show (x,y,w,h) + hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 441 --- Cairo.liftIO $ print ("createRectangle",x,y,width,height) hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 448 - let (x,y,width,height) = normaliseBounds' pt1 pt2 + let (x0,y0,width,height) = normaliseBounds' pt1 pt2 hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 452 - Cairo.translate (fromIntegral x + fromIntegral width / 2) - (fromIntegral y + fromIntegral height / 2) + Cairo.translate (fromIntegral (x) + fromIntegral width / 2) + (fromIntegral (y) + fromIntegral height / 2) hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 458 - in Region drawing x y width height + in Region drawing x0 y0 width height hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 462 -createPolygon (p@(x,y):ps) = - let minMax (x,y) (minx,maxx,miny,maxy) = +createPolygon (p@(x0,y0):ps) = + let minMax (minx,maxx,miny,maxy) (x,y) = hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 470 - (minx,maxx,miny,maxy) = foldr minMax (x,x,y,y) ps [_$_] + (minx,maxx,miny,maxy) = foldl' minMax (x0,x0,y0,y0) (p:ps) hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 472 - Cairo.moveTo (fromIntegral x) (fromIntegral y) + Cairo.save + Cairo.translate (fromIntegral (x-minx)) (fromIntegral (y-miny)) + Cairo.moveTo (fromIntegral x0) (fromIntegral y0) hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 478 + Cairo.restore hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 503 --- Cairo.liftIO $ print ("combineRegion",x,y,width,height) hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 512 --- Cairo.liftIO $ print ("mask surface",x,y) hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 678 +--------------------------- +-- Event Handling Functions +--------------------------- + hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 717 - if noEvents then return Nothing + if noEvents then -- Sync with the main GUI loop or we can end up spinning on + -- maybeGetWindowEvent and prevent the screen redrawing. + -- We also introduce a very short delay here of 5ms. This + -- prevents the program from using 100% cpu and redrawing + -- constantly. This actually makes animation much smoother + -- since the process gets treated as interactive rather than + -- as a CPU hog so the scheduler gives us the benefit on + -- latency. Even with a 5ms delay here we can animate at up + -- to 200fps. + do syncVar <- newEmptyMVar + Gtk.timeoutAddFull (putMVar syncVar () >> return False) + Gtk.priorityDefaultIdle 10 + takeMVar syncVar + return Nothing hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 747 + Closed -> return '\x0' hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 751 -getKey win = getKeyEx win True >> getKeyEx win False +getKey win = do + ch <- getKeyEx win True + if ch == '\x0' then return ch + else getKeyEx win False hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 770 -getWindowTick :: Window -> IO () -getWindowTick win = do - ps <- takeMVar (timerVar win) - p <- newEmptyMVar - putMVar (timerVar win) (p:ps) - takeMVar p --block until the timer fills this MVar - |
From: Duncan C. <dun...@wo...> - 2007-10-15 14:44:24
|
Wed Aug 1 20:10:49 PDT 2007 Duncan Coutts <du...@ha...> * Fix doc typo, "the the" hunk ./gtk/Graphics/UI/Gtk/Gdk/Events.hsc 224 - -- | The coordinates of the click relative the the screen origin. + -- | The coordinates of the click relative to the screen origin. |
From: Duncan C. <dun...@wo...> - 2007-10-15 14:44:23
|
Sun Aug 5 07:45:21 PDT 2007 Peter Gavin <pg...@gm...> * small makefile changes to clean up documentation files that were not being removed hunk ./Makefile.am 1725 - docs/reference/minus.gif docs/reference/haddock.js \ + docs/reference/plus.gif docs/reference/minus.gif \ + docs/reference/haddock.js \ hunk ./Makefile.am 1729 - $(foreach LETTER, A B C D E F G H I J K L M N O P Q R S T U V W X \ + $(foreach LETTER, A B C D E F G H I J K L M N O P Q R S T U V W X Y \ |
From: Duncan C. <dun...@wo...> - 2007-10-15 14:44:22
|
Tue Aug 14 11:28:14 PDT 2007 Duncan Coutts <du...@ha...> * Fix ref counting bug in sourceBufferCreateMarker (reported by bwwx in #haskell) The docs say that gtk_source_buffer_create_marker returns a new GtkSourceMarker, owned by the buffer. So we need to ref the object, so we should use makeGObject rather than constructNewGObject. hunk ./sourceview/Graphics/UI/Gtk/SourceView/SourceBuffer.chs 228 - constructNewGObject mkSourceMarker $ + makeNewGObject mkSourceMarker $ |
From: Duncan C. <dun...@wo...> - 2007-10-15 14:44:22
|
Mon Jul 16 05:37:08 PDT 2007 A....@ke... * Fix bug in TreeStore on empty stores. This fixes a bug when running e.g. treeModelIterNChildren store Nothing when store is an empty TreeStore. hunk ./gtk/Graphics/UI/Gtk/ModelView/TreeStore.hs 320 -checkSuccess depth iter cache = (cmp cur iter && not (null sibs), cache') +checkSuccess depth iter cache = case advanceCache depth iter cache of + cache'@((cur,sibs):_) -> (cmp cur iter && not (null sibs), cache') + [] -> (False, []) |
From: Duncan C. <dun...@wo...> - 2007-09-24 12:15:47
|
Thu Sep 20 06:20:32 PDT 2007 hth...@zo... * Change Source File Names, Change Window Titles and Screenshots Source file Names now match XHTMl chapters, Added and changed some window titles and screen shots for consistency Removed references to chapters from source code files, except in the very first (GtkChap2a.hs) move ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap10.hs ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap4-5.hs move ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap11.hs ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap4-6.hs move ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap12.hs ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap4-7.hs move ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap13.hs ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap5-1.hs move ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap3a.hs ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap2a.hs move ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap3b.hs ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap2b.hs move ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap4.hs ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap3-1.hs move ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap5a.hs ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap3-2.hs move ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap5b.hs ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap3-3.hs move ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap6a.hs ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap4-1a.hs move ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap6b.hs ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap4-1b.hs move ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap7.hs ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap4-2.hs move ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap8.hs ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap4-3.hs move ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap9.hs ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap4-4.hs move ./docs/tutorial/Tutorial_Port/Images/GtkChap13.png ./docs/tutorial/Tutorial_Port/Images/GtkChap5-1.png move ./docs/tutorial/Tutorial_Port/chap13.xhtml ./docs/tutorial/Tutorial_Port/chap5-1.xhtml hunk ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap2a.hs 1 -{- GTK 2.0 Tutorial: Chapter 3a, Getting Started +{- GTK 2.0 Tutorial: Chapter 2: Getting Started hunk ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap2a.hs 3 - To run with GHCi: ghci GtkChap3.hs - To compile with GHC: ghc --make GtkChap3.hs -o chap + To run with GHCi: ghci GtkChap2a.hs + To compile with GHC: ghc --make GtkChap2a.hs -o chap hunk ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap2a.hs 13 + windowSetTitle window "Step One" hunk ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap2b.hs 12 - containerChild := button , containerBorderWidth := 10 ] + containerChild := button , containerBorderWidth := 10, [_$_] + windowTitle := "Hello"] hunk ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap3-1.hs 1 --- GTK 2.0 Tutorial: Chapter 4, Moving On - hunk ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap3-1.hs 11 - containerBorderWidth := 10, containerChild := hbox ] + containerBorderWidth := 10, containerChild := hbox, + windowTitle := "Packing" ] hunk ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap3-2.hs 1 --- GTK 2.0 Tutorial: Chapter 5a, Packing Widgets - hunk ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap3-3.hs 1 --- GTK 2.0 Tutorial: Chapter 5b, Table - hunk ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap4-1b.hs 1 --- Chapter 7, Radio Button - --- packeds not good! - hunk ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap4-2.hs 1 --- Chapter 9, Range Widgets, Example - hunk ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap4-2.hs 7 - set window [windowTitle := "range controls", + set window [windowTitle := "Range Controls", binary ./docs/tutorial/Tutorial_Port/Images/GtkChap2a.png binary ./docs/tutorial/Tutorial_Port/Images/GtkChap2b.png binary ./docs/tutorial/Tutorial_Port/Images/GtkChap3-1.png binary ./docs/tutorial/Tutorial_Port/Images/GtkChap4-2.png |
From: Duncan C. <dun...@wo...> - 2007-09-24 12:15:47
|
Thu Sep 20 19:13:10 PDT 2007 Alex Tarkovsky <ale...@gm...> * Patch Chapter 5.1 into the ToC and header/footer navigation hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 16 - <span class="nav-next"><a href="chap4-8.xhtml">Next</a></span> + <span class="nav-next"><a href="chap5-1.xhtml">Next</a></span> hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 346 - <span class="nav-next"><a href="chap4-8.xhtml">Next</a><br />4.8 Calendar</span> + <span class="nav-next"><a href="chap5-1.xhtml">Next</a><br />5.1 Calendar</span> hunk ./docs/tutorial/Tutorial_Port/chap5-1.xhtml 14 - <!-- [_$_] -<span class="nav-previous"><a href="chap12.xhtml">Previous</a></span> ---> + <span class="nav-previous"><a href="chap4-7.xhtml">Previous</a></span> hunk ./docs/tutorial/Tutorial_Port/chap5-1.xhtml 18 - <!-- [_$_] - <span class="nav-next"><a href="chap14.html">Next</a></span> - --> + <span class="nav-next"><a href="chap5-2.xhtml">Next</a></span> hunk ./docs/tutorial/Tutorial_Port/chap5-1.xhtml 210 - <!-- <span class="nav-previous"><a href="chap12.xhtml">Previous</a><br />Spin Buttons</span> - --> + <span class="nav-previous"><a href="chap4-7.xhtml">Previous</a><br />Spin Buttons</span> hunk ./docs/tutorial/Tutorial_Port/chap5-1.xhtml 214 - <!-- <span class="nav-next"><a href="chap14.xhtml">Next</a><br />Packing Demonstration Program</span> - --> + <span class="nav-next"><a href="chap5-2.xhtml">Next</a><br />File Chooser</span> hunk ./docs/tutorial/Tutorial_Port/index.xhtml 59 + </ol> + </li> + <li>5. Aggregated Widgets + <ol> + <li><a href="chap5-1.xhtml">5.1 Calendar</a></li> hunk ./docs/tutorial/Tutorial_Port/index.xhtml 65 - <li><a href="chap4-8.xhtml">4.8 Calendar</a></li> + <li><a href="chap5-2.xhtml">5.2 File Chooser</a></li> |
From: Duncan C. <dun...@wo...> - 2007-09-21 11:56:02
|
Sun Sep 16 09:14:14 PDT 2007 hth...@zo... * Tutorial Port Calendar (chapter 13) Changed to XHTML. Links need to be added and there are 2 unordered lists with no <div> and id yet addfile ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap13.hs hunk ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap13.hs 1 +import Graphics.UI.Gtk + +main :: IO () +main= do + initGUI + window <- windowNew + set window [windowTitle := "Calendar", + windowDefaultWidth:= 200, + windowDefaultHeight:= 100] + mainbox <- vBoxNew True 0 + containerAdd window mainbox + + hbox1 <- hBoxNew True 0 + boxPackStart mainbox hbox1 PackGrow 0 + + cal <-calendarNew + boxPackStart hbox1 cal PackGrow 0 [_$_] + + vbox1 <- vBoxNew True 0 + frame1 <- frameNew + set frame1 [frameLabel := "Display Options", + containerBorderWidth := 10, + frameLabelYAlign := 0.5, [_$_] + frameLabelXAlign := 0.5, + containerChild := vbox1 ] + boxPackStart hbox1 frame1 PackGrow 0 + headingopt <- addDisplayOpt vbox1 "Show Heading" + daynameopt <- addDisplayOpt vbox1 "Show Day Names" + monchngopt <- addDisplayOpt vbox1 "No Month Change" + weeknumopt <- addDisplayOpt vbox1 "Show Week Numbers" + + set headingopt [toggleButtonActive := True] + set daynameopt [toggleButtonActive := True] + + reslabel <- labelNew Nothing + showMess cal reslabel "Nothing Done Yet" + frame2 <- frameNew + set frame2 [frameLabel := "Last Action:", + containerBorderWidth := 10, [_$_] + containerChild := reslabel] + boxPackStart mainbox frame2 PackGrow 0 [_$_] + + mySetOnToggled headingopt cal calendarShowHeading + mySetOnToggled daynameopt cal calendarShowDayNames + mySetOnToggled monchngopt cal calendarNoMonthChange + mySetOnToggled weeknumopt cal calendarShowWeekNumbers + + onDaySelected cal (showMess cal reslabel "Day Selected") + onDaySelectedDoubleClick cal [_$_] + (showMess cal reslabel "Double Click Day Selected") + + widgetShowAll window + onDestroy window mainQuit + mainGUI + + +addDisplayOpt :: VBox -> String -> IO CheckButton +addDisplayOpt box lbl = do + cb <- checkButtonNewWithLabel lbl + boxPackStart box cb PackGrow 5 + return cb + +mySetOnToggled :: CheckButton -> Calendar -> [_$_] + Attr Calendar Bool -> [_$_] + IO (ConnectId CheckButton) +mySetOnToggled cb cl att = onToggled cb $ do + cbstate <- get cb toggleButtonActive + set cl [att := cbstate] + +showMess :: Calendar -> Label -> String -> IO () +showMess cal lbl str = do [_$_] + (year, month, day) <- calendarGetDate cal + labelSetText lbl $ str ++ "\n" ++ "Date = " ++ + (show year) ++ "//" ++ [_$_] + (myshow (month +1)) -- month is 0 to 11 + ++ "//" ++ (myshow day) [_$_] + where myshow n | n <= 9 = '0':(show n) + | otherwise = show n + +{- Commented out for platform specific testing: +These signals all seem to be implemented as onDaySelected. +The platform was: Gtk2Hs 0.9.12 on Fedora Core 6 + + onMonthChanged cal (showMess cal reslabel "Month Changed") + onNextMonth cal (showMess cal reslabel "Next Month Selected") + onNextYear cal (showMess cal reslabel "Next Year Selected") + onPrevMonth cal (showMess cal reslabel "Previous Month Selected") + onPrevYear cal (showMess cal reslabel "Previous Year Selected") +-} addfile ./docs/tutorial/Tutorial_Port/Images/GtkChap13.png binary ./docs/tutorial/Tutorial_Port/Images/GtkChap13.png addfile ./docs/tutorial/Tutorial_Port/chap13.xhtml hunk ./docs/tutorial/Tutorial_Port/chap13.xhtml 1 +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> + <head> + <meta http-equiv="Content-Type" + content="text/html; charset=utf-8" /> + <title>Gtk2Hs Tutorial: Calendar</title> + <link href="default.css" type="text/css" rel="stylesheet" /> + </head> + <body> + <div id="header"> + <h1>Gtk2Hs Tutorial</h1> + <!-- [_$_] +<span class="nav-previous"><a href="chap12.xhtml">Previous</a></span> +--> + <span class="nav-home"> + <a href="index.xhtml">Home</a> + </span> + <!-- [_$_] + <span class="nav-next"><a href="chap14.html">Next</a></span> + --> + </div> + <h3>Calendar</h3> + <p>The Calendar widget is an effective way to display and + retrieve monthly date related information. It is a very simple + widget to create and work with. Use:</p> + <pre class="codebox"> +calendarNew: IO Calendar +</pre> + <p>By default the current date is shown. To retrieve the date + from a calendar use:</p> + <pre class="codebox"> +calendarGetDate :: CalendarClass self => self -> IO (Int, Int, Int) +</pre> + <p>where the interpretation is (year, month, day). Note that + the months start with a 0, so you'll have to add 1 to get it + right. The related attributes are:</p> + <pre class="codebox"> +calendarYear :: CalendarClass self => Attr self Int +calendarMonth :: CalendarClass self => Attr self Int +calendarDay :: CalendarClass self => Attr self Int +</pre> + <p>The Calendar widget has a few options that allow you to + change the way the widget looks and operates by using the + function [_$_] + <code>calendarSetDisplayOptions</code>. To retrieve the + settings use: [_$_] + <code>calendarGetDisplayOptions</code>.</p> + <pre class="codebox"> +calendarSetDisplayOptions :: CalendarClass self => self -> [CalendarDisplayOptions] -> IO () +calendarGetDisplayOptions :: CalendarClass self => self -> IO [CalendarDisplayOptions] +</pre> + <p> + <code>CalendarDisplayOptions</code>has the following + constructors:</p> + <ul> + <li>CalendarShowHeading: this option specifies that the month + and year should be shown when drawing the calendar</li> + <li>CalendarShowDayNames: this option specifies that the + three letter descriptions should be displayed for each day + (eg Mon,Tue, etc.).</li> + <li>CalendarNoMonthChange: this option states that the user + should not and can not change the currently displayed month. + This can be good if you only need to display a particular + month such as if you are displaying 12 calendar widgets for + every month in a particular year.</li> + <li>CalendarShowWeekNumbers: this option specifies that the + number for each week should be displayed down the left side + of the calendar. (eg. Jan 1 = Week 1,Dec 31 = Week 52).</li> + <li>CalendarWeekStartMonday (but see note below): this option + states that the calendar week will start on Monday instead of + Sunday which is the default. This only affects the order in + which days are displayed from left to right.</li> + </ul> + <p>These options can also be set and retrieved through Boolean + attributes using the generic [_$_] + <code>get</code>and [_$_] + <code>set</code>functions.</p> + <p>Note: there is no attribute for CalendarWeekStartMonday and + using the [_$_] + <code>calendarSetDisplay</code>function resulted in a run-time + message that the first day of the week was taken from the + locale and GTK_CALENDAR_WEEK_START_MONDAY is ignored.</p> + <p>Finally, any number of days in the month may be "marked". A + marked day is highlighted within the calendar display. The + following functions (there are no attributes) are provided to + manipulate marked days:</p> + <pre class="codebox"> +calendarMarkDay :: CalendarClass self => self -> Int -> IO Bool +calendarUnmarkDay :: CalendarClass self => self -> Int -> IO Bool +calendarClearMarks :: CalendarClass self => self -> IO () +</pre> + <p>The Boolean value is not used (always True). Note that marks + are persistent across month and year changes.</p> + <p>The Calendar widget can generate a number of signals + indicating date selection and change. The names of these + signals are:</p> + <ul> + <li>onDaySelected</li> + <li>onDaySelectedDoubleClick</li> + </ul> + <p>Note: the following are also mentioned in the API + documentation, but appear to implemented as onDaySelected. See + the comment in the example code.</p> + <ul> + <li>onMonthChanged</li> + <li>onNextMonth</li> + <li>onNextYear</li> + <li>onPrevMonth</li> + <li>onPrevYear</li> + </ul> + <p>The following example illustrates the use of the Calendar + widget:</p> + <p> + <img src="./Images/GtkChap13.png" alt="GtkChap13.png" + id="graphics1" /> + </p> + <pre class="codebox"> +import Graphics.UI.Gtk + +main :: IO () +main= do + initGUI + window <- windowNew + set window [windowTitle := "Calendar", + windowDefaultWidth:= 200, + windowDefaultHeight:= 100] + mainbox <- vBoxNew True 0 + containerAdd window mainbox + + hbox1 <- hBoxNew True 0 + boxPackStart mainbox hbox1 PackGrow 0 + + cal <-calendarNew + boxPackStart hbox1 cal PackGrow 0 [_$_] + + vbox1 <- vBoxNew True 0 + frame1 <- frameNew + set frame1 [frameLabel := "Display Options", + containerBorderWidth := 10, + frameLabelYAlign := 0.5, [_$_] + frameLabelXAlign := 0.5, + containerChild := vbox1 ] + boxPackStart hbox1 frame1 PackGrow 0 + headingopt <- addDisplayOpt vbox1 "Show Heading" + daynameopt <- addDisplayOpt vbox1 "Show Day Names" + monchngopt <- addDisplayOpt vbox1 "No Month Change" + weeknumopt <- addDisplayOpt vbox1 "Show Week Numbers" + + set headingopt [toggleButtonActive := True] + set daynameopt [toggleButtonActive := True] + + reslabel <- labelNew Nothing + showMess cal reslabel "Nothing Done Yet" + frame2 <- frameNew + set frame2 [frameLabel := "Last Action:", + containerBorderWidth := 10, [_$_] + containerChild := reslabel] + boxPackStart mainbox frame2 PackGrow 0 [_$_] + + mySetOnToggled headingopt cal calendarShowHeading + mySetOnToggled daynameopt cal calendarShowDayNames + mySetOnToggled monchngopt cal calendarNoMonthChange + mySetOnToggled weeknumopt cal calendarShowWeekNumbers + + onDaySelected cal (showMess cal reslabel "Day Selected") + onDaySelectedDoubleClick cal [_$_] + (showMess cal reslabel "Double Click Day Selected") + + widgetShowAll window + onDestroy window mainQuit + mainGUI + + +addDisplayOpt :: VBox -> String -> IO CheckButton +addDisplayOpt box lbl = do + cb <- checkButtonNewWithLabel lbl + boxPackStart box cb PackGrow 5 + return cb + +mySetOnToggled :: CheckButton -> Calendar -> [_$_] + Attr Calendar Bool -> [_$_] + IO (ConnectId CheckButton) +mySetOnToggled cb cl att = onToggled cb $ do + cbstate <- get cb toggleButtonActive + set cl [att := cbstate] + +showMess :: Calendar -> Label -> String -> IO () +showMess cal lbl str = do [_$_] + (year, month, day) <- calendarGetDate cal + labelSetText lbl $ str ++ "\n" ++ "Date = " ++ + (show year) ++ "//" ++ [_$_] + (myshow (month +1)) -- month is 0 to 11 + ++ "//" ++ (myshow day) [_$_] + where myshow n | n <= 9 = '0':(show +n) + | otherwise = show n + +{- Commented out for platform specific testing: +These signals all seem to be implemented as onDaySelected. +The platform was: Gtk2Hs 0.9.12 on Fedora Core 6 + + onMonthChanged cal (showMess cal reslabel "Month Changed") + onNextMonth cal (showMess cal reslabel "Next Month Selected") + onNextYear cal (showMess cal reslabel "Next Year Selected") + onPrevMonth cal (showMess cal reslabel "Previous Month +Selected") + onPrevYear cal (showMess cal reslabel "Previous Year +Selected") +-} +</pre> + <div id="footer"> + <!-- <span class="nav-previous"><a href="chap12.xhtml">Previous</a><br />Spin Buttons</span> + --> + <span class="nav-home"> + <a href="index.xhtml">Home</a> + </span> + <!-- <span class="nav-next"><a href="chap14.xhtml">Next</a><br />Packing Demonstration Program</span> + --> + </div> + </body> +</html> |
From: Duncan C. <dun...@wo...> - 2007-09-18 12:11:46
|
Sun Sep 16 12:20:47 PDT 2007 Alex Tarkovsky <ale...@gm...> * Gtk2Hs Tutorial: XHTML-ize remaining files through chapter12; rename files according to ToC move ./docs/tutorial/Tutorial_Port/Images/GtkChap10.png ./docs/tutorial/Tutorial_Port/Images/GtkChap4-5.png move ./docs/tutorial/Tutorial_Port/Images/GtkChap11.png ./docs/tutorial/Tutorial_Port/Images/GtkChap4-6.png move ./docs/tutorial/Tutorial_Port/Images/GtkChap12.png ./docs/tutorial/Tutorial_Port/Images/GtkChap4-7.png move ./docs/tutorial/Tutorial_Port/Images/GtkChap3a.png ./docs/tutorial/Tutorial_Port/Images/GtkChap2a.png move ./docs/tutorial/Tutorial_Port/Images/GtkChap3b.png ./docs/tutorial/Tutorial_Port/Images/GtkChap2b.png move ./docs/tutorial/Tutorial_Port/Images/GtkChap4.png ./docs/tutorial/Tutorial_Port/Images/GtkChap3-1.png move ./docs/tutorial/Tutorial_Port/Images/GtkChap5a1.png ./docs/tutorial/Tutorial_Port/Images/GtkChap3-2a.png move ./docs/tutorial/Tutorial_Port/Images/GtkChap5a2.png ./docs/tutorial/Tutorial_Port/Images/GtkChap3-2b.png move ./docs/tutorial/Tutorial_Port/Images/GtkChap5b.png ./docs/tutorial/Tutorial_Port/Images/GtkChap3-3.png move ./docs/tutorial/Tutorial_Port/Images/GtkChap6a.png ./docs/tutorial/Tutorial_Port/Images/GtkChap4-1a.png move ./docs/tutorial/Tutorial_Port/Images/GtkChap6b.png ./docs/tutorial/Tutorial_Port/Images/GtkChap4-1b.png move ./docs/tutorial/Tutorial_Port/Images/GtkChap7.png ./docs/tutorial/Tutorial_Port/Images/GtkChap4-2.png move ./docs/tutorial/Tutorial_Port/Images/GtkChap8.png ./docs/tutorial/Tutorial_Port/Images/GtkChap4-3.png move ./docs/tutorial/Tutorial_Port/Images/GtkChap9.png ./docs/tutorial/Tutorial_Port/Images/GtkChap4-4.png move ./docs/tutorial/Tutorial_Port/chap10.html ./docs/tutorial/Tutorial_Port/chap4-5.xhtml move ./docs/tutorial/Tutorial_Port/chap11.html ./docs/tutorial/Tutorial_Port/chap4-6.xhtml move ./docs/tutorial/Tutorial_Port/chap12.html ./docs/tutorial/Tutorial_Port/chap4-7.xhtml move ./docs/tutorial/Tutorial_Port/chap3.xhtml ./docs/tutorial/Tutorial_Port/chap2.xhtml move ./docs/tutorial/Tutorial_Port/chap4.xhtml ./docs/tutorial/Tutorial_Port/chap3-1.xhtml move ./docs/tutorial/Tutorial_Port/chap5a.html ./docs/tutorial/Tutorial_Port/chap3-2.xhtml move ./docs/tutorial/Tutorial_Port/chap5b.html ./docs/tutorial/Tutorial_Port/chap3-3.xhtml move ./docs/tutorial/Tutorial_Port/chap6.html ./docs/tutorial/Tutorial_Port/chap4-1.xhtml move ./docs/tutorial/Tutorial_Port/chap7.html ./docs/tutorial/Tutorial_Port/chap4-2.xhtml move ./docs/tutorial/Tutorial_Port/chap8.html ./docs/tutorial/Tutorial_Port/chap4-3.xhtml move ./docs/tutorial/Tutorial_Port/chap9.html ./docs/tutorial/Tutorial_Port/chap4-4.xhtml hunk ./docs/tutorial/Tutorial_Port/chap2.xhtml 14 - <span class="nav-previous"><a href="index.xhtml">Previous</a></span> + <span class="nav-previous"><!-- a href="chap1.xhtml" -->Previous<!-- /a --></span> hunk ./docs/tutorial/Tutorial_Port/chap2.xhtml 16 - <span class="nav-next"><a href="chap4.xhtml">Next</a></span> + <span class="nav-next"><a href="chap3-1.xhtml">Next</a></span> hunk ./docs/tutorial/Tutorial_Port/chap2.xhtml 19 -<h2>Getting Started</h2> +<h2>2. Getting Started</h2> hunk ./docs/tutorial/Tutorial_Port/chap2.xhtml 45 -<p><img src="./Images/GtkChap3a.png" alt="GtkChap3a" id="GtkChap3a" /></p> +<p><img src="Images/GtkChap2a.png" alt="Window" id="imgGtkChap2a" /></p> hunk ./docs/tutorial/Tutorial_Port/chap2.xhtml 64 -ghc --make GtkChap3a.hs -o Chap3a +ghc --make GtkChap2.hs -o Chap2 hunk ./docs/tutorial/Tutorial_Port/chap2.xhtml 68 -assuming <code>GtkChap3a.hs</code> is the filename. Alternatively you can use +assuming <code>GtkChap2.hs</code> is the filename. Alternatively you can use hunk ./docs/tutorial/Tutorial_Port/chap2.xhtml 129 -<p><img src="./Images/GtkChap3b.png" alt="GtkChap3b" id="GtkChap3b" /></p> +<p><img src="Images/GtkChap2b.png" alt="Hello World application" id="imgGtkChap2b" /></p> hunk ./docs/tutorial/Tutorial_Port/chap2.xhtml 154 -<i>Inspector</i> pane. There is a +<em>Inspector</em> pane. There is a hunk ./docs/tutorial/Tutorial_Port/chap2.xhtml 171 - containerChild := button, containerBorderWidth := 10 ] + containerChild := button, containerBorderWidth := 10] hunk ./docs/tutorial/Tutorial_Port/chap2.xhtml 189 - <span class="nav-previous"><a href="index.xhtml">Previous</a><br />Table of Contents</span> + <span class="nav-previous"><!-- a href="chap1.xhtml" -->Previous<!-- /a --><br />1. Introduction</span> hunk ./docs/tutorial/Tutorial_Port/chap2.xhtml 191 - <span class="nav-next"><a href="chap4.xhtml">Next</a><br />Packing Widgets</span> + <span class="nav-next"><a href="chap3-1.xhtml">Next</a><br />3.1 Packing Widgets</span> hunk ./docs/tutorial/Tutorial_Port/chap3-1.xhtml 14 - <span class="nav-previous"><a href="chap3.xhtml">Previous</a></span> + <span class="nav-previous"><a href="chap2.xhtml">Previous</a></span> hunk ./docs/tutorial/Tutorial_Port/chap3-1.xhtml 16 - <span class="nav-next"><a href="chap5a.html">Next</a></span> + <span class="nav-next"><a href="chap3-2.xhtml">Next</a></span> hunk ./docs/tutorial/Tutorial_Port/chap3-1.xhtml 19 -<h2>Packing Widgets</h2> +<h2>3.1 Packing Widgets</h2> hunk ./docs/tutorial/Tutorial_Port/chap3-1.xhtml 67 -<p><img src="Images/GtkChap4.png" alt="GtkChap4" width="210" height="229" id="graphics1" /></p> +<p><img src="Images/GtkChap3-1.png" alt="Packed buttons" id="imgGtkChap3-1" /></p> hunk ./docs/tutorial/Tutorial_Port/chap3-1.xhtml 80 - containerBorderWidth := 10, containerChild := hbox ] + containerBorderWidth := 10, containerChild := hbox] hunk ./docs/tutorial/Tutorial_Port/chap3-1.xhtml 123 - <span class="nav-previous"><a href="chap3.xhtml">Previous</a><br />Getting Started</span> + <span class="nav-previous"><a href="chap2.xhtml">Previous</a><br />2. Getting Started</span> hunk ./docs/tutorial/Tutorial_Port/chap3-1.xhtml 125 - <span class="nav-next"><a href="chap5a.html">Next</a><br />Packing Demonstration Program</span> + <span class="nav-next"><a href="chap3-2.xhtml">Next</a><br />3.2 Packing Demonstration Program</span> hunk ./docs/tutorial/Tutorial_Port/chap3-2.xhtml 1 -<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> - -<html> +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> hunk ./docs/tutorial/Tutorial_Port/chap3-2.xhtml 5 - <meta name="generator" content= - "HTML Tidy for Linux/x86 (vers 11 February 2007), see www.w3.org"> - <meta http-equiv="CONTENT-TYPE" content= - "text/html; charset=us-ascii"> - - <title>Packing Demonstration Program</title> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <title>Gtk2Hs Tutorial: Packing Demonstration Program</title> + <link href="default.css" type="text/css" rel="stylesheet" /> hunk ./docs/tutorial/Tutorial_Port/chap3-2.xhtml 10 -<body lang="en-US" text="#000000" link="#0000FF" vlink="#840084" -bgcolor="#FFFFFF" dir="ltr"> - <table summary="links to other pages" width="100%" border="0" - cellpadding="0" cellspacing="0" style= - "page-break-before: always"> - <tr> - <th colspan="3"> - <p align="center">Gtk2HsTutorial</p> - </th> - </tr> - - <tr valign="bottom"> - <td width="10%"> - <p align="left"><a href= - "chap4.html"><<<Previous</a></p> - </td> - - <td width="80%"> - <p align="center">Packing Demonstration</p> - </td> +<body> hunk ./docs/tutorial/Tutorial_Port/chap3-2.xhtml 12 - <td width="10%"> - <p align="right"><a href="chap5b.html">Next - >>></a></p> - </td> - </tr> - </table> - <hr> +<div id="header"> + <h1>Gtk2Hs Tutorial</h1> + <span class="nav-previous"><a href="chap3-1.xhtml">Previous</a></span> + <span class="nav-home"><a href="index.xhtml">Home</a></span> + <span class="nav-next"><a href="chap3-3.xhtml">Next</a></span> +</div> hunk ./docs/tutorial/Tutorial_Port/chap3-2.xhtml 19 - <h1><a name="SEC-PACKINGDEMONSTRATIONPROGRAM" id= - "SEC-PACKINGDEMONSTRATIONPROGRAM"></a>Packing Demonstration - Program</h1> +<h2>3.2 Packing Demonstration Program</h2> hunk ./docs/tutorial/Tutorial_Port/chap3-2.xhtml 21 - <p>The base of all widgets here is a vertical box, which itself - is a child of the window. The child widgets are not displayed - homogeneously and there is no additional spacing (other than the - standard spacing). There are 6 horizontal boxes in the vertical - box, as defined by the function makeBox, which has the type as - shown. Furthermore, there are 2 labels in the vertical box as - well as 2 horizontal separators. The last widget is the quit - button, whose <i>onClicked</i> signal is attached to the - <i>mainQuit</i> function.</p> +<p> +The base of all widgets here is a vertical box, which itself is a child of the +window. The child widgets are not displayed homogeneously and there is no +additional spacing (other than the standard spacing). There are six horizontal +boxes in the vertical box, as defined by the function <code>makeBox</code>, +which has the type as shown. Furthermore, there are two labels in the vertical +box as well as two horizontal separators. The last widget is the <em>Quit</em> +button, whose <code>onClicked</code> signal is attached to the +<code>mainQuit</code> function. +</p> hunk ./docs/tutorial/Tutorial_Port/chap3-2.xhtml 32 - <p>The separators are created with <i>hSeparatorNew</i> and they - are spaced by <i>boxPackStart</i> with a padding of 10 pixels. - The labels are created by <i>labelNew</i> which takes a <i>Maybe - String</i> and their positioning is set by - <i>miscSetAlignment</i> to be left and top justified.</p> +<p> +The separators are created with <code>hSeparatorNew</code> and they are spaced +by <code>boxPackStart</code> with a padding of ten pixels. The labels are +created by <code>labelNew</code> which takes a <code>Maybe String</code> and +their positioning is set by <code>miscSetAlignment</code> to be left and top +justified. +</p> hunk ./docs/tutorial/Tutorial_Port/chap3-2.xhtml 40 - <p><br></p> +<p><img src="Images/GtkChap3-2a.png" alt="Packing demo application" id="imgGtkChap3-2a" /></p> hunk ./docs/tutorial/Tutorial_Port/chap3-2.xhtml 42 - <p><img src="Images/GtkChap5a1.png" name="graphics1" alt= - "GtkChap5a" align="bottom" width="505" height="328" border="0" - id="graphics1"></p> +<p> +The function <code>makeBox :: Bool -> Int -> Packing -> Int -> IO +HBox</code> demonstrates how Gtk2Hs widgets fit into the Haskell type system. +<code>Packing</code> is just a type like <code>Int</code> and <code>Bool</code> +and <code>IO HBox</code> is just like <code>IO String</code> in the usual +<code>IO</code>. The function creates five buttons, labels them with the +appropriate text and packs them into a horizontal box. The function is then +used in the main program to create the desired ways of packing. +</p> hunk ./docs/tutorial/Tutorial_Port/chap3-2.xhtml 52 - <p>The function <i>makeBox :: Bool -> Int -> Packing -> - Int -> IO HBox</i> demonstrates how Gtk2Hs widgets fit into - the Haskell type system. <i>Packing</i> is just a type like - <i>Int</i> and <i>Bool</i> and <i>IO HBox is just like IO - String</i> in the usual IO. The function creates 5 buttons, - labels them with the appropriate text and packs them into a - horizontal box. The function is then used in the main program to - create the desired ways of packing.</p><br> - - <table summary="Haskell code" width="100%" border="0" - cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> - <tr> - <td> - <pre> +<pre class="codebox"> hunk ./docs/tutorial/Tutorial_Port/chap3-2.xhtml 57 - initGUI - window <- windowNew - vbox <- vBoxNew False 0 - set window [containerBorderWidth := 10, [_$_] - windowTitle := "Packing Demonstration", - containerChild := vbox ] - label1 <- labelNew (Just "hBoxNew False 0") - miscSetAlignment label1 0 0 - boxPackStart vbox label1 PackNatural 0 - box1 <- makeBox False 0 PackNatural 0 - boxPackStart vbox box1 PackNatural 0 - box2 <- makeBox False 0 PackRepel 0 - boxPackStart vbox box2 PackNatural 0 [_$_] - box3 <- makeBox False 0 PackGrow 0 - boxPackStart vbox box3 PackNatural 0 - sep1 <- hSeparatorNew - boxPackStart vbox sep1 PackNatural 10 [_$_] - label2 <- labelNew (Just "hBoxNew True 0") - miscSetAlignment label2 0 0 - boxPackStart vbox label2 PackNatural 0 - box4 <- makeBox True 0 PackNatural 0 - boxPackStart vbox box4 PackNatural 0 - box5 <- makeBox True 0 PackRepel 0 - boxPackStart vbox box5 PackNatural 0 [_$_] - box6 <- makeBox False 0 PackGrow 0 - boxPackStart vbox box6 PackNatural 0 - sep <- hSeparatorNew - boxPackStart vbox sep PackNatural 10 [_$_] - quitbox <- hBoxNew False 0 - boxPackStart vbox quitbox PackNatural 0 - quitbutton <- buttonNewWithLabel "Quit" - boxPackStart quitbox quitbutton PackRepel 0 - onClicked quitbutton mainQuit [_$_] - onDestroy window mainQuit [_$_] - widgetShowAll window - mainGUI + initGUI + window <- windowNew + vbox <- vBoxNew False 0 + set window [containerBorderWidth := 10, + windowTitle := "Packing Demonstration", + containerChild := vbox] + label1 <- labelNew (Just "hBoxNew False 0") + miscSetAlignment label1 0 0 + boxPackStart vbox label1 PackNatural 0 + box1 <- makeBox False 0 PackNatural 0 + boxPackStart vbox box1 PackNatural 0 + box2 <- makeBox False 0 PackRepel 0 + boxPackStart vbox box2 PackNatural 0 + box3 <- makeBox False 0 PackGrow 0 + boxPackStart vbox box3 PackNatural 0 + sep1 <- hSeparatorNew + boxPackStart vbox sep1 PackNatural 10 + label2 <- labelNew (Just "hBoxNew True 0") + miscSetAlignment label2 0 0 + boxPackStart vbox label2 PackNatural 0 + box4 <- makeBox True 0 PackNatural 0 + boxPackStart vbox box4 PackNatural 0 + box5 <- makeBox True 0 PackRepel 0 + boxPackStart vbox box5 PackNatural 0 + box6 <- makeBox False 0 PackGrow 0 + boxPackStart vbox box6 PackNatural 0 + sep <- hSeparatorNew + boxPackStart vbox sep PackNatural 10 + quitbox <- hBoxNew False 0 + boxPackStart vbox quitbox PackNatural 0 + quitbutton <- buttonNewWithLabel "Quit" + boxPackStart quitbox quitbutton PackRepel 0 + onClicked quitbutton mainQuit + onDestroy window mainQuit + widgetShowAll window + mainGUI hunk ./docs/tutorial/Tutorial_Port/chap3-2.xhtml 97 - box <- hBoxNew homogeneous spacing - button1 <- buttonNewWithLabel "boxPackStart" - boxPackStart box button1 packing padding - button2 <- buttonNewWithLabel "box" - boxPackStart box button2 packing padding - button3 <- buttonNewWithLabel "button" - boxPackStart box button3 packing padding - button4 <- case packing of [_$_] - PackNatural -> buttonNewWithLabel "PackNatural" - PackRepel -> buttonNewWithLabel "PackRepel" - PackGrow -> buttonNewWithLabel "PackGrow" - boxPackStart box button4 packing padding [_$_] - button5 <- buttonNewWithLabel (show padding) - boxPackStart box button5 packing padding [_$_] - return box + box <- hBoxNew homogeneous spacing + button1 <- buttonNewWithLabel "boxPackStart" + boxPackStart box button1 packing padding + button2 <- buttonNewWithLabel "box" + boxPackStart box button2 packing padding + button3 <- buttonNewWithLabel "button" + boxPackStart box button3 packing padding + button4 <- case packing of + PackNatural -> buttonNewWithLabel "PackNatural" + PackRepel -> buttonNewWithLabel "PackRepel" + PackGrow -> buttonNewWithLabel "PackGrow" + boxPackStart box button4 packing padding + button5 <- buttonNewWithLabel (show padding) + boxPackStart box button5 packing padding + return box hunk ./docs/tutorial/Tutorial_Port/chap3-2.xhtml 113 - </td> - </tr> - </table> - - <p>The image below shows the effects of resizing the window - horizontally. In the first group, with homogeneous <i>False</i> - horizontal resizing leaves the first row of buttons as it is, - spaces the second row evenly, and enlarges the buttons in the - third row. In the second group the buttons are set to be packed - homogeneously, and the first 2 rows will look the same. Resizing - the window vertically just add extra space at the end, because - the vertical box was initialized with <i>False</i>.</p><img src= - "Images/GtkChap5a2.png" name="graphics2" alt="GtkChap5a resized" - align="bottom" id="graphics2"><br> - <hr> - - <table summary="links to other pages" width="100%" border="0" - cellpadding="0" cellspacing="0"> - <tr valign="top"> - <td width="33%"> - <p align="left"><a href="chap4.html"><<< - Previous</a></p> - </td> - - <td width="34%"> - <p align="center"><a href="chap1.html">Home</a></p> - </td> hunk ./docs/tutorial/Tutorial_Port/chap3-2.xhtml 114 - <td width="33%"> - <p align="right"><a href="chap5b.html">Next - >>></a></p> - </td> - </tr> +<p> +The image below shows the effects of resizing the window horizontally. In the +first group, with <var>homogeneous</var> set to <var>False</var> horizontal +resizing leaves the first row of buttons as it is, spaces the second row +evenly, and enlarges the buttons in the third row. In the second group the +buttons are set to be packed homogeneously, and the first two rows will look +the same. Resizing the window vertically just adds extra space at the end, +because the vertical box was initialized with <var>False</var>. +</p> hunk ./docs/tutorial/Tutorial_Port/chap3-2.xhtml 124 - <tr valign="top"> - <td width="50%"> - <p align="left">Packing Widgets</p> - </td> +<p><img src="Images/GtkChap3-2b.png" alt="Resized packing demo application" id="imgGtkChap3-2b" /></p> hunk ./docs/tutorial/Tutorial_Port/chap3-2.xhtml 126 - <td width="50%"> - <p align="right">Packing Using Tables</p> - </td> - </tr> - </table> +<div id="footer"> + <span class="nav-previous"><a href="chap3-1.xhtml">Previous</a><br />3.1 Packing Widgets</span> + <span class="nav-home"><a href="index.xhtml">Home</a></span> + <span class="nav-next"><a href="chap3-3.xhtml">Next</a><br />3.3 Packing Using Tables</span> +</div> hunk ./docs/tutorial/Tutorial_Port/chap3-2.xhtml 132 - <p><br> - <br></p> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 1 -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> - -<html> +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 5 - <meta name="generator" content= - "HTML Tidy for Linux/x86 (vers 11 February 2007), see www.w3.org"> - <meta http-equiv="CONTENT-TYPE" content= - "text/html; charset=us-ascii"> - - <title>Packing Using Tables</title> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <title>Gtk2Hs Tutorial: Packing Using Tables</title> + <link href="default.css" type="text/css" rel="stylesheet" /> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 10 -<body lang="en-US" text="#000000" link="#0000FF" vlink="#840084" -bgcolor="#FFFFFF" dir="ltr"> - <table summary="links to other pages" width="100%" border="0" - cellpadding="0" cellspacing="0"> - <tr> - <th colspan="3"> - <p align="center">Gtk2Hs Tutorial</p> - </th> - </tr> - - <tr valign="bottom"> - <td width="10%"> - <p align="left"><a href="chap5a.html"><<< - Previous</a></p> - </td> - - <td width="80%"> - <p align="center">Tables</p> - </td> +<body> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 12 - <td width="10%"> - <p align="right"><a href="chap6.html">Next - >>></a></p> - </td> - </tr> - </table> - <hr> +<div id="header"> + <h1>Gtk2Hs Tutorial</h1> + <span class="nav-previous"><a href="chap3-2.xhtml">Previous</a></span> + <span class="nav-home"><a href="index.xhtml">Home</a></span> + <span class="nav-next"><a href="chap4-1.xhtml">Next</a></span> +</div> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 19 - <h2><a name="SEC-PACKINGUSINGTABLES" id= - "SEC-PACKINGUSINGTABLES"></a>Packing Using Tables</h2> +<h2>3.3 Packing Using Tables</h2> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 21 - <p>Let's take a look at another way of packing - Tables. These - can be extremely useful in certain situations.</p> +<p> +Let's take a look at another way of packing: <em>tables</em>. These can be +extremely useful in certain situations. Using tables, we create a grid that we +can place widgets in. The widgets may take up as many spaces as we specify. +</p> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 27 - <p>Using tables, we create a grid that we can place widgets in. - The widgets may take up as many spaces as we specify.</p> +<p> +The first thing to look at, of course, is the <code>tableNew</code> function: +</p> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 31 - <p>The first thing to look at, of course, is the <i>tableNew</i> - function:</p> - - <table summary="Haskell code" width="100%" border="0" - cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> - <tr> - <td> - <pre> +<pre class="codebox"> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 34 - </td> - </tr> - </table> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 35 - <p>The first argument is the number of rows to make in the table, - while the second, obviously, is the number of columns.</p> +<p> +The first argument is the number of rows to make in the table, while the +second, obviously, is the number of columns. +</p> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 40 - <p>The boolean argument (homogeneous) has to do with how the - table's boxes are sized. If homogeneous is TRUE, the table boxes - are resized to the size of the largest widget in the table. If - homogeneous is FALSE, the size of a table boxes is dictated by - the tallest widget in its same row, and the widest widget in its - column.</p> +<p> +The boolean argument (<var>homogeneous</var>) has to do with how the table's +boxes are sized. If <var>homogeneous</var> is set to <var>True</var>, the table +boxes are resized to the size of the largest widget in the table. If +<var>homogeneous</var> is <var>False</var>, the size of a table boxes is +dictated by the tallest widget in its same row, and the widest widget in its +column. +</p> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 49 - <p>The rows and columns are laid out from 0 to n, where n was the - number specified in the call to <i>tableNew</i>. So, if you - specify rows = 2 and columns = 2, the layout would look something - like this:</p> +<p> +The rows and columns are laid out from <var>0</var> to <var>n</var>, where +<var>n</var> was the number specified in the call to <code>tableNew</code>. So +if you specify <var>rows</var> = <var>2</var> and <var>columns</var> = +<var>2</var>, the layout would look something like this: +</p> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 56 - <table summary="Haskell code" width="100%" border="0" - cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> - <tr> - <td> - <pre> +<pre class="codebox"> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 64 - </td> - </tr> - </table> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 65 - <p>Note that the coordinate system starts in the upper left hand - corner. To place a widget into a box, use the following - function:</p> +<p> +Note that the coordinate system starts in the upper left hand corner. To place +a widget into a box, use the following function: +</p> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 70 - <table summary="Haskell code" width="100%" border="0" - cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> - <tr> - <td> - <pre> -tableAttach :: (TableClass self, WidgetClass child) => [_$_] - self -- self - the table - -> child -- child - The widget to add. - -> Int [_$_] --- leftAttach - the column number to attach the left side of a child widget to. - -> Int [_$_] --- rightAttach - the column number to attach the right side of a child widget to. - -> Int -- topAttach - the row number to attach the top of a child widget to. - -> Int -- bottomAttach - the row number to attach the bottom of a child widget to. - -> [AttachOptions] [_$_] --- xoptions - Used to specify the properties of the child widget when the table is resized. - -> [AttachOptions] [_$_] --- yoptions - The same as xoptions, except this field determines behaviour of vertical resizing. - -> Int [_$_] --- xpadding - An integer value specifying the padding on the left and right of the widget being added to the table. - -> Int -- ypadding - The amount of padding above and below the child widget. +<pre class="codebox"> +tableAttach :: (TableClass self, WidgetClass child) + => self -- self - The table. + -> child -- child - The widget to add. + -> Int -- leftAttach - The column number to attach the left + -- side of a child widget to. + -> Int -- rightAttach - The column number to attach the right + -- side of a child widget to. + -> Int -- topAttach - The row number to attach the top of a + -- child widget to. + -> Int -- bottomAttach - The row number to attach the bottom + -- of a child widget to. + -> [AttachOptions] -- xoptions - Used to specify the properties of the + -- child widget when the table is + -- resized. + -> [AttachOptions] -- yoptions - The same as xoptions, except this + -- field determines behaviour of + -- vertical resizing. + -> Int -- xpadding - An integer value specifying the + -- padding on the left and right of the + -- widget being added to the table. + -> Int -- ypadding - The amount of padding above and below + -- the child widget. hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 95 - </td> - </tr> - </table> - - <p>The first argument (self) is the table you've created and the - second (child) the widget you wish to place in the table.</p> - - <p>The left and right attach arguments specify where to place the - widget, and how many boxes to use. If you want a button in the - lower right table entry of our 2x2 table, and want it to fill - that entry <i>only</i>, left_attach would be = 1, right_attach = - 2, top_attach = 1, bottom_attach = 2.</p> - - <p>Now, if you wanted a widget to take up the whole top row of - our 2x2 table, you'd use left_attach = 0, right_attach = 2, - top_attach = 0, bottom_attach = 1.</p> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 96 - <p>The xoptions and yoptions are used to specify packing options - and the list may contain more than one to allow multiple - options.</p> +<p> +The first argument (<var>self</var>) is the table you've created and the second +(<var>child</var>) is the widget you wish to place in the table. +</p> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 101 - <p>These options are:</p> +<p> +The left and right attach arguments specify where to place the widget, and how +many boxes to use. If you want a button in the lower right table entry of our +2x2 table, and want it to fill that entry <em>only</em>, +<var>leftAttach</var> would be = <var>1</var>, <var>rightAttach</var> = +<var>2</var>, <var>topAttach</var> = <var>1</var>, and <var>bottomAttach</var> += <var>2</var>. +</p> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 110 - <dl> - <dt><tt>Fill</tt></dt> +<p> +Now, if you wanted a widget to take up the whole top row of our 2x2 table, +you'd use <var>leftAttach</var> = <var>0</var>, <var>rightAttach</var> = +<var>2</var>, <var>topAttach</var> = 0, and <var>bottomAttach</var> = +<var>1</var>. +</p> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 117 - <dd>If the table box is larger than the widget, and - <tt>Fill</tt> is specified, the widget will expand to use all - the room available.</dd> +<p> +The <var>xoptions</var> and <var>yoptions</var> are used to specify packing +options and the list may contain more than one to allow multiple options. +</p> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 122 - <dt><tt>Shrink</tt></dt> +<p>These options are:</p> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 124 - <dd>If the table widget was allocated less space then was - requested (usually by the user resizing the window), then the - widgets would normally just be pushed off the bottom of the - window and disappear. If <tt>Shrink</tt> is specified, the - widgets will shrink with the table.</dd> +<dl> + <dt><code>Fill</code></dt> + <dd> + If the table box is larger than the widget, and <code>Fill</code> is + specified, the widget will expand to use all the room available. + </dd> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 131 - <dt><tt>Expand</tt></dt> + <dt><code>Shrink</code></dt> + <dd> + If the table widget was allocated less space then was requested (usually by + the user resizing the window), then the widgets would normally just be pushed + off the bottom of the window and disappear. If <code>Shrink</code> is + specified, the widgets will shrink with the table. + </dd> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 139 - <dd>This will cause the table to expand to use up any remaining - space in the window.</dd> - </dl> + <dt><code>Expand</code></dt> + <dd> + This will cause the table to expand to use up any remaining space in the + window. + </dd> +</dl> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 146 - <p>Padding is just like in boxes, creating a clear area around - the widget specified in pixels.</p> +<p> +Padding is just like in boxes, creating a clear area around the widget +specified in pixels. +</p> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 151 - <p><i>tableAttach</i> has many options. So, there's a - shortcut:</p> +<p> +<code>tableAttach</code> has many options, so there's a shortcut: +</p> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 155 - <table summary="Haskell code" width="100%" border="0" - cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> - <tr> - <td> - <pre> -tableAttachDefaults :: (TableClass self, WidgetClass widget) => self [_$_] - -> widget -- widget - The child widget to add. - -> Int [_$_] --- leftAttach - The column number to attach the left side of the child widget to. - -> Int [_$_] --- rightAttach - The column number to attach the right side of the child widget to. - -> Int [_$_] --- topAttach - The row number to attach the top of the child widget to. - -> Int [_$_] --- bottomAttach - The row number to attach the bottom of the child widget to. +<pre class="codebox"> +tableAttachDefaults :: (TableClass self, WidgetClass widget) + => self -- self - The table. + -> widget -- widget - The child widget to add. + -> Int -- leftAttach - The column number to attach the left side of + -- the child widget to. + -> Int -- rightAttach - The column number to attach the right side of + -- the child widget to. + -> Int -- topAttach - The row number to attach the top of the child + -- widget to. + -> Int -- bottomAttach - The row number to attach the bottom of the + -- child widget to. hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 169 - </td> - </tr> - </table> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 170 - <p>The values used for the <i>AttachOptions</i> are <tt>[Expand, - Fill]</tt>, and the padding is set to 0. The rest of the - arguments are identical to the previous function.</p> +<p> +The values used for the <code>[AttachOptions]</code> parameters are +<var>[Expand, Fill]</var>, and the padding is set to <var>0</var>. The rest of +the arguments are identical to the previous function. +</p> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 176 - <p>We also have tableSetRowSpacing and tableSetColSpacing. These - place spacing at the specified row or column.</p> +<p> +We also have <code>tableSetRowSpacing</code> and +<code>tableSetColSpacing</code>. These place spacing at the specified row or +column. +</p> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 182 - <table summary="Haskell code" width="100%" border="0" - cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> - <tr> - <td> - <pre> +<pre class="codebox"> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 185 - </td> - </tr> - </table> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 186 - <p>and,</p> - - <table summary="Haskell code" width="100%" border="0" - cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> - <tr> - <td> - <pre> +<pre class="codebox"> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 189 - </td> - </tr> - </table> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 190 - <p>The first <i>Int</i> argument is the row/column and the second - the spacing in pixels. Note that for columns, the space goes to - the right of the column, and for rows, the space goes below the - row.</p> +<p> +The first <code>Int</code> argument is the row/column and the second is the +spacing in pixels. Note that for columns, the space goes to the right of the +column, and for rows, the space goes below the row. +</p> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 196 - <p>You can also set a consistent spacing of all rows and/or - columns with:</p> +<p> +You can also set a consistent spacing of all rows and/or columns with: +</p> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 200 - <table summary="Haskell code" width="100%" border="0" - cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> - <tr> - <td> - <pre> +<pre class="codebox"> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 203 - </td> - </tr> - </table> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 204 - <p>and,</p> +<p>and:</p> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 206 - <table summary="Haskell code" width="100%" border="0" - cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> - <tr> - <td> - <pre> +<pre class="codebox"> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 209 - </td> - </tr> - </table> - - <p>Note that with these calls, the last row and last column do - not get any spacing.</p> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 210 - <p><br> - <br></p> +<p> +Note that with these calls, the last row and last column do not get any +spacing. +</p> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 215 - <h2><a name="SEC-TABLEPACKINGEXAMPLES" id= - "SEC-TABLEPACKINGEXAMPLES"></a>Table Packing Example</h2> +<h3>Table Packing Example</h3> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 217 - <p>Here we make a window with three buttons in a 2x2 table. The - first two buttons will be placed in the upper row. A third, quit - button, is placed in the lower row, spanning both columns. Which - means it should look something like this:</p> +<p> +Here we make a window with three buttons in a 2x2 table. The first two buttons +will be placed in the upper row. A third button (<em>Quit</em>) is placed in +the lower row, spanning both columns, which means it should look something like +this: +</p> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 224 - <p><img src="Images/GtkChap5b.png" align="bottom" alt= - "Table Packing"></p> +<p><img src="Images/GtkChap3-3.png" alt="Table packing" id="imgGtkChap3-3" /></p> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 226 - <p>Here's the source code:</p> +<p>Here's the source code:</p> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 228 - <table summary="Haskell code" width="100%" border="0" - cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> - <tr> - <td> - <pre> +<pre class="codebox"> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 233 - initGUI - window <- windowNew - set window [windowTitle := "Table", containerBorderWidth := 20, - windowDefaultWidth := 150, windowDefaultHeight := 100 ] - table <- tableNew 2 2 True - containerAdd window table - button1 <- buttonNewWithLabel "On" - onClicked button1 (buttonSwitch button1) - tableAttachDefaults table button1 0 1 0 1 - button2 <- buttonNewWithLabel "Off" - onClicked button2 (buttonSwitch button2) - tableAttachDefaults table button2 1 2 0 1 - button3 <- buttonNewWithLabel "Quit" - onClicked button3 mainQuit - tableAttachDefaults table button3 0 2 1 2 - onDestroy window mainQuit [_$_] - widgetShowAll window - mainGUI + initGUI + window <- windowNew + set window [windowTitle := "Table", containerBorderWidth := 20, + windowDefaultWidth := 150, windowDefaultHeight := 100] + table <- tableNew 2 2 True + containerAdd window table + button1 <- buttonNewWithLabel "On" + onClicked button1 (buttonSwitch button1) + tableAttachDefaults table button1 0 1 0 1 + button2 <- buttonNewWithLabel "Off" + onClicked button2 (buttonSwitch button2) + tableAttachDefaults table button2 1 2 0 1 + button3 <- buttonNewWithLabel "Quit" + onClicked button3 mainQuit + tableAttachDefaults table button3 0 2 1 2 + onDestroy window mainQuit + widgetShowAll window + mainGUI hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 254 - txt <- buttonGetLabel b - let newtxt = case txt of - "Off" -> "On" - "On" -> "Off" - buttonSetLabel b newtxt [_$_] + txt <- buttonGetLabel b + let newtxt = case txt of + "Off" -> "On" + "On" -> "Off" + buttonSetLabel b newtxt hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 260 - </td> - </tr> - </table> - <hr> - - <p>The <i>buttonSwitch</i> function is attached to both buttons - in the top row. The <i>buttonGetLabel</i> function is an example - of how to get an attribute from a widget using a standard method. - There is also a more general alternative <i>get</i> (analogous to - <i>set</i>) which takes a widget and an attribute. In the above - example this should be:</p> - - <table summary="Haskell code" width="100%" border="0" - cellpadding="2" cellspacing="0" bgcolor="#E0E0E0"> - <col width="256*"> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 261 - <tr> - <td width="100%"> - <p>txt <- get b buttonLabel</p> - </td> - </tr> - </table> +<p> +The <code>buttonSwitch</code> function is attached to both buttons in the top +row. The <code>buttonGetLabel</code> function is an example of how to get an +attribute from a widget using a standard method. There is also a more general +alternative <code>get</code> (analogous to <code>set</code>) which takes a +widget and an attribute. In the above example this should be: +</p> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 269 - <p>with the same result.</p> - - <table summary="links to other pages" width="100%" border="0" - cellpadding="0" cellspacing="0"> - <tr valign="top"> - <td width="33%"> - <p align="left"><a href="chap5a.html"><<< - Previous</a></p> - </td> - - <td width="34%"> - <p align="center"><a href="chap1.html">Home</a></p> - </td> - - <td width="33%"> - <p align="right"><a href="chap6.html">Next - >>></a></p> - </td> - </tr> +<pre class="codebox"> + txt <- get b buttonLabel +</pre> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 273 - <tr valign="top"> - <td width="33%"> - <p align="left">Packing Demonstration</p> - </td> +<p> +with the same result. +</p> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 277 - <td width="33%"> - <p align="right">Button Widget</p> - </td> - </tr> - </table> +<div id="footer"> + <span class="nav-previous"><a href="chap3-2.xhtml">Previous</a><br />3.2 Packing Demonstration Program</span> + <span class="nav-home"><a href="index.xhtml">Home</a></span> + <span class="nav-next"><a href="chap4-1.xhtml">Next</a><br />4.1 The Button Widget</span> +</div> hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 283 - <p><br> - <br></p> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 1 -<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> - -<html> +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 5 - <meta name="generator" content= - "HTML Tidy for Linux/x86 (vers 11 February 2007), see www.w3.org"> - <meta http-equiv="CONTENT-TYPE" content= - "text/html; charset=us-ascii"> - - <title>The Button Widget</title> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <title>Gtk2Hs Tutorial: The Button Widget</title> + <link href="default.css" type="text/css" rel="stylesheet" /> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 10 -<body lang="en-US" text="#000000" link="#0000FF" vlink="#840084" -bgcolor="#FFFFFF" dir="ltr"> - <table summary="links to other pages" width="100%" border="0" - cellpadding="0" cellspacing="0"> - <tr> - <th colspan="3"> - <p align="center">GTK2Hs Tutorial</p> - </th> - </tr> - - <tr valign="bottom"> - <td width="10%"> - <p align="left"><a href= - "chap5b.html"><<<Previous</a></p> - </td> +<body> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 12 - <td width="80%"></td> +<div id="header"> + <h1>Gtk2Hs Tutorial</h1> + <span class="nav-previous"><a href="chap3-3.xhtml">Previous</a></span> + <span class="nav-home"><a href="index.xhtml">Home</a></span> + <span class="nav-next"><a href="chap4-2.xhtml">Next</a></span> +</div> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 19 - <td width="10%"> - <p align="right"><a href="chap7.html">Next - >>></a></p> - </td> - </tr> - </table> - <hr> +<h2>4.1 The Button Widget</h2> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 21 - <h2><a name="CH-BUTTONWIDGET" id="CH-BUTTONWIDGET"></a>The Button - Widget</h2> +<h3>Normal Buttons</h3> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 23 - <h2><a name="SEC-NORMALBUTTONS" id="SEC-NORMALBUTTONS"></a>Normal - Buttons</h2> +<p> +We've almost seen all there is to see of the button widget. It's pretty simple. +There is however more than one way to create a button. You can use the +<code>buttonNewWithLabel</code> or <code>buttonNewWithMnemonic</code> to create +a button with a label, use <code>buttonNewFromStock</code> to create a button +containing the image and text from a stock item or use <code>buttonNew</code> +to create a blank button. It's then up to you to pack a label or pixmap into +this new button. To do this, create a new box, and then pack your objects into +this box using the usual <code>boxPackStart</code> (or <code>boxPackEnd</code> +to pack from the end), and then use <code>containerAdd</code> to pack the box +into the button. +</p> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 36 - <p>We've almost seen all there is to see of the button widget. - It's pretty simple. There is however more than one way to create - a button. You can use the <i>buttonNewWithLabel</i> or - <i>buttonNewWithMnemonic</i> to create a button with a label, use - <i>buttonNewFromStock</i> to create a button containing the image - and text from a stock item or use <i>buttonNew</i> to create a - blank button. It's then up to you to pack a label or pixmap into - this new button. To do this, create a new box, and then pack your - objects into this box using the usual <i>boxPackStart</i> (or - <i>boxPackEnd</i> to pack from the end), and then use - <i>containerAdd</i> to pack the box into the button.</p> +<p> +<code>buttonNewWithMnemonic</code> and <code>buttonNewFromStock</code> both +take a string as first argument. Use an underline to mark a character as a +mnemonic, which is a keyboard accelerator. Pressing <strong>Alt</strong> and +that key activates the button. In the second function the string is a +<code>stockId</code>, an identifier to a list of predefined images with labels. +</p> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 44 - <p align="center"><i>buttonNewWithMnemonic</i> and - <i>buttonNewFromStock</i> both take a string as first argument. - Use an underline to mark a character as a mnemonic, which is a - keyboard accelarator. Pressing Alt and that key activates the - button. In the second function the string is a <i>stockId</i>, an - identifier to a list of predefined images with labels.</p> +<p> +Here's an example of using <code>buttonNew</code> to create a button with an +image and a label in it. +</p> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 49 - <p>Here's an example of using <i>buttonNew</i> to create a button - with a image and a label in it.</p> +<p><img src="Images/GtkChap4-1a.png" alt="Button with image" id="imgGtkChap4-1a" /></p> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 51 - <p><img src="./Images/GtkChap6a.png" name="graphics1" alt= - "Chap6a" align="bottom" id="graphics1"></p> - - <table summary="Haskell code" width="100%" border="0" - cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> - <tr> - <td> - <pre> +<pre class="codebox"> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 59 - containerBorderWidth := 10 ] + containerBorderWidth := 10] hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 62 - box <- labelBox "info.xpm" "cool button" + box <- labelBox "info.xpm" "cool button" hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 71 - box <- hBoxNew False 0 - set box [containerBorderWidth := 2 ] + box <- hBoxNew False 0 + set box [containerBorderWidth := 2] hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 75 - boxPackStart box image PackNatural 3 [_$_] + boxPackStart box image PackNatural 3 hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 77 - return box [_$_] + return box hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 79 - </td> - </tr> - </table> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 80 - <p>The <i>labelBox</i> function could be used to pack images and - labels into any widget that can be a container. The image comes - from a file using <i>imageNewFromFile</i> and the label comes - from <i>labelNew</i> , which takes a <i>Maybe String</i> as its - argument. <i>Nothing</i> means no label.</p> +<p> +The <code>labelBox</code> function could be used to pack images and labels into +any widget that can be a container. The image comes from a file using +<code>imageNewFromFile</code> and the label comes from <code>labelNew</code>, +which takes a <code>Maybe String</code> as its argument. <code>Nothing</code> +means no label. +</p> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 88 - <p>The <i>Button</i> widget has the following basic signals, - which are almost self explaining:</p> +<p> +The <code>Button</code> widget has the following basic signals, which are +almost self-explanatory: +</p> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 93 - <ul> - <li> - <p><tt>onPressed</tt> - emitted when pointer button is - pressed within Button widget</p> - </li> +<ul> + <li> + <code>onPressed</code> - emitted when pointer button is pressed within + <code>Button</code> widget + </li> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 99 - <li> - <p><tt>onReleased</tt> - emitted when pointer button is - released within Button widget</p> - </li> + <li> + <code>onReleased</code> - emitted when pointer button is released within + <code>Button</code> widget + </li> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 104 - <li> - <p><tt>onClicked</tt> - emitted when pointer button is - pressed and then released within Button widget</p> - </li> + <li> + <code>onClicked</code> - emitted when pointer button is pressed and then + released within <code>Button</code> widget + </li> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 109 - <li> - <p><tt>onEnter</tt> - emitted when pointer enters Button - widget</p> - </li> + <li> + <code>onEnter</code> - emitted when pointer enters <code>Button</code> widget + </li> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 113 - <li> - <p><tt>onLeave</tt> - emitted when pointer leaves Button - widget</p> - </li> - </ul> - <hr> + <li> + <code>onLeave</code> - emitted when pointer leaves <code>Button</code> widget + </li> +</ul> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 118 - <h2><a name="SEC-TOGGLEBUTTONS" id="SEC-TOGGLEBUTTONS"></a>Toggle - Buttons</h2> +<h3>Toggle Buttons</h3> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 120 - <p>Toggle buttons are derived from normal buttons and are very - similar, except they will always be in one of two states, - alternated by a click. They may be depressed, and when you click - again, they will pop back up. Click again, and they will pop back - down.</p> +<p> +Toggle buttons are derived from normal buttons and are very similar, except +they will always be in one of two states, alternated by a click. They may be +depressed, and when you click again, they will pop back up. Click again, and +they will pop back down. +</p> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 127 - <p>Toggle buttons are the basis for check buttons and radio - buttons, as such, many of the calls used for toggle buttons are - inherited by radio and check buttons. I will point these out when - we come to them.</p> +<p> +Toggle buttons are the basis for check buttons and radio buttons, as such, many +of the calls used for toggle buttons are inherited by radio and check buttons. +I will point these out when we come to them. +</p> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 133 - <p>Creating a new toggle button:</p> +<p> +Creating a new toggle button: +</p> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 137 - <table summary="Haskell code" width="100%" border="0" - cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> - <tr> - <td> - <pre> +<pre class="codebox"> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 144 - </td> - </tr> - </table> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 145 - <p>As you can imagine, these work identically to the normal - button widget calls. The first creates a blank toggle button, and - the last two, a button with a label widget already packed into - it. The mnemonic variant additionally parses the label for - '_'-prefixed mnemonic characters.</p> +<p> +As you can imagine, these work identically to the normal button widget calls. +The first creates a blank toggle button, and the last two, a button with a +label widget already packed into it. The mnemonic variant additionally parses +the label for "_"-prefixed mnemonic characters. +</p> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 152 - <p>To retrieve the state of the toggle widget, including radio - and check buttons, we use:</p> +<p> +To retrieve the state of the toggle widget, including radio and check buttons, +we use: +</p> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 157 - <table summary="Haskell code" width="100%" border="0" - cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> - <tr> - <td> - <pre> +<pre class="codebox"> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 160 - </td> - </tr> - </table> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 161 - <p>Returns <i>True</i> if the toggle button is pressed in and - <i>False</i> if it is raised.</p> +<p> +This returns <var>True</var> if the toggle button is pressed in and +<var>False</var> if it is raised. +</p> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 166 - <p>To force the state of a toggle button, and its children, the - radio and check buttons, use this function:</p> +<p> +To force the state of a toggle button, and its children, the radio and check +buttons, use this function: +</p> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 171 - <table summary="Haskell code" width="100%" border="0" - cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> - <tr> - <td> - <pre> +<pre class="codebox"> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 174 - </td> - </tr> - </table> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 175 - <p>The above call can be used to set the state of the toggle - button, and its children the radio and check buttons. Passing in - your created button as the first argument, and <i>True</i> of - <i>False</i> for the second state argument to specify whether it - should be down (depressed) or up (released). Default is up, or - <i>False</i>.</p> +<p> +The above call can be used to set the state of the toggle button, and its +children the radio and check buttons. Passing in your created button as the +first argument, and <var>True</var> or <var>False</var> for the second state +argument to specify whether it should be down (depressed) or up (released). +Default is up, or <var>False</var>. +</p> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 183 - <p>Note that when you use the toggleButtonSetActive function, and - the state is actually changed, it causes the <i>onClicked</i> and - <i>onToggled</i> signals to be emitted from the button.</p> - <hr> +<p> +Note that when you use the <code>toggleButtonSetActive</code> function, and the +state is actually changed, it causes the <code>onClicked</code> and +<code>onToggled</code> signals to be emitted from the button. +</p> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 189 - <h2>Check Buttons</h2> +<h3>Check Buttons</h3> hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 191 - <p>Check buttons inherit many properties and functions from the - the toggle buttons above, but look a little different. Rather - than being buttons with text inside them, they are small squares - with the text to the right of them. These are often used for - toggling options on and off in applications.</p> +<p> +Check buttons inherit many properties and functions from the the toggle buttons +above, but look a little different. Rather than being buttons with text inside +them, they are small squares with the text to the right of them. These are +often used for tog... [truncated message content] |
From: Duncan C. <dun...@wo...> - 2007-09-14 16:29:47
|
Thu Sep 13 09:05:29 PDT 2007 Bertram Felgenhauer <in...@gm...> * Make gtk2hs build with ghc 6.8 - Add additional dependencies induced by the base package split. - fix one API breakage. move ./gnomevfs/System/Gnome/VFS/Ops.chs ./gnomevfs/System/Gnome/VFS/Ops.chs.pp hunk ./Makefile.am 152 +if HAVE_SPLIT_BASE +tools_c2hs_c2hsLocal_EXTERNALDEPS += pretty containers array +endif hunk ./Makefile.am 389 +if HAVE_SPLIT_BASE +libHSgtk_a_EXTERNALDEPS += containers array +endif hunk ./Makefile.am 1619 +if HAVE_SPLIT_BASE +libHSsoegtk_a_EXTERNALDEPS += old-time +endif hunk ./Makefile.am 1705 +if HAVE_SPLIT_BASE +libHSgnomevfs_a_EXTERNALDEPS += bytestring +endif hunk ./Makefile.am 1744 - gnomevfs/System/Gnome/VFS/Ops.chs \ + gnomevfs/System/Gnome/VFS/Ops.chs.pp \ hunk ./configure.ac 152 +dnl check for a recent ghc-6.7 or later as a proxy for the base package split +GTKHS_PROG_CHECK_VERSION($GHC_VERSION, -ge, 6.7.20070912, [ +HAVE_SPLIT_BASE=yes +AC_DEFINE([HAVE_SPLIT_BASE], [1], [Using split base package.]) +]) +AM_CONDITIONAL(HAVE_SPLIT_BASE, test "$HAVE_SPLIT_BASE" = "yes") +AC_SUBST(HAVE_SPLIT_BASE) hunk ./gnomevfs/System/Gnome/VFS/Ops.chs.pp 59 - [_$_] + hunk ./gnomevfs/System/Gnome/VFS/Ops.chs.pp 147 +#ifdef HAVE_SPLIT_BASE + BS.packCStringLen (castPtr cBuffer, bytesRead)) +#else hunk ./gnomevfs/System/Gnome/VFS/Ops.chs.pp 151 +#endif |
From: Axel S. <A....@ke...> - 2007-09-13 13:38:24
|
Mon Sep 10 06:13:54 PDT 2007 hth...@zo... * GTK Tutorial Port Spin Boxes (Chapter 12) Alex Tarkovsky will implement a change from HTML 4 Provisional to XHTML strict and a corresponding change in file names and extensions. New additions by me will match that, but until Alex's patches have been applied I'll carry on as before. However, this means that links will be broken. This chapter 12 patch is standalone, for the moment. addfile ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap12.hs hunk ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap12.hs 1 +import Graphics.UI.Gtk + +main:: IO () +main = do + initGUI + window <- windowNew + mainbox <- vBoxNew False 0 + set window [windowTitle := "Spin Buttons", containerBorderWidth := 10, + windowDefaultWidth := 250, + windowDefaultHeight := 200, + containerChild := mainbox ] + hbox1 <- hBoxNew False 0 [_$_] + frame1 <- frameNew + set frame1 [frameLabel := "Simple SpinButtons", containerChild := hbox1, + frameLabelYAlign := 0.8, frameShadowType := ShadowOut] [_$_] + boxPackStart mainbox frame1 PackNatural 5 + [_$_] + spinD <- myAddSpinButton hbox1 "Day:" 1.0 31.0 + spinM <- myAddSpinButton hbox1 "Month:" 1.0 12.0 + spinY <- myAddSpinButton hbox1 "Year:" 2000.0 2100.0 + set spinY [spinButtonValue := 2007] + + vbox1 <- vBoxNew False 5 + frame2 <- frameNew + set frame2 [frameLabel := "More Features", containerChild := vbox1, + frameLabelYAlign := 0.8, frameShadowType:= ShadowOut ] + boxPackStart mainbox frame2 PackNatural 5 + [_$_] + hbox2 <- hBoxNew False 0 + boxPackStart vbox1 hbox2 PackNatural 0 [_$_] + + spinLarge <- myAddSpinButton hbox2 "Value:" (-1000.0) 1000.0 + adj <- adjustmentNew 0.0 (-100.0) 100.0 0.25 10.0 0.0 + spinButtonConfigure spinLarge adj 0.0 2 + spnctl <- myAddSpinButton hbox2 "Decimal:" 0.0 10.0 [_$_] + set spnctl [spinButtonValue := 2.0] + [_$_] + tsnap <- checkButtonNewWithLabel "Snap to 0.25-ticks" + boxPackStart vbox1 tsnap PackNatural 0 + + tnumr <- checkButtonNewWithLabel "Numeric only input mode" [_$_] + boxPackStart vbox1 tnumr PackNatural 0 + + twrap <- checkButtonNewWithLabel "Wraparound at limits" [_$_] + boxPackStart vbox1 twrap PackNatural 0 + + widgetShowAll window + + onValueSpinned spnctl $ do newdig <- get spnctl spinButtonValue + set spinLarge [spinButtonDigits := (round newdig)] + + onToggled tsnap $ do st <- get tsnap toggleButtonActive + set spinLarge [spinButtonSnapToTicks := st] + + onToggled tnumr $ do st <- get tnumr toggleButtonActive + set spinLarge [spinButtonNumeric := st] + + onToggled twrap $ do st <- get twrap toggleButtonActive + set spinLarge [spinButtonWrap := st] + + onDestroy window mainQuit + mainGUI + +myAddSpinButton :: HBox -> String -> Double -> Double -> IO SpinButton +myAddSpinButton box name min max = do + vbox <- vBoxNew False 0 + boxPackStart box vbox PackRepel 0 + label <- labelNew (Just name) + miscSetAlignment label 0.0 0.5 + boxPackStart vbox label PackNatural 0 + spinb <- spinButtonNewWithRange min max 1.0 + boxPackStart vbox spinb PackNatural 0 + return spinb + + + addfile ./docs/tutorial/Tutorial_Port/Images/GtkChap12.png binary ./docs/tutorial/Tutorial_Port/Images/GtkChap12.png addfile ./docs/tutorial/Tutorial_Port/chap12.html hunk ./docs/tutorial/Tutorial_Port/chap12.html 1 +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> + +<html> +<head> + <meta name="generator" content= + "HTML Tidy for Linux/x86 (vers 11 February 2007), see www.w3.org"> + <meta http-equiv="CONTENT-TYPE" content= + "text/html; charset=us-ascii"> + + <title>Spin Buttons</title> +</head> + +<body lang="en-US" text="#000000" link="#0000FF" vlink="#840084" +bgcolor="#FFFFFF" dir="ltr"> + <table summary="links to other pages" width="100%" border="0" + cellpadding="0" cellspacing="0"> + <tr> + <th colspan="3"> + <p align="center">Gtk2Hs Tutorial</p> + </th> + </tr> + + <tr valign="bottom"> + <td width="10%"> + <p align="left"><a href="chap11.html"><<< + Previous</a></p> + </td> + + <td width="80%"> + <p align="center">Next</p> + </td><!-- + <TD WIDTH=10%> + <P ALIGN=RIGHT><A HREF="chap13.html">Next >>></A></P> + </TD> + --> + </tr> + </table> + <hr> + + <h2><a name="SEC-SPINBUTTONS" id="SEC-SPINBUTTONS"></a>Spin + Buttons</h2> + + <p>The <i>SpinButton</i> widget is generally used to allow the + user to select a value from a range of numeric values. It + consists of a text entry box with up and down arrow buttons + attached to the side. Selecting one of the buttons causes the + value to "spin" up and down the range of possible values. The + entry box may also be edited directly to enter a specific value. + <i>SpinButton</i> is an instance of <i>EditableClass</i>, so the + attributes and functions defined there are also available.</p> + + <p>The spin button allows the value to have zero or a number of + decimal places and to be incremented/decremented in configurable + steps. The action of holding down one of the buttons optionally + results in an acceleration of change in the value according to + how long it is depressed.</p> + + <p><i>SpinButton</i> uses an <i>Adjustment</i> object to hold + information about the range of values that the spin button can + take. Recall that an <i>Adjustment</i> widget is created with the + following function:</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> + <tr> + <td> + <pre> +adjustmentNew + :: Double -- value + -> Double -- lower + -> Double -- upper + -> Double -- stepIncrement + -> Double -- pageIncrement + -> Double -- pageSize + -> IO Adjustment +</pre> + </td> + </tr> + </table> + + <p>These attributes of an <i>Adjustment</i> are used by the + <i>SpinButton</i> in the following way:</p> + + <ul> + <li>value: initial value for the Spin Button</li> + + <li>lower: lower range value</li> + + <li>upper: upper range value</li> + + <li>stepIncrement: value to increment/decrement when pressing + mouse button 1 on a button</li> + + <li>pageIncrement: value to increment/decrement when pressing + mouse button 2 on a button</li> + + <li>pageSize: unused</li> + </ul> + + <p>Additionally, mouse button 3 can be used to jump directly to + the upper or lower values when used to select one of the buttons. + Note that this may depend on the way your mouse is configured on + your computer system.</p> + + <p>Lets look at how to create a spin button:</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> + <tr> + <td> + <pre> +spinButtonNew :: Adjustment -> Double -> Int -> IO SpinButton +</pre> + </td> + </tr> + </table> + + <p>The second argument (climbRate) take a value between 0.0 and + 1.0 and indicates how fast the spin button changes when an arrow + is clicked on. The third argument specifies the number of decimal + places to which the value will be displayed.</p> + + <p>There also is a convenience constructor that allows creation + of a spin button without manually creating an adjustment.</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="0" bgcolor="#E0E0E0"> + <col width="256*"> + + <tr> + <td width="100%"> + <pre> +spinButtonNewWithRange :: Double -> Double -> Double -> IO SpinButton +</pre> + </td> + </tr> + </table> + + <p>The three arguments, all of type <i>Double</i>, specify the + minum allowable value, the maximum allowable value, and the + increment added or subtracted by spinning the widget.</p> + + <p>A Spin Button can be reconfigured after creation using the + following function:</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> + <tr> + <td> + <pre> +spinButtonConfigure :: SpinButtonClass self => self -. Adjustment -> Double -> Int +</pre> + </td> + </tr> + </table> + + <p>The first argument specifies the <i>SpinButton</i> widget that + is to be reconfigured. The other arguments are the climbRate and + the number of decimal places (digits) to disply.</p> + + <p>The <i>SpinButton</i> attributes, which can be retrieved and + changed with the generic <i>get</i> and <i>set</i> functions + are:</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> + <tr> + <td> + <pre> +spinButtonAdjustment :: SpinButtonClass self => Attr self Adjustment +spinButtonClimbRate :: SpinButtonClass self => Attr self Double +spinButtonDigits :: SpinButtonClass self => Attr self Int + +spinButtonSnapToTicks :: SpinButtonClass self => Attr self Bool +spinButtonNumeric :: SpinButtonClass self => Attr self Bool +spinButtonWrap :: SpinButtonClass self => Attr self Bool + +spinButtonValue :: SpinButtonClass self => Attr self Double +</pre> + </td> + </tr> + </table> + + <p>The first three are as discussed before. The attribute + <i>spinButtonSnapToTicks</i> determines whether erroneous values + are automatically changed to the spin button's nearest increment + (default is False). Attribute <i>spinButtonNumeric</i> determines + whether non-numeric characters should be ignored (default False), + and <i>spinButtonWrap</i> is used to set whether a spin button + should wraparound upon reaching its limits (default False).</p> + + <p>Attribute <i>spinButtonValue</i> is used to read the current + value or set a new value (default is 0).</p> + + <p>To change the value of a spin button you can also use:</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="0" bgcolor="#E0E0E0"> + <col width="256*"> + + <tr> + <td width="100%"> + <pre> +spinButtonSpin :: SpinButtonClass self => self -> SpinType -> Double -> IO () +</pre> + </td> + </tr> + </table> + + <p>where <i>SpinType</i> determines the kind of change and + <i>Double</i> (increment) determines the value.</p> + + <p><i>SpinType</i> has the following constructors:</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> + <tr> + <td> + <pre> +SpinStepForward +SpinStepBackward +SpinPageForward +SpinPageBackward +SpinHome +SpinEnd +SpinUserDefined +</pre> + </td> + </tr> + </table> + + <p>Many of these settings use values from the <i>Adjustment</i> + object that is associated with a spin button. + <i>SpinStepForward</i> and <i>SpinStepBackward</i>change the + value of the spin button by the amount specified by the + increment, unless it is equal to 0, in which case the value is + changed by the value of the stepIncrement in the adjustment. + <i>SpinPageForward</i> and <i>SpinPageBackward</i> simply alter + the value of the Spin Button by the increment. + <i>SpinPageHome</i> and <i>SpinPageEnd</i> set the value to the + bottom repectively the top of the <i>Adjustment</i> range. + <i>i>SpinUserDefined</i> simply alters the value of the spin + button by the specified amount.</p> + + <p>A spin button has an update policy:</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> + <tr> + <td> + <pre> +spinButtonUpdatePolicy :: SpinButtonClass self => Attr self SpinButtonUpdatePolicy +</pre> + </td> + </tr> + </table> + + <p>The constructors of <i>SpinButtonUpdatePolicy</i> are either + <i>UdateAlways</i> or <i>UpdateIfValid</i>. These policies affect + the behavior of a Spin Button when parsing inserted text and + synchronizing its value with the values of the Adjustment. In the + case of <i>UpdateIfValid</i> the spin button only value gets + changed if the text input is a numeric value within the range + specified by the Adjustment. Otherwise the text is reset to the + current value. In case of <i>UpdateAlways</i> we ignore errors + while converting text into a numeric value.</p> + + <p>Finally, you can explicitly request that a Spin Button update + itself:</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> + <tr> + <td> + <pre> +spinButtonUpdate :: SpinButtonClass self => self -> IO () +</pre> + </td> + </tr> + </table> + + <p>It's example time again; this is a screenshot after playing + around with some of the settings.</p> + + <p><img src="./Images/GtkChap12.png" alt="GtkChap12.png" align= + "bottom"></p> + + <p>The spin buttons have all been created with the following + function which uses <i>spinButtonNewWithRange</i>. Because the + stepIncrement will be 1.0 in all cases, this is not a parameter + in <i>myAddSpinButton</i>.</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="0" bgcolor="#E0E0E0"> + <col width="256*"> + + <tr> + <td width="100%"> + <pre style="margin-bottom: 0.5cm"> +myAddSpinButton :: HBox -> String -> Double -> Double -> IO SpinButton +myAddSpinButton box name min max = do + vbox <- vBoxNew False 0 + boxPackStart box vbox PackRepel 0 + label <- labelNew (Just name) + miscSetAlignment label 0.0 0.5 + boxPackStart vbox label PackNatural 0 + spinb <- spinButtonNewWithRange min max 1.0 + boxPackStart vbox spinb PackNatural 0 + return spinb +</pre> + </td> + </tr> + </table> + + <p>In the <i>main</i> function we use one of the spin buttons + which already exist, but give it a new adjustment with + <i>spinButtonConfigure</i>. The old limits of -1000.0 and 1000.0 + are now replaced with -100.0 and 100.0. Note the brackets around + the negative numbers. The initial value is set at 0.0 and the + step increment is 0.25. The page increment, which is what you get + when pressing mouse button 2 on the arrow in the spin button, is + set at 10.0. The page size, which is not used, is 0.0 here. + Pressing mouse button 3 on an arrow jumps to the appropriate + limit of -100.0 or 100.0.</p> + + <p>The new signal here is <i>onValueSpinned</i> ,which is emitted + whenever the user changes the value of a spin button. Here it is + used to control the number of decimal digits which are to be + displayed in the spinLarge spin button. Note the rounding of the + value, which is needed to convert the <i>Double</i> to an + <i>Integral</i> type.</p> + + <p>In this example we've used the generic <i>get</i> and + <i>set</i> functions on attributes rather than the corresponding + functions, which are also available. This is actually the + recommended style when programming Gtk2Hs, and in the future many + specific functions will be deprecated.<br></p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="0" bgcolor="#E0E0E0"> + <col width="256*"> + + <tr> + <td width="100%"> + <pre> +import Graphics.UI.Gtk + +main:: IO () +main = do + initGUI + window <- windowNew + mainbox <- vBoxNew False 0 + set window [windowTitle := "Spin Buttons", containerBorderWidth := 10, + windowDefaultWidth := 250, + windowDefaultHeight := 200, + containerChild := mainbox ] + hbox1 <- hBoxNew False 0 [_$_] + frame1 <- frameNew + set frame1 [frameLabel := "Simple SpinButtons", containerChild := hbox1, + frameLabelYAlign := 0.8, frameShadowType := ShadowOut] [_$_] + boxPackStart mainbox frame1 PackNatural 5 + [_$_] + spinD <- myAddSpinButton hbox1 "Day:" 1.0 31.0 + spinM <- myAddSpinButton hbox1 "Month:" 1.0 12.0 + spinY <- myAddSpinButton hbox1 "Year:" 2000.0 2100.0 + set spinY [spinButtonValue := 2007] + + vbox1 <- vBoxNew False 5 + frame2 <- frameNew + set frame2 [frameLabel := "More Features", containerChild := vbox1, + frameLabelYAlign := 0.8, frameShadowType:= ShadowOut ] + boxPackStart mainbox frame2 PackNatural 5 + [_$_] + hbox2 <- hBoxNew False 0 + boxPackStart vbox1 hbox2 PackNatural 0 [_$_] + + spinLarge <- myAddSpinButton hbox2 "Value:" (-1000.0) 1000.0 + adj <- adjustmentNew 0.0 (-100.0) 100.0 0.25 10.0 0.0 + spinButtonConfigure spinLarge adj 0.0 2 + spnctl <- myAddSpinButton hbox2 "Decimal:" 0.0 10.0 [_$_] + set spnctl [spinButtonValue := 2.0] + [_$_] + tsnap <- checkButtonNewWithLabel "Snap to 0.25-ticks" + boxPackStart vbox1 tsnap PackNatural 0 + + tnumr <- checkButtonNewWithLabel "Numeric only input mode" [_$_] + boxPackStart vbox1 tnumr PackNatural 0 + + twrap <- checkButtonNewWithLabel "Wraparound at limits" [_$_] + boxPackStart vbox1 twrap PackNatural 0 + + widgetShowAll window + + onValueSpinned spnctl $ do newdig <- get spnctl spinButtonValue + set spinLarge [spinButtonDigits := (round newdig)] + + onToggled tsnap $ do st <- get tsnap toggleButtonActive + set spinLarge [spinButtonSnapToTicks := st] + + onToggled tnumr $ do st <- get tnumr toggleButtonActive + set spinLarge [spinButtonNumeric := st] + + onToggled twrap $ do st <- get twrap toggleButtonActive + set spinLarge [spinButtonWrap := st] + + onDestroy window mainQuit + mainGUI +</pre> + </td> + </tr> + </table><br> + + <table summary="links to other pages" width="100%" border="0" + cellpadding="0" cellspacing="0"> + <tr valign="top"> + <td width="33%"> + <p align="left"><a href="chap11.html"><<< + Previous</a></p> + </td> + + <td width="34%"> + <p align="center"><a href="chap1.html">Home</a></p> + </td><!-- + <TD WIDTH=33%> + <P ALIGN=RIGHT><A HREF="chap13.html">Next >>></A></P> + </TD> + --> + </tr> + + <tr valign="top"> + <td width="33%"> + <p align="left">Text Entries and Status Bars</p> + </td> + + <td width="34%"> + <p align="center"><br></p> + </td> + + <td width="33%"> + <p align="right">To be continued</p> + </td> + </tr> + </table> +</body> +</html> |
From: Duncan C. <dun...@wo...> - 2007-09-12 16:01:04
|
Thu Sep 6 14:03:32 PDT 2007 Alex Tarkovsky <ale...@gm...> * XHTML-ize and CSS-ify ToC and chapters 3 and 4; renumber ToC move ./docs/tutorial/Tutorial_Port/chap3.html ./docs/tutorial/Tutorial_Port/chap3.xhtml move ./docs/tutorial/Tutorial_Port/chap4.html ./docs/tutorial/Tutorial_Port/chap4.xhtml hunk ./docs/tutorial/Tutorial_Port/chap1.html 1 -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> - -<html> -<head> - <meta name="generator" content= - "HTML Tidy for Linux/x86 (vers 11 February 2007), see www.w3.org"> - <meta http-equiv="CONTENT-TYPE" content= - "text/html; charset=us-ascii"> - - <title>Gtk2Hs Tutorial</title> -</head> - -<body lang="en-US" text="#000000" link="#0000FF" vlink="#840084" -bgcolor="#FFFFFF" dir="ltr"> - <h2 align="center"><a name="Gtk2Hs-TUT" id= - "Gtk2Hs-TUT"></a><a name="AEN2" id="AEN2"></a>Gtk2Hs Tutorial - (part 1)</h2> - - <h3>Hans van Thiel</h3> - <hr> - <br> - <br> - - <h3>The start of a port and adaptation to Gtk2Hs of the:</h3> - - <h3>GTK+2.0 Tutorial by</h3> - - <h3><a name="AEN6" id="AEN6"></a>Tony Gale</h3> - - <h3><a name="AEN9" id="AEN9"></a>Ian Main</h3> - - <h3><a name="AEN12" id="AEN12"></a>& the GTK team</h3> - <hr> - - <dl> - <dt><b>Table of Contents</b></dt> - - <dt><br> - <br> - Introduction and Overview: not available yet...</dt> - - <dt><br> - <a href="chap3.html">Getting Started</a></dt> - - <dt><br> - <a href="chap4.html">Packing Widgets</a></dt> - - <dt><br> - <a href="chap5a.html">Packing Demonstration Program</a></dt> - - <dt><br> - <a href="chap5b.html">Packing Using Tables</a></dt> - - <dt><br> - <a href="chap6.html">The Button Widget</a></dt> - - <dt><br> - <a href="chap7.html">Adjustments, Scale and Range</a></dt> - </dl><br> - - <dl> - <dt><br> - <a href="chap8.html">Labels</a></dt> - - <dt><br> - <a href="chap9.html">Arrows and Tooltips</a></dt> - - <dt><br> - <a href="chap10.html">Dialogs, Stock Items and Progress - Bars</a></dt> - - <dt><br> - <a href="chap11.html">Text Entries and Statusbars</a></dt> - </dl><br> - <hr> - <br> - - <h1><a name="CH-COPYRIGHT" id="CH-COPYRIGHT"></a>Tutorial - Copyright and Permissions Notice</h1> - - <p>The GTK Tutorial is Copyright (C) 1997 Ian Main.</p> - - <p>Copyright (C) 1998-2002 Tony Gale.</p> - - <p>Copyright (C) 2007 Hans van Thiel</p> - - <p>Permission is granted to make and distribute verbatim copies - of this manual provided the copyright notice and this permission - notice are preserved on all copies.</p> - - <p>Permission is granted to copy and distribute modified versions - of this document under the conditions for verbatim copying, - provided that this copyright notice is included exactly as in the - original, and that the entire resulting derived work is - distributed under the terms of a permission notice identical to - this one.</p> - - <p>Permission is granted to copy and distribute translations of - this document into another language, under the above conditions - for modified versions.</p> - - <p>If you are intending to incorporate this document into a - published work, please contact the maintainer, and we will make - an effort to ensure that you have the most up to date information - available.</p> - - <p>There is no guarantee that this document lives up to its - intended purpose. This is simply provided as a free resource. As - such, the authors and maintainers of the information provided - within can not make any guarantee that the information is even - accurate.</p> - <hr> - - <table summary="links to other pages" width="100%" border="0" - cellpadding="0" cellspacing="0"> - <tr valign="top"> - <td width="33%"> - <p align="left"><br></p> - </td> - - <td width="34%"> - <p align="center"><br></p> - </td> - - <td width="33%"> - <p align="right"><a href="chap3.html">Next - >>></a></p> - </td> - </tr> - - <tr valign="top"> - <td width="33%"> - <p align="left"><br></p> - </td> - - <td width="34%"> - <p align="center"> </p> - </td> - - <td width="33%"> - <p align="right"><br></p> - </td> - </tr> - </table> -</body> -</html> rmfile ./docs/tutorial/Tutorial_Port/chap1.html addfile ./docs/tutorial/Tutorial_Port/default.css addfile ./docs/tutorial/Tutorial_Port/index.xhtml hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 1 -<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> - -<html> +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 5 - <meta name="generator" content= - "HTML Tidy for Linux/x86 (vers 11 February 2007), see www.w3.org"> - <meta http-equiv="CONTENT-TYPE" content= - "text/html; charset=us-ascii"> - - <title>Getting Started</title> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <title>Gtk2Hs Tutorial: Getting Started</title> + <link href="default.css" type="text/css" rel="stylesheet" /> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 10 -<body lang="en-US" text="#000000" link="#0000FF" vlink="#840084" -bgcolor="#FFFFFF" dir="ltr"> - <table summary="links to other pages" width="100%" border="0" - cellpadding="0" cellspacing="0"> - <tr> - <th colspan="3"> - <p align="center">Gtk2Hs Tutorial</p> - </th> - </tr> - - <tr valign="bottom"> - <td width="10%"> - <p align="left"><a href= - "chap1.html"><<<Previous</a></p> - </td> +<body> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 12 - <td width="80%"></td> +<div id="header"> + <h1>Gtk2Hs Tutorial</h1> + <span class="nav-previous"><a href="index.xhtml">Previous</a></span> + <span class="nav-home"><a href="index.xhtml">Home</a></span> + <span class="nav-next"><a href="chap4.xhtml">Next</a></span> +</div> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 19 - <td width="10%"> - <p align="right"><a href="chap4.html">Next - >>></a></p> - </td> - </tr> - </table> - <hr> +<h2>Getting Started</h2> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 21 - <h3><a name="CH-GETTINGSTARTED" id= - "CH-GETTINGSTARTED"></a>Getting Started</h3> +<p> +The first thing to do, of course, is download Gtk2Hs and install it. You can +always get the latest version from +<a href="http://haskell.org/gtk2hs/">http://haskell.org/gtk2hs/</a> and several +Linux versions have their own Gtk2Hs packages. For Windows there is an +installer available. +</p> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 29 - <p>The first thing to do, of course, is download Gtk2Hs and - install it. You can always get the latest version from <a href= - "http://haskell.org/gtk2hs/">http://haskell.org/gtk2hs/</a> and - several Linux versions have their own Gtk2Hs packages. For - Windows there is an installer available.</p> +<p> +The next thing is to open the Gtk2Hs API reference documentation for your +version. You will need to use this extensively to be able to find the names for +widgets, methods, attributes and signals you might want to use. The contents +lists all modules and there is also an index. Inside each module description +there is also a class hierarchy. If a method, attribute or signal you expect is +missing, it might belong to one of the superclasses of which your widget type +is an instance. +</p> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 39 - <p>The next thing is to open the Gtk2Hs API reference - documentation for your version. You will need to use this - extensively to be able to find the names for widgets, methods, - attributes and signals you might want to use. The <i>contents</i> - list all modules and there is also an <i>index</i>. Inside each - module description there is also a class hierarchy. If a method, - attribute or signal you expect is missing, it might belong to one - of the superclasses of which your widget type is an instance.</p> +<p> +To begin our introduction to Gtk2Hs, we'll start with the simplest program +possible. This program will create a 200x200 pixel window and has no way of +exiting except to be killed by using the shell. +</p> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 45 - <p>To begin our introduction to Gk2Hs, we'll start with the - simplest program possible. This program will create a 200x200 - pixel window and has no way of exiting except to be killed by - using the shell.</p> +<p><img src="./Images/GtkChap3a.png" alt="GtkChap3a" id="GtkChap3a" /></p> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 47 - <p><img src="./Images/GtkChap3a.png" align="bottom" alt= - "GtkChap3a"></p> - - <table summary="haskell code" width="100%" border="0" - cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> - <tr> - <td> - <pre> +<pre class="codebox"> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 57 - </td> - </tr> - </table> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 58 - <p>You can compile the above program with the Glasgow Haskell - Compiler (GHC) using:</p> +<p> +You can compile the above program with the Glasgow Haskell Compiler (GHC) +using: +</p> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 63 - <p><tt>ghc --make GtkChap3a.hs -o Chap3a</tt></p> +<pre class="codebox"> +ghc --make GtkChap3a.hs -o Chap3a +</pre> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 67 - <p>assuming GtkChap3a.hs is the filename. Alternatively you can - use the interactive GHCi, for earlier and later versions of - Gtk2Hs. (Because of threading problems intermediate versions will - not work interactively. Gtk2Hs does not work with Hugs.)</p> +<p> +assuming <code>GtkChap3a.hs</code> is the filename. Alternatively you can use +the interactive GHCi, for earlier and later versions of Gtk2Hs. (Because of +threading problems intermediate versions will not work interactively. Gtk2Hs +does not work with Hugs.) +</p> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 74 - <p>The first line imports the Gtk2Hs graphics library.</p> +<p> +The first line of the program imports the Gtk2Hs graphics library. +</p> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 78 - <p>All Gtk2Hs programs run in main and the first line:</p> +<p> +All Gtk2Hs programs run in <code>main</code>. The first line of that function's +<code>do</code> block: +</p> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 83 - <table summary="haskell code" width="100%" border="0" - cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> - <tr> - <td> - <pre> +<pre class="codebox"> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 86 - </td> - </tr> - </table> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 87 - <p>is called in all Gk2Hs applications. The next two lines of - code create and display a window.</p> +<p> +is a function called in all Gtk2Hs applications. +</p> + +<p> +The next two lines in the block create and display a window and its contents: +</p> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 95 - <table summary="haskell code" width="100%" border="0" - cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> - <tr> - <td> - <pre> +<pre class="codebox"> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 99 - </td> - </tr> - </table> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 100 - <p>Rather than create a window of 0x0 size, a window without - children is set to 200x200 by default so you can still manipulate - it. Widgets that can be visible (not all can) may be shown or - hidden using their own methods, but the second line works on a - widget (here the window) and all its children.</p> +<p> +Rather than create a window of 0x0 size, a window without children is set to +200x200 by default so you can still manipulate it. Widgets that can be visible +(not all can) may be shown or hidden using their own methods, but the second +line works on a widget (here the window) and all its children. +</p> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 107 - <p>The last line enters the Gtk2Hs main processing loop.</p> +<p> +The last line of <code>main</code> enters the Gtk2Hs main processing loop: +</p> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 111 - <table summary="haskell code" width="100%" border="0" - cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> - <tr> - <td> - <pre> +<pre class="codebox"> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 114 - </td> - </tr> - </table> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 115 - <p>mainGUI is another call you will see in every Gtk2Hs - application. When control reaches this point, Gtk2Hs will sleep - waiting for X events (such as button or key presses), timeouts, - or file IO notifications to occur. In our simple example, - however, events are ignored.</p> +<p> +and is another call you will see in every Gtk2Hs application. When control +reaches this point, Gtk2Hs will sleep waiting for X events (such as button or +key presses), timeouts, or file IO notifications to occur. In our simple +example, however, events are ignored. +</p> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 122 - <h3><a name="SEC-HELLOWORLD" id="SEC-HELLOWORLD"></a>Hello World - in Gtk2Hs</h3> +<h3>"Hello World" in Gtk2Hs</h3> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 124 - <p>Now for a program with a widget (a button). It's the classic - hello world à la Gtk2Hs.</p> +<p> +Now for a program with a widget (a button): the classic "hello world" à +la Gtk2Hs. +</p> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 129 - <p><img src="./Images/GtkChap3b.png" name="graphics2" align= - "bottom" alt="GtkChap3b" id="graphics2"></p> +<p><img src="./Images/GtkChap3b.png" alt="GtkChap3b" id="GtkChap3b" /></p> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 131 - <p>If the button is clicked it will display the text <i>Hello - World</i>. This is implemented in the Haskell function - <i>hello</i> with a button <i>b</i> as its argument. The type - declaration actually states the type variable <i>o</i> is an - instance of class <i>ButtonClass</i>. Gtk2Hs extensively uses - Haskell classes to map the object hierarchy of the original Gtk - widgets. Each widget in Gtk2Hs, of course, has a Haskell - type.</p> +<p> +If the button is clicked it will display the text "Hello World". This is +implemented in the Haskell function <code>hello</code> with a button +<var>b</var> as its argument. The type declaration actually states the type +variable <var>o</var> is an instance of class <code>ButtonClass</code>. Gtk2Hs +extensively uses Haskell classes to map the object hierarchy of the original +GTK widgets. Each widget in Gtk2Hs, of course, has a Haskell type. +</p> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 140 - <p>Widgets, and the classes their types belong to, usually have - attributes. These can be set either by named methods or by the - general <i>set</i> function, which uses a list-like notation as - shown below. Of special interest here is the - <i>containerChild</i> attribute of the window (actually a - superclass of the window) which states the relationship with the - button. Because of this <i>widgetShowAll window</i> will also - make the button visible.</p> +<p> +Widgets, and the classes their types belong to, usually have attributes. These +can be set either by named methods or by the general <code>set</code> function, +which uses a list-like notation as shown below. Of special interest here is the +<code>containerChild</code> attribute of the window (actually of a superclass +of the window) which states the relationship with the button. Because of this +relationship <code>widgetShowAll window</code> will also make the button +visible. +</p> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 150 - <p>Widgets are connected to other widgets in a graphical - dependency tree (not to be confused with the class hierarchy). - Gtk2hs also works with the Glade visual interface designer and, - if you use Glade, such connections are visible in the <i>Widget - tree</i> window. There is a <a href= - "http://haskell.org/gtk2hs/docs/tutorial/glade/">separate - introductory tutorial</a> on how to use Glade with Gtk2Hs.</p> +<p> +Widgets are connected to other widgets in a graphical dependency tree (not to +be confused with the class hierarchy). Gtk2Hs also works with the Glade visual +interface designer and, if you use Glade, such connections are visible in the +<i>Inspector</i> pane. There is a +<a href="http://haskell.org/gtk2hs/docs/tutorial/glade/">separate introductory +tutorial</a> on how to use Glade with Gtk2Hs. +</p> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 159 - <table summary="haskell code" width="100%" border="0" - cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> - <tr> - <td> - <pre> +<pre class="codebox"> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 171 - containerChild := button , containerBorderWidth := 10 ] + containerChild := button, containerBorderWidth := 10 ] hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 177 - </td> - </tr> - </table> - <hr> - - <p>Gtk2Hs is event driven. The mainGUI function will sleep until - something happens, like a mouse being clicked, a window being - destroyed or something else typical for a widget. Such events - then trigger signals which in turn trigger user defined functions - to be evaluated. In this case the <i>onClicked</i> signal, - emitted by the user clicking the button, is linked to the text - being displayed on the same button. When the user destroys the - window, unlike as with the first program, <i>main</i> now exits - cleanly.</p> - - <p><br> - <br></p> - - <table summary="links to other pages" width="100%" border="0" - cellpadding="0" cellspacing="0"> - <tr valign="top"> - <td width="33%"> - <p align="left"><a href="chap1.html"><<< - Previous</a></p> - </td> - - <td width="34%"> - <p align="center"><a href="chap1.html">Home</a></p> - </td> - - <td width="33%"> - <p align="right"><a href="chap4.html">Next - >>></a></p> - </td> - </tr> - - <tr valign="top"> - <td width="33%"> - <p align="left">Contents</p> - </td> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 178 - <td width="34%"> - <p align="center"> </p> - </td> +<p> +Gtk2Hs is event driven. The <code>mainGUI</code> function will sleep until +something happens, like a mouse being clicked, a window being destroyed or +something else typical for a widget. Such events then trigger signals which in +turn trigger user-defined functions to be evaluated. In this case the +<code>onClicked</code> signal, emitted by the user clicking the button, is +linked to the text being displayed on the same button. When the user destroys +the window, unlike with the first program, <code>main</code> now exits cleanly. +</p> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 188 - <td width="33%"> - <p align="right">Packing Widgets</p> - </td> - </tr> - </table> +<div id="footer"> + <span class="nav-previous"><a href="index.xhtml">Previous</a><br />Table of Contents</span> + <span class="nav-home"><a href="index.xhtml">Home</a><br /> </span> + <span class="nav-next"><a href="chap4.xhtml">Next</a><br />Packing Widgets</span> +</div> hunk ./docs/tutorial/Tutorial_Port/chap3.xhtml 194 - <p><br> - <br></p> hunk ./docs/tutorial/Tutorial_Port/chap4.xhtml 1 -<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> - -<html> +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> hunk ./docs/tutorial/Tutorial_Port/chap4.xhtml 5 - <meta name="generator" content= - "HTML Tidy for Linux/x86 (vers 11 February 2007), see www.w3.org"> - - <title>Packing Widgets</title> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <title>Gtk2Hs Tutorial: Packing Widgets</title> + <link href="default.css" type="text/css" rel="stylesheet" /> hunk ./docs/tutorial/Tutorial_Port/chap4.xhtml 10 -<body lang="en-US" text="#000000" link="#0000FF" vlink="#840084" -bgcolor="#FFFFFF" dir="ltr"> - <table summary="links to other pages" width="100%" border="0" - cellpadding="0" cellspacing="0" style= - "page-break-before: always"> - <tr> - <th colspan="3"> - <p align="center">GTK2Hs Tutorial</p> - </th> - </tr> - - <tr valign="bottom"> - <td width="10%"> - <p align="left"><a href= - "chap3.html"><<<Previous</a></p> - </td> +<body> hunk ./docs/tutorial/Tutorial_Port/chap4.xhtml 12 - <td width="80%"></td> +<div id="header"> + <h1>Gtk2Hs Tutorial</h1> + <span class="nav-previous"><a href="chap3.xhtml">Previous</a></span> + <span class="nav-home"><a href="index.xhtml">Home</a></span> + <span class="nav-next"><a href="chap5a.html">Next</a></span> +</div> hunk ./docs/tutorial/Tutorial_Port/chap4.xhtml 19 - <td width="10%"> - <p align="right"><a href="chap5a.html">Next - >>></a></p> - </td> - </tr> - </table> - <hr> +<h2>Packing Widgets</h2> hunk ./docs/tutorial/Tutorial_Port/chap4.xhtml 21 - <h1><a name="CH-PACKINGWIDGETS" id= - "CH-PACKINGWIDGETS"></a>Packing Widgets</h1> +<p> +When creating an application, you'll want to put more than one widget inside a +window. Our first "hello world" example only used one widget so we could simply +use <code>set</code> to specify a <code>containerChild</code> widget for +<code>window</code>, or use <code>containerAdd</code> to "pack" the widget into +the window. But when you want to put more than one widget into a window, how do +you control where that widget is positioned? This is where packing comes in. +</p> hunk ./docs/tutorial/Tutorial_Port/chap4.xhtml 30 - <p>When creating an application, you'll want to put more than one - widget inside a window. Our first <i>helloworld</i> example only - used one widget so we could simply use a <i>set</i> (of the - <i>containerChild</i> attribute) or a <i>containerAdd</i> to - "pack" the widget into the window. But when you want to put more - than one widget into a window, how do you control where that - widget is positioned? This is where packing comes in.</p> +<h3>Theory of Packing Boxes</h3> hunk ./docs/tutorial/Tutorial_Port/chap4.xhtml 32 - <h1><a name="SEC-THEORYOFPACKINGBOXES" id= - "SEC-THEORYOFPACKINGBOXES"></a>Theory of Packing Boxes</h1> +<p> +Most packing is done by creating boxes. These are invisible widget containers +that we can pack our widgets into which come in two forms: a horizontal box and +a vertical box. When packing widgets into a horizontal box, the objects are +inserted horizontally from left to right or right to left depending on the call +used. In a vertical box, widgets are packed from top to bottom or vice versa. +You may use any combination of boxes inside or beside other boxes to create the +desired effect. +</p> hunk ./docs/tutorial/Tutorial_Port/chap4.xhtml 42 - <p>Most packing is done by creating boxes. These are invisible - widget containers that we can pack our widgets into which come in - two forms, a horizontal box, and a vertical box. When packing - widgets into a horizontal box, the objects are inserted - horizontally from left to right or right to left depending on the - call used. In a vertical box, widgets are packed from top to - bottom or vice versa. You may use any combination of boxes inside - or beside other boxes to create the desired effect.</p> +<p> +To create a new horizontal box, we use <code>hBoxNew</code>, and for vertical +boxes, <code>vBoxNew</code>. Both take a <code>Bool</code> and an +<code>Int</code> parameter. The first parameter will give all children equal +space allotments if set to <var>True</var> and the second sets the number of +pixels to place by default between the children. +</p> hunk ./docs/tutorial/Tutorial_Port/chap4.xhtml 50 - <p>To create a new horizontal box, we use <i>hBoxNew</i>, and for - vertical boxes, <i>vBoxNew</i>. Both take a Bool and an Int - parameter. The first will give all children equal space - allotments if set True and the second sets the number of pixels - to place by default between the children.</p> +<p> +The <code>boxPackStart</code> and <code>boxPackEnd</code> functions are used to +place objects inside of these containers. The <code>boxPackStart</code> +function will start at the top and work its way down in a <code>VBox</code>, +and pack left to right in an <code>HBox</code>. <code>boxPackEnd</code> will do +the opposite, packing from bottom to top in a <code>VBox</code>, and right to +left in an <code>HBox</code>. Using these functions allows us to right justify +or left justify our widgets and they may be mixed in any way to achieve the +desired effect. We will use <code>boxPackStart</code> in most of our examples. +</p> hunk ./docs/tutorial/Tutorial_Port/chap4.xhtml 61 - <p>The <i>boxPackStart</i> and <i>boxPackEnd</i> functions are - used to place objects inside of these containers. The - <i>boxPackStart</i> function will start at the top and work its - way down in a vbox, and pack left to right in an hbox. - <i>boxPackEnd</i> will do the opposite, packing from bottom to - top in a vbox, and right to left in an hbox. Using these - functions allows us to right justify or left justify our widgets - and may be mixed in any way to achieve the desired effect. We - will use <i>boxPackStart</i> in most of our examples. An object - may be another container or a widget. In fact, many widgets are - actually containers themselves, including the button, but we - usually only use a label inside a button.</p> +<p> +An object may be another container or a widget. In fact, many widgets are +actually containers themselves—including <code>button</code>, but we +usually only use a <code>label</code> inside a <code>button</code>. +</p> hunk ./docs/tutorial/Tutorial_Port/chap4.xhtml 67 - <p><img src="Images/GtkChap4.png" name="graphics1" alt="GtkChap4" - align="bottom" width="210" height="229" border="0" id= - "graphics1"></p> +<p><img src="Images/GtkChap4.png" alt="GtkChap4" width="210" height="229" id="graphics1" /></p> hunk ./docs/tutorial/Tutorial_Port/chap4.xhtml 69 - <table summary="Haskell code" width="100%" border="0" - cellpadding="2" cellspacing="0" bgcolor="#E0E0E0"> - <col width="256*"> - - <tr> - <td width="100%"> - <pre> +<pre class="codebox"> hunk ./docs/tutorial/Tutorial_Port/chap4.xhtml 74 - initGUI - window <- windowNew - hbox <- hBoxNew True 10 - button1 <- buttonNewWithLabel "Button 1" - button2 <- buttonNewWithLabel "Button 2" - set window [windowDefaultWidth := 200, windowDefaultHeight := 200, - containerBorderWidth := 10, containerChild := hbox ] - boxPackStart hbox button1 PackGrow 0 - boxPackStart hbox button2 PackGrow 0 - widgetShowAll window - onDestroy window mainQuit - mainGUI + initGUI + window <- windowNew + hbox <- hBoxNew True 10 + button1 <- buttonNewWithLabel "Button 1" + button2 <- buttonNewWithLabel "Button 2" + set window [windowDefaultWidth := 200, windowDefaultHeight := 200, + containerBorderWidth := 10, containerChild := hbox ] + boxPackStart hbox button1 PackGrow 0 + boxPackStart hbox button2 PackGrow 0 + onDestroy window mainQuit + widgetShowAll window + mainGUI hunk ./docs/tutorial/Tutorial_Port/chap4.xhtml 87 - </td> - </tr> - </table> - - <p><br> - <br></p> hunk ./docs/tutorial/Tutorial_Port/chap4.xhtml 88 - <p>By using these calls, GTK knows where you want to place your - widgets so it can do automatic resizing and other nifty things. - The <i>Packing</i> parameter specifies the way the widgets in the - container behave when the window is resized. <i>PackNatural</i> - means the widgets will retain their size and stay where they are, - <i>PackGrow</i> <span style="font-style: normal">means they will - be resized, and using</span> <i>PackRepel</i> t<span style= - "font-style: normal">he widgets will be padded equally on both - sides. The last parameter is an Int, which specifies any extra - padding to be put between this child and its - neighbours.</span></p> +<p> +By using <code>boxPackStart</code> or <code>boxPackEnd</code>, GTK knows where +you want to place your widgets so it can do automatic resizing and other nifty +things. +</p> hunk ./docs/tutorial/Tutorial_Port/chap4.xhtml 94 - <p style="font-style: normal">Note that the packing only applies - to the dimension of the box. If, for example, you specify - <i>PackNatural</i> instead of <i>Packgrow</i> in the above, - resizing horizontally will keep the buttons at their original - size, but resizing vertically will also resize the buttons. This - is because the buttons are placed homogoneously in the horizontal - box (first parameter <i>True</i>) and the box itself will resize - with the window. The next example will make the effects more - clear.</p> - <hr> - - <table summary="links to other pages" width="100%" border="0" - cellpadding="0" cellspacing="0"> - <tr valign="top"> - <td width="33%"> - <p align="left"><a href="chap3.html"><<< - Previous</a></p> - </td> - - <td width="34%"> - <p align="center"><a href="chap1.html">Home</a></p> - </td> +<pre class="codebox"> +boxPackStart :: (WidgetClass child, BoxClass self) => self -> child -> Packing -> Int -> IO () +</pre> hunk ./docs/tutorial/Tutorial_Port/chap4.xhtml 98 - <td width="33%"> - <p align="right"><a href="chap5a.html">Next - >>></a></p> - </td> - </tr> +<pre class="codebox"> +boxPackEnd :: (WidgetClass child, BoxClass self) => self -> child -> Packing -> Int -> IO () +</pre> hunk ./docs/tutorial/Tutorial_Port/chap4.xhtml 102 - <tr valign="top"> - <td width="33%"> - <p align="left">Getting Started</p> - </td> +<p> +The <code>Packing</code> parameter specifies the way the widgets in the +container behave when the window is resized. <code>PackNatural</code> means the +widgets will retain their size and stay where they are, <code>PackGrow</code> +means they will be resized, and using <code>PackRepel</code> the widgets will +be padded equally on both sides. The last parameter is an <code>Int</code>, +which specifies any extra padding to be put between this child and its +neighbours. +</p> hunk ./docs/tutorial/Tutorial_Port/chap4.xhtml 112 - <td width="34%"> - <p align="center"> </p> - </td> +<p> +Note that the packing only applies to the dimension of the box. If, for +example, you specify <code>PackNatural</code> instead of <code>PackGrow</code> +in the above, resizing horizontally will keep the buttons at their original +size, but resizing vertically will also resize the buttons. This is because the +buttons are placed homogeneously in the horizontal box (the first parameter is +<var>True</var>) and the box itself will resize with the window. The next +example will make the effects more clear. +</p> hunk ./docs/tutorial/Tutorial_Port/chap4.xhtml 122 - <td width="33%"> - <p align="right">Packing Demonstration Program</p> - </td> - </tr> - </table> +<div id="footer"> + <span class="nav-previous"><a href="chap3.xhtml">Previous</a><br />Getting Started</span> + <span class="nav-home"><a href="index.xhtml">Home</a></span> + <span class="nav-next"><a href="chap5a.html">Next</a><br />Packing Demonstration Program</span> +</div> hunk ./docs/tutorial/Tutorial_Port/chap4.xhtml 128 - <p><br> - <br></p> hunk ./docs/tutorial/Tutorial_Port/default.css 1 +a:link, a:visited { + text-decoration: none; +} + +body { + margin: 0px; + border: 20px solid #e7e7e7; + padding: 20px; + color: #000000; + background-color: #ffffff; +} + +h1 { + text-align: center; +} + +h2, h3 { + border-bottom: 1px solid #ccc; +} + +.codebox { + overflow: auto; + margin: 10px; + border: 1px solid #ccc; + padding: 10px; + color: #000000; + background-color: #eee; +} + +.nav-home { + float: left; + width: 34%; + text-align: center; +} + +.nav-next { + float: left; + width: 33%; + text-align: right; +} + +.nav-previous { + float: left; + width: 33%; + text-align: left; +} + +#authors { + text-align: center; +} + +#authors h3 { + border-style: none; +} + +#credits { + margin-top: 40px; + margin-bottom: 40px; + text-align: center; +} + +#credits h3 { + border-style: none; +} + +#footer { + margin: 40px; + border: 0px; + border-top: 1px solid #ccc; +} + +#header { + margin: 0px 40px 40px 40px; + border: 0px; + border-bottom: 1px solid #ccc; +} + +#header h1 { + margin-top: 0px; + font-size: medium; + text-align: center; +} + +#title h2 { + border-style: none; + text-align: center; +} + +#toc ol { + line-height: 200%; + list-style-type: none; +} hunk ./docs/tutorial/Tutorial_Port/index.xhtml 1 +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <title>Gtk2Hs Tutorial</title> + <link href="default.css" type="text/css" rel="stylesheet" /> +</head> + +<body> + +<div id="title"> + <h2>Gtk2Hs Tutorial</h2> +</div> + +<div id="authors"> + <h3>Hans van Thiel</h3> +</div> + +<div id="credits"> + <h4>An Adaptation of the GTK+ 2.0 Tutorial by</h4> + <h3>Tony Gale</h3> + <h3>Ian Main</h3> + <h4>&</h4> + <h3>The GTK Team</h3> +</div> + +<div id="toc"> + <h3>Table of Contents</h3> + <ol> + <li><a href="chap1.xhtml"></a>1. Introduction <i>— Not Available Yet</i></li> + + <li><a href="chap3.xhtml">2. Getting Started</a></li> + + <li>3. Packing + <ol> + <li><a href="chap4.xhtml">3.1 Packing Widgets</a></li> + + <li><a href="chap5a.html">3.2 Packing Demonstration Program</a></li> + + <li><a href="chap5b.html">3.3 Packing Using Tables</a></li> + </ol> + </li> + <li>4. Miscellaneous Widgets + <ol> + <li><a href="chap6.html">4.1 The Button Widget</a></li> + + <li><a href="chap7.html">4.2 Adjustments, Scale and Range</a></li> + + <li><a href="chap8.html">4.3 Labels</a></li> + + <li><a href="chap9.html">4.4 Arrows and Tooltips</a></li> + + <li><a href="chap10.html">4.5 Dialogs, Stock Items and Progress Bars</a></li> + + <li><a href="chap11.html">4.6 Text Entries and Status Bars</a></li> + </ol> + </li> + </ol> +</div> + +<h3>Tutorial Copyright and Permissions Notice</h3> + +<p>The GTK Tutorial is Copyright © 1997 Ian Main.</p> + +<p>Copyright © 1998-2002 Tony Gale.</p> + +<p>Copyright © 2007 Hans van Thiel and Alex Tarkovsky.</p> + +<p> +Permission is granted to make and distribute verbatim copies of this manual +provided the copyright notice and this permission notice are preserved on all +copies. +</p> + +<p> +Permission is granted to copy and distribute modified versions of this document +under the conditions for verbatim copying, provided that this copyright notice +is included exactly as in the original, and that the entire resulting derived +work is distributed under the terms of a permission notice identical to this +one. +</p> + +<p> +Permission is granted to copy and distribute translations of this document into +another language, under the above conditions for modified versions. +</p> + +<p> +If you are intending to incorporate this document into a published work, please +contact the maintainer, and we will make an effort to ensure that you have the +most up to date information available. +</p> + +<p> +There is no guarantee that this document lives up to its intended purpose. This +is simply provided as a free resource. As such, the authors and maintainers of +the information provided within can not make any guarantee that the information +is even accurate. +</p> + +<div id="footer"> + <span class="nav-previous"> </span> + <span class="nav-home"> </span> + <span class="nav-next"><a href="chap3.xhtml">Next</a><br />Getting Started</span> +</div> + +</body> +</html> |
From: Duncan C. <dun...@wo...> - 2007-09-04 20:16:32
|
Tue Sep 4 06:50:20 PDT 2007 Alex Tarkovsky <ale...@gm...> * Remove broken links from Glade tutorial hunk ./docs/tutorial/glade/index.t2t 11 -developers wanting to write Gtk+ apps using Glade. We assume you are using -Linux, but because the Gtk+ toolkit, the Glade Interface Designer and Gtk2Hs +developers wanting to write GTK+ apps using Glade. We assume you are using +Linux, but because the GTK+ toolkit, the Glade Interface Designer and Gtk2Hs hunk ./docs/tutorial/glade/index.t2t 17 -[Gtk2Hs http://haskell.org/gtk2hs/] of an -[original tutorial http://www.writelinux.com/glade/] for C and the Gtk+ C API. +[Gtk2Hs http://haskell.org/gtk2hs/] of an original tutorial for C and the GTK+ +C API. hunk ./docs/tutorial/glade/index.t2t 22 -- [Gtk+ http://www.gtk.org/] libraries +- [GTK+ http://www.gtk.org/] libraries hunk ./docs/tutorial/glade/index.t2t 62 -wait! We can't add widgets just yet. Widgets in Gtk+ apps are //packed//. +wait! We can't add widgets just yet. Widgets in GTK+ apps are //packed//. hunk ./docs/tutorial/glade/index.t2t 324 -For Glade see [part 2 http://eddy.writelinux.com/part2/] of the -[original tutorial http://www.writelinux.com/glade/]. - hunk ./docs/tutorial/glade/index.t2t 330 -The original [C version http://writelinux.com/glade/] of this tutorial was -written by Eddy Ahmed. It was adapted for Haskell and Gtk2Hs by +The original C version of this tutorial was written by Eddy Ahmed. It was +adapted for Haskell and Gtk2Hs by hunk ./docs/tutorial/glade/index.t2t 335 -Copyright 2002 [Eddy Ahmed http://www.writelinux.com/] +Copyright 2002 Eddy Ahmed. |
From: Duncan C. <dun...@wo...> - 2007-09-04 12:36:33
|
Mon Sep 3 10:36:46 PDT 2007 Duncan Coutts <du...@ha...> * Fix gconf_MOSTLYCLEANFILES typo hunk ./Makefile.am 965 - $(libHSgconf_a_CHSFILES:.chs=_stub.h) \ + $(libHSgconf_a_CHSFILES:.chs=_stub.o) \ |
From: Duncan C. <dun...@wo...> - 2007-09-04 12:36:32
|
Fri Aug 31 06:25:07 PDT 2007 hth...@zo... * Tutorial_Port Text Entries and Statusbars (Chapter 11) + links update addfile ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap11.hs hunk ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap11.hs 1 +import Graphics.UI.Gtk + +main :: IO () +main= do + initGUI + window <- windowNew + set window [windowTitle := "Text Entry", containerBorderWidth := 10] + + vb <- vBoxNew False 0 + containerAdd window vb + + hb <- hBoxNew False 0 + boxPackStart vb hb PackNatural 0 + + txtfield <- entryNew + boxPackStart hb txtfield PackNatural 5 + button <- buttonNewFromStock stockInfo + boxPackStart hb button PackNatural 0 + + txtstack <- statusbarNew + boxPackStart vb txtstack PackNatural 0 + id <- statusbarGetContextId txtstack "Line" + + widgetShowAll window + widgetSetSensitivity button False + + onEntryActivate txtfield (saveText txtfield button txtstack id) + onPressed button (statusbarPop txtstack id) + onDestroy window mainQuit + mainGUI + +saveText :: Entry -> Button -> Statusbar -> ContextId -> IO () +saveText fld b stk id = do + txt <- entryGetText fld + let mesg | txt == reverse txt = "\"" ++ txt ++ "\"" ++ + " is equal to its reverse" + | otherwise = "\"" ++ txt ++ "\"" ++ + " is not equal to its reverse" + widgetSetSensitivity b True + msgid <- statusbarPush stk id mesg + return () + [_$_] + + + + + addfile ./docs/tutorial/Tutorial_Port/Images/GtkChap11.png binary ./docs/tutorial/Tutorial_Port/Images/GtkChap11.png hunk ./docs/tutorial/Tutorial_Port/chap1.html 71 + + <dt><br> + <a href="chap11.html">Text Entries and Statusbars</a></dt> hunk ./docs/tutorial/Tutorial_Port/chap10.html 31 - </td><!-- - <TD WIDTH=10%> - <P ALIGN=RIGHT><A HREF="chap11.html">Next >>></A></P> - </TD> [_$_] - --> + </td> + + <td width="10%"> + <p align="right"><a href="chap11.html">Next + >>></a></p> + </td> hunk ./docs/tutorial/Tutorial_Port/chap10.html 278 - </td><!-- - <TD WIDTH=33%> - <P ALIGN=RIGHT><A HREF="chap11.html">Next >>></A></P> - </TD> - --> + </td> + + <td width="33%"> + <p align="right"><a href="chap11.html">Next + >>></a></p> + </td> hunk ./docs/tutorial/Tutorial_Port/chap10.html 296 - <p align="right">To be continued</p> + <p align="right">Text Entries and Satusbars</p> addfile ./docs/tutorial/Tutorial_Port/chap11.html hunk ./docs/tutorial/Tutorial_Port/chap11.html 1 +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> + +<html> +<head> + <meta name="generator" content= + "HTML Tidy for Linux/x86 (vers 11 February 2007), see www.w3.org"> + <meta http-equiv="CONTENT-TYPE" content= + "text/html; charset=us-ascii"> + + <title>Text Entries and Statusbars</title> +</head> + +<body lang="en-US" text="#000000" link="#0000FF" vlink="#840084" +bgcolor="#FFFFFF" dir="ltr"> + <table summary="links to other pages" width="100%" border="0" + cellpadding="0" cellspacing="0"> + <tr> + <th colspan="3"> + <p align="center">Gtk2Hs Tutorial</p> + </th> + </tr> + + <tr valign="bottom"> + <td width="10%"> + <p align="left"><a href="chap10.html"><<< + Previous</a></p> + </td> + + <td width="80%"> + <p align="center"><br></p> + </td><!-- + <TD WIDTH=10%> + <P ALIGN=RIGHT><A HREF="chap12.html">Next >>></A></P> + </TD> + --> + </tr> + </table> + <hr> + + <h2><a name="SEC-TEXTENTRIES" id="SEC-TEXTENTRIES"></a>Text + Entries and Status Bars</h2> + + <p>The <i>Entry</i> widget allows text to be typed and displayed + in a single line text box. A fairly large set of key bindings are + supported by default. The user can choose between insert and + overwite mode by toggling the Insert key.</p> + + <p>Create a new <i>Entry</i> widget with the following + function.</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> + <tr> + <td> + <pre> +entryNew :: IO Entry +</pre> + </td> + </tr> + </table> + + <p>To replace or get the text which is currently within the + <i>Entry</i> widget:</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> + <tr> + <td> + <pre> +entrySetText :: EntryClass self => self -> String -> IO () + +entryGetText :: EntryClass self => self -> IO String +</pre> + </td> + </tr> + </table> + + <p>If we don't want the contents of the <i>Entry</i> to be + changed by someone typing into it, we can change its editable + state. We can also set visibility (e.g. for passwords), the + maximum number of characters (0 if no maximum), whether the entry + has a frame or not, the number of characters to leave space for, + and a few other attributes. Text completion is also possible (see + <i>EntryCompletion</i> in the API documentation for its use). The + <i>Entry</i> attributes, which, of course, can be accessed with + <i>get</i> and <i>set</i> are:</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> + <tr> + <td> + <pre> +entryEditable :: EntryClass self => Attr self Bool -- default True + +entryVisibility :: EntryClass self => Attr self Bool -- default True + +entryMaxLength :: EntryClass self => Attr self Int -- 0 if no maximum, limit 66535 + +entryHasFrame :: EntryClass self => Attr self Bool -- default False + +entryWidthChars :: EntryClass self => Attr self Int -- default -1, no space set +</pre> + </td> + </tr> + </table> + + <p>The <i>Entry</i> type is an instance of <i>EditableClass</i> + and many attributes and methods are defined there. Some + particularly useful ones are:</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="0" bgcolor="#E0E0E0"> + <col width="256*"> + + <tr> + <td width="100%"> + <pre> +editableInsertText :: EditableClass self => self -> String -> Int -> IO Int + +editableDeleteText :: EditableClass self -> Int -> Int -> IO () + +editableSelectRegion :: EditableClass self => self -> Int -> Int -> IO () + +editableDeleteSelection :: EditableClass self -> IO () +</pre> + </td> + </tr> + </table> + + <p>where the parameters of type <i>Int</i> denote the appropriate + start or end positions. The user can also cut, copy and paste + to/from the clipboard.</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="0" bgcolor="#E0E0E0"> + <col width="256*"> + + <tr> + <td width="100%"> + <pre> +editableCutClipboard :: EditableClass self => self -> IO () + +editableCopyClipboard :: EditableClass self => self -> IO () + +editablePasteClipboard :: EditableClass self => self -> IO () +</pre> + </td> + </tr> + </table> + + <p>These all take the current cursor position. You can get and + set that position with:</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="0" bgcolor="#E0E0E0"> + <col width="256*"> + + <tr> + <td width="100%"> + <pre> +editableGetPosition :: EditableClass self => self -> IO Int + +editableSetPosition :: EditableClass self => self -> Int +</pre> + </td> + </tr> + </table> + + <p>The cursor is displayed before the character with the given + (base 0) index in the widget. The value must be less than or + equal to the number of characters in the widget. A value of -1 + indicates that the position should be set after the last + character in the entry.</p> + + <p>The Editable class has a number of signals which use higher + order functions (not discussed here). The <i>Entry</i> widget + itself has a signal, which is sent after the user presses the + Enter key:</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="0" bgcolor="#E0E0E0"> + <col width="256*"> + + <tr> + <td width="100%"> + <pre> +onEntryActivate :: EntryClass ec => ec -> IO () -> IO (ConnectId ec) +</pre> + </td> + </tr> + </table> + + <p>There are also signals sent when text is copied, cut or pasted + to the clipboard, and when the user toggles overwrite/insert + mode.</p> + + <p>Statusbars are simple widgets used to display a text message. + They keep a stack of the messages pushed onto them, so that + popping the current message will re-display the previous text + message. A statusbar has a resize grip by default, so the user + can resize it.</p> + + <p>In order to allow different parts of an application to use the + same statusbar to display messages, the statusbar widget issues + Context Identifiers which are used to identify different "users". + The message on top of the stack is the one displayed, no matter + what context it is in. Messages are stacked in last-in-first-out + order, not context identifier order. A statusbar is created + with:</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> + <tr> + <td> + <pre> +statusbarNew :: IO Statusbar +</pre> + </td> + </tr> + </table> + + <p>A new Context Identifier is generated by the following + function, with a String used as textual description of the + context:</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> + <tr> + <td> + <pre> +statusbarGetContextId :: StatusbarClass self => self -> String -> IO ContextId +</pre> + </td> + </tr> + </table> + + <p>There are three functions that can operate on statusbars:</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> + <tr> + <td> + <pre> +statusbarPush :: StatusbarClass self => self -> ContextId -> String -> IO MessageId + +statusbarPop :: StatusbarClass self => self -> ContextId -> IO () + +statusbarRemove :: StatusbarClass self => self -> ContextId -> MessageId -> IO () +</pre> + </td> + </tr> + </table> + + <p>The first, <i>statusbarPush</i> , is used to add a new message + to the statusbar. It returns a <i>MessageId</i>, which can be + passed later to <i>statusbarRemove</i> to remove the message with + the given <i>ContextId</i> and <i>MessageId</i> from the + statusbar's stack. Function <i>statusbarPop</i> removes the + message highest in the stack with the given context + identifier.</p> + + <p>Statusbars, like progress bars, are used to display messages + to the user about some ongoing operation. We'll simulate such an + operation in the example below, by testing whether the text the + user submits (by pressing Enter) is the same as its reverse, and + pushing the result on the stack. The user can then see the + results by pressing the information button, which pops the stack + of messages. The first time the stack is empty, so the button is + greyed out using:</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="0" bgcolor="#E0E0E0"> + <col width="256*"> + + <tr> + <td width="100%"> + <pre> +widgetSetSensitivity :: WidgetClass self => self -> Bool -> IO () +</pre> + </td> + </tr> + </table> + + <p>Note that status bars would not be the first choice here, + since there is no testing if the stack is empty, but the example + does show how they can be applied. The resize handle of the + status bar is not very clear, but it is there, at the bottom + right.</p> + + <p><img src="./Images/GtkChap11.png" alt="GtkChap11.png" align= + "bottom"></p><br> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="0" bgcolor="#E0E0E0"> + <col width="256*"> + + <tr> + <td width="100%"> + <pre> +import Graphics.UI.Gtk + +main :: IO () +main= do + initGUI + window <- windowNew + set window [windowTitle := "Text Entry", containerBorderWidth := 10] + + vb <- vBoxNew False 0 + containerAdd window vb + + hb <- hBoxNew False 0 + boxPackStart vb hb PackNatural 0 + + txtfield <- entryNew + boxPackStart hb txtfield PackNatural 5 + button <- buttonNewFromStock stockInfo + boxPackStart hb button PackNatural 0 + + txtstack <- statusbarNew + boxPackStart vb txtstack PackNatural 0 + id <- statusbarGetContextId txtstack "Line" + + widgetShowAll window + widgetSetSensitivity button False + + onEntryActivate txtfield (saveText txtfield button txtstack id) + onPressed button (statusbarPop txtstack id) + onDestroy window mainQuit + mainGUI + +saveText :: Entry -> Button -> Statusbar -> ContextId -> IO () +saveText fld b stk id = do + txt <- entryGetText fld + let mesg | txt == reverse txt = "\"" ++ txt ++ "\"" ++ + " is equal to its reverse" + | otherwise = "\"" ++ txt ++ "\"" ++ + " is not equal to its reverse" + widgetSetSensitivity b True + msgid <- statusbarPush stk id mesg + return () +</pre> + </td> + </tr> + </table><br> + + <table summary="links to other pages" width="100%" border="0" + cellpadding="0" cellspacing="0"> + <tr valign="top"> + <td width="33%"> + <p align="left"><a href="chap10.html"><<< + Previous</a></p> + </td> + + <td width="34%"> + <p align="center"><a href="chap1.html">Home</a></p> + </td><!-- + <TD WIDTH=33%> + <P ALIGN=RIGHT><A HREF="chap12.html">Next >>></A></P> + </TD> + --> + </tr> + + <tr valign="top"> + <td width="33%"> + <p align="left">Dialogs, Progress Bars</p> + </td> + + <td width="34%"> + <p align="center"><br></p> + </td> + + <td width="33%"> + <p align="right">To be continued</p> + </td> + </tr> + </table> +</body> +</html> |
From: Duncan C. <dun...@wo...> - 2007-09-04 12:36:30
|
Fri Aug 31 03:53:57 PDT 2007 hth...@zo... * Dialogs StockItems Progress Bars (chapter 10) Chapter 10 plus crrected links in Chapter 1 and Chapter 8 addfile ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap10.hs hunk ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap10.hs 1 +import Graphics.UI.Gtk + +main :: IO () +main = do + initGUI + [_$_] + dia <- dialogNew + set dia [windowTitle := "Time Flies"] + dialogAddButton dia stockApply ResponseApply + dialogAddButton dia stockCancel ResponseCancel + dialogAddButton dia stockClose ResponseClose + + pr <- progressBarNew + progressBarSetPulseStep pr 1.0 + + upbox <- dialogGetUpper dia + boxPackStart upbox pr PackGrow 10 + widgetShowAll upbox + [_$_] + answer <- dialogRun dia + if answer == ResponseApply [_$_] + then do tmhandle <- timeoutAdd (showPulse pr) 500 + return () + else widgetDestroy dia + [_$_] + onDestroy dia mainQuit + mainGUI + +showPulse :: ProgressBar -> IO Bool +showPulse b = do progressBarPulse b + return True addfile ./docs/tutorial/Tutorial_Port/Images/GtkChap10.png binary ./docs/tutorial/Tutorial_Port/Images/GtkChap10.png hunk ./docs/tutorial/Tutorial_Port/chap1.html 16 - "Gtk2Hs-TUT"></a><a name="AEN2" id="AEN2"></a>Gtk2Hs - Tutorial (part 1)</h2> + "Gtk2Hs-TUT"></a><a name="AEN2" id="AEN2"></a>Gtk2Hs Tutorial + (part 1)</h2> hunk ./docs/tutorial/Tutorial_Port/chap1.html 60 - <dt><br> + + <dl> + <dt><br> hunk ./docs/tutorial/Tutorial_Port/chap1.html 64 + + <dt><br> + <a href="chap9.html">Arrows and Tooltips</a></dt> + + <dt><br> + <a href="chap10.html">Dialogs, Stock Items and Progress + Bars</a></dt> addfile ./docs/tutorial/Tutorial_Port/chap10.html hunk ./docs/tutorial/Tutorial_Port/chap10.html 1 +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> + +<html> +<head> + <meta name="generator" content= + "HTML Tidy for Linux/x86 (vers 11 February 2007), see www.w3.org"> + <meta http-equiv="CONTENT-TYPE" content= + "text/html; charset=us-ascii"> + + <title>Dialogs, Stock Items and Progress Bars</title> +</head> + +<body lang="en-US" text="#000000" link="#0000FF" vlink="#840084" +bgcolor="#FFFFFF" dir="ltr"> + <table summary="links to other pages" width="100%" border="0" + cellpadding="0" cellspacing="0"> + <tr> + <th colspan="3"> + <p align="center">Gtk2Hs Tutorial</p> + </th> + </tr> + + <tr valign="bottom"> + <td width="10%"> + <p align="left"><a href="chap9.html"><<< + Previous</a></p> + </td> + + <td width="80%"> + <p align="center"><br></p> + </td><!-- + <TD WIDTH=10%> + <P ALIGN=RIGHT><A HREF="chap11.html">Next >>></A></P> + </TD> [_$_] + --> + </tr> + </table> + + <h2><a name="SEC-DIALOGS" id="SEC-DIALOGS"></a>Dialogs, Stock + Items and Progress Bars</h2> + + <p>A dialog is an example of a composite widget. It consists of a + window, an upper part which is a vertical box, and an action area + which is a horizontal box. By default, both parts are separated + by a horizontal separator.</p> + + <p>The <i>Dialog</i> widget can be used for pop-up messages to + the user, and other similar tasks. The basic functions needed + are:</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> + <tr> + <td> + <pre> +dialogNew :: IO Dialog + +dialogRun :: DialogClass self => self -> IO ResponseID +</pre> + </td> + </tr> + </table> + + <p>You add buttons into the action area with:</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="0" bgcolor="#E0E0E0"> + <col width="256*"> + + <tr> + <td width="100%"> + <pre> +dialogAddButton :: DialogClass self => self -> String -> ResponseId -> IO Button +</pre> + </td> + </tr> + </table> + + <p>Any widget can be added in a similar way with + <i>dialogAddActionWidget.</i></p> + + <p>The <i>String</i> in <i>dialogAddButton</i> can be the text of + the button, but since dialogs are mostly used for standard + situations a <i>StockItem</i> will usually be more + appropriate.</p> + + <p><i>StockItems</i> are resources which are known throughout + Gtk2Hs, such as standard <i>IconSets.</i> You can define your + own, but many useful ones are listed in the + <i>Graphics.UI.Gtk.General.StockItems</i> module. They have an + identifier <i>StockId</i> ,which is a type synonym for + <i>String</i>. From this identifier a widget (usually a button) + with the appropriate standard text and icon is automatically + selected.</p> + + <p>If you use a <i>StockId</i> when adding a button to a dialog, + you can also use a pre-defined <i>ResponseId</i> constructor with + the buttons. (<i>ResponseId</i> is not a <i>String.</i>) + Customized responses may be constructed with <i>ResponseUser + Int</i> .</p> + + <p>Whenever a dialog button is pressed, its response is passed to + the calling application through <i>dialogRun</i>. According to + the Gtk2Hs API documentation <i>dialogRun</i> blocks in a + recursive main loop until the dialog either emits the response + signal, or is destroyed. The default mode is modal, which means + the user cannot access any other window while <i>dialogRun</i> is + waiting for a response.</p> + + <p>Progress bars are used to show the status of an ongoing + operation.</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> + <tr> + <td> + <pre> +progressBarNew :: IO ProgressBar +</pre> + </td> + </tr> + </table> + + <p>Though there is only one type, there are two distinct ways to + use a progress bar. If it is known how much of the task has been + completed, the fraction (between 0.0 and 1.0 inclusive) can be + set with:</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> + <tr> + <td> + <pre> +progressBarSetFraction :: ProgressBarClass self => self -> Double -> IO () +</pre> + </td> + </tr> + </table> + + <p>This causes the progress bar to be filled in with the + specified amount (between 0.0 and 1.0). To trace the progress + this function should be called at regular times during the + operation.</p> + + <p>When it is not known how much of the operation has been + completed, the bar can be moved back and forth with:</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="0" bgcolor="#E0E0E0"> + <col width="256*"> + + <tr> + <td width="100%"> + <pre> +progressBarPulse :: ProgressBarClass self => self -> IO () +</pre> + </td> + </tr> + </table> + + <p>This function must also be called repeatedly, to show that the + activity is going on. There are several other functions to + control the display of a progress bar, like orientation, + additional text etc.; they are fairly trivial.</p> + + <p>Application, however, is not trivial because progress bars are + usually applied with timeouts or other such functions to give the + illusion of multitasking. With concurrent Haskell you can also + use threads and communication between threads.</p> + + <p>In the following example we'll simulate an activity using + <i>timeoutAdd</i>, which runs a function repeatedly at the + interval specified, in milliseconds. The function is passed to + <i>timeoutAdd</i> and must return a type of <i>IO Bool</i>. When + true the timeout is run again, when false it stops. The priority + of <i>timeoutAdd</i> is <i>priorityDefault</i> of type + <i>Priority</i>.</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="0" bgcolor="#E0E0E0"> + <col width="256*"> + + <tr> + <td width="100%"> + <pre> +timeoutAdd :: IO Bool -> Int -> IO HandlerId +</pre> + </td> + </tr> + </table> + + <p>In the example we define the function <i>showPulse</i> , which + causes the progress bar to pulse and always returns <i>IO + True.</i> The pulse step, the amount which the indicator moves + through the bar, is set to 1.0 with + <i>progressBarSetPulseStep</i>.</p> + + <p><br> + <img src="./Images/GtkChap10.png" align="bottom" alt= + "GtkChap10"><br></p> + + <p>The example is somewhat atypical of the use of a dialog, since + we keep it to show the progress after the user has pressed the + apply button. To close the application the dialog must be + destroyed by destroying the window. The close and cancel buttons + don't work after apply has been selected. If selected, instead of + Apply, the first time, the application will close. This is done + by testing the response from dialogRun.</p> + + <p>If the dialog widget is destroyed, <i>mainQuit</i> is called. + As mentioned above, a <i>Dialog</i> consists of a window and two + boxes. The boxes must be accessed through special functions, and + the progress bar is packed into the upper part using + <i>dialogGetUpper</i>. The buttons in a dialog are visible by + default, but the widgets in the upper part are not. A + <i>Dialog</i> is an instance of the <i>WindowClass,</i> and so we + can set the title and/or default length and height if we + want.</p> + + <p style="font-style: normal">A trivial feature to watch out for: + a widget can only be made visible if its parent is visible. So, + to show the progress bar, we use <i>widgetShowAll</i> on the + vertical box and not <i>widgetShow</i> on the progress bar.</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> + <tr> + <td> + <pre> +import Graphics.UI.Gtk + +main :: IO () +main = do + initGUI + [_$_] + dia <- dialogNew + set dia [windowTitle := "Time Flies"] + dialogAddButton dia stockApply ResponseApply + dialogAddButton dia stockCancel ResponseCancel + dialogAddButton dia stockClose ResponseClose + + pr <- progressBarNew + progressBarSetPulseStep pr 1.0 + + upbox <- dialogGetUpper dia + boxPackStart upbox pr PackGrow 10 + widgetShowAll upbox + [_$_] + answer <- dialogRun dia + if answer == ResponseApply [_$_] + then do tmhandle <- timeoutAdd (showPulse pr) 500 + return () + else widgetDestroy dia + [_$_] + onDestroy dia mainQuit + mainGUI + +showPulse :: ProgressBar -> IO Bool +showPulse b = do progressBarPulse b + return True +</pre> + </td> + </tr> + </table> + <hr> + + <table summary="links to other pages" width="100%" border="0" + cellpadding="0" cellspacing="0"> + <tr valign="top"> + <td width="33%"> + <p align="left"><a href="chap9.html"><<< + Previous</a></p> + </td> + + <td width="34%"> + <p align="center"><a href="chap1.html">Home</a></p> + </td><!-- + <TD WIDTH=33%> + <P ALIGN=RIGHT><A HREF="chap11.html">Next >>></A></P> + </TD> + --> + </tr> + + <tr valign="top"> + <td width="33%"> + <p align="left">Arrows and Tooltips</p> + </td> + + <td width="34%"> + <p align="center"><br></p> + </td> + + <td width="33%"> + <p align="right">To be continued</p> + </td> + </tr> + </table> + + <p><br> + <br></p> +</body> +</html> hunk ./docs/tutorial/Tutorial_Port/chap8.html 1 -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> hunk ./docs/tutorial/Tutorial_Port/chap8.html 168 + hunk ./docs/tutorial/Tutorial_Port/chap8.html 279 - </td><!-- - <TD WIDTH=33%> - <P ALIGN=RIGHT><A HREF="chap9.html">Next >>></A></P> - </TD [_$_] - --> + </td> + + <td width="33%"> + <p align="right"><a href="chap9.html">Next + >>></a></p> + </td> |
From: Duncan C. <dun...@wo...> - 2007-09-04 12:36:29
|
Mon Sep 3 10:36:46 PDT 2007 Duncan Coutts <du...@ha...> * Fix gconf_MOSTLYCLEANFILES typo hunk ./Makefile.am 941 - $(libHSgconf_a_CHSFILES:.chs=_stub.h) \ + $(libHSgconf_a_CHSFILES:.chs=_stub.o) \ |
From: Duncan C. <dun...@wo...> - 2007-09-04 12:36:26
|
Wed Aug 8 10:16:54 PDT 2007 Duncan Coutts <du...@ha...> * Import CUInt in the Types.chs modules as GType seems to be CUInt now Reported in Fedora 8 that c2hs reports GType as CUInt whereas it previously was CULong, so we now import both in the Hierarchy.chs.template. hunk ./tools/hierarchyGen/Hierarchy.chs.template 34 -import Foreign.C.Types (CULong) +import Foreign.C.Types (CULong, CUInt) |
From: Duncan C. <dun...@wo...> - 2007-09-03 09:23:07
|
Sat Sep 1 02:48:53 PDT 2007 Alex Tarkovsky <ale...@gm...> * Gtk2Hs tutorial: chapter 3 updates hunk ./docs/tutorial/Tutorial_Port/chap3.html 55 - of the super classes of which your widget type is an - instance.</p> + of the superclasses of which your widget type is an instance.</p> hunk ./docs/tutorial/Tutorial_Port/chap3.html 73 -main = do [_$_] +main = do hunk ./docs/tutorial/Tutorial_Port/chap3.html 168 - general <i>set</i> function, which uses a list like notation as + general <i>set</i> function, which uses a list-like notation as hunk ./docs/tutorial/Tutorial_Port/chap3.html 170 - <i>containerChild</i> attribute of the window (actually a super - class of the window) which states the relationship with the + <i>containerChild</i> attribute of the window (actually a + superclass of the window) which states the relationship with the hunk ./docs/tutorial/Tutorial_Port/chap3.html 179 - tree</i> window. There is a separate introductory tutorial on how - to use Glade with Gtk2Hs.</p> + tree</i> window. There is a <a href= + "http://haskell.org/gtk2hs/docs/tutorial/glade/">separate + introductory tutorial</a> on how to use Glade with Gtk2Hs.</p> hunk ./docs/tutorial/Tutorial_Port/chap3.html 194 -main = do [_$_] +main = do hunk ./docs/tutorial/Tutorial_Port/chap3.html 203 - mainGUI [_$_] + mainGUI |
From: Duncan C. <dun...@wo...> - 2007-08-31 11:28:18
|
Thu Aug 30 13:23:33 PDT 2007 hth...@zo... * Arrows and Tooltips Chapter 9 addfile ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap9.hs hunk ./docs/tutorial/Tutorial_Port/Example_Code/GtkChap9.hs 1 +import Graphics.UI.Gtk + +main :: IO () +main = do + initGUI + window <- windowNew + set window [windowTitle := "Arrow Tips", [_$_] + windowDefaultWidth := 200, + windowDefaultHeight := 200, containerBorderWidth := 20 ] + + table <- tableNew 5 5 True + containerAdd window table + [_$_] + button1 <- buttonNew + button2 <- buttonNew + button3 <- buttonNew + button4 <- buttonNew + + tableAttachDefaults table button1 0 1 2 3 + tableAttachDefaults table button2 2 3 0 1 + tableAttachDefaults table button3 4 5 2 3 + tableAttachDefaults table button4 2 3 4 5 + + tlt <- tooltipsNew + + arrow1 <- arrowNew ArrowLeft ShadowEtchedIn [_$_] + containerAdd button1 arrow1 + tooltipsSetTip tlt button1 "West" "T1" + + arrow2 <- arrowNew ArrowUp ShadowEtchedOut + containerAdd button2 arrow2 + tooltipsSetTip tlt button2 "North" "T2" + + arrow3 <- arrowNew ArrowRight ShadowEtchedIn + containerAdd button3 arrow3 + tooltipsSetTip tlt button3 "East" "T3" + + arrow4 <- arrowNew ArrowDown ShadowEtchedOut + containerAdd button4 arrow4 + tooltipsSetTip tlt button4 "South" "T4" + + tooltipsEnable tlt + widgetShowAll window + onDestroy window mainQuit + mainGUI + + + [_$_] addfile ./docs/tutorial/Tutorial_Port/Images/GtkChap9.png binary ./docs/tutorial/Tutorial_Port/Images/GtkChap9.png addfile ./docs/tutorial/Tutorial_Port/chap9.html hunk ./docs/tutorial/Tutorial_Port/chap9.html 1 +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> + +<html> +<head> + <meta name="generator" content= + "HTML Tidy for Linux/x86 (vers 11 February 2007), see www.w3.org"> + <meta http-equiv="CONTENT-TYPE" content= + "text/html; charset=us-ascii"> + + <title>Arrows and Tooltips</title> +</head> + +<body lang="en-US" text="#000000" link="#0000FF" vlink="#840084" +bgcolor="#FFFFFF" dir="ltr"> + <table summary="links to other pages" width="100%" border="0" + cellpadding="0" cellspacing="0"> + <tr> + <th colspan="3"> + <p align="center">Gtk2Hs Tutorial</p> + </th> + </tr> + + <tr valign="bottom"> + <td width="10%"> + <p align="left"><a href="chap8.html"><<< + Previous</a></p> + </td> + + <td width="80%"> + <p align="center"><br></p> + </td> + + <td width="10%"> + <p align="right"><a href="chap10.html">Next + >>></a></p> + </td> + </tr> + </table> + <hr> + + <h2><a name="SEC-ARROWS" id="SEC-ARROWS"></a>Arrows and + Tooltips</h2> + + <p>The Arrow widget draws an arrowhead, facing in a number of + possible directions and having a number of possible styles. Like + the Label widget, it emits no signals.</p> + + <p>There are only two functions for manipulating an Arrow + widget:</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> + <tr> + <td> + <pre> +arrowNew :: ArrowType -> ShadowType -> IO Arrow + +arrowSet :: ArrowClass self => self -> ArrowType -> ShadowType -> IO () +</pre> + </td> + </tr> + </table> + + <p>The <i>ArrowType</i> has 5 constructors:</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> + <tr> + <td> + <pre> +ArrowUp +ArrowDown +ArrowLeft +ArrowRight +ArrowNone +</pre> + </td> + </tr> + </table> + + <p>The <i>ShadowType</i> also has 5 constructors:</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> + <tr> + <td> + <pre> +ShadowNone +ShadowIn +ShadowOut +ShadowEtchedIn +ShadowEtchedOut +</pre> + </td> + </tr> + </table> + + <p>Tooltips are the little text strings that pop up when you + leave your pointer over a button or other widget for a few + seconds.</p> + + <p>Widgets that do not receive events (widgets that do not have + their own window) will not work with tooltips.</p> + + <p>The first call you will use creates a new tooltip. You only + need to do this once for a set of tooltips.</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> + <tr> + <td> + <pre> +tooltipsNew :: IO Tooltips +</pre> + </td> + </tr> + </table> + + <p>Then, for every widget, use:</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> + <tr> + <td> + <pre> +tooltipsSetTip :: (TooltipsClass self, WidgetClass widget) [_$_] +=> self -> widget -> String -> String -> IO () +</pre> + </td> + </tr> + </table> + + <p>The first argument is the tooltip you've already created, + followed by the widget you wish to have this tooltip pop up for, + and the text you wish it to say. The last argument is a text + string that can be used as an identifier.</p> + + <p>You can turn the tips associated with a <i>Tooltips</i> value + on or off using:</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="2" bgcolor="#E0E0E0"> + <tr> + <td> + <pre style="margin-bottom: 0.5cm"> +tooltipsEnable :: TooltipsClass self => self -> IO () +tooltipsDisable :: TooltipsClass self => self -> IO () +</pre> + </td> + </tr> + </table> + + <p>Here's an example to illustrate the use of arrows and + tooltips.</p> + + <p><br> + <img src="./Images/GtkChap9.png" align="bottom" alt= + "GtkChap9"><br></p> + + <p>The window above has been resized from its default size, to + show how the packing in a table preserves the spacing of the + buttons with their arrows.</p> + + <p>Note: the tooltips don't work with GHCi (on my machine) but + they do when compiled. You cannot see them in the screenshot, of + course.</p> + + <table summary="Haskell code" width="100%" border="0" + cellpadding="2" cellspacing="0" bgcolor="#E0E0E0"> + <col width="256*"> + + <tr> + <td width="100%"> + <pre> +import Graphics.UI.Gtk + +main :: IO () +main = do + initGUI + window <- windowNew + set window [windowTitle := "Arrow Tips", [_$_] + windowDefaultWidth := 200, + windowDefaultHeight := 200, containerBorderWidth := 20 ] + + table <- tableNew 5 5 True + containerAdd window table + [_$_] + button1 <- buttonNew + button2 <- buttonNew + button3 <- buttonNew + button4 <- buttonNew + + tableAttachDefaults table button1 0 1 2 3 + tableAttachDefaults table button2 2 3 0 1 + tableAttachDefaults table button3 4 5 2 3 + tableAttachDefaults table button4 2 3 4 5 + + tlt <- tooltipsNew + + arrow1 <- arrowNew ArrowLeft ShadowEtchedIn [_$_] + containerAdd button1 arrow1 + tooltipsSetTip tlt button1 "West" "T1" + + arrow2 <- arrowNew ArrowUp ShadowEtchedOut + containerAdd button2 arrow2 + tooltipsSetTip tlt button2 "North" "T2" + + arrow3 <- arrowNew ArrowRight ShadowEtchedIn + containerAdd button3 arrow3 + tooltipsSetTip tlt button3 "East" "T3" + + arrow4 <- arrowNew ArrowDown ShadowEtchedOut + containerAdd button4 arrow4 + tooltipsSetTip tlt button4 "South" "T4" + + tooltipsEnable tlt + widgetShowAll window + onDestroy window mainQuit + mainGUI +</pre> + </td> + </tr> + </table> + <hr> + + <table summary="links to other pages" width="100%" border="0" + cellpadding="0" cellspacing="0"> + <tr valign="top"> + <td width="33%"> + <p align="left"><a href="chap8.html"><<< + Previous</a></p> + </td> + + <td width="34%"> + <p align="center"><a href="chap1.html">Home</a></p> + </td> + + <td width="33%"> + <p align="right"><a href="chap10.html">Next + >>></a></p> + </td> + </tr> + + <tr valign="top"> + <td width="33%"> + <p align="left">Labels</p> + </td> + + <td width="34%"> + <p align="center"><br></p> + </td> + + <td width="33%"> + <p align="right">Dialogs, Stock Items Progress Bars</p> + </td> + </tr> + </table> + + <p><br> + <br></p> +</body> +</html> |
From: Duncan C. <dun...@wo...> - 2007-08-30 18:40:18
|
Thu Aug 30 11:41:07 PDT 2007 Duncan Coutts <du...@ha...> * Undo accidentally-comitted debugging change to soe hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 87 -define USE_CAIRO +#define USE_CAIRO |
From: Duncan C. <dun...@wo...> - 2007-08-30 13:38:46
|
Thu Aug 30 06:16:22 PDT 2007 Duncan Coutts <du...@ha...> * Remove a bit of soe debug cruft. hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 435 -instance Show Region where show (Region _ x y w h) = show (x,y,w,h) - hunk ./soegtk/Graphics/SOE/Gtk.hs.pp 450 - Cairo.translate (fromIntegral (x) + fromIntegral width / 2) - (fromIntegral (y) + fromIntegral height / 2) + Cairo.translate (fromIntegral x + fromIntegral width / 2) + (fromIntegral y + fromIntegral height / 2) |
From: Duncan C. <dun...@wo...> - 2007-08-30 12:43:47
|
Thu Aug 30 05:44:10 PDT 2007 Duncan Coutts <du...@ha...> * Add missing _stub to list in Makefile.am hunk ./Makefile.am 643 + gtk/Graphics/UI/Gtk/ModelView/ComboBox_stub.o \ |