GuiTV (empty) → 0.2
raw patch · 8 files changed
+271/−0 lines, 8 filesdep +DeepArrowdep +TVdep +basebuild-type:Customsetup-changed
Dependencies added: DeepArrow, TV, base, phooey
Files
- CHANGES +0/−0
- GuiTV.cabal +39/−0
- Makefile +13/−0
- README +16/−0
- Setup.lhs +3/−0
- TODO +0/−0
- src/Examples.hs +140/−0
- src/Interface/TV/UI.hs +60/−0
+ CHANGES view
+ GuiTV.cabal view
@@ -0,0 +1,39 @@+Name: GuiTV+Version: 0.2+Synopsis: GUIs for Tangible Values+Category: Interfaces, User Interfaces+Description:+ GuiTV is a very small library that extends the TV (tangible value)+ framework with graphical user interfaces, using Phooey. (See+ <http://haskell.org/haskellwiki/TV> and+ <http://haskell.org/haskellwiki/Phooey>.) The functionality was part of+ the TV package up to version 0.1.1. I moved it out to eliminate the+ dependency of core TV on Phooey and hence on wxHaskell, as the latter+ can be difficult to install.+ .+ Try out the examples in @src\/Examples.hs@.+ .+ For more information, including examples, please see the project wiki+ page <http://haskell.org/haskellwiki/GuiTV>+ .+ This page and the module documentation pages have links to colorized+ source code and to wiki pages where you can read and contribute /user+ comments/. Enjoy!+ .+ © 2007 by Conal Elliott; BSD3 license.+Author: Conal Elliott +Maintainer: conal@conal.net+Homepage: http://haskell.org/haskellwiki/GuiTV+Package-Url: http://darcs.haskell.org/packages/GuiTV+Copyright: (c) 2007 by Conal Elliott+License: BSD3+Stability: experimental+Hs-Source-Dirs: src+Build-Depends: base, DeepArrow, phooey>=0.1, TV+tested-with: GHC==6.6+Extensions: CPP+Exposed-Modules: + Interface.TV.UI+Extra-Source-Files: + Examples+ghc-options: -O -W
+ Makefile view
@@ -0,0 +1,13 @@+# See README for Cabal-based building. Other fancy stuff (like haddock) here.++user = conal++configure_args=--disable-use-packages --haddock-args="\+ --read-interface=http://haskell.org/ghc/docs/latest/html/libraries/base,c:/ghc/ghc-6.6/doc/html/libraries/base/base.haddock \+ --read-interface=http://darcs.haskell.org/packages/DeepArrow/doc/html,c:/Haskell/packages/DeepArrow-0.0.1/doc/html/DeepArrow.haddock \+ --read-interface=http://darcs.haskell.org/packages/phooey/doc/html,c:/Haskell/packages/phooey-0.2.1/doc/html/phooey.haddock \+ --read-interface=http://darcs.haskell.org/packages/TV/doc/html,c:/Haskell/packages/TV-0.2/doc/html/TV.haddock \+ $(source_args)\+ $(comments_args)\+ "+include ../my-cabal-make.inc
+ README view
@@ -0,0 +1,16 @@+GuiTV is a small library for GUI-style visualizing functional values. It+can also be viewed as an approach to functional GUIs. It is implemented+very simply by using Phooey (http://haskell.org/haskellwiki/phooey) in the+TV framework (http://haskell.org/haskellwiki/TV). For a fuller+description and link to documentation, please see the project wiki page:++ http://haskell.org/haskellwiki/GuiTV++You can configure, build, generate haddock docs, and install all in the+usual way with Cabal commands.++ runhaskell Setup.lhs configure+ runhaskell Setup.lhs build+ runhaskell Setup.lhs install++See src/Examples.hs for examples.
+ Setup.lhs view
@@ -0,0 +1,3 @@+#!/usr/bin/env runhaskell +> import Distribution.Simple +> main = defaultMain
+ TODO view
+ src/Examples.hs view
@@ -0,0 +1,140 @@+{-# OPTIONS -fglasgow-exts #-}++module Examples where++import Data.List (sort)++import Interface.TV.UI++-- To pick up the FunArr instance for OFun. GHC bug?+import Interface.TV.OFun()++main = runBoth shopping++-- Run both UI and IO flavors+runBoth :: CTV a -> IO ()+runBoth tv = runUI tv >> runIO tv++tv0 :: CTV String+tv0 = tv (oTitle "message" stringOut) "Hello World!"++tv1 :: CTV Int+tv1 = tv (oTitle "answer" showOut) (42 :: Int)++reverseT :: DefaultOut ([a] -> [a]) => CTV ([a] -> [a])+reverseT = tv (oTitle "reverse" defaultOut) reverse++-- This one reverses twice+revTwice :: CTV (String -> String)+revTwice = reverseT ->| reverseT++apples, bananas :: CInput Int+apples = iTitle "apples" defaultIn+bananas = iTitle "bananas" defaultIn++total :: Show a => COutput a+total = oTitle "total" showOut++shoppingO :: COutput (Int -> Int -> Int)+shoppingO = oTitle "shopping list" $+ oLambda apples (oLambda bananas total)++shopping :: CTV (Int -> Int -> Int)+shopping = tv shoppingO (+)++shoppingPr :: CTV ((Int,Int) -> Int)+shoppingPr = tv ( oTitle "shopping list -- curried" $ + oLambda (iPair apples bananas) total )+ (uncurry (+))++shoppingPr' :: CTV ((Int,Int) -> Int)+shoppingPr' = uncurryA $$ shopping+++applesU, bananasU :: Input UI Int+applesU = iTitle "apples" (islider 3 (0,10))+bananasU = iTitle "bananas" (islider 7 (0,10))++shoppingUO :: Output UI (Int -> Int -> Int)+shoppingUO = oTitle "shopping list" $+ oLambda applesU (oLambda bananasU total)++shoppingU :: TV UI (Int -> Int -> Int)+shoppingU = tv shoppingUO (+)++shoppingPrU :: TV UI ((Int,Int) -> Int)+shoppingPrU = uncurryA $$ shoppingU+++-- This one is polymorphic in value, so say something like+-- "runBoth (sortT :: CTV ([String] -> [String]))". If you leave out the type+-- annotation, a will default to Int.+sortT :: (Read a, Show a, Ord a) => CTV ([a] -> [a])+sortT = tv (oTitle "sort" $ interactLineRS []) sort+++---- Composition.++-- Idea: unwords, sort, words++instance DefaultOut [String] where defaultOut = showOut+instance DefaultIn [String] where defaultIn = readIn []+++wordsT :: CTV (String -> [String]) +wordsT = tv ( oTitle "function: words" $+ oLambda (iTitle "sentence in" defaultIn)+ (oTitle "words out" defaultOut))+ words++unwordsT :: CTV ([String] -> String) +unwordsT = tv ( oTitle "function: unwords" $+ oLambda (iTitle "words in" defaultIn)+ (oTitle "sentence out" defaultOut))+ unwords++sortWordsT :: CTV (String -> String)+sortWordsT = wordsT ->| sortT ->| unwordsT+++---- IO examples++testO :: Output KIO (String -> String)+testO = oLambda (fileIn "test.txt") defaultOut++-- Apply a function on the lines or on the words of a string.+onLines, onWords :: ([String] -> [String]) -> (String -> String)+onLines = wrapF unlines lines+onWords = wrapF unwords words++perLine,perWord :: (String -> String) -> (String -> String)+perLine f = onLines (map f)+perWord f = onWords (map f)++-- io3, ... :: TV KIO (String -> String)++io3 = tv testO (onLines reverse) -- reverse the lines+io4 = tv testO (onWords reverse) -- reverse words+io5 = tv testO (perLine (onWords reverse)) -- reverse words on each line++io3' = tv testO (perLine reverse) -- reverse each line+io4' = tv testO (perWord reverse) -- reverse each word+io5' = tv testO (perLine (perWord reverse)) -- reverse each word, leaving lines+++-- Find lines with 0 < length < n+short :: Int -> [String] -> [String]+short n = filter (tween 1 n . length)+ where tween lo hi i = lo <= i && i < hi++-- Extract lines from a file before a function and combine lines after.+shortO :: FilePath -> Output KIO ([String] -> [String])+shortO path = oLambda (fmap lines (fileIn path)) (cofmap unlines defaultOut)++-- Nearly equivalent, but retains more Output structure:+-- shortO path = cofmap (wrapF unlines lines) (oLambda (fileIn path) defaultOut)++shortT :: FilePath -> Int -> TV KIO ([String] -> [String])+shortT path n = tv (shortO path) (sort . short n)++-- Example: runTV (shortT "c:/conal/Misc/quotes.tw" 100)
+ src/Interface/TV/UI.hs view
@@ -0,0 +1,60 @@+{-# OPTIONS -fglasgow-exts #-}++----------------------------------------------------------------------+-- |+-- Module : Interface.TV.UI+-- Copyright : (c) Conal Elliott 2006+-- License : LGPL+-- +-- Maintainer : conal@conal.net+-- Stability : experimental+-- Portability : portable+-- +-- Graphical 'UI' instances of TV classes, plus UI-specific tools+----------------------------------------------------------------------++module Interface.TV.UI+ (+ islider , runUI+ , UI, module Interface.TV -- re-exports+ ) where++import Control.Arrow (pure,(>>>))++import Graphics.UI.Phooey hiding (runUI,islider)+import qualified Graphics.UI.Phooey as Ph (islider)++import Interface.TV+++{----------------------------------------------------------+ Instances+----------------------------------------------------------}++instance Present UI where+ presentPair = fromLeft+ presentLambda = fromTop+ presentTitle = title+ -- presentCompose = id++-- For the Eros version, I'll want presentCompose to replace all inner+-- handles with one outer handle.++instance ToIO UI where toIO = runNamedUI "TV + Phooey"++instance CommonInsOuts UI where+ putString = stringDisplay+ getString = textEntry+++-- | Integer-valued slider, given initial value and bounds+islider :: Int+ -> (Int,Int)+ -> Input UI Int+islider initial bounds =+ iPrim (pure (const bounds) >>> Ph.islider initial)+++-- | Type-disambiguating alias for 'runTV'+runUI :: RunTV UI+runUI = runTV