-- pipe.hs
import System.Process
import System.Environment
main :: IO ()
a:_ <- getArgs
(_, Just so, _, _) <- createProcess (proc "runghc" ["randomList.hs",a]) { std_out = CreatePipe }
_ <- createProcess (proc "/home/i/myPlayer/viewer" []) { std_in = UseHandle so }
return ()
-- randomList.hs
import System.Random
import System.Process
import System.Posix.Time (epochTime)
import System.Environment
import System.Directory
import System.FilePath.Posix
imnum = 10
lines' = return . lines
randomize :: [FilePath] -> IO [FilePath]
randomize lst = do
let c = length lst
r <- fromEnum <$> epochTime >>= (\x -> return (randomRs (0, (c-1)) (mkStdGen x) ))
return [lst !! x|x <- take imnum r]
dirFilePairs :: [FilePath] -> IO [(FilePath,FilePath)]
dirFilePairs lst = return [(takeDirectory x,x) | x <- lst]
fileFilePairs :: [(FilePath,FilePath)] -> IO [(FilePath,FilePath)]
fileFilePairs = mapM (\(a,b) -> do{aa <- getAA a; return (aa,b)})
where
getAA p = do
fs <- listDirectory p >>= filtFile ".jpg"
if fs == [] then return "cd.jpg"
else return $ p ++ ['/'] ++ head(fs)
filtFile ex = return . filter (\x -> takeExtension x == ex)
main = do
fs <- getArgs >>= \(a:_) -> readFile a
lines' fs >>= randomize >>= dirFilePairs >>= fileFilePairs >>= print
1,1 全て
-- viewer.hs
import Graphics.UI.Gtk
import System.Process
import MyButton
iSize = 100
getAps :: IO [(FilePath,FilePath)]
getAps = getContents >>= return . read
func1 f = createProcess (proc "audacious" [f]) >> return ()
main = do
aps <- getAps
initGUI
w <- windowNew
set w [windowWindowPosition := WinPosNone,
windowDefaultWidth := 400, windowDefaultHeight := 900]
vb <- vBoxNew False 0
sw <- scrolledWindowNew Nothing Nothing
scrolledWindowAddWithViewport sw vb
containerAdd w sw
bs <- mapM (\(a,b) -> newImgButton iSize (a,b) func1) aps
mapM (containerAdd vb) bs
widgetShowAll w
w `on` unrealize $ mainQuit
mainGUI
~
-- MyButton.hs
module MyButton where
import Graphics.UI.Gtk
newImgButton size (f,f') func = do
p <- pixbufNewFromFileAtSize f size size
i <- imageNewFromPixbuf p
b <- buttonNew
set b [buttonImage := i]
l <- labelNew $ Just $ drop 12 f'
set l [labelWrap := True]
hb <- hBoxNew False 0
containerAdd hb b
containerAdd hb l
b `on` buttonActivated $ func f'
return hb
2025年4月7日月曜日
myPlayer
登録:
コメントの投稿 (Atom)
myPlayer
-- pipe.hs import System.Process import System.Environment main :: IO () a:_ IO [FilePath] randomize lst = do let c = length lst ...
-
この画像(IMGP2850.JPG)を表示します。 ただこのやり方だと元画像の大きさそのままで表示されます。 サイズを変更して表示するには一旦Pixbufのインスタンスをつくってから Buttonに貼り付けます。 かんたんな画像のビューアーをつくり...
-
上のコードをコピペして実行する。 $ runghc a.hs a.hs:3:11: error: Variable not in scope: n たぶんこのようなエラーになるはずです。 最初はなぜエラーになるのか理解できませんでした。 Vim上ではまったく...
-
手続き的なscanlの説明 foldの動作をxへの代入、再代入と捉えると分かりやすくなります。 直接foldの動きを見るのではなく、 まずscanlの動作を見てみます。 scanlの型は Prelude> :t scanl scanl :: (a -> ...
0 件のコメント:
コメントを投稿