This library contains definitions and functions to implement graphical user interfaces for Curry programs. It is based on Tcl/Tk and its basic ideas are described in detail in the PADL 2000 paper.
@authors Michael Hanus, Bernd Brassel
data GuiPort
The port to a GUI is just the stream connection to a GUI where Tcl/Tk communication is done.
data Widget
The type of possible widgets in a GUI.
Constructors:
PlainButton
:: [ConfItem] -> Widget
Canvas
:: [ConfItem] -> Widget
CheckButton
:: [ConfItem] -> Widget
Entry
:: [ConfItem] -> Widget
Label
:: [ConfItem] -> Widget
ListBox
:: [ConfItem] -> Widget
Message
:: [ConfItem] -> Widget
MenuButton
:: [ConfItem] -> Widget
Scale
:: Int -> Int -> [ConfItem] -> Widget
ScrollH
:: WidgetRef -> [ConfItem] -> Widget
ScrollV
:: WidgetRef -> [ConfItem] -> Widget
TextEdit
:: [ConfItem] -> Widget
Row
:: [ConfCollection] -> [Widget] -> Widget
Col
:: [ConfCollection] -> [Widget] -> Widget
Matrix
:: [ConfCollection] -> [[Widget]] -> Widget
data ConfItem
The data type for possible configurations of a widget.
Constructors:
Active
:: Bool -> ConfItem
Anchor
:: String -> ConfItem
Background
:: String -> ConfItem
Foreground
:: String -> ConfItem
Handler
:: Event -> (GuiPort -> IO [ReconfigureItem]) -> ConfItem
Height
:: Int -> ConfItem
CheckInit
:: String -> ConfItem
CanvasItems
:: [CanvasItem] -> ConfItem
List
:: [String] -> ConfItem
Menu
:: [MenuItem] -> ConfItem
WRef
:: WidgetRef -> ConfItem
Text
:: String -> ConfItem
Width
:: Int -> ConfItem
Fill
:: ConfItem
FillX
:: ConfItem
FillY
:: ConfItem
TclOption
:: String -> ConfItem
data ReconfigureItem
Data type for describing configurations that are applied to a widget or GUI by some event handler.
Constructors:
WidgetConf
:: WidgetRef -> ConfItem -> ReconfigureItem
StreamHandler
:: Handle -> (Handle -> GuiPort -> IO [ReconfigureItem]) -> ReconfigureItem
RemoveStreamHandler
:: Handle -> ReconfigureItem
data Event
The data type of possible events on which handlers can react. This list is still incomplete and might be extended or restructured in future releases of this library.
Constructors:
DefaultEvent
:: Event
MouseButton1
:: Event
MouseButton2
:: Event
MouseButton3
:: Event
KeyPress
:: Event
Return
:: Event
Known instances:
data ConfCollection
The data type for possible configurations of widget collections (e.g., columns, rows).
Constructors:
CenterAlign
:: ConfCollection
LeftAlign
:: ConfCollection
RightAlign
:: ConfCollection
TopAlign
:: ConfCollection
BottomAlign
:: ConfCollection
data MenuItem
The data type for specifying items in a menu.
Constructors:
MButton
:: (GuiPort -> IO [ReconfigureItem]) -> String -> MenuItem
MSeparator
:: MenuItem
MMenuButton
:: String -> [MenuItem] -> MenuItem
data CanvasItem
The data type of items in a canvas. The last argument are further options in Tcl/Tk (for testing).
Constructors:
CLine
:: [(Int, Int)] -> String -> CanvasItem
CPolygon
:: [(Int, Int)] -> String -> CanvasItem
CRectangle
:: (Int, Int) -> (Int, Int) -> String -> CanvasItem
COval
:: (Int, Int) -> (Int, Int) -> String -> CanvasItem
CText
:: (Int, Int) -> String -> String -> CanvasItem
data WidgetRef
The (hidden) data type of references to a widget in a GUI window. Note that the constructor WRefLabel will not be exported so that values can only be created inside this module.
data Style
The data type of possible text styles.
Constructors:
Bold
:: Style
Italic
:: Style
Underline
:: Style
Fg
:: Color -> Style
Bg
:: Color -> Style
data Color
The data type of possible colors.
Constructors:
Black
:: Color
Blue
:: Color
Brown
:: Color
Cyan
:: Color
Gold
:: Color
Gray
:: Color
Green
:: Color
Magenta
:: Color
Orange
:: Color
Pink
:: Color
Purple
:: Color
Red
:: Color
Tomato
:: Color
Turquoise
:: Color
Violet
:: Color
White
:: Color
Yellow
:: Color
Horizontal alignment of widgets.
Vertical alignment of widgets.
matrix
:: [[Widget]] -> Widget
Matrix alignment of widgets.
Prints the generated Tcl commands of a main widget (useful for debugging).
runPassiveGUI
:: String -> Widget -> IO GuiPort
IO action to show a Widget in a new GUI window in passive mode, i.e., ignore all GUI events.
:: String
|
the title of the main window containing the widget |
-> Widget
|
the widget shown in the new window |
-> IO GuiPort
|
runGUI
:: String -> Widget -> IO ()
IO action to run a Widget in a new window.
:: String
|
the title of the main window containing the widget |
-> Widget
|
the widget shown in the new window |
-> IO ()
|
runGUIwithParams
:: String -> String -> Widget -> IO ()
IO action to run a Widget in a new window.
:: String
|
the title of the main window containing the widget |
-> String
|
parameter string passed to the initial wish command |
-> Widget
|
the widget shown in the new window |
-> IO ()
|
runInitGUI
:: String -> Widget -> (GuiPort -> IO [ReconfigureItem]) -> IO ()
IO action to run a Widget in a new window. The GUI events are processed after executing an initial action on the GUI.
:: String
|
the title of the main GUI window |
-> Widget
|
the widget shown in the new GUI window |
-> GuiPort -> IO [ReconfigureItem]
|
the initial command executed before activating the GUI |
-> IO ()
|
runInitGUIwithParams
:: String -> String -> Widget -> (GuiPort -> IO [ReconfigureItem]) -> IO ()
IO action to run a Widget in a new window. The GUI events are processed after executing an initial action on the GUI.
:: String
|
the title of the main GUI window |
-> String
|
parameter string passed to the initial wish command |
-> Widget
|
the widget shown in the new GUI window |
-> GuiPort -> IO [ReconfigureItem]
|
the initial command executed before activating the GUI |
-> IO ()
|
runControlledGUI
:: String -> (Widget, String -> GuiPort -> IO ()) -> Handle -> IO ()
Runs a Widget in a new GUI window and process GUI events. In addition, an event handler is provided that process messages received from an external stream identified by a handle (third argument). This operation is useful to run a GUI that should react on user events as well as messages written to the given handle.
:: String
|
the title of the main window containing the widget |
-> (Widget, String -> GuiPort -> IO ())
|
a pair (widget,exth) where widget is the widget shown in the new window and exth is the event handler for external messages |
-> Handle
|
the handle of the stream of external messages |
-> IO ()
|
runConfigControlledGUI
:: String -> (Widget, String -> GuiPort -> IO [ReconfigureItem]) -> Handle -> IO ()
Runs a Widget in a new GUI window and process GUI events. In addition, an event handler is provided that process messages received from an external stream identified by a handle (third argument). This operation is useful to run a GUI that should react on user events as well as messages written to the given handle.
:: String
|
the title of the main window containing the widget |
-> (Widget, String -> GuiPort -> IO [ReconfigureItem])
|
a pair (widget,exth) where widget is the widget shown in the new window and exth is the event handler for external messages that returns a list of widget reference/configuration pairs which is applied after the handler in order to configure some GUI widgets |
-> Handle
|
the handle of the stream of external messages |
-> IO ()
|
runInitControlledGUI
:: String -> (Widget, String -> GuiPort -> IO ()) -> (GuiPort -> IO [ReconfigureItem]) -> Handle -> IO ()
Runs a Widget in a new GUI window and process GUI events after executing an initial action on the GUI window. In addition, an event handler is provided that process messages received from an external message stream. This operation is useful to run a GUI that should react on user events as well as messages written to the given handle.
:: String
|
the title of the main window containing the widget |
-> (Widget, String -> GuiPort -> IO ())
|
a pair (widget,exth) where widget is the widget shown in the new window and exth is the event handler for external messages |
-> GuiPort -> IO [ReconfigureItem]
|
the initial command executed before starting the GUI |
-> Handle
|
the handle of the stream of external messages |
-> IO ()
|
runHandlesControlledGUI
:: String -> (Widget, [Handle -> GuiPort -> IO [ReconfigureItem]]) -> [Handle] -> IO ()
Runs a Widget in a new GUI window and process GUI events. In addition, a list of event handlers is provided that process inputs received from a corresponding list of handles to input streams. Thus, if the i-th handle has some data available, the i-th event handler is executed with the i-th handle as a parameter. This operation is useful to run a GUI that should react on inputs provided by other processes, e.g., via sockets.
:: String
|
the title of the main window containing the widget |
-> (Widget, [Handle -> GuiPort -> IO [ReconfigureItem]])
|
a pair (widget,handlers) where widget is the widget shown in the new window and handlers is a list of event handler for external inputs |
-> [Handle]
|
a list of handles to the external input streams for the corresponding event handlers |
-> IO ()
|
runInitHandlesControlledGUI
:: String -> (Widget, [Handle -> GuiPort -> IO [ReconfigureItem]]) -> (GuiPort -> IO [ReconfigureItem]) -> [Handle] -> IO ()
Runs a Widget in a new GUI window and process GUI events after executing an initial action on the GUI window. In addition, a list of event handlers is provided that process inputs received from a corresponding list of handles to input streams. Thus, if the i-th handle has some data available, the i-th event handler is executed with the i-th handle as a parameter. This operation is useful to run a GUI that should react on inputs provided by other processes, e.g., via sockets.
:: String
|
the title of the main window containing the widget |
-> (Widget, [Handle -> GuiPort -> IO [ReconfigureItem]])
|
a pair (widget,handlers) where widget is the widget shown in the new window and handlers is a list of event handler for external inputs |
-> GuiPort -> IO [ReconfigureItem]
|
the initial command executed before starting the GUI |
-> [Handle]
|
a list of handles to the external input streams for the corresponding event handlers |
-> IO ()
|
setConfig
:: WidgetRef -> ConfItem -> GuiPort -> IO ()
Changes the current configuration of a widget (deprecated operation, only included for backward compatibility). Warning: does not work for Command options!
An event handler for terminating the GUI.
getValue
:: WidgetRef -> GuiPort -> IO String
Gets the (String) value of a variable in a GUI.
setValue
:: WidgetRef -> String -> GuiPort -> IO ()
Sets the (String) value of a variable in a GUI.
updateValue
:: (String -> String) -> WidgetRef -> GuiPort -> IO ()
Updates the (String) value of a variable w.r.t. to an update function.
appendValue
:: WidgetRef -> String -> GuiPort -> IO ()
Appends a String value to the contents of a TextEdit widget and adjust the view to the end of the TextEdit widget.
appendStyledValue
:: WidgetRef -> String -> [Style] -> GuiPort -> IO ()
Appends a String value with style tags to the contents of a TextEdit widget
and adjust the view to the end of the TextEdit widget.
Different styles can be combined, e.g., to get bold blue text on a
red background. If codeBold/code, codeItalic/code
and
codeUnderline/code
are combined, currently all but one of these are
ignored.
This is an experimental function and might be changed in the future.
addRegionStyle
:: WidgetRef -> (Int, Int) -> (Int, Int) -> Style -> GuiPort -> IO ()
Adds a style value in a region of a TextEdit widget.
The region is specified a start and end position similarly
to codegetCursorPosition/code.
Different styles can be combined, e.g., to get bold blue text on a
red background. If codeBold/code, codeItalic/code
and
codeUnderline/code
are combined, currently all but one of these are
ignored.
This is an experimental function and might be changed in the future.
removeRegionStyle
:: WidgetRef -> (Int, Int) -> (Int, Int) -> Style -> GuiPort -> IO ()
Removes a style value in a region of a TextEdit widget.
The region is specified a start and end position similarly
to codegetCursorPosition/code.
This is an experimental function and might be changed in the future.
getCursorPosition
:: WidgetRef -> GuiPort -> IO (Int, Int)
Get the position (line,column) of the insertion cursor in a TextEdit widget. Lines are numbered from 1 and columns are numbered from 0.
seeText
:: WidgetRef -> (Int, Int) -> GuiPort -> IO ()
Adjust the view of a TextEdit widget so that the specified line/column character is visible. Lines are numbered from 1 and columns are numbered from 0.
focusInput
:: WidgetRef -> GuiPort -> IO ()
Sets the input focus of this GUI to the widget referred by the first argument. This is useful for automatically selecting input entries in an application.
addCanvas
:: WidgetRef -> [CanvasItem] -> GuiPort -> IO ()
Adds a list of canvas items to a canvas referred by the first argument.
popupMessage
:: String -> IO ()
A simple popup message.
Cmd
:: (GuiPort -> IO ()) -> ConfItem
A simple event handler that can be associated to a widget. The event handler takes a GUI port as parameter in order to read or write values from/into the GUI.
Command
:: (GuiPort -> IO [ReconfigureItem]) -> ConfItem
An event handler that can be associated to a widget. The event handler takes a GUI port as parameter (in order to read or write values from/into the GUI) and returns a list of widget reference/configuration pairs which is applied after the handler in order to configure some GUI widgets.
Button
:: (GuiPort -> IO ()) -> [ConfItem] -> Widget
A button with an associated event handler which is activated if the button is pressed.
ConfigButton
:: (GuiPort -> IO [ReconfigureItem]) -> [ConfItem] -> Widget
A button with an associated event handler which is activated if the button is pressed. The event handler is a configuration handler (see Command) that allows the configuration of some widgets.
TextEditScroll
:: [ConfItem] -> Widget
A text edit widget with vertical and horizontal scrollbars. The argument contains the configuration options for the text edit widget.
ListBoxScroll
:: [ConfItem] -> Widget
A list box widget with vertical and horizontal scrollbars. The argument contains the configuration options for the list box widget.
CanvasScroll
:: [ConfItem] -> Widget
A canvas widget with vertical and horizontal scrollbars. The argument contains the configuration options for the text edit widget.
EntryScroll
:: [ConfItem] -> Widget
An entry widget with a horizontal scrollbar. The argument contains the configuration options for the entry widget.
getOpenFile
:: IO String
Pops up a GUI for selecting an existing file. The file with its full path name will be returned (or "" if the user cancels the selection).
getOpenFileWithTypes
:: [(String, String)] -> IO String
Pops up a GUI for selecting an existing file. The parameter is a list of pairs of file types that could be selected. A file type pair consists of a name and an extension for that file type. The file with its full path name will be returned (or "" if the user cancels the selection).
getSaveFile
:: IO String
Pops up a GUI for choosing a file to save some data. If the user chooses an existing file, she/he will asked to confirm to overwrite it. The file with its full path name will be returned (or "" if the user cancels the selection).
getSaveFileWithTypes
:: [(String, String)] -> IO String
Pops up a GUI for choosing a file to save some data. The parameter is a list of pairs of file types that could be selected. A file type pair consists of a name and an extension for that file type. If the user chooses an existing file, she/he will asked to confirm to overwrite it. The file with its full path name will be returned (or "" if the user cancels the selection).
chooseColor
:: IO String
Pops up a GUI dialog box to select a color. The name of the color will be returned (or "" if the user cancels the selection).