packages feed

Chart-gtk (empty) → 0.15

raw patch · 5 files changed

+181/−0 lines, 5 filesdep +Chartdep +arraydep +basesetup-changed

Dependencies added: Chart, array, base, cairo, colour, data-accessor, data-accessor-template, gtk, mtl, old-locale, time

Files

+ Chart-gtk.cabal view
@@ -0,0 +1,29 @@+Name: Chart-gtk+Version: 0.15+License: BSD3+License-file: LICENSE+Copyright: Tim Docker, 2006-2010+Author: Tim Docker <tim@dockerz.net>+Maintainer: Tim Docker <tim@dockerz.net>+Homepage: http://www.dockerz.net/software/chart.html+Synopsis: Utility functions for using the chart library with GTK+Description: Utility functions for using the chart library with GTK+Category: Graphics+Cabal-Version: >= 1.6+Build-Type: Simple++flag splitbase+  description: Choose the new smaller, split-up base package.++library+  if flag(splitbase)+    Build-depends: base >= 3 && < 5, old-locale, time, mtl, array+  else+    Build-depends: base < 3+  Build-depends: cairo >= 0.9.11, time, mtl, array, data-accessor == 0.2.*, +                 data-accessor-template >= 0.2.1.1 && < 0.3, colour >= 2.2.1,+                 gtk >= 0.9.11, Chart == 0.15++  Exposed-modules:+        Graphics.Rendering.Chart.Gtk+        Graphics.Rendering.Chart.Gtk.Simple
+ Graphics/Rendering/Chart/Gtk.hs view
@@ -0,0 +1,81 @@+-----------------------------------------------------------------------------+-- |+-- Module      :  Graphics.Rendering.Chart.Gtk+-- Copyright   :  (c) Tim Docker 2006+-- License     :  BSD-style (see chart/COPYRIGHT)++module Graphics.Rendering.Chart.Gtk(+    renderableToWindow,+    createRenderableWindow,+    updateCanvas+    ) where++import qualified Graphics.UI.Gtk as G+import qualified Graphics.UI.Gtk.Gdk.Events as GE+import qualified Graphics.Rendering.Cairo as C+import Graphics.Rendering.Chart+import Graphics.Rendering.Chart.Renderable+import Graphics.Rendering.Chart.Types+import Data.List (isPrefixOf)+import Data.IORef+import Control.Monad(when)+import System.IO.Unsafe(unsafePerformIO)++-- do action m for any keypress (except meta keys)+anyKey :: (Monad m) => m a -> GE.Event -> m Bool+anyKey m (GE.Key {GE.eventKeyName=key})+    | any (`isPrefixOf` key) ignores = return True+    | otherwise                      = m >> return True+  where ignores = ["Shift","Control","Alt",+                   "Super","Meta","Hyper"]++-- Yuck. But we really want the convenience function+-- renderableToWindow as to be callable without requiring+-- initGUI to be called first. But newer versions of+-- gtk insist that initGUI is only called once+guiInitVar :: IORef Bool+{-# NOINLINE guiInitVar #-}+guiInitVar = unsafePerformIO (newIORef False)++initGuiOnce :: IO ()+initGuiOnce = do+    v <- readIORef guiInitVar+    when (not v) $ do+        -- G.initGUI+        G.unsafeInitGUIForThreadedRTS+        writeIORef guiInitVar True++-- | Display a renderable in a gtk window.+--+-- Note that this is a convenience function that initialises GTK on+-- it's first call, but not subsequent calls. Hence it's +-- unlikely to be compatible with other code using gtk. In +-- that case use createRenderableWindow.+renderableToWindow :: Renderable a -> Int -> Int -> IO ()+renderableToWindow chart windowWidth windowHeight = do+    initGuiOnce+    window <- createRenderableWindow chart windowWidth windowHeight+    -- press any key to exit the loop+    G.onKeyPress window $ anyKey (G.widgetDestroy window)+    G.onDestroy window G.mainQuit+    G.widgetShowAll window+    G.mainGUI++-- | Create a new GTK window displaying a renderable.+createRenderableWindow :: Renderable a -> Int -> Int -> IO G.Window+createRenderableWindow chart windowWidth windowHeight = do+    window <- G.windowNew+    canvas <- G.drawingAreaNew+    G.widgetSetSizeRequest window windowWidth windowHeight+    G.onExpose canvas $ const (updateCanvas chart canvas)+    G.set window [G.containerChild G.:= canvas]+    return window+++updateCanvas :: Renderable a -> G.DrawingArea  -> IO Bool+updateCanvas chart canvas = do+    win <- G.widgetGetDrawWindow canvas+    (width, height) <- G.widgetGetSize canvas+    let sz = (fromIntegral width,fromIntegral height)+    G.renderWithDrawable win $ runCRender (render chart sz) bitmapEnv+    return True
+ Graphics/Rendering/Chart/Gtk/Simple.hs view
@@ -0,0 +1,32 @@+-----------------------------------------------------------------------------+-- |+-- Module      :  Graphics.Rendering.Chart.Gtk.Simple+-- Copyright   :  (c) David Roundy 2007, Tim Docker 2012+-- License     :  BSD-style (see chart/COPYRIGHT)+--+-- Additional gtk specific functions to support the "simple" chart+-- framework. See Graphics.Rendering.Chart.Simple for details.+-----------------------------------------------------------------------------++module Graphics.Rendering.Chart.Gtk.Simple(+   plotWindow+   ) where++import Graphics.Rendering.Chart+import Graphics.Rendering.Chart.Gtk+import Graphics.Rendering.Chart.Simple.Internal++-- | Display a plot on the screen.++plotWindow :: PlotWindowType a => a+plotWindow = plw []+class PlotWindowType t where+    plw     :: [UPlot] -> t+instance (PlotArg a, PlotWindowType r) => PlotWindowType (a -> r) where+    plw args = \ a -> plw (toUPlot a ++ args)+instance PlotWindowType (IO a) where+    plw args = do+        renderableToWindow (toRenderable $ uplot (reverse args)) 640 480+        return undefined++
+ LICENSE view
@@ -0,0 +1,31 @@+Copyright (c) 2006, Tim Docker++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are+met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * The names of contributors may not be used to endorse or promote+      products derived from this software without specific prior+      written permission. ++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,8 @@+#!/usr/bin/env runghc++module Main where++import Distribution.Simple++main :: IO ()+main = defaultMain