Difference between revisions of "WxHaskell/Tips and tricks"
m |
PabloCouto (talk | contribs) |
||
(2 intermediate revisions by 2 users not shown) | |||
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) == |
||
+ | Note: The workaround below is not necessary after version 0.90.1.0 of wxHaskell. However, to run wxHaskell inside ghci it may be necessary to pass the <code>-fno-ghci-sandbox</code> flag. ghci may still crash if trying to run wxHaskell a second time per session; this is a known issue. |
||
⚫ | |||
+ | |||
⚫ | |||
== Other tips == |
== Other tips == |
||
Line 63: | Line 65: | ||
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]] |
Latest revision as of 14:04, 4 October 2014
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
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
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
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
Mac OS X (Darwin)
Note: The workaround below is not necessary after version 0.90.1.0 of wxHaskell. However, to run wxHaskell inside ghci it may be necessary to pass the -fno-ghci-sandbox
flag. ghci may still crash if trying to run wxHaskell a second time per session; this is a known issue.
- 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
Other tips
Idle event
Use the idle event for automation.
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!
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