GtkTV 0.0.2 → 0.0.3
raw patch · 3 files changed
+61/−25 lines, 3 files
Files
- GtkTV.cabal +3/−3
- examples/test.hs +14/−11
- src/Interface/TV/Gtk.hs +44/−11
GtkTV.cabal view
@@ -1,5 +1,5 @@ Name: GtkTV-Version: 0.0.2+Version: 0.0.3 Cabal-Version: >= 1.2 Synopsis: Gtk-based GUIs for Tangible Values Category: User Interfaces@@ -7,12 +7,12 @@ GtkTV is a very small library that extends the TV (tangible value) framework with graphical user interfaces, using gtk2hs. .- © 2007 by Conal Elliott; BSD3 license.+ © 2009, 2010 by Conal Elliott; BSD3 license. Author: Conal Elliott Maintainer: conal@conal.net Homepage: http://haskell.org/haskellwiki/GtkTV Package-Url: http://code.haskell.org/~conal/code/GtkTV-Copyright: (c) 2009 by Conal Elliott+Copyright: (c) 2009, 2010 by Conal Elliott License: BSD3 License-File: COPYING Stability: experimental
examples/test.hs view
@@ -4,7 +4,7 @@ -- | -- Module : test -- Copyright : (c) Conal Elliott 2009--- License : GPL-3+-- License : BSD3 -- -- Maintainer : conal@conal.net -- Stability : experimental@@ -14,9 +14,10 @@ import Data.Lambda (lambda) -- or use oLambda import Data.Pair (pair) -- or use iPair, oPair+import Data.Title (title) -- or use iTitle, oTitle -import Interface.TV-import Interface.TV.Gtk+import Interface.TV (tv,runTV)+import Interface.TV.Gtk (In,Out,R,toggleI,textO,sliderRI,sliderII) {--------------------------------------------------------------------@@ -24,19 +25,21 @@ --------------------------------------------------------------------} i1 :: In R-i1 = iTitle "size" $ sliderRI (0,10) 3+i1 = title "size" $ sliderRI (0,10) 3 i2 :: In Bool-i2 = iTitle "happy" $ toggleI False+i2 = title "happy" $ toggleI False i3 :: In (R, Bool)-i3 = iPair i1 i2+i3 = pair i1 i2 i4 :: In Int-i4 = iTitle "cookies" $ sliderII (0,10) 5+i4 = title "cookies" $ sliderII (0,10) 5 +-- testI i = runOut "test" (lambda i textO) show+ testI :: Show a => In a -> IO ()-testI i = runOut (oLambda i textO) "test" show+testI i = runTV (tv (lambda i textO) show) t1,t2,t3,t4,t5 :: IO () t1 = testI i1@@ -48,13 +51,13 @@ -- t5 = runUI TextureIn "Gtk.hs" print -- t6 = runUI TextureIn "/home/conal/Pictures/phone pics/Image002.jpg" print --- WORKING HERE: curried function.- o6 :: Out (R -> Bool -> String) o6 = lambda i1 $ lambda i2 $ textO t6 :: IO ()-t6 = runOut o6 "currying" (\ a b -> show (a,b))+-- t6 = runOut "currying" o6 (\ a b -> show (a,b))++t6 = runTV $ tv (title "currying" o6) (curry show) {-
src/Interface/TV/Gtk.hs view
@@ -12,7 +12,12 @@ -- Gtk-based GUIs in the TV (tangible value) framework ---------------------------------------------------------------------- -module Interface.TV.Gtk where+module Interface.TV.Gtk+ ( -- * TV type specializations+ In, Out, GTV, runGTV+ -- * UI primitives+ , R, sliderRI, sliderII, toggleI, toggleO, textI, textO, clockI, fileNameI+ ) where import Control.Applicative (liftA2,(<$>)) import Control.Monad (when)@@ -25,32 +30,50 @@ import Data.Pair import Data.Lambda +import qualified Control.Compose as C+import Control.Compose (ToOI(..))+ import Interface.TV.Input import Interface.TV.Output+import Interface.TV.Tangible import Graphics.UI.Gtk -- as Gtk ++{--------------------------------------------------------------------+ TV type specializations+--------------------------------------------------------------------}+ type In = Input MkI type Out = Output MkI MkO+type GTV = TV MkI MkO - -- IPrim :: src a -> Input src a- -- OPrim :: snk a -> Output src snk a+-- Type specialization+runGTV :: GTV a -> IO ()+runGTV = runTV +{--------------------------------------------------------------------+ Representations+--------------------------------------------------------------------}+ -- Make a input UI.-newtype MkI a = MkI { unMkI :: MkI' a }+newtype MkI a = MkI (MkI' a) -- Representation type for 'MkI'. Takes a change call-back and produces a widget and a -- polling operation and a clean-up action. type MkI' a = IO () -> IO (Widget, IO a, IO ()) -- Make an output UI.-newtype MkO a = MkO { unMkO :: MkO' a }+newtype MkO a = MkO (MkO' a) -- Representation type for 'MkO'. Give a widget and a way to send it new--- info to disply and a clean-up action.+-- info to display and a clean-up action. type MkO' a = IO (Widget, OI a, IO ()) +-- Currently, the clean-up actions are created only by clockDtI, and just+-- propagated by the other combinators.+ -- | Sink of information type OI a = a -> IO () @@ -58,11 +81,13 @@ result :: (b -> b') -> ((a -> b) -> (a -> b')) result = (.) +-- runOut :: String -> Out a -> a -> IO ()+-- runOut name out a = runMkO name (output out) a -runOut :: Out a -> String -> a -> IO ()-runOut out name a = do+runMkO :: String -> MkO a -> OI a+runMkO name (MkO mko') a = do initGUI- (wid,sink,cleanup) <- unMkO (output out)+ (wid,sink,cleanup) <- mko' sink a window <- windowNew set window [ windowDefaultWidth := 200 -- , windowDefaultHeight := 200@@ -76,7 +101,15 @@ mainGUI return () +instance ToOI MkO where+ toOI mkO = C.Flip (runMkO "GtkTV" mkO) ++{--------------------------------------------------------------------+ UI primitives+--------------------------------------------------------------------}++ data Orient = Horizontal | Vertical deriving (Read,Show) boxNew :: Orient -> Bool -> Int -> IO Box@@ -185,8 +218,8 @@ do w <- checkButtonNew return (toWidget w, toggleButtonSetActive w, return ()) -mkFileName :: FilePath -> In FilePath-mkFileName start = primMkI $ \ refresh ->+fileNameI :: FilePath -> In FilePath+fileNameI start = primMkI $ \ refresh -> do w <- fileChooserButtonNew "Select file" FileChooserActionOpen fileChooserSetFilename w start onCurrentFolderChanged w refresh