Created
November 25, 2019 09:49
-
-
Save Taneb/ca1ed27adee7da28e91ec8b3aa48af08 to your computer and use it in GitHub Desktop.
Simple image viewer in Haskell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import qualified Data.ByteString.Char8 as B -- bad | |
import qualified Graphics.UI.Gtk as Gtk | |
import System.Environment | |
import qualified System.GIO as GIO | |
updateImage :: Gtk.ImageClass o => o -> Maybe GIO.File -> Maybe GIO.File -> GIO.FileMonitorEvent -> IO () | |
updateImage image (Just file) _ GIO.FileMonitorEventChanged = do | |
pixbuf <- Gtk.pixbufNewFromFile . B.unpack $ GIO.filePath file | |
Gtk.set (Gtk.toImage image) | |
[ Gtk.imagePixbuf Gtk.:= pixbuf | |
] | |
updateImage _ _ _ _ = pure () | |
main :: IO () | |
main = do | |
[ path ] <- getArgs | |
let file = GIO.fileFromPath $ B.pack path | |
_ <- Gtk.initGUI | |
fileMonitor <- GIO.fileMonitor file [] Nothing | |
window <- Gtk.windowNew | |
image <- Gtk.imageNew | |
Gtk.on fileMonitor GIO.fileMonitorChanged (updateImage image) | |
Gtk.set window | |
[ Gtk.containerChild Gtk.:= image | |
] | |
Gtk.on window Gtk.objectDestroy Gtk.mainQuit | |
Gtk.widgetShowAll window | |
Gtk.mainGUI |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment