How can I make a graphical command line in haskell/gtk2hs?
Asked Answered
A

2

7

I'm trying to create my first "real program" in haskell (something that solves integrals if polynomials) but I'm completely stumped with this part of it:

I want to make something very simple a bit like GHCi:

> user input
program output
> user input
program output
> user input
program output
> 

except that my program output is images (using LaTeX to turn mathematical expressions into PNGs) - so I can't do this using System.IO. I think it will be possible with gtk2hs which I've managed to install but I can't figure out how to make this input/output dialogue.

Please show me how it's done if you have the time. Thanks a lot!

Anacrusis answered 26/11, 2010 at 1:32 Comment(1)
I thought I saw a graphing program in Haskell somewhere, but I can't seem to find it. Then again, I'm not entirely sure it was in Haskell, either.Flawy
A
4

We managed to come up with the following solution, thanks to ClaudiusMaximus.

module Main where

import Graphics.UI.Gtk

main = do
 initGUI

 ----------------

 win <- windowNew
 onDestroy win mainQuit

 vb <- vBoxNew False 3
 log <- vBoxNew False 2

 sc <- scrolledWindowNew Nothing Nothing
 scrolledWindowSetPolicy sc PolicyNever PolicyAutomatic

 sw <- layoutNew Nothing Nothing

 en <- entryNew

 ----------------

 scrolledWindowAddWithViewport sc log
 boxPackStart vb sc PackGrow 0
 boxPackStart vb en PackNatural 0
 set win [ containerChild := vb ]

 en `onEntryActivate` do
   txt <- entryGetText en
   entrySetText en ""
   l <- labelNew (Just txt)
   boxPackStart log l PackNatural 0
   widgetShowAll log
   Just ran <- scrolledWindowGetVScrollbar sc
   adj <- rangeGetAdjustment ran
   max <- adjustmentGetUpper adj
   adjustmentSetValue adj max

 ----------------

 widgetShowAll win
 mainGUI
Anacrusis answered 27/11, 2010 at 20:52 Comment(0)
B
0

I think you should first implement the backend, i.e. the code for parsing a command and creating the output image. If that works, you could then implement the GUI. Basically, you need something light a text entry for input and an text and drawing widget for output. As GUI programming is (IMHO) not trivial, you should first look at some GTK/gtk2hs tutorials / introductions.

Bayle answered 27/11, 2010 at 9:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.