[Gtk2Hs Tutorial: XHTML-ize remaining files through chapter12; rename files according to ToC Alex Tarkovsky **20070916192047] 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 - Previous + Previous hunk ./docs/tutorial/Tutorial_Port/chap2.xhtml 16 - Next + Next hunk ./docs/tutorial/Tutorial_Port/chap2.xhtml 19 -

Getting Started

+

2. Getting Started

hunk ./docs/tutorial/Tutorial_Port/chap2.xhtml 45 -

GtkChap3a

+

Window

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 GtkChap3a.hs is the filename. Alternatively you can use +assuming GtkChap2.hs is the filename. Alternatively you can use hunk ./docs/tutorial/Tutorial_Port/chap2.xhtml 129 -

GtkChap3b

+

Hello World application

hunk ./docs/tutorial/Tutorial_Port/chap2.xhtml 154 -Inspector pane. There is a +Inspector 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 - Previous
Table of Contents
+ Previous
1. Introduction
hunk ./docs/tutorial/Tutorial_Port/chap2.xhtml 191 - Next
Packing Widgets
+ Next
3.1 Packing Widgets
hunk ./docs/tutorial/Tutorial_Port/chap3-1.xhtml 14 - Previous + Previous hunk ./docs/tutorial/Tutorial_Port/chap3-1.xhtml 16 - Next + Next hunk ./docs/tutorial/Tutorial_Port/chap3-1.xhtml 19 -

Packing Widgets

+

3.1 Packing Widgets

hunk ./docs/tutorial/Tutorial_Port/chap3-1.xhtml 67 -

GtkChap4

+

Packed buttons

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 - Previous
Getting Started
+ Previous
2. Getting Started
hunk ./docs/tutorial/Tutorial_Port/chap3-1.xhtml 125 - Next
Packing Demonstration Program
+ Next
3.2 Packing Demonstration Program
hunk ./docs/tutorial/Tutorial_Port/chap3-2.xhtml 1 - - - + + + hunk ./docs/tutorial/Tutorial_Port/chap3-2.xhtml 5 - - - - Packing Demonstration Program + + Gtk2Hs Tutorial: Packing Demonstration Program + hunk ./docs/tutorial/Tutorial_Port/chap3-2.xhtml 10 - - - - - - - - - - + hunk ./docs/tutorial/Tutorial_Port/chap3-2.xhtml 12 - - -
-

Gtk2HsTutorial

-
-

<<<Previous

-
-

Packing Demonstration

-
-

Next - >>>

-
-
+ hunk ./docs/tutorial/Tutorial_Port/chap3-2.xhtml 19 -

Packing Demonstration - Program

+

3.2 Packing Demonstration Program

hunk ./docs/tutorial/Tutorial_Port/chap3-2.xhtml 21 -

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 onClicked signal is attached to the - mainQuit function.

+

+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 makeBox, +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 Quit +button, whose onClicked signal is attached to the +mainQuit function. +

hunk ./docs/tutorial/Tutorial_Port/chap3-2.xhtml 32 -

The separators are created with hSeparatorNew and they - are spaced by boxPackStart with a padding of 10 pixels. - The labels are created by labelNew which takes a Maybe - String and their positioning is set by - miscSetAlignment to be left and top justified.

+

+The separators are created with hSeparatorNew and they are spaced +by boxPackStart with a padding of ten pixels. The labels are +created by labelNew which takes a Maybe String and +their positioning is set by miscSetAlignment to be left and top +justified. +

hunk ./docs/tutorial/Tutorial_Port/chap3-2.xhtml 40 -


+

Packing demo application

hunk ./docs/tutorial/Tutorial_Port/chap3-2.xhtml 42 -

-

+

+The function makeBox :: Bool -> Int -> Packing -> Int -> IO +HBox demonstrates how Gtk2Hs widgets fit into the Haskell type system. +Packing is just a type like Int and Bool +and IO HBox is just like IO String in the usual +IO. 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. +

hunk ./docs/tutorial/Tutorial_Port/chap3-2.xhtml 52 -

The function makeBox :: Bool -> Int -> Packing -> - Int -> IO HBox demonstrates how Gtk2Hs widgets fit into - the Haskell type system. Packing is just a type like - Int and Bool and IO HBox is just like IO - String 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.


- - - - - -
-
+
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
-      
- -

The image below shows the effects of resizing the window - horizontally. In the first group, with homogeneous False - 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 False.

GtkChap5a resized
-
- - - - - - hunk ./docs/tutorial/Tutorial_Port/chap3-2.xhtml 114 - - +

+The image below shows the effects of resizing the window horizontally. In the +first group, with homogeneous set to False 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 False. +

hunk ./docs/tutorial/Tutorial_Port/chap3-2.xhtml 124 - - +

Resized packing demo application

hunk ./docs/tutorial/Tutorial_Port/chap3-2.xhtml 126 - - -
-

<<< - Previous

-
-

Home

-
-

Next - >>>

-
-

Packing Widgets

-
-

Packing Using Tables

-
+ hunk ./docs/tutorial/Tutorial_Port/chap3-2.xhtml 132 -


-

hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 1 - - - + + + hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 5 - - - - Packing Using Tables + + Gtk2Hs Tutorial: Packing Using Tables + hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 10 - - - - - - - - - - + hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 12 - - -
-

Gtk2Hs Tutorial

-
-

<<< - Previous

-
-

Tables

-
-

Next - >>>

-
-
+ hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 19 -

Packing Using Tables

+

3.3 Packing Using Tables

hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 21 -

Let's take a look at another way of packing - Tables. These - can be extremely useful in certain situations.

+

+Let's take a look at another way of packing: tables. 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. +

hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 27 -

Using tables, we create a grid that we can place widgets in. - The widgets may take up as many spaces as we specify.

+

+The first thing to look at, of course, is the tableNew function: +

hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 31 -

The first thing to look at, of course, is the tableNew - function:

- - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 34
-      
hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 35 -

The first argument is the number of rows to make in the table, - while the second, obviously, is the number of columns.

+

+The first argument is the number of rows to make in the table, while the +second, obviously, is the number of columns. +

hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 40 -

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.

+

+The boolean argument (homogeneous) has to do with how the table's +boxes are sized. If homogeneous is set to 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. +

hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 49 -

The rows and columns are laid out from 0 to n, where n was the - number specified in the call to tableNew. So, if you - specify rows = 2 and columns = 2, the layout would look something - like this:

+

+The rows and columns are laid out from 0 to n, where +n was the number specified in the call to tableNew. So +if you specify rows = 2 and columns = +2, the layout would look something like this: +

hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 56 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 64
-      
hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 65 -

Note that the coordinate system starts in the upper left hand - corner. To place a widget into a box, use the following - function:

+

+Note that the coordinate system starts in the upper left hand corner. To place +a widget into a box, use the following function: +

hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 70 - - - - -
-
-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.
+
+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
-      
- -

The first argument (self) is the table you've created and the - second (child) the widget you wish to place in the table.

- -

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 only, left_attach would be = 1, right_attach = - 2, top_attach = 1, bottom_attach = 2.

- -

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.

hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 96 -

The xoptions and yoptions are used to specify packing options - and the list may contain more than one to allow multiple - options.

+

+The first argument (self) is the table you've created and the second +(child) is the widget you wish to place in the table. +

hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 101 -

These options are:

+

+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 only, +leftAttach would be = 1, rightAttach = +2, topAttach = 1, and bottomAttach += 2. +

hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 110 -
-
Fill
+

+Now, if you wanted a widget to take up the whole top row of our 2x2 table, +you'd use leftAttach = 0, rightAttach = +2, topAttach = 0, and bottomAttach = +1. +

hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 117 -
If the table box is larger than the widget, and - Fill is specified, the widget will expand to use all - the room available.
+

+The xoptions and yoptions are used to specify packing +options and the list may contain more than one to allow multiple options. +

hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 122 -
Shrink
+

These options are:

hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 124 -
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 Shrink is specified, the - widgets will shrink with the table.
+
+
Fill
+
+ If the table box is larger than the widget, and Fill is + specified, the widget will expand to use all the room available. +
hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 131 -
Expand
+
Shrink
+
+ 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 Shrink is + specified, the widgets will shrink with the table. +
hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 139 -
This will cause the table to expand to use up any remaining - space in the window.
-
+
Expand
+
+ This will cause the table to expand to use up any remaining space in the + window. +
+
hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 146 -

Padding is just like in boxes, creating a clear area around - the widget specified in pixels.

+

+Padding is just like in boxes, creating a clear area around the widget +specified in pixels. +

hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 151 -

tableAttach has many options. So, there's a - shortcut:

+

+tableAttach has many options, so there's a shortcut: +

hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 155 - - - - -
-
-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.
+
+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
-      
hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 170 -

The values used for the AttachOptions are [Expand, - Fill], and the padding is set to 0. The rest of the - arguments are identical to the previous function.

+

+The values used for the [AttachOptions] parameters are +[Expand, Fill], and the padding is set to 0. The rest of +the arguments are identical to the previous function. +

hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 176 -

We also have tableSetRowSpacing and tableSetColSpacing. These - place spacing at the specified row or column.

+

+We also have tableSetRowSpacing and +tableSetColSpacing. These place spacing at the specified row or +column. +

hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 182 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 185
-      
hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 186 -

and,

- - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 189
-      
hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 190 -

The first Int 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.

+

+The first Int 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. +

hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 196 -

You can also set a consistent spacing of all rows and/or - columns with:

+

+You can also set a consistent spacing of all rows and/or columns with: +

hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 200 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 203
-      
hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 204 -

and,

+

and:

hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 206 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 209
-      
- -

Note that with these calls, the last row and last column do - not get any spacing.

hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 210 -


-

+

+Note that with these calls, the last row and last column do not get any +spacing. +

hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 215 -

Table Packing Example

+

Table Packing Example

hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 217 -

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:

+

+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 (Quit) is placed in +the lower row, spanning both columns, which means it should look something like +this: +

hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 224 -

-

+

Table packing

hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 226 -

Here's the source code:

+

Here's the source code:

hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 228 - - - - -
-
+
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
-      
-
- -

The buttonSwitch function is attached to both buttons - in the top row. The buttonGetLabel function is an example - of how to get an attribute from a widget using a standard method. - There is also a more general alternative get (analogous to - set) which takes a widget and an attribute. In the above - example this should be:

- - - hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 261 - - - -
-

txt <- get b buttonLabel

-
+

+The buttonSwitch function is attached to both buttons in the top +row. The buttonGetLabel function is an example of how to get an +attribute from a widget using a standard method. There is also a more general +alternative get (analogous to set) which takes a +widget and an attribute. In the above example this should be: +

hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 269 -

with the same result.

- - - - - - - - - +
+  txt <- get b buttonLabel
+
hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 273 - - +

+with the same result. +

hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 277 - - -
-

<<< - Previous

-
-

Home

-
-

Next - >>>

-
-

Packing Demonstration

-
-

Button Widget

-
+ hunk ./docs/tutorial/Tutorial_Port/chap3-3.xhtml 283 -


-

hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 1 - - - + + + hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 5 - - - - The Button Widget + + Gtk2Hs Tutorial: The Button Widget + hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 10 - - - - - - - - + hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 12 - + hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 19 - - -
-

GTK2Hs Tutorial

-
-

<<<Previous

-
-

Next - >>>

-
-
+

4.1 The Button Widget

hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 21 -

The Button - Widget

+

Normal Buttons

hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 23 -

Normal - Buttons

+

+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 +buttonNewWithLabel or buttonNewWithMnemonic to create +a button with a label, use buttonNewFromStock to create a button +containing the image and text from a stock item or use buttonNew +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 boxPackStart (or boxPackEnd +to pack from the end), and then use containerAdd to pack the box +into the button. +

hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 36 -

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 buttonNewWithLabel or - buttonNewWithMnemonic to create a button with a label, use - buttonNewFromStock to create a button containing the image - and text from a stock item or use buttonNew 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 boxPackStart (or - boxPackEnd to pack from the end), and then use - containerAdd to pack the box into the button.

+

+buttonNewWithMnemonic and buttonNewFromStock both +take a string as first argument. Use an underline to mark a character as a +mnemonic, which is a keyboard accelerator. Pressing Alt and +that key activates the button. In the second function the string is a +stockId, an identifier to a list of predefined images with labels. +

hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 44 -

buttonNewWithMnemonic and - buttonNewFromStock 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 stockId, an - identifier to a list of predefined images with labels.

+

+Here's an example of using buttonNew to create a button with an +image and a label in it. +

hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 49 -

Here's an example of using buttonNew to create a button - with a image and a label in it.

+

Button with image

hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 51 -

-

- - - - - -
-
+
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
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 80 -

The labelBox function could be used to pack images and - labels into any widget that can be a container. The image comes - from a file using imageNewFromFile and the label comes - from labelNew , which takes a Maybe String as its - argument. Nothing means no label.

+

+The labelBox function could be used to pack images and labels into +any widget that can be a container. The image comes from a file using +imageNewFromFile and the label comes from labelNew, +which takes a Maybe String as its argument. Nothing +means no label. +

hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 88 -

The Button widget has the following basic signals, - which are almost self explaining:

+

+The Button widget has the following basic signals, which are +almost self-explanatory: +

hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 93 - hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 118 -

Toggle - Buttons

+

Toggle Buttons

hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 120 -

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.

+

+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. +

hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 127 -

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.

+

+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. +

hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 133 -

Creating a new toggle button:

+

+Creating a new toggle button: +

hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 137 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 144
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 145 -

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.

+

+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. +

hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 152 -

To retrieve the state of the toggle widget, including radio - and check buttons, we use:

+

+To retrieve the state of the toggle widget, including radio and check buttons, +we use: +

hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 157 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 160
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 161 -

Returns True if the toggle button is pressed in and - False if it is raised.

+

+This returns True if the toggle button is pressed in and +False if it is raised. +

hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 166 -

To force the state of a toggle button, and its children, the - radio and check buttons, use this function:

+

+To force the state of a toggle button, and its children, the radio and check +buttons, use this function: +

hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 171 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 174
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 175 -

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 True of - False for the second state argument to specify whether it - should be down (depressed) or up (released). Default is up, or - False.

+

+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 True or False for the second state +argument to specify whether it should be down (depressed) or up (released). +Default is up, or False. +

hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 183 -

Note that when you use the toggleButtonSetActive function, and - the state is actually changed, it causes the onClicked and - onToggled signals to be emitted from the button.

-
+

+Note that when you use the toggleButtonSetActive function, and the +state is actually changed, it causes the onClicked and +onToggled signals to be emitted from the button. +

hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 189 -

Check Buttons

+

Check Buttons

hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 191 -

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.

+

+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. +

hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 198 -

The creation functions are similar to those of the normal - button.

+

+The creation functions are similar to those of the normal button. +

hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 202 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 209
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 210 -

The checkButtonNewWithLabel function creates a check button - with a label beside it.

+

+The checkButtonNewWithLabel function creates a check button with a +label beside it. +

hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 215 -

CheckButton is an instance of ToggleButtonClass - and the onToggled signal is used when a CheckButton - is checked or unchecked, just as with the toggle button.

-
+

+CheckButton is an instance of ToggleButtonClass and +the onToggled signal is used when a CheckButton is +checked or unchecked, just as with the toggle button. +

hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 221 -

Radio Buttons

+

Radio Buttons

hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 223 -

Radio buttons are similar to check buttons except they are - grouped so that only one may be selected/depressed at a time. - This is good for places in your application where you need to - select from a short list of options. Creating a new radio button - is done with one of these calls:

+

+Radio buttons are similar to check buttons except they are grouped so that only +one may be selected/depressed at a time. This is good for places in your +application where you need to select from a short list of options. Creating a +new radio button is done with one of these calls: +

hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 230 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 237
-radioButtonNewFromWidget :: RadioButton -> IO RadioButton 
+radioButtonNewFromWidget :: RadioButton -> IO RadioButton
hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 243
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 244 -

You'll notice the extra argument to tthe last three functions. - They are used to link the new buttons to the ones constructed - earlier in a group.

+

+You'll notice the extra argument to the last three functions. They are used to +link the new buttons to the ones constructed earlier in a group. +

hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 249 -

It is also a good idea to explicitly set which button should - be the default depressed button with:

+

+It is also a good idea to explicitly set which button should be the default +depressed button with: +

hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 254 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 257
-      
- -

This is described in the section on toggle buttons, and works - in exactly the same way. Once the radio buttons are grouped - together, only one of the group may be active at a time. If the - user clicks on one radio button, and then on another, the first - radio button will first emit a onToggled signal (to report - becoming inactive), and then the second will emit its - onToggled signal (to report becoming active).

hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 258 -

The following example creates a radio button group with three - buttons, and when the user presses one of the radiobuttons, the - toggled ones will report this to stdout , using putStrLn - in the setRadioState function defined below.

+

+This is described in the section on toggle buttons, and works in exactly the +same way. Once the radio buttons are grouped together, only one of the group +may be active at a time. If the user clicks on one radio button, and then on +another, the first radio button will first emit a onToggled signal +(to report becoming inactive), and then the second will emit its +onToggled signal (to report becoming active). +

hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 267 -


- Chap6b

+

+The following example creates a radio button group with three buttons, and when +the user presses one of the radio buttons, the toggled ones will report this to +stdout, using putStrLn in the +setRadioState function defined below. +

hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 274 - - +

Radio buttons

hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 276 - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 282
-  window <- windowNew
-  set window [windowTitle := "Radio Button", containerBorderWidth := 5 ,
-              windowDefaultWidth := 200, windowDefaultHeight := 150 ]
-  box1 <- vBoxNew False 0
+  window  <- windowNew
+  set window [windowTitle := "Radio Button", containerBorderWidth := 5,
+              windowDefaultWidth := 200, windowDefaultHeight := 150]
+  box1    <- vBoxNew False 0
hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 287
-  box2 <- vBoxNew False 10
+  box2    <- vBoxNew False 10
hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 300
-  sep <- hSeparatorNew
+  sep     <- hSeparatorNew
hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 302
-  box3 <- vBoxNew False 10
+  box3    <- vBoxNew False 10
hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 305
-  closeb <- buttonNewWithLabel "close"
+  closeb  <- buttonNewWithLabel "close"
hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 318
-      
-
- - - - - - - - - - - - - - - - - - hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 319 - - -
-

<<< - Previous

-
-

Home

-
-

Next - >>>

-
-

Tables

-
-

 

-
-

Adjustments

-
+ hunk ./docs/tutorial/Tutorial_Port/chap4-1.xhtml 325 -


-

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 1 - - - + + + hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 5 - - - - Adjustments + + Gtk2Hs Tutorial: Adjustments, Scale and Range + hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 10 - - - - - - - - - - + hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 12 - - -
-

GTK2Hs Tutorial

-
-

<<<Previous

-
-

Next - >>>

-
-
+ hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 19 -

Adjustments, - Scale and Range

+

4.2 Adjustments, Scale and Range

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 21 -

GTK has various widgets that can be visually adjusted by the - user using the mouse or the keyboard, such as the range widgets, - described in the range widget section. There are also a few - widgets that display some adjustable portion of a larger area of - data, such as the text widget and the viewport widget.

+

+Gtk2Hs has various widgets that can be visually adjusted by the user using the +mouse or the keyboard, such as the range widgets, described in the range widget +section. There are also a few widgets that display some adjustable portion of a +larger area of data, such as the text widget and the viewport widget. +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 28 -

Obviously, an application needs to be able to react to changes - the user makes in range widgets. One way to do this would be to - have each widget emit its own type of signal when its adjustment - changes. But you may also want to connect the adjustments of - several widgets together, so that adjusting one adjusts the - others. The most obvious example of this is connecting a - scrollbar to a panning viewport or a scrolling text area.

+

+Obviously, an application needs to be able to react to changes the user makes +in range widgets. One way to do this would be to have each widget emit its own +type of signal when its adjustment changes. But you may also want to connect +the adjustments of several widgets together, so that adjusting one adjusts the +others. The most obvious example of this is connecting a scrollbar to a panning +viewport or a scrolling text area. +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 37 -

The adjustment object can be used to store the configuration - parameters and values of range widgets, such as scrollbars and - scale controls. Because Adjustment is derived from - GObject and Object, adjustments can emit signals, - which can be used not only to allow your program to react to user - input on adjustable widgets, but also to propagate adjustment - values transparently between adjustable widgets.

+

+The adjustment object can be used to store the configuration parameters and +values of range widgets, such as scrollbars and scale controls. Because +Adjustment is derived from GObject and +Object, adjustments can emit signals, which can be used not only +to allow your program to react to user input on adjustable widgets, but also to +propagate adjustment values transparently between adjustable widgets. +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 46 -

Many of the widgets which use adjustment objects, like - ScrolledWindow, can create their own adjustments, but you - create one yourself with:

+

+Many of the widgets which use adjustment objects, like +ScrolledWindow, can create their own adjustments, but you create +one yourself with: +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 52 - - - - -
-
-adjustmentNew 
-:: Double            -- value, the initial value of the range
--> Double            -- lower, the minimum value of the range
--> Double            -- upper, the maximum value of the range
--> Double            -- stepIncrement, the smaller of two possible increments
--> Double            -- pageIncrement, the larger of two possible increments
--> Double            -- pageSize, the size of the visible area
--> IO Adjustment
+
+adjustmentNew :: Double        -- value         - The initial value of the range
+              -> Double        -- lower         - The minimum value of the range
+              -> Double        -- upper         - The maximum value of the range
+              -> Double        -- stepIncrement - The smaller of two possible increments
+              -> Double        -- pageIncrement - The larger of two possible increments
+              -> Double        -- pageSize      - The size of the visible area
+              -> IO Adjustment
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 61
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 62 -

The creation function takes every value that is contained in - the object: value is the initial value and should be - between the upper and lower bounds of the - slider. Clicking on the arrows increases this value by - stepIncrement. Clicking in the slider advances by - pageIncrement. The pageSize is needed to - determine if the end of the slider is still in the range. You can - get and set all the parameters of an adjustment by methods or - using the general set and get functions on the - adjustment attributes.

+

+The creation function takes every value that is contained in the object: +value is the initial value and should be between the +upper and lower bounds of the slider. Clicking on the +arrows increases this value by stepIncrement. Clicking in the +slider advances by pageIncrement. The pageSize is +needed to determine if the end of the slider is still in the range. You can get +and set all the parameters of an adjustment by methods or using the general +set and get functions on the adjustment attributes. +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 73 - - - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 76
-      
- -

is the signal emitted when the value of the adjustment - changes, and

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 77 - - +

+is the signal emitted when the value of the adjustment changes, and: +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 81 - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 84
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 85 -

is the signal emitted when one or more of the other than the - value fields have changed.

+

+is the signal emitted when one or more of the other than the value fields have +changed. +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 90 -

Scale and Range Widgets

+

Scale and Range Widgets

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 92 -

Scale widgets are used to allow the user to visually select - and manipulate a value within a specific range using a slider. - You might want to use a scale widget, for example, to adjust the - magnification level on a zoomed preview of a picture, or to - control the brightness of a color, or to specify the number of - minutes of inactivity before a screensaver takes over the - screen.

+

+Scale widgets are used to allow the user to visually select and manipulate a +value within a specific range using a slider. You might want to use a scale +widget, for example, to adjust the magnification level on a zoomed preview of a +picture, or to control the brightness of a color, or to specify the number of +minutes of inactivity before a screensaver takes over the screen. +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 100 -

The following functions create vertical and horizontal scale - widgets, respectively:

+

+The following functions create vertical and horizontal scale widgets, +respectively: +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 105 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 110
-      
- -

There are also two constructors which do not take an - adjustment:

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 111 - - +

+There are also two constructors which do not take an adjustment: +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 115 - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 120
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 121 -

The Double parameters refer to the minimum and maximum - values and the step. The step increment (preferably a power of - 10) is the value the scale moves when the arrow keys are - used.

+

+The Double parameters refer to the minimum and maximum values and +the step. The step increment (preferably a power of 10) is the value the scale +moves when the arrow keys are used. +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 127 -

Horizontal and vertical scales are instances of - ScaleClass and their common behaviors are defined in the - module: Graphics.UI.Gtk.Abstract.Scale.

+

+Horizontal and vertical scales are instances of ScaleClass and +their common behaviors are defined in the module +Graphics.UI.Gtk.Abstract.Scale. +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 133 -

Scale widgets can display their current value as a number - beside the trough. The default behaviour is to show the value, - but you can change this with this function:

+

+Scale widgets can display their current value as a number beside the trough. +The default behaviour is to show the value, but you can change this with this +function: +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 139 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 142
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 143 -

The value displayed by a scale widget is rounded to one - decimal point by default, as is the value field in its - Adjustment. You can change this with:

+

+The value displayed by a scale widget is rounded to one decimal point by +default, as is the value field in its Adjustment. You +can change this with: +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 149 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 152
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 153 -

Finally, the value can be drawn in different positions - relative to the trough:

+

+Finally, the value can be drawn in different positions relative to the trough: +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 157 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 160
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 161 -

The PositionType is defined as:

+

+The PositionType is defined as: +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 165 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 168
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 169 -

Scale itself inherits many methods form its base class, - which is Range.

+

+Scale itself inherits many methods form its base class, which is +Range. +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 174 -

Setting the Update - Policy

+

Setting the Update Policy

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 176 -

The "update policy" of a range widget defines at what points - during user interaction it will change the value field - of its Adjustment and emit the onRangeValueChanged signal - on this Adjustment. The update policies, are defined by the - UpdateType, which has three constructors:

+

+The update policy of a range widget defines at what points during user +interaction it will change the value field of its +Adjustment and emit the onRangeValueChanged signal +on this Adjustment. The update policies are defined by the +UpdateType, which has three constructors: +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 184 -
-
UpdateContinuous
+
+
UpdateContinuous
+
+ This is the default. The onRangeValueChanged signal is emitted + continuously, i.e., whenever the slider is moved by even the tiniest + amount. +
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 192 -
This is the default. The onRangeValueChanged signal - is emitted continuously, i.e., whenever the slider is moved by - even the tiniest amount.
+
UpdateDiscontinuous
+
+ The onRangeValueChanged signal is only emitted once the slider + has stopped moving and the user has released the mouse button. +
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 198 -
UpdateDiscontinuous
+
UpdateDelayed
+
+ The onRangeValueChanged signal is emitted when the user releases + the mouse button, or if the slider stops moving for a short period of time. +
+
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 205 -
The onRangeValueChanged signal is only emitted once - the slider has stopped moving and the user has released the - mouse button.
+

+The update policy of a range widget can be set by: +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 209 -
UpdateDelayed
- -
The onRangeValueChanged signal is emitted when the - user releases the mouse button, or if the slider stops moving - for a short period of time.
-
- -

The update policy of a range widget can be set by:

- - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 212
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 213 -

Getting and Setting - Adjustments

+

Getting and Setting Adjustments

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 215 -

Getting and setting the adjustment for a range widget "on the - fly" is done, predictably, with:

+

+Getting and setting the adjustment for a range widget on the fly is done, +predictably, with: +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 220 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 225
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 226 -

rangeSetAdjustment does absolutely nothing if - you pass it the adjustment that it is already using, - regardless of whether you changed any of its fields or not. If - you pass it a new Adjustment, it will unreference the old one if - it exists (possibly destroying it), connect the appropriate - signals to the new one, and call the private function - gtk_range_adjustment_changed(), which will (or at least, - is supposed to...) recalculate the size and/or position of the - slider and redraw if necessary. As mentioned in the section on - adjustments, if you wish to reuse the same Adjustment, when you - modify its values directly, you should emit the "changed" signal - on it.

+

+rangeSetAdjustment does absolutely nothing if you pass it the +adjustment that it is already using, regardless of whether you changed +any of its fields or not. If you pass it a new Adjustment, it will +unreference the old one if it exists (possibly destroying it), connect the +appropriate signals to the new one, and call the private function +gtk_range_adjustment_changed(), which will (or at least, is +supposed to...) recalculate the size and/or position of the slider and redraw +if necessary. As mentioned in the section on adjustments, if you wish to reuse +the same Adjustment, when you modify its values directly, you +should emit the changed signal on it. +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 239 -

Key and Mouse bindings

+

Key and Mouse Bindings

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 241 -

All of the GTK range widgets react to mouse clicks in more or - less the same way. Clicking button-1 in the trough will cause its - adjustment's stepIncrement to be added or - subtracted from its value, and the slider to be - moved accordingly. Clicking mouse button-2 in the trough will - jump the slider to the point at which the button was clicked. - Clicking button-3 in the trough of a range or any button on a - scrollbar's arrows will cause its adjustment's value to change by - stepIncrement at a time.

+

+All of the Gtk2Hs range widgets react to mouse clicks in more or less the same +way. Clicking mouse button 1 in the trough will cause its adjustment's +stepIncrement to be added or subtracted from its value, +and the slider to be moved accordingly. Clicking mouse button 2 in the trough +will jump the slider to the point at which the button was clicked. Clicking +mouse button 3 in the trough of a range or any button on a scrollbar's arrows +will cause its adjustment's value to change by stepIncrement at a +time. +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 252 -

Note: this did not work on Linux Fedora 6 with the standard - mouse bindings.

+

+Note: This did not work on Linux Fedora 6 with the standard mouse bindings. +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 256 -

Scrollbars are not focusable, thus have no key bindings. The - key bindings for the other range widgets (which are, of course, - only active when the widget has focus) do not - differentiate between horizontal and vertical range widgets.

+

+Scrollbars are not focusable, thus have no key bindings. The key bindings for +the other range widgets (which are, of course, only active when the widget has +focus) do not differentiate between horizontal and vertical range +widgets. +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 263 -

All range widgets can be operated with the left, right, up and - down arrow keys, as well as with the Page Up and - Page Down keys. The arrows move the slider up and down - by stepIncrement, while Page Up and - Page Down move it by pageIncrement. - Homeand Endmove to the beginning and end of the - slide.

+

+All range widgets can be operated with the left, right, up and down arrow keys, +as well as with the Page Up and Page Down +keys. The arrows move the slider up and down by stepIncrement, +while Page Up and Page Down move it by +pageIncrement. Home and End move +to the beginning and end of the slider. +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 272 -

The user can also move the slider all the way to one end or - the other of the trough using the keyboard. This is done with the - Home and End keys.

-
+

+The user can also move the slider all the way to one end or the other of the +trough using the keyboard. This is done with the Home and +End keys. +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 278 -

Example

+

Example

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 280 -

This example puts up a window with three range widgets all - connected to the same adjustment, and a couple of controls for - adjusting some of the parameters mentioned above, so you can see - how they affect the way these widgets work for the user.

+

+This example puts up a window with three range widgets all connected to the +same adjustment, and a couple of controls for adjusting some of the parameters +mentioned above so you can see how they affect the way these widgets work for +the user. +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 287 -

GtkChap7

+

Range widgets example

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 289 -

The three scales are placed so the vertical is next to the two - horizontal ones, one above the other. So we need a horizontal box - for the vertical scale and a vertical box next to it for the - horizontal scales. The scales and the boxes must be packed with - PackGrow so the scales will resize with the main box, - which is a vertical box in the window.

+

+The three scales are placed so the vertical is next to the two horizontal ones, +one above the other. So we need a horizontal box for the vertical scale and a +vertical box next to it for the horizontal scales. The scales and the boxes +must be packed with PackGrow so the scales will resize with the +main box, which is a vertical box in the window. +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 297 -

All three scales ar constructed with the same adjustment, - setting the initial value at 0.0, the minimum value at 0.0, the - maximu value at 101.0, the step increment at 0.1 , the page - increment at 1.0 and the page size at 1.0 .

+

+All three scales ar constructed with the same adjustment, setting the initial +value at 0.0, the minimum value at 0.0, the maximum value at 101.0, the step +increment at 0.1, the page increment at 1.0 and the page size at 1.0. +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 303 - - - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 306
-      
- -


-

- -

The user can control whether the scale values are displayed - with a checkButton. This is packed into the main box and - set to be active initially. A check button is a toggle button and - when the user checks or uncehecks it th onToggled signal - is sent. this causes the toggleDisplay function to be evaluated, - which is defined as:

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 307 - - +

+The user can control whether the scale values are displayed with a +checkButton. This is packed into the main box and set to be active +initially. A check button is a toggle button and when the user checks or +uncehecks it the onToggled signal is sent. this causes the +toggleDisplay function to be evaluated, which is defined as: +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 315 - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 317
-toggleDisplay b scls = sequence_ (map change scls) where 
+toggleDisplay b scls = sequence_ (map change scls) where
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 321
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 322 -

The function has a checkButton type as its parameter, - and a list of instances of ScaleClass . However, a list - can only contain values of the same type, and vScale and hScale - are different types. So, we can use the function on lists of - vertical scales or horizontal scales, but lists containing both - types result in a typing error.

+

+The function has a checkButton type as its parameter, and a list +of instances of ScaleClass. However, a list can only contain +values of the same type, and vScale and hScale are +different types. So, we can use the function on lists of vertical scales or +horizontal scales, but lists containing both types result in a typing error. +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 330 -

The user can select the positionType using a widget not - mentioned before, a ComboBox. This allows a selection of - choices as shown below. The one to be set active is determined by - an index, which is 0 here, the first one.

+

+The user can select the positionType using a widget not mentioned +before, a ComboBox. This allows a selection of choices as shown +below. The one to be set active is determined by an index, which is 0 here, the +first one. +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 337 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 341
-  comboBoxAppendText cb "TOP" 
+  comboBoxAppendText cb "TOP"
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 343
-  comboBoxAppendText cb "LEFT" 
-  comboBoxAppendText cb "RIGHT"  
+  comboBoxAppendText cb "LEFT"
+  comboBoxAppendText cb "RIGHT"
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 348
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 349 -

A second comboBox lets the user select the update - policy, one of the three UpDateType constructors.

+

+A second comboBox lets the user select the update policy, one of +the three UpdateType constructors. +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 354 - - - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 358
-  comboBoxAppendText cb "Continuous" 
+  comboBoxAppendText cb "Continuous"
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 360
-  comboBoxAppendText cb "Delayed" 
+  comboBoxAppendText cb "Delayed"
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 364
-      
- -

The combo boxes themselves just display text, of course. To - select the position, respectively the update policy, we - define:

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 365 - - +

+The combo boxes themselves just display text, of course. To select the +position, respectively the update policy, we define: +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 370 - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 375
-                (Just "TOP") -> PosTop
+                (Just "TOP")    -> PosTop
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 377
-                (Just "LEFT") -> PosLeft
-                (Just "RIGHT") -> PosRight
-                Nothing -> error "GtkChap9.hs setScalePos: no position set"
-    scaleSetValuePos sc pos 
+                (Just "LEFT")   -> PosLeft
+                (Just "RIGHT")  -> PosRight
+                Nothing         -> error "setScalePos: no position set"
+    scaleSetValuePos sc pos
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 386
-                (Just "Continuous") -> UpdateContinuous
+                (Just "Continuous")    -> UpdateContinuous
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 388
-                (Just "Delayed") -> UpdateDelayed
-                Nothing -> error "GtkChap9.hs setUpdatePol: no policy set"
-    rangeSetUpdatePolicy sc pol 
+                (Just "Delayed")       -> UpdateDelayed
+                Nothing                -> error "setUpdatePol: no policy set"
+    rangeSetUpdatePolicy sc pol
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 392
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 393 -

Here we have not used lists to manage the vertical and - horizontal scales, so each horizontal scale is addressed - separately.

+

+Here we have not used lists to manage the vertical and horizontal scales, so +each horizontal scale is addressed separately. +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 398 -

The number of precision shown on the three scles will be - managed with another scale, for which we use a new adjustment. - The maximum precision is 10 and each increment is 1. The - precision of this control scale itself is set to 1.

+

+The number of precision shown on the three scles will be managed with another +scale, for which we use a new adjustment. The maximum precision is 10 and each +increment is 1. The precision of this control scale itself is set to 1. +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 404 - - - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 407
-      
- -

When the control adjustment changes the signal - onValueChanged will be emitted and then the defined - function setDigits is evaluated.

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 408 -


+

+When the control adjustment changes the signal onValueChanged will +be emitted and then the defined function setDigits is evaluated. +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 413 - - - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 416
-                      set sc [scaleDigits := (round val) ]
+                      set sc [scaleDigits := (round val)]
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 418
-      
- -

Here we use the general functions set and get on - the attributes; we might have used the appropriate methods as - well. Note that the Double of the adjustment value must be - rounded to an Integral type.

- -

We use another horizontal scale to manage the page size of the - three example scales. When set at 0.0 the scales can reach their - initial maximum of 100.0 and when set at 100.0 the scales are - fixed at the lowest value. This involves the adjusting of the - adjustment by a the onValueChanged signal from a third - adjustment by this code snippet:

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 419 -


+

+Here we use the general functions set and get on the +attributes; we might have used the appropriate methods as well. Note that the +Double of the adjustment value must be rounded to an +Integral type. +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 426 - - +

+We use another horizontal scale to manage the page size of the three example +scales. When set at 0.0 the scales can reach their initial maximum of 100.0 and +when set at 100.0 the scales are fixed at the lowest value. This involves the +adjusting of the adjustment by a the onValueChanged signal from a +third adjustment by this code snippet: +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 434 - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 438
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 439 -


+

+The main function is: +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 443 -

The main function is:

- - - - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 449
-  window <- windowNew
+  window  <- windowNew
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 451
-              windowDefaultWidth := 250 ]
+              windowDefaultWidth := 250]
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 459
-  vsc <- vScaleNew adj1
+  vsc  <- vScaleNew adj1
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 463
-  boxPackStart box1 box2 PackGrow 0 
+  boxPackStart box1 box2 PackGrow 0
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 474
-  box3 <- hBoxNew False 10
+  box3   <- hBoxNew False 10
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 478
-  opt1 <- makeOpt1
+  opt1   <- makeOpt1
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 481
-  box4 <- hBoxNew False 10
+  box4   <- hBoxNew False 10
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 485
-  opt2 <- makeOpt2
+  opt2   <- makeOpt2
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 490
-  box5 <- hBoxNew False 0
+  box5   <- hBoxNew False 0
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 495
-  dsc <- hScaleNew adj2
+  dsc    <- hScaleNew adj2
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 501
-  box6 <- hBoxNew False 0
+  box6   <- hBoxNew False 0
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 506
-  psc <- hScaleNew adj3
+  psc    <- hScaleNew adj3
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 513
-  onChanged opt1 $ do setScalePos opt1 hsc1 
+  onChanged opt1 $ do setScalePos opt1 hsc1
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 517
-  onChanged opt2 $ do setUpdatePol opt2 hsc1 
+  onChanged opt2 $ do setUpdatePol opt2 hsc1
hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 532
-      
- -

The non standard functions used in the listing have already - been listed above.

-
- - - - - - - - - hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 533 - - +

+The non standard functions used in the listing have already been listed above. +

hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 537 - - -
-

<<< - Previous

-
-

Home

-
-

Next - >>>

-
-

Button

-
-

to be continued...

-
+ hunk ./docs/tutorial/Tutorial_Port/chap4-2.xhtml 543 -


-

hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 1 - - - + + + hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 5 - - - - Labels + + Gtk2Hs Tutorial: Labels + hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 10 - - - - - - - - - - + hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 12 - - -
-

Gtk2Hs Tutorial

-
-

<<< - Previous

-
-

Next - >>>

-
-
+ hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 19 -

Labels

+

4.3 Labels

hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 21 -

Labels are used a lot in Gtk2Hs, and are relatively simple. - Labels emit no signals as they do not have an associated X - window. If you need to catch signals, or do clipping, place it - inside an EventBox widget, which allows you to catch - signals for widgets which do not have their own window, or a - button.

+

+Labels are used a lot in Gtk2Hs, and are relatively simple. Labels emit no +signals as they do not have an associated X window. If you need to catch +signals, or do clipping, place it inside an EventBox widget, +which allows you to catch signals for widgets which do not have their own +window, or a button. +

hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 29 -

To create a new label, use:

+

+To create a new label, use: +

hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 33 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 38
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 39 -

With the second function, if characters in the string are - preceded by an underscore, they are underlined. If you need a - literal underscore character in a label, use '__' (two - underscores). The first underlined character represents a - keyboard accelerator called a mnemonic. When that key is pressed - the activable widget which contains the label (e.g. a button) - will be activated. The widget which is to be affected can also be - set by labelSetMnemonicWidget.

+

+With the second function, if characters in the string are preceded by an +underscore, they are underlined. If you need a literal underscore character in +a label, use "__" (two underscores). The first underlined character represents +a keyboard accelerator called a mnemonic. When that key is pressed the +activable widget which contains the label (e.g. a button) will be activated. +The widget which is to be affected can also be set by +labelSetMnemonicWidget. +

hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 49 -

To change the label's text after creation, or to get the - label's text, use the functions:

+

+To change the label's text after creation, or to get the label's text, use the +functions: +

hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 54 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 59
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 60 -

or, of course, the generic set or get functions. - The space needed for the new string will be automatically - adjusted if needed. You can produce multi-line labels by putting - line breaks in the label string. If you have multi-line labels - the lines can be justified relatively to each other using:

+

+or, of course, the generic set or get functions. The +space needed for the new string will be automatically adjusted if needed. You +can produce multi-line labels by putting line breaks in the label string. If +you have multi-line labels the lines can be justified relatively to each other +using: +

hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 68 - - - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 71
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 72 -

where the type Justification has one of four - constructors:

+

+where the type Justification has one of four constructors: +

hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 76 - - - - -
-
-JustifyLeft
-JustifyRight
-JustifyCenter
-JustifyFill
-
-
+ hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 83 -

The label widget is also capable of line wrapping the text - automatically. This can be activated using:

+

+The label widget is also capable of line wrapping the text automatically. This +can be activated using: +

hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 88 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 91
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 92 -

If you want your label underlined, then you can set a pattern - on the label:

+

+If you want your label underlined, then you can set a pattern on the label: +

hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 96 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 99
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 100 -

The list of Ints marks the underlined parts of the label text - alternated by the non-interlined parts. For example, [3,1,3] - means first 3 characters underlined, the next not, the next 3 - underlined.

+

+The list of Ints marks the underlined parts of the label text +alternated by the non-interlined parts. For example, [3, 1, 3] means +first three characters underlined, the next not, and the next three underlined. +

hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 106 -

You can also make text in a lable selectable, so the user can - copy and paste it, and use some formatting options.

+

+You can also make text in a lable selectable, so the user can copy and paste +it, and use some formatting options. +

hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 111 -

Below is a short example to illustrate a few of - these functions. It makes use of the Frame widget to - better demonstrate the label styles. A Frame is just an - ornament like a HSeparator and a VSeparator but it - surrounds the widget and is an instance of Container. - Therefore the widget it frames must be added to it with - containerAdd. A frame itself can have a label to convey - information about its contents.

+

+Below is a short example to illustrate a few of these functions. It makes use +of the Frame widget to better demonstrate the label styles. A +Frame is just an ornament like a HSeparator and a +VSeparator but it surrounds the widget and is an instance of +Container. Therefore the widget it frames must be added to it with +containerAdd. A frame itself can have a label to convey +information about its contents. +

hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 121 -

GtkChap8

+

Label examples

hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 123 -

Because all the labels are framed, a function - myLabelWithFrameNew is defined, which returns a - tuple.Gtk2Hs is truly Haskell, so you can use all the Haskell - data types and features. The justifications are pretty obvious, - but they only refer to the lines inside the label. So, to to - right justify label2 itself, you need miscSetAlignment as - shown below. The last two widgets in the left horizontal box are - packed with boxPackEnd instead of the usual - boxPackStart. The button label demonstrates the use of a - mnemonic as an accellarator key. Pressing Alt_C on the keyboard - has the same effect as clicking the button.

+

+Because all the labels are framed, a function myLabelWithFrameNew +is defined, which returns a tuple. Gtk2Hs is truly Haskell, so you can use all +the Haskell data types and features. The justifications are pretty obvious, but +they only refer to the lines inside the label. So, to right justify +label2 itself, you need miscSetAlignment as shown +below. The last two widgets in the left horizontal box are packed with +boxPackEnd instead of the usual boxPackStart. The +button label demonstrates the use of a mnemonic as an accellerator key. +Pressing Alt-C on the keyboard has the same effect as clicking +the button. +

hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 136 -

Note: when tested on Fedora 6, pressing Enter or the space bar - also had this effect. Also note the effect of the y-character on - the placement of the underline.

+

+Note: When tested on Fedora 6, pressing Enter +or the space bar also had this effect. Also note the effect of the character +"y" on the placement of the underline. +

hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 142 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 147
-     initGUI
-     window <- windowNew
-     set window [windowTitle := "Labels", containerBorderWidth := 10 ]
-     mainbox <- vBoxNew False 10
-     containerAdd window mainbox 
-     hbox <- hBoxNew True 5
-     boxPackStart mainbox hbox PackNatural 0
-     vbox1 <- vBoxNew False 10
-     vbox2 <- vBoxNew False 0
-     boxPackStart hbox vbox1 PackNatural 0 
-     boxPackStart hbox vbox2 PackNatural 0
+  initGUI
+  window  <- windowNew
+  set window [windowTitle := "Labels", containerBorderWidth := 10]
+  mainbox <- vBoxNew False 10
+  containerAdd window mainbox
+  hbox    <- hBoxNew True 5
+  boxPackStart mainbox hbox PackNatural 0
+  vbox1   <- vBoxNew False 10
+  vbox2   <- vBoxNew False 0
+  boxPackStart hbox vbox1 PackNatural 0
+  boxPackStart hbox vbox2 PackNatural 0
+
+  (label1,frame1) <- myLabelWithFrameNew
+  boxPackStart vbox1 frame1 PackNatural 0
+  labelSetText label1 "Penny Harter"
hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 163
-     (label1,frame1) <- myLabelWithFrameNew
-     boxPackStart vbox1 frame1 PackNatural 0
-     labelSetText label1 "Penny Harter"
+  (label2,frame2) <- myLabelWithFrameNew
+  boxPackStart vbox1 frame2 PackNatural 0
+  labelSetText label2 "broken bowl\nthe pieces\nstill rocking"
+  miscSetAlignment label2 0.0 0.0
+  hsep1           <- hSeparatorNew
+  boxPackStart vbox1 hsep1 PackNatural 10
hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 170
-     (label2,frame2) <- myLabelWithFrameNew
-     boxPackStart vbox1 frame2 PackNatural 0
-     labelSetText label2 "broken bowl\nthe pieces\nstill rocking"
-     miscSetAlignment label2 0.0 0.0
-     hsep1 <- hSeparatorNew
-     boxPackStart vbox1 hsep1 PackNatural 10
+  (label3,frame3) <- myLabelWithFrameNew
+  boxPackStart vbox1 frame3 PackNatural 0
+  labelSetText label3 "Gary Snyder"
hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 174
-     (label3,frame3) <- myLabelWithFrameNew
-     boxPackStart vbox1 frame3 PackNatural 0
-     labelSetText label3 "Gary Snyder"
+  (label4,frame4) <- myLabelWithFrameNew
+  boxPackStart vbox1 frame4 PackNatural 0
+  labelSetText label4 "After weeks of watching the roof leak\nI fixed it tonight\nby moving a single board"
+  labelSetJustify label4 JustifyCenter
hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 179
-     (label4,frame4) <- myLabelWithFrameNew
-     boxPackStart vbox1 frame4 PackNatural 0
-     labelSetText label4 "After weeks of watching the roof leak\nI fixed it tonight\nby moving a single board"
-     labelSetJustify label4 JustifyCenter
+  (label5,frame5) <- myLabelWithFrameNew
+  boxPackStart vbox2 frame5 PackNatural 0
+  labelSetText label5 "Kobayashi Issa"
hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 183
-     (label5,frame5) <- myLabelWithFrameNew
-     boxPackStart vbox2 frame5 PackNatural 0
-     labelSetText label5 "Kobayashi Issa"
-    
-     (label7,frame7) <- myLabelWithFrameNew
-     boxPackEnd vbox2 frame7 PackNatural 0
-     labelSetText label7 "only one guy and\nonly one fly trying to\nmake the guest room do"
-     labelSetJustify label7 JustifyRight
+  (label7,frame7) <- myLabelWithFrameNew
+  boxPackEnd vbox2 frame7 PackNatural 0
+  labelSetText label7 "only one guy and\nonly one fly trying to\nmake the guest room do"
+  labelSetJustify label7 JustifyRight
hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 188
-     (label6,frame6) <- myLabelWithFrameNew
-     boxPackEnd vbox2 frame6 PackNatural 10
-     labelSetText label6 "One Guy"
-     frameSetLabel frame6 "Title:"
-     labelSetPattern label6 [3,1,3]
+  (label6,frame6) <- myLabelWithFrameNew
+  boxPackEnd vbox2 frame6 PackNatural 10
+  labelSetText label6 "One Guy"
+  frameSetLabel frame6 "Title:"
+  labelSetPattern label6 [3, 1, 3]
hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 194
-     button <- buttonNew
-     boxPackEnd mainbox button PackNatural 20
-     buttonlabel <- labelNewWithMnemonic "Haiku _Clicked"
-     containerAdd button buttonlabel
+  button      <- buttonNew
+  boxPackEnd mainbox button PackNatural 20
+  buttonlabel <- labelNewWithMnemonic "Haiku _Clicked"
+  containerAdd button buttonlabel
hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 199
-     widgetShowAll window
-     onClicked button (putStrLn "button clicked...")
-     onDestroy window mainQuit
-     mainGUI
+  widgetShowAll window
+  onClicked button (putStrLn "button clicked...")
+  onDestroy window mainQuit
+  mainGUI
hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 207
-           label <- labelNew Nothing
-           frame <- frameNew
-           containerAdd frame label
-           frameSetShadowType frame ShadowOut
-           return (label, frame)
--- Haikus quoted from X.J. Kennedy, Dana Gioia, Introduction to Poetry, Longman, 1997
-
-
-
- - - - - - + label <- labelNew Nothing + frame <- frameNew + containerAdd frame label + frameSetShadowType frame ShadowOut + return (label, frame) hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 213 - - hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 214 - - - - +-- Haikus quoted from X.J. Kennedy, Dana Gioia, Introduction to Poetry, Longman, 1997 + hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 217 - - -
-

<<< - Previous

-
-

Home

-
-

Next - >>>

-
-

Adjustments, Scale and Range

-
-

 

-
-

to be continued...

-
+ hunk ./docs/tutorial/Tutorial_Port/chap4-3.xhtml 223 -


-

hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 1 - - - + + + hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 5 - - - - Arrows and Tooltips + + Gtk2Hs Tutorial: Arrows and Tooltips + hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 10 - - - - - - - - - - + hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 12 - - -
-

Gtk2Hs Tutorial

-
-

<<< - Previous

-
-


-
-

Next - >>>

-
-
+ hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 19 -

Arrows and - Tooltips

+

4.4 Arrows and Tooltips

hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 21 -

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.

+

+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. +

hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 27 -

There are only two functions for manipulating an Arrow - widget:

+

+There are only two functions for manipulating an Arrow widget: +

hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 31 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 36
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 37 -

The ArrowType has 5 constructors:

+

+The ArrowType has five constructors: +

hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 41 - - - - -
-
-ArrowUp
-ArrowDown
-ArrowLeft
-ArrowRight
-ArrowNone
-
-
+ hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 49 -

The ShadowType also has 5 constructors:

+

+The ShadowType also has five constructors: +

hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 53 - - - - -
-
-ShadowNone
-ShadowIn
-ShadowOut
-ShadowEtchedIn
-ShadowEtchedOut
-
-
+ hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 61 -

Tooltips are the little text strings that pop up when you - leave your pointer over a button or other widget for a few - seconds.

+

+Tooltips are the little text strings that pop up when you leave your pointer +over a button or other widget for a few seconds. +

hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 66 -

Widgets that do not receive events (widgets that do not have - their own window) will not work with tooltips.

+

+Widgets that do not receive events (widgets that do not have their own window) +will not work with tooltips. +

hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 71 -

The first call you will use creates a new tooltip. You only - need to do this once for a set of tooltips.

+

+The first call you will use creates a new tooltip. You only need to do this +once for a set of tooltips. +

hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 76 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 79
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 80 -

Then, for every widget, use:

+

+Then, for every widget, use: +

hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 84 - - - - -
-
-tooltipsSetTip :: (TooltipsClass self, WidgetClass widget) 
-=> self -> widget -> String -> String -> IO ()
+
+tooltipsSetTip :: (TooltipsClass self, WidgetClass widget)
+  => self -> widget -> String -> String -> IO ()
hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 88
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 89 -

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.

+

+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. +

hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 95 -

You can turn the tips associated with a Tooltips value - on or off using:

+

+You can turn the tips associated with a Tooltips value on or off +using: +

hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 100 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 104
-      
- -

Here's an example to illustrate the use of arrows and - tooltips.

hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 105 -


- -

+

+Here's an example to illustrate the use of arrows and tooltips. +

hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 109 -

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.

+

Arrow and tooltip example

hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 111 -

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.

+

+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. +

hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 116 - - +

+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. +

hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 121 - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 126
-     initGUI
-     window <- windowNew
-     set window [windowTitle := "Arrow Tips", 
-                 windowDefaultWidth := 200,
-                 windowDefaultHeight := 200, containerBorderWidth := 20 ]
+  initGUI
+  window <- windowNew
+  set window [windowTitle := "Arrow Tips",
+              windowDefaultWidth := 200,
+              windowDefaultHeight := 200, containerBorderWidth := 20]
hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 132
-     table <- tableNew 5 5 True
-     containerAdd window table
-     
-     button1 <- buttonNew
-     button2 <- buttonNew
-     button3 <- buttonNew
-     button4 <- buttonNew
+  table <- tableNew 5 5 True
+  containerAdd window table
hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 135
-     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
+  button1 <- buttonNew
+  button2 <- buttonNew
+  button3 <- buttonNew
+  button4 <- buttonNew
hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 140
-     tlt <- tooltipsNew
+  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
hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 145
-     arrow1 <- arrowNew ArrowLeft ShadowEtchedIn 
-     containerAdd button1 arrow1
-     tooltipsSetTip tlt button1 "West" "T1"
+  tlt <- tooltipsNew
hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 147
-     arrow2 <- arrowNew ArrowUp ShadowEtchedOut
-     containerAdd button2 arrow2
-     tooltipsSetTip tlt button2 "North" "T2"
+  arrow1 <- arrowNew ArrowLeft ShadowEtchedIn
+  containerAdd button1 arrow1
+  tooltipsSetTip tlt button1 "West" "T1"
hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 151
-     arrow3 <- arrowNew ArrowRight ShadowEtchedIn
-     containerAdd button3 arrow3
-     tooltipsSetTip tlt button3 "East" "T3"
+  arrow2 <- arrowNew ArrowUp ShadowEtchedOut
+  containerAdd button2 arrow2
+  tooltipsSetTip tlt button2 "North" "T2"
hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 155
-     arrow4 <- arrowNew ArrowDown ShadowEtchedOut
-     containerAdd button4 arrow4
-     tooltipsSetTip tlt button4 "South" "T4"
+  arrow3 <- arrowNew ArrowRight ShadowEtchedIn
+  containerAdd button3 arrow3
+  tooltipsSetTip tlt button3 "East" "T3"
hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 159
-     tooltipsEnable tlt
-     widgetShowAll window
-     onDestroy window mainQuit
-     mainGUI
-
-
-
- - - - - - + arrow4 <- arrowNew ArrowDown ShadowEtchedOut + containerAdd button4 arrow4 + tooltipsSetTip tlt button4 "South" "T4" hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 163 - - - - - - - + tooltipsEnable tlt + widgetShowAll window + onDestroy window mainQuit + mainGUI + hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 169 - - -
-

<<< - Previous

-
-

Home

-
-

Next - >>>

-
-

Labels

-
-


-
-

Dialogs, Stock Items Progress Bars

-
+ hunk ./docs/tutorial/Tutorial_Port/chap4-4.xhtml 175 -


-

hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 1 - - - + + + hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 5 - - - - Dialogs, Stock Items and Progress Bars + + Gtk2Hs Tutorial: Dialogs, Stock Items and Progress Bars + hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 10 - - - - - - - - - - + hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 12 - - -
-

Gtk2Hs Tutorial

-
-

<<< - Previous

-
-


-
-

Next - >>>

-
+ hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 19 -

Dialogs, Stock - Items and Progress Bars

+

4.5 Dialogs, Stock Items and Progress Bars

hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 21 -

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.

+

+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. +

hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 27 -

The Dialog widget can be used for pop-up messages to - the user, and other similar tasks. The basic functions needed - are:

+

+The Dialog widget can be used for pop-up messages to the user, and +other similar tasks. The basic functions needed are: +

hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 32 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 37
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 38 -

You add buttons into the action area with:

+

+You add buttons into the action area with: +

hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 42 - - - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 45
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 46 -

Any widget can be added in a similar way with - dialogAddActionWidget.

+

+Any widget can be added in a similar way with +dialogAddActionWidget. +

hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 51 -

The String in dialogAddButton can be the text of - the button, but since dialogs are mostly used for standard - situations a StockItem will usually be more - appropriate.

+

+The String in dialogAddButton can be the text of the +button, but since dialogs are mostly used for standard situations a +StockItem will usually be more appropriate. +

hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 57 -

StockItems are resources which are known throughout - Gtk2Hs, such as standard IconSets. You can define your - own, but many useful ones are listed in the - Graphics.UI.Gtk.General.StockItems module. They have an - identifier StockId ,which is a type synonym for - String. From this identifier a widget (usually a button) - with the appropriate standard text and icon is automatically - selected.

+

+StockItems are resources which are known throughout Gtk2Hs, such +as standard IconSets. You can define your own, but many useful +ones are listed in the Graphics.UI.Gtk.General.StockItems module. +They have an identifier StockId, which is a type synonym for +String. From this identifier a widget (usually a button) with the +appropriate standard text and icon is automatically selected. +

hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 66 -

If you use a StockId when adding a button to a dialog, - you can also use a pre-defined ResponseId constructor with - the buttons. (ResponseId is not a String.) - Customized responses may be constructed with ResponseUser - Int .

+

+If you use a StockId when adding a button to a dialog, you can +also use a pre-defined ResponseId constructor with the buttons. +(ResponseId is not a String.) Customized responses +may be constructed with ResponseUser Int. +

hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 73 -

Whenever a dialog button is pressed, its response is passed to - the calling application through dialogRun. According to - the Gtk2Hs API documentation dialogRun 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 dialogRun is - waiting for a response.

+

+Whenever a dialog button is pressed, its response is passed to the calling +application through dialogRun. According to the Gtk2Hs API +documentation dialogRun 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 +dialogRun is waiting for a response. +

hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 82 -

Progress bars are used to show the status of an ongoing - operation.

+

+Progress bars are used to show the status of an ongoing operation. +

hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 86 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 89
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 90 -

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:

+

+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: +

hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 96 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 99
-      
- -

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.

hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 100 -

When it is not known how much of the operation has been - completed, the bar can be moved back and forth with:

+

+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. +

hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 106 - - +

+When it is not known how much of the operation has been completed, the bar can +be moved back and forth with: +

hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 111 - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 114
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 115 -

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.

+

+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. +

hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 121 -

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.

+

+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. +

hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 128 -

In the following example we'll simulate an activity using - timeoutAdd, which runs a function repeatedly at the - interval specified, in milliseconds. The function is passed to - timeoutAdd and must return a type of IO Bool. When - true the timeout is run again, when false it stops. The priority - of timeoutAdd is priorityDefault of type - Priority.

+

+In the following example we'll simulate an activity using +timeoutAdd, which runs a function repeatedly at the interval +specified, in milliseconds. The function is passed to timeoutAdd +and must return a type of IO Bool. When true the timeout is run +again, when false it stops. The priority of timeoutAdd is +priorityDefault of type Priority. +

hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 137 - - - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 140
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 141 -

In the example we define the function showPulse , which - causes the progress bar to pulse and always returns IO - True. The pulse step, the amount which the indicator moves - through the bar, is set to 1.0 with - progressBarSetPulseStep.

+

+In the example we define the function showPulse, which causes the +progress bar to pulse and always returns IO True. The pulse step, +the amount which the indicator moves through the bar, is set to 1.0 with +progressBarSetPulseStep. +

hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 148 -


- -

+

Progress bar pulsing

hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 150 -

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.

+

+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. +

hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 159 -

If the dialog widget is destroyed, mainQuit is called. - As mentioned above, a Dialog 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 - dialogGetUpper. The buttons in a dialog are visible by - default, but the widgets in the upper part are not. A - Dialog is an instance of the WindowClass, and so we - can set the title and/or default length and height if we - want.

+

+If the dialog widget is destroyed, mainQuit is called. As +mentioned above, a Dialog 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 dialogGetUpper. The buttons in a +dialog are visible by default, but the widgets in the upper part are not. A +Dialog is an instance of the WindowClass, and so we +can set the title and/or default length and height if we want. +

hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 169 -

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 widgetShowAll on the - vertical box and not widgetShow on the progress bar.

+

+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 +widgetShowAll on the vertical box and not widgetShow +on the progress bar. +

hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 176 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 181
-     initGUI
-     
-     dia <- dialogNew
-     set dia [windowTitle := "Time Flies"]
-     dialogAddButton dia stockApply  ResponseApply
-     dialogAddButton dia stockCancel ResponseCancel
-     dialogAddButton dia stockClose  ResponseClose
+  initGUI
+
+  dia <- dialogNew
+  set dia [windowTitle := "Time Flies"]
+  dialogAddButton dia stockApply  ResponseApply
+  dialogAddButton dia stockCancel ResponseCancel
+  dialogAddButton dia stockClose  ResponseClose
hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 189
-     pr <- progressBarNew
-     progressBarSetPulseStep pr 1.0
+  pr <- progressBarNew
+  progressBarSetPulseStep pr 1.0
hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 192
-     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
+  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
hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 209
-      
-
- - - - - - - - - - - - - - hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 210 - - -
-

<<< - Previous

-
-

Home

-
-

Next - >>>

-
-

Arrows and Tooltips

-
-


-
-

Text Entries and Satusbars

-
+ hunk ./docs/tutorial/Tutorial_Port/chap4-5.xhtml 216 -


-

hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 1 - - - + + + hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 5 - - - - Text Entries and Statusbars + + Gtk2Hs Tutorial: Text Entries and Status Bars + hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 10 - - - - - - - - + hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 12 - - -
-

Gtk2Hs Tutorial

-
-

<<< - Previous

-
-


-
-
+ hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 19 -

Text - Entries and Status Bars

+

4.6 Text Entries and Status Bars

hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 21 -

The Entry 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.

+

+The Entry 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. +

hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 28 -

Create a new Entry widget with the following - function.

+

+Create a new Entry widget with the following function. +

hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 32 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 35
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 36 -

To replace or get the text which is currently within the - Entry widget:

+

+To replace or get the text which is currently within the Entry +widget: +

hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 41 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 46
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 47 -

If we don't want the contents of the Entry 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 - EntryCompletion in the API documentation for its use). The - Entry attributes, which, of course, can be accessed with - get and set are:

+

+If we don't want the contents of the Entry 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 EntryCompletion in the API documentation for its +use). The Entry attributes, which, of course, can be accessed with +get and set are: +

hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 58 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 69
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 70 -

The Entry type is an instance of EditableClass - and many attributes and methods are defined there. Some - particularly useful ones are:

+

+The Entry type is an instance of EditableClass and +many attributes and methods are defined there. Some particularly useful ones +are: +

hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 76 - - - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 85
-      
- -

where the parameters of type Int denote the appropriate - start or end positions. The user can also cut, copy and paste - to/from the clipboard.

hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 86 - - +

+where the parameters of type Int denote the appropriate start or +end positions. The user can also cut, copy and paste to/from the clipboard. +

hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 91 - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 98
-      
- -

These all take the current cursor position. You can get and - set that position with:

hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 99 - - +

+These all take the current cursor position. You can get and set that position +with: +

hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 104 - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 109
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 110 -

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.

+

+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. +

hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 117 -

The Editable class has a number of signals which use higher - order functions (not discussed here). The Entry widget - itself has a signal, which is sent after the user presses the - Enter key:

+

+The Editable class has a number of signals which use higher order +functions (not discussed here). The Entry widget itself has a +signal, which is sent after the user presses the Enter key: +

hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 123 - - - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 126
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 127 -

There are also signals sent when text is copied, cut or pasted - to the clipboard, and when the user toggles overwrite/insert - mode.

+

+There are also signals sent when text is copied, cut or pasted to the +clipboard, and when the user toggles overwrite/insert mode. +

hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 132 -

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.

+

+Status bars 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 status bar has a resize grip by +default, so the user can resize it. +

hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 139 -

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:

+

+In order to allow different parts of an application to use the same status bar +to display messages, the status bar widget issues ContextIds 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 status bar is created +with: +

hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 148 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 151
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 152 -

A new Context Identifier is generated by the following - function, with a String used as textual description of the - context:

+

+A new ContextId is generated by the following function, with a +String used as textual description of the context: +

hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 157 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 160
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 161 -

There are three functions that can operate on statusbars:

+

+There are three functions that can operate on status bars: +

hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 165 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 172
-      
- -

The first, statusbarPush , is used to add a new message - to the statusbar. It returns a MessageId, which can be - passed later to statusbarRemove to remove the message with - the given ContextId and MessageId from the - statusbar's stack. Function statusbarPop removes the - message highest in the stack with the given context - identifier.

hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 173 -

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:

+

+The first, statusbarPush, is used to add a new message to the +status bar. It returns a MessageId, which can be passed later to +statusbarRemove to remove the message with the given +ContextId and MessageId from the status bar's stack. +Function statusbarPop removes the message highest in the stack +with the given context identifier. +

hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 182 - - +

+Status bars, 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: +

hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 192 - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 195
-      
- -

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.

hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 196 -

GtkChap11.png


+

+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. +

hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 203 - - +

Status bar example

hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 205 - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 210
-     initGUI
-     window <- windowNew
-     set window [windowTitle := "Text Entry", containerBorderWidth := 10]
+  initGUI
+  window <- windowNew
+  set window [windowTitle := "Text Entry", containerBorderWidth := 10]
hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 214
-     vb <- vBoxNew False 0
-     containerAdd window vb
+  vb <- vBoxNew False 0
+  containerAdd window vb
hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 217
-     hb <- hBoxNew False 0
-     boxPackStart vb hb PackNatural 0
+  hb <- hBoxNew False 0
+  boxPackStart vb hb PackNatural 0
hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 220
-     txtfield <- entryNew
-     boxPackStart hb txtfield PackNatural 5
-     button <- buttonNewFromStock stockInfo
-     boxPackStart hb button PackNatural 0
+  txtfield <- entryNew
+  boxPackStart hb txtfield PackNatural 5
+  button <- buttonNewFromStock stockInfo
+  boxPackStart hb button PackNatural 0
hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 225
-     txtstack <- statusbarNew
-     boxPackStart vb txtstack PackNatural 0
-     id <- statusbarGetContextId txtstack "Line"
+  txtstack <- statusbarNew
+  boxPackStart vb txtstack PackNatural 0
+  id <- statusbarGetContextId txtstack "Line"
hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 229
-     widgetShowAll window
-     widgetSetSensitivity button False
+  widgetShowAll window
+  widgetSetSensitivity button False
hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 232
-     onEntryActivate txtfield (saveText txtfield button txtstack id)
-     onPressed button (statusbarPop txtstack id)
-     onDestroy window mainQuit
-     mainGUI
+  onEntryActivate txtfield (saveText txtfield button txtstack id)
+  onPressed button (statusbarPop txtstack id)
+  onDestroy window mainQuit
+  mainGUI
hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 239
-         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 ()
+    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 ()
hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 248
-      

- - - - - - - - - - hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 249 - + hunk ./docs/tutorial/Tutorial_Port/chap4-6.xhtml 255 - - -
-

<<< - Previous

-
-

Home

-
-

Dialogs, Progress Bars

-
-


-
-

To be continued

-
hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 1 - - - + + + hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 5 - - - - Spin Buttons + + Gtk2Hs Tutorial: Spin Buttons + hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 10 - - - - - - - - + hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 12 - - -
-

Gtk2Hs Tutorial

-
-

<<< - Previous

-
-

Next

-
-
+ hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 19 -

Spin - Buttons

+

4.7 Spin Buttons

hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 21 -

The SpinButton 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. - SpinButton is an instance of EditableClass, so the - attributes and functions defined there are also available.

+

+The SpinButton 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. +SpinButton is an instance of EditableClass, so the +attributes and functions defined there are also available. +

hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 31 -

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.

+

+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. +

hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 38 -

SpinButton uses an Adjustment object to hold - information about the range of values that the spin button can - take. Recall that an Adjustment widget is created with the - following function:

+

+SpinButton uses an Adjustment object to hold +information about the range of values that the spin button can take. Recall +that an Adjustment widget is created with the following function: +

hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 44 - - - - -
-
-adjustmentNew
-               :: Double           -- value
-               -> Double           -- lower
-               -> Double           -- upper
-               -> Double           -- stepIncrement
-               -> Double           -- pageIncrement
-               -> Double           -- pageSize
-               -> IO Adjustment
+
+adjustmentNew :: Double        -- value
+              -> Double        -- lower
+              -> Double        -- upper
+              -> Double        -- stepIncrement
+              -> Double        -- pageIncrement
+              -> Double        -- pageSize
+              -> IO Adjustment
hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 53
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 54 -

These attributes of an Adjustment are used by the - SpinButton in the following way:

+

+These attributes of an Adjustment are used by the +SpinButton in the following way: +

hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 59 - hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 75 -

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.

+

+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. +

hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 81 -

Lets look at how to create a spin button:

+

+Let's look at how to create a spin button: +

hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 85 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 88
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 89 -

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.

+

+The second argument (climbRate) takes 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. +

hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 96 -

There also is a convenience constructor that allows creation - of a spin button without manually creating an adjustment.

+

+There also is a convenience constructor that allows creation of a spin button +without manually creating an adjustment. +

hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 101 - - - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 104
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 105 -

The three arguments, all of type Double, specify the - minum allowable value, the maximum allowable value, and the - increment added or subtracted by spinning the widget.

+

+The three arguments, all of type Double, specify the minum +allowable value, the maximum allowable value, and the increment added or +subtracted by spinning the widget. +

hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 111 -

A Spin Button can be reconfigured after creation using the - following function:

+

+A SpinButton can be reconfigured after creation using the +following function: +

hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 116 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 119
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 120 -

The first argument specifies the SpinButton widget that - is to be reconfigured. The other arguments are the climbRate and - the number of decimal places (digits) to disply.

+

+The first argument specifies the SpinButton widget that is to be +reconfigured. The other arguments are the climbRate and the number +of decimal places (digits) to disply. +

hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 126 -

The SpinButton attributes, which can be retrieved and - changed with the generic get and set functions - are:

+

+The SpinButton attributes, which can be retrieved and changed with +the generic get and set functions are: +

hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 131 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 142
-      
- -

The first three are as discussed before. The attribute - spinButtonSnapToTicks determines whether erroneous values - are automatically changed to the spin button's nearest increment - (default is False). Attribute spinButtonNumeric determines - whether non-numeric characters should be ignored (default False), - and spinButtonWrap is used to set whether a spin button - should wraparound upon reaching its limits (default False).

hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 143 -

Attribute spinButtonValue is used to read the current - value or set a new value (default is 0).

+

+The first three are as discussed before. The attribute +spinButtonSnapToTicks determines whether erroneous values are +automatically changed to the spin button's nearest increment (default is +False). Attribute spinButtonNumeric determines whether +non-numeric characters should be ignored (default False), and +spinButtonWrap is used to set whether a spin button should +wraparound upon reaching its limits (default False). +

hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 153 -

To change the value of a spin button you can also use:

+

+Attribute spinButtonValue is used to read the current value or set +a new value (default is 0). +

hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 158 - - +

+To change the value of a spin button you can also use: +

hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 162 - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 165
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 166 -

where SpinType determines the kind of change and - Double (increment) determines the value.

+

+where SpinType determines the kind of change and +Double (increment) determines the value. +

hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 171 -

SpinType has the following constructors:

+

+SpinType has the following constructors: +

hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 175 - - - - -
-
-SpinStepForward
-SpinStepBackward
-SpinPageForward
-SpinPageBackward
-SpinHome
-SpinEnd
-SpinUserDefined
-
-
+ hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 185 -

Many of these settings use values from the Adjustment - object that is associated with a spin button. - SpinStepForward and SpinStepBackwardchange 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. - SpinPageForward and SpinPageBackward simply alter - the value of the Spin Button by the increment. - SpinPageHome and SpinPageEnd set the value to the - bottom repectively the top of the Adjustment range. - i>SpinUserDefined simply alters the value of the spin - button by the specified amount.

+

+Many of these settings use values from the Adjustment object that +is associated with a spin button. SpinStepForward and +SpinStepBackward 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. +SpinPageForward and SpinPageBackward simply alter the +value of the SpinButton by the increment. +SpinPageHome and SpinPageEnd set the value to the +bottom repectively the top of the Adjustment range. +i>SpinUserDefined simply alters the value of the spin button by +the specified amount.

hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 198 -

A spin button has an update policy:

+

+A spin button has an update policy: +

hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 202 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 205
-      
hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 206 -

The constructors of SpinButtonUpdatePolicy are either - UdateAlways or UpdateIfValid. 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 UpdateIfValid 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 UpdateAlways we ignore errors - while converting text into a numeric value.

+

+The constructors of SpinButtonUpdatePolicy are either +UdateAlways or UpdateIfValid. These policies affect +the behavior of a SpinButton when parsing inserted text and +synchronizing its value with the values of the Adjustment. In the +case of UpdateIfValid 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 UpdateAlways we ignore errors while converting text into a +numeric value. +

hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 218 -

Finally, you can explicitly request that a Spin Button update - itself:

+

+Finally, you can explicitly request that a SpinButton update +itself: +

hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 223 - - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 226
-      
- -

It's example time again; this is a screenshot after playing - around with some of the settings.

hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 227 -

GtkChap12.png

+

+It's example time again. This is a screenshot after playing around with some of +the settings: +

hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 232 -

The spin buttons have all been created with the following - function which uses spinButtonNewWithRange. Because the - stepIncrement will be 1.0 in all cases, this is not a parameter - in myAddSpinButton.

+

Spin button example

hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 234 - - +

+The spin buttons have all been created with the following function which uses +spinButtonNewWithRange. Because the stepIncrement will +be 1.0 in all cases, this is not a parameter in myAddSpinButton. +

hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 240 - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 243
-        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
+    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
hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 252
-      
- -

In the main function we use one of the spin buttons - which already exist, but give it a new adjustment with - spinButtonConfigure. 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.

hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 253 -

The new signal here is onValueSpinned ,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 Double to an - Integral type.

+

+In the main function we use one of the spin buttons which already +exist, but give it a new adjustment with spinButtonConfigure. 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. +

hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 264 -

In this example we've used the generic get and - set 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.

+

+The new signal here is onValueSpinned, 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 Double to an Integral type. +

hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 272 - - +

+In this example we've used the generic get and set +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. +

hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 279 - - - -
-
+
hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 284
-     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]
+    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
hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 296
-     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     
+    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]
hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 301
-     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
+    vbox1  <- vBoxNew False 5
+    frame2 <- frameNew
+    set frame2 [frameLabel := "More Features", containerChild := vbox1,
+                frameLabelYAlign := 0.8, frameShadowType:= ShadowOut]
+    boxPackStart mainbox frame2 PackNatural 5
hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 307
-     tnumr <- checkButtonNewWithLabel "Numeric only input mode"   
-     boxPackStart vbox1 tnumr PackNatural 0
+    hbox2 <- hBoxNew False 0
+    boxPackStart vbox1 hbox2 PackNatural 0
hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 310
-     twrap <- checkButtonNewWithLabel "Wraparound at limits"   
-     boxPackStart vbox1 twrap 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]
hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 316
-     widgetShowAll window
+    tsnap <- checkButtonNewWithLabel "Snap to 0.25-ticks"
+    boxPackStart vbox1 tsnap PackNatural 0
hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 319
-     onValueSpinned spnctl $ do newdig <- get spnctl spinButtonValue
-                                set spinLarge [spinButtonDigits := (round newdig)]
+    tnumr <- checkButtonNewWithLabel "Numeric only input mode"
+    boxPackStart vbox1 tnumr PackNatural 0
hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 322
-     onToggled tsnap $ do st <- get tsnap toggleButtonActive
-                          set spinLarge [spinButtonSnapToTicks := st]
+    twrap <- checkButtonNewWithLabel "Wraparound at limits"
+    boxPackStart vbox1 twrap PackNatural 0
hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 325
-     onToggled tnumr $ do st <- get tnumr toggleButtonActive
-                          set spinLarge [spinButtonNumeric := st]
+    widgetShowAll window
hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 327
-     onToggled twrap $ do st <- get twrap toggleButtonActive
-                          set spinLarge [spinButtonWrap := st]
+    onValueSpinned spnctl $ do newdig <- get spnctl spinButtonValue
+                               set spinLarge [spinButtonDigits := (round newdig)]
hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 330
-     onDestroy window mainQuit
-     mainGUI
-
-

+ onToggled tsnap $ do st <- get tsnap toggleButtonActive + set spinLarge [spinButtonSnapToTicks := st] hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 333 - - - + onToggled tnumr $ do st <- get tnumr toggleButtonActive + set spinLarge [spinButtonNumeric := st] hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 336 - - + onToggled twrap $ do st <- get twrap toggleButtonActive + set spinLarge [spinButtonWrap := st] hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 339 - - + onDestroy window mainQuit + mainGUI + hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 343 - + hunk ./docs/tutorial/Tutorial_Port/chap4-7.xhtml 349 - - -
-

<<< - Previous

-
-

Home

-
-

Text Entries and Status Bars

-
-


-
-

To be continued

-
hunk ./docs/tutorial/Tutorial_Port/default.css 47 + +.notebox { + margin: 10px; + border: 1px solid #ccc; + padding: 10px; + color: #000000; + background-color: #ffe; + font-style: italic; +} hunk ./docs/tutorial/Tutorial_Port/index.xhtml 31 -
  • 1. Introduction — Not Available Yet
  • +
  • 1. Introduction — Not Available Yet
  • hunk ./docs/tutorial/Tutorial_Port/index.xhtml 33 -
  • 2. Getting Started
  • +
  • 2. Getting Started
  • hunk ./docs/tutorial/Tutorial_Port/index.xhtml 37 -
  • 3.1 Packing Widgets
  • +
  • 3.1 Packing Widgets
  • hunk ./docs/tutorial/Tutorial_Port/index.xhtml 39 -
  • 3.2 Packing Demonstration Program
  • +
  • 3.2 Packing Demonstration Program
  • hunk ./docs/tutorial/Tutorial_Port/index.xhtml 41 -
  • 3.3 Packing Using Tables
  • +
  • 3.3 Packing Using Tables
  • hunk ./docs/tutorial/Tutorial_Port/index.xhtml 46 -
  • 4.1 The Button Widget
  • +
  • 4.1 The Button Widget
  • hunk ./docs/tutorial/Tutorial_Port/index.xhtml 48 -
  • 4.2 Adjustments, Scale and Range
  • +
  • 4.2 Adjustments, Scale and Range
  • hunk ./docs/tutorial/Tutorial_Port/index.xhtml 50 -
  • 4.3 Labels
  • +
  • 4.3 Labels
  • hunk ./docs/tutorial/Tutorial_Port/index.xhtml 52 -
  • 4.4 Arrows and Tooltips
  • +
  • 4.4 Arrows and Tooltips
  • hunk ./docs/tutorial/Tutorial_Port/index.xhtml 54 -
  • 4.5 Dialogs, Stock Items and Progress Bars
  • +
  • 4.5 Dialogs, Stock Items and Progress Bars
  • hunk ./docs/tutorial/Tutorial_Port/index.xhtml 56 -
  • 4.6 Text Entries and Status Bars
  • +
  • 4.6 Text Entries and Status Bars
  • + +
  • 4.7 Spin Buttons
  • + +
  • 4.8 Calendar
  • hunk ./docs/tutorial/Tutorial_Port/index.xhtml 109 - Next
    Getting Started
    + Next
    1. Introduction