Personal tools

WxHaskell/Tips and tricks

From HaskellWiki

< WxHaskell(Difference between revisions)
Jump to: navigation, search
 
(Added category wxHaskell)
(2 intermediate revisions by one user not shown)
Line 1: Line 1:
 
== Getting Started ==
 
== Getting Started ==
* read carefully http://wxhaskell.sourceforge.net/quickstart.html - it contains more information than you think
+
* read carefully [[WxHaskell/Quick start | Quick start]] - it contains more information than you think
 
* we include below some orientation for the most essential wxhaskell concepts
 
* we include below some orientation for the most essential wxhaskell concepts
 
* see samples/wx/Minimal.hs
 
* see samples/wx/Minimal.hs
Line 13: Line 13:
   
 
* Don't bother looking at the the examples yet, the API is better for this
 
* Don't bother looking at the the examples yet, the API is better for this
* See the Haddock-generated documentation for Graphics.UI.WX.Layout
+
* See the Haddock-generated documentation for [http://wxhaskell.sourceforge.net/doc/Graphics-UI-WXCore-Layout.html Graphics.UI.WX.Layout]
 
* Got layout troubles? Packing things inside yet another panel seems to help sometimes
 
* Got layout troubles? Packing things inside yet another panel seems to help sometimes
   
Line 23: Line 23:
 
== Mac OS X (Darwin) ==
 
== Mac OS X (Darwin) ==
   
* for ghci usage download EnableGui.hs from wxhaskell.sourceforge.net/download/EnableGUI.hs and <br /><code> ghc -fffi -package wx EnableGUI.hs<br /> ghci -package wx HelloTest.hs EnableGui.hs<br />-- followed by :m +EnableGUI and <br />enableGUI >> main</code>
+
* for ghci usage download EnableGui.hs from wxhaskell.sourceforge.net/download/EnableGUI.hs and <br /><code> ghc -XForeignFunctionInterface -package wx EnableGUI.hs<br /> ghci -package wx HelloTest.hs EnableGui.hs<br />-- followed by :m +EnableGUI and <br />enableGUI >> main</code>
   
 
== Other tips ==
 
== Other tips ==
Line 63: Line 63:
   
 
When the user closes PARAMS, one of the final things it should do is call this update function
 
When the user closes PARAMS, one of the final things it should do is call this update function
  +
  +
  +
[[Category:wxHaskell]]

Revision as of 20:51, 15 January 2012

Contents

1 Getting Started

  • read carefully Quick start - it contains more information than you think
  • we include below some orientation for the most essential wxhaskell concepts
  • see samples/wx/Minimal.hs

2 Text

  • retrieving the text of a TextCtrl: mytext <- get mytextEntry text
  • staticText misbehaves on resize: make sure that you are giving the widget enough space... for example, if you want a one-line staticText, you should
    • use hfill on the staticText
    • not use hfill (or hfloat...) or any other widgets in the same row

3 Layout

  • Don't bother looking at the the examples yet, the API is better for this
  • See the Haddock-generated documentation for Graphics.UI.WX.Layout
  • Got layout troubles? Packing things inside yet another panel seems to help sometimes

4 Scroll Bars

  • scrollbars are just windows. You create a scrollFrame, and any widgets you want inside the scrollbars, you make this scrollFrame their parent
  • see samples/wx/ImageViewer.hs
  • the following widgets (controls) already include scrollbars : listBox

5 Mac OS X (Darwin)

  • for ghci usage download EnableGui.hs from wxhaskell.sourceforge.net/download/EnableGUI.hs and
    ghc -XForeignFunctionInterface -package wx EnableGUI.hs
    ghci -package wx HelloTest.hs EnableGui.hs
    -- followed by :m +EnableGUI and
    enableGUI >> main

6 Other tips

6.1 Idle event

Use the idle event for automation.

6.2 Long computations

Scenario: you've got a looooooong computation and you want to update a progress bar or you want to have a 'STOP' button which aborts the computation

Solution:

  • wxcApp(Safe)Yield

FIXME: elaborate on this!

6.3 Managing multiple windows

Scenario: you have a main window MAIN with some information. You want to create a secondary window PARAMS in which the user edits some configuration stuff. When the user closes PARAMS, the window MAIN should be updated to reflect the new settings.

You have some code which looks like

set paramsButton [ on command := do createParamsWindow
                                    updateMainWindow ]

Problem: MAIN is not updated... at least, not until you call PARAMS a second time.

Observations:

  • This is NOT a problem with Haskell laziness

Explanation: updateMainWindow tries to read the new configuration value, but it does not succeed, because no configuration values have changed. Why not? Simpler than it looks: all the createParamsWindow function does is creates a window with some widgets, assign some commands to said widgets, and return. There's nothing in the createParamsWindow code that says the function should only return when PARAMS has been closed.

Solution: Pass createParamsWindow a function which updates the MAIN window:

set paramsButton [ on command := do createParamsWindow updateMainWindow ]

When the user closes PARAMS, one of the final things it should do is call this update function