Terminology (Re: [GUI] Re: Know you backends)

Daan Leijen daanleijen@xs4all.nl
Fri, 31 Jan 2003 23:46:22 +0100


This is a multi-part message in MIME format.

------=_NextPart_000_00EA_01C2C982.F5D629E0
Content-Type: multipart/alternative;
	boundary="----=_NextPart_001_00EB_01C2C982.F5D629E0"


------=_NextPart_001_00EB_01C2C982.F5D629E0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

> I propose a simple program which pops up a window saying
> 'Hello World' with a button saying 'Bye' which you click and it =
changes
> the message to 'Goodbye'. if you click the button again the program
> exits.

Hi all, here is the goodbye demo in ObjectIO.=20
It shows nicely how a gui in the ObjectIO library is decribed
purely as a datatype (i.e. Dialog in this case) and how it maintains
local state for you.

All the best,
    Daan.

ps. Off course, I am not an ObjectIO expert so maybe Peter van Achten
has an even nicer solution.=20

pps. Everyone with a recent ghc on windows can run this program at home: =
 ghci ByeDemo.hs -package objectio

-------------------------------------------------------------------------=
-------

{------------------------------------------------------------------------=
--------This program implements the "goodbye" demo as posted by John =
Meacham onthe Haskell GUI mailing list. The program is specified as:I =
propose a simple program which pops up a window saying 'Hello World' =
with a button saying 'Bye' which you click and it changes the message to =
'Goodbye'. if you click the button again the program exits.This demo =
also uses a nice layout: the label and button are centeredin the dialog. =
Instead of a window, a dialog is used since it resizesautomatically to =
accomodate the controls.The dialog maintains a boolean local state that =
says whether the buttonis clicked for the first time or not. (The =
process state is unused.)When the button is clicked the "bye" function =
is called. This function checks the local state to see whether this is =
the first time that it is called.If so it changes the text of the label =
and updates the local state.Otherwise it closes the =
process.-----------------------------------------------------------------=
---------------}module Main whereimport Graphics.UI.ObjectIOmain  =3D do =
displayId <- openId       startIO NDI () (openDialog True (dialog =
displayId)) []  -- local state =3D True, process state =3D ()  where     =
 dialog displayId      =3D Dialog "Bye!"         (   TextControl "Hello =
World"             [ControlPos (Center,zero), ControlId displayId]       =
 :+: ButtonControl "Bye"             [ControlPos (Center,zero), =
ControlFunction bye]         )         [WindowClose (noLS closeProcess)] =
     where        -- called on a button click with a local state/process =
state tuple.        bye (firstTime,ps)          | firstTime  =3D do =
setControlText displayId "Goodbye"                            return =
(False,ps)          | otherwise  =3D do closeProcess ps                  =
          return (False,ps)
------=_NextPart_001_00EB_01C2C982.F5D629E0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1126" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>&gt; I propose a simple program which =
pops up a=20
window saying<BR>&gt; 'Hello World' with a button saying 'Bye' which you =
click=20
and it changes<BR>&gt; the message to 'Goodbye'. if you click the button =
again=20
the program<BR>&gt; exits.<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Hi all, here is the goodbye demo in =
ObjectIO.=20
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>It shows nicely how a gui&nbsp;in the =
ObjectIO=20
library is decribed</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>purely as a datatype (i.e. Dialog in =
this case) and=20
how it maintains</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>local state for you.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>All the best,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; Daan.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>ps. Off course, I am not an ObjectIO =
expert so=20
maybe Peter van Achten</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>has an even nicer solution. =
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT><FONT face=3DArial =
size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>pps. Everyone with a recent ghc on =
windows can run=20
this program at home:&nbsp; <FONT face=3DCourier>ghci ByeDemo.hs =
-package=20
objectio</FONT></FONT></DIV>
<DIV>
<HR>
</DIV><PRE>{-------------------------------------------------------------=
-------------------<BR>This program implements the "goodbye" demo as =
posted by John Meacham on<BR>the Haskell GUI mailing list. The program =
is specified as:</PRE><PRE>I propose a simple program which pops up a =
window saying 'Hello World' <BR>with a button saying 'Bye' which you =
click and it changes the message <BR>to 'Goodbye'. if you click the =
button again the program exits.</PRE><PRE>This demo also uses a nice =
layout: the label and button are centered<BR>in the dialog. Instead of a =
window, a dialog is used since it resizes<BR>automatically to accomodate =
the controls.</PRE><PRE>The dialog maintains a boolean local state that =
says whether the button<BR>is clicked for the first time or not. (The =
process state is unused.)<BR>When the button is clicked the "bye" =
function is called. This function <BR>checks the local state to see =
whether this is the first time that it is called.<BR>If so it changes =
the text of the label and updates the local state.<BR>Otherwise it =
closes the =
process.<BR>-------------------------------------------------------------=
-------------------}<BR>module Main where</PRE><PRE>import =
Graphics.UI.ObjectIO</PRE><PRE>main<BR>&nbsp; =3D do displayId &lt;- =
openId<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; startIO NDI () =
(openDialog True (dialog displayId)) []&nbsp; -- local state =3D True, =
process state =3D ()<BR>&nbsp; where&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp; =
dialog displayId<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =3D Dialog "Bye!" =
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (&nbsp;&nbsp; TextControl =
"Hello World" =
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
[ControlPos (Center,zero), ControlId =
displayId]<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :+: =
ButtonControl "Bye" =
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
[ControlPos (Center,zero), ControlFunction bye] =
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ) =
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [WindowClose (noLS =
closeProcess)]<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
where<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- called on a =
button click with a local state/process state =
tuple.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bye =
(firstTime,ps)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
| firstTime&nbsp; =3D do setControlText displayId =
"Goodbye"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return =
(False,ps)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | =
otherwise&nbsp; =3D do closeProcess =
ps<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp; return (False,ps)<BR></PRE></BODY></HTML>

------=_NextPart_001_00EB_01C2C982.F5D629E0--

------=_NextPart_000_00EA_01C2C982.F5D629E0
Content-Type: application/octet-stream;
	name="ByeDemo.hs"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="ByeDemo.hs"

{------------------------------------------------------------------------=
--------=0A=
This program implements the "goodbye" demo as posted by John Meacham on=0A=
the Haskell GUI mailing list. The program is specified as:=0A=
=0A=
I propose a simple program which pops up a window saying 'Hello World' =0A=
with a button saying 'Bye' which you click and it changes the message =0A=
to 'Goodbye'. if you click the button again the program exits.=0A=
=0A=
This demo also uses a nice layout: the label and button are centered=0A=
in the dialog. Instead of a window, a dialog is used since it resizes=0A=
automatically to accomodate the controls.=0A=
=0A=
The dialog maintains a boolean local state that says whether the button=0A=
is clicked for the first time or not. (The process state is unused.)=0A=
When the button is clicked the "bye" function is called. This function =0A=
checks the local state to see whether this is the first time that it is =
called.=0A=
If so it changes the text of the label and updates the local state.=0A=
Otherwise it closes the process.=0A=
-------------------------------------------------------------------------=
-------}=0A=
module Main where=0A=
=0A=
import Graphics.UI.ObjectIO=0A=
=0A=
main=0A=
  =3D do displayId <- openId=0A=
       startIO NDI () (openDialog True (dialog displayId)) []  -- local =
state =3D True=0A=
  where		=0A=
    dialog displayId=0A=
      =3D Dialog "Bye!" =0A=
        (   TextControl "Hello World" =0A=
            [ControlPos (Center,zero), ControlId displayId]=0A=
        :+: ButtonControl "Bye" =0A=
            [ControlPos (Center,zero), ControlFunction bye] =0A=
        ) =0A=
        [WindowClose (noLS closeProcess)]=0A=
      where=0A=
        -- called on a button click with a local state/process state =
tuple.=0A=
        bye (firstTime,ps)=0A=
          | firstTime  =3D do setControlText displayId "Goodbye"=0A=
                            return (False,ps)=0A=
          | otherwise  =3D do closeProcess ps=0A=
                            return (False,ps)=0A=
		
------=_NextPart_000_00EA_01C2C982.F5D629E0--