aboutsummaryrefslogtreecommitdiffstats
path: root/main.hs
blob: d92c6330895c2819745beb82ccd5a9390a0d2f06 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{-# LANGUAGE OverloadedStrings #-}

import Graphics.UI.Gtk
import qualified Control.Monad.IO.Class as Cl
import qualified RealCalc

main :: IO ()
main = do _ <- initGUI
          w <- windowNew
          set w [ windowDecorated := False, windowResizable := False ]
          grid <- gridNew
          input <- entryNew
          output <- entryNew
          set output [ entryEditable := False ]
          clip <- Cl.liftIO $ clipboardGet selectionPrimary
          gridAttach grid input 0 0 1 1
          gridAttach grid output 0 1 1 1
          containerAdd w grid
          _ <- w `on` deleteEvent $ do
            Cl.liftIO mainQuit
            return False
          _ <- input `on` keyReleaseEvent $ do
            k <- eventKeyName
            let quit = Cl.liftIO mainQuit
            case k of
              "Escape" -> quit
              "Return" -> quit
              _ -> return ()
            s <- Cl.liftIO $ entryGetText input
            case RealCalc.calculate s of
              Nothing -> return ()
              Just r -> do Cl.liftIO $ clipboardSetText clip r
                           Cl.liftIO $ set output [ entryText := r ]
            return False
          widgetShowAll w
          mainGUI