<commit_before>{-----------------------------------------------------------------------------------------
 Copyright (c) <NAME> 2003
 wxWindows License.

 An image viewer in wxHaskell.
-----------------------------------------------------------------------------------------}
module Main where

import Graphics.UI.WXH
import Graphics.UI.WX

main :: IO ()
main
  = start imageViewer

-- Specify image files.
imageFiles
   = [("Image files",["*.bmp","*.jpg","*.gif","*.png"])
     ,("Portable Network Graphics (*.png)",["*.png"])
     ,("BMP files (*.bmp)",["*.bmp"])
     ,("JPG files (*.jpg)",["*.jpg"])
     ,("GIF files (*.gif)",["*.gif"])
     ]

-- The image viewer.
imageViewer :: IO ()
imageViewer
  = do -- the main frame
       f      <- frame [text := "ImageViewer"]

       -- use a mutable variable to hold the image
       vbitmap <- varCreate Nothing

       -- add a scrollable window widget in the frame
       sw     <- scrolledWindow f [scrollRate := sz 10 10, on paint := onPaint vbitmap]

       -- create file menu
       file   <- menuList  "&File" []
       mclose <- menuItem file "&Close\tCtrl+C" "Close the image" [enable := False]
       open   <- menuItem file "&Open\tCtrl+O" "Open an image" []
       menuLine file
       quit   <- menuQuit file "&Quit\tCtrl+Q" "Quit the demo" []

       -- create Help menu
       help   <- menuHelp "&Help" []
       about  <- menuAbout help "&About" "About ImageViewer" []

       -- create statusbar field
       status <- statusField [text := "Welcome to the wxHaskell ImageViewer"]

       -- set the statusbar, menubar, layout, and add menu item event handlers
       set f [statusbar       := [status]
             ,menubar         := [file,help]
             ,layout          := fill (widget sw)
             ,on (menu about) := infoDialog f "About ImageViewer" "This is a wxHaskell demo"
             ,on (menu quit)  := close f
             ,on (menu open)  := onOpen f sw vbitmap mclose status 
             ,on (menu mclose):= onClose  sw vbitmap mclose status
             ,on closing      :~ \prev -> do closeImage vbitmap; prev 
             ,clientSize       := sz 300 200
             ]

  where
    onOpen :: Frame a -> ScrolledWindow b -> Var (Maybe (Bitmap ())) -> MenuItem c -> StatusField -> IO ()
    onOpen f sw vbitmap mclose status
      = do mbfname <- fileOpenDialog f True True "Open image" imageFiles "" ""
           case mbfname of
             Nothing    -> return ()
             Just fname -> openImage sw vbitmap mclose status fname

    onClose sw vbitmap mclose status
      = do closeImage vbitmap
           set mclose [enable := False]
           set sw     [virtualSize := sz 0 0]
           set status [text := ""]
           repaint sw

    closeImage vbitmap
      = do mbBitmap <- varSwap vbitmap Nothing
           case mbBitmap of
             Nothing -> return ()
             Just bm -> bitmapDelete bm

    openImage sw vbitmap mclose status fname
      = do -- load the new bitmap
           bm <- bitmapCreateFromFile fname  -- can fail with exception
           closeImage vbitmap
           varSet vbitmap (Just bm)
           set mclose [enable := True]
           set status [text := fname]<commit_msg>[wxhaskell-from-cvs @ 2003-07-20 16:45:19 by dleijen]<commit_after>{-----------------------------------------------------------------------------------------
 Copyright (c) <NAME> 2003
 wxWindows License.

 An image viewer in wxHaskell.
-----------------------------------------------------------------------------------------}
module Main where

import Graphics.UI.WXH
import Graphics.UI.WX

main :: IO ()
main
  = start imageViewer

-- Specify image files.
imageFiles
   = [("Image files",["*.bmp","*.jpg","*.gif","*.png"])
     ,("Portable Network Graphics (*.png)",["*.png"])
     ,("BMP files (*.bmp)",["*.bmp"])
     ,("JPG files (*.jpg)",["*.jpg"])
     ,("GIF files (*.gif)",["*.gif"])
     ]

-- The image viewer.
imageViewer :: IO ()
imageViewer
  = do -- the main frame
       f      <- frame [text := "ImageViewer"]

       -- use a mutable variable to hold the image
       vbitmap <- varCreate Nothing

       -- add a scrollable window widget in the frame
       sw     <- scrolledWindow f [scrollRate := sz 10 10, on paint := onPaint vbitmap]

       -- create file menu
       file   <- menuList  "&File" []
       mclose <- menuItem file "&Close\tCtrl+C" "Close the image" [enable := False]
       open   <- menuItem file "&Open\tCtrl+O" "Open an image" []
       menuLine file
       quit   <- menuQuit file "&Quit\tCtrl+Q" "Quit the demo" []

       -- create Help menu
       help   <- menuHelp "&Help" []
       about  <- menuAbout help "&About" "About ImageViewer" []

       -- create statusbar field
       status <- statusField [text := "Welcome to the wxHaskell ImageViewer"]

       -- set the statusbar, menubar, layout, and add menu item event handlers
       set f [statusbar       := [status]
             ,menubar         := [file,help]
             ,layout          := fill (widget sw)
             ,clientSize      := sz 300 200
             ,on (menu about) := infoDialog f "About ImageViewer" "This is a wxHaskell demo"
             ,on (menu quit)  := close f
             ,on (menu open)  := onOpen f sw vbitmap mclose status 
             ,on (menu mclose):= onClose  sw vbitmap mclose status
             ,on closing      :~ \prev -> do closeImage vbitmap; prev 
             ]

  where
    onOpen :: Frame a -> ScrolledWindow b -> Var (Maybe (Bitmap ())) -> MenuItem c -> StatusField -> IO ()
    onOpen f sw vbitmap mclose status
      = do mbfname <- fileOpenDialog f True True "Open image" imageFiles "" ""
           case mbfname of
             Nothing    -> return ()
             Just fname -> openImage sw vbitmap mclose status fname

    onClose sw vbitmap mclose status
      = do closeImage vbitmap
           set mclose [enable := False]
           set sw     [virtualSize := sz 0 0]
           set status [text := ""]
           repaint sw

    closeImage vbitmap
      = do mbBitmap <- varSwap vbitmap Nothing
           case mbBitmap of
             Nothing -> return ()
             Just bm -> bitmapDelete bm

    openImage sw vbitmap mclose status fname
      = do -- load the new bitmap
           bm <- bitmapCreateFromFile fname  -- can fail with exception
           closeImage vbitmap
           varSet vbitmap (Just bm)
           set mclose [enable := True]
           set status [text := fname]
{'fraction_non_alphanumeric': 0.16515034695451042, 'fraction_numerical': 0.007093292212798767, 'mean_word_length': 1.6441092539747248, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2728239', 'n_tokens_mistral': 1865, 'n_tokens_neox': 1770, 'n_words': 641}