System.Glib.Attributes

glib-0.13.4.1: Binding to the GLIB library for Gtk2Hs.

Maintainer | gtk2hs-users@lists.sourceforge.net
Stability | experimental
Portability | portable
Safe Haskell | Safe
Language | Haskell98

System.Glib.Attributes

Contents

- Attribute types
- Interface for getting, setting and updating attributes
- Internal attribute constructors

Description

Attributes interface

Attributes of an object can be get and set. Getting the value of an object's attribute is straingtforward. As an example consider a `button` widget and an attribute called `buttonLabel`.

    value <- get button buttonLabel

The syntax for setting or updating an attribute is only slightly more complex. At the simplest level it is just:

    set button [ buttonLabel := value ]

However as the list notation would indicate, you can set or update multiple attributes of the same object in one go:

    set button [ buttonLabel := value, buttonFocusOnClick := False ]

You are not limited to setting the value of an attribute, you can also apply an update function to an attribute's value. That is the function receives the current value of the attribute and returns the new value.

    set spinButton [ spinButtonValue :~ (+1) ]

There are other variants of these operators, (see `AttrOp`). `:=>` and `:~>` and like `:=` and `:~` but operate in the `IO` monad rather than being pure. There is also `::=` and `::~` which take the object as an extra parameter.

Attributes can be read only, write only or both read/write.

Synopsis

- type Attr o a = ReadWriteAttr o a a
- type ReadAttr o a = ReadWriteAttr o a ()
- type WriteAttr o b = ReadWriteAttr o () b
- data ReadWriteAttr o a b
- data AttrOp o
  - = (ReadWriteAttr o a b) := b
  - | (ReadWriteAttr o a b) :~ (a -> b)
  - | (ReadWriteAttr o a b) :=> (IO b)
  - | (ReadWriteAttr o a b) :~> (a -> IO b)
  - | (ReadWriteAttr o a b) ::= (o -> b)
  - | (ReadWriteAttr o a b) ::~ (o -> a -> b)
- get :: o -> ReadWriteAttr o a b -> IO a
- set :: o -> [AttrOp o] -> IO ()
- newNamedAttr :: String -> (o -> IO a) -> (o -> b -> IO ()) -> ReadWriteAttr o a b
- readNamedAttr :: String -> (o -> IO a) -> ReadAttr o a
- writeNamedAttr :: String -> (o -> b -> IO ()) -> WriteAttr o b
- newAttr :: (o -> IO a) -> (o -> b -> IO ()) -> ReadWriteAttr o a b
- readAttr :: (o -> IO a) -> ReadAttr o a
- writeAttr :: (o -> b -> IO ()) -> WriteAttr o b

# Attribute types

type Attr o a = ReadWriteAttr o a a #

An ordinary attribute. Most attributes have the same get and set types.

type ReadAttr o a = ReadWriteAttr o a () #

A read-only attribute.

type WriteAttr o b = ReadWriteAttr o () b #

A write-only attribute.

data ReadWriteAttr o a b #

A generalised attribute with independent get and set types.

Instances

Show (ReadWriteAttr o a b) # |
Methods showsPrec :: Int -> ReadWriteAttr o a b -> ShowS # show :: ReadWriteAttr o a b -> String # showList :: [ReadWriteAttr o a b] -> ShowS #

# Interface for getting, setting and updating attributes

data AttrOp o #

A set or update operation on an attribute.

Constructors

(ReadWriteAttr o a b) := b infixr 0 | Assign a value to an attribute.
(ReadWriteAttr o a b) :~ (a -> b) infixr 0 | Apply an update function to an attribute.
(ReadWriteAttr o a b) :=> (IO b) infixr 0 | Assign the result of an IO action to an attribute.
(ReadWriteAttr o a b) :~> (a -> IO b) infixr 0 | Apply a IO update function to an attribute.
(ReadWriteAttr o a b) ::= (o -> b) infixr 0 | Assign a value to an attribute with the object as an argument.
(ReadWriteAttr o a b) ::~ (o -> a -> b) infixr 0 | Apply an update function to an attribute with the object as an argument.

get :: o -> ReadWriteAttr o a b -> IO a #

Get an Attr of an object.

set :: o -> [AttrOp o] -> IO () #

Set a number of properties for some object.

# Internal attribute constructors

newNamedAttr :: String -> (o -> IO a) -> (o -> b -> IO ()) -> ReadWriteAttr o a b #

Create a new attribute with a getter and setter function.

readNamedAttr :: String -> (o -> IO a) -> ReadAttr o a #

Create a new read-only attribute.

writeNamedAttr :: String -> (o -> b -> IO ()) -> WriteAttr o b #

Create a new write-only attribute.

newAttr :: (o -> IO a) -> (o -> b -> IO ()) -> ReadWriteAttr o a b #

Create a new attribute with a getter and setter function.

readAttr :: (o -> IO a) -> ReadAttr o a #

Create a new read-only attribute.

writeAttr :: (o -> b -> IO ()) -> WriteAttr o b #

Create a new write-only attribute.