File tree Expand file tree Collapse file tree 5 files changed +51
-12
lines changed
Expand file tree Collapse file tree 5 files changed +51
-12
lines changed Original file line number Diff line number Diff line change 1+ {-# LANGUAGE TemplateHaskell #-}
2+ module GUI.DataFiles
3+ ( ui
4+ , loadLogo
5+ ) where
6+ import System.IO
7+
8+ import Data.FileEmbed
9+ import Graphics.UI.Gtk (Pixbuf , pixbufNewFromFile )
10+ import Language.Haskell.TH
11+ import System.IO.Temp
12+ import qualified Data.ByteString as B
13+ import qualified Data.Text.Encoding as TE
14+
15+ uiFile :: FilePath
16+ uiFile = " threadscope.ui"
17+
18+ logoFile :: FilePath
19+ logoFile = " threadscope.png"
20+
21+ -- | Textual representaion of the UI file
22+ ui :: Q Exp
23+ ui = [| TE. decodeUtf8 $ (makeRelativeToProject uiFile >>= embedFile) | ]
24+
25+ renderLogo :: B. ByteString -> IO Pixbuf
26+ renderLogo bytes =
27+ withSystemTempFile logoFile $ \ path h -> do
28+ B. hPut h bytes
29+ hClose h
30+ pixbufNewFromFile path
31+
32+ -- | Load the logo file as a 'Pixbuf'.
33+ loadLogo :: Q Exp
34+ loadLogo = [| renderLogo $ (makeRelativeToProject logoFile >>= embedFile) | ]
Original file line number Diff line number Diff line change 1+ {-# LANGUAGE TemplateHaskell #-}
12module GUI.Dialogs where
23
3- import Paths_threadscope (getDataFileName , version )
4+ import GUI.DataFiles (loadLogo )
5+ import Paths_threadscope (version )
46
57import Graphics.UI.Gtk
68
@@ -13,8 +15,7 @@ import System.FilePath
1315aboutDialog :: WindowClass window => window -> IO ()
1416aboutDialog parent
1517 = do dialog <- aboutDialogNew
16- logoPath <- getDataFileName " threadscope.png"
17- logo <- pixbufNewFromFile logoPath
18+ logo <- $ loadLogo
1819 set dialog [
1920 aboutDialogName := " ThreadScope" ,
2021 aboutDialogVersion := showVersion version,
Original file line number Diff line number Diff line change 11{-# LANGUAGE CPP #-}
2+ {-# LANGUAGE TemplateHaskell #-}
23module GUI.Main (runGUI ) where
34
45-- Imports for GTK
@@ -16,13 +17,12 @@ import Control.Exception
1617import Data.Array
1718import Data.Maybe
1819
19- import Paths_threadscope
20-
2120-- Imports for ThreadScope
2221import qualified GUI.App as App
2322import qualified GUI.MainWindow as MainWindow
2423import GUI.Types
2524import Events.HECs hiding (Event )
25+ import GUI.DataFiles (ui )
2626import GUI.Dialogs
2727import Events.ReadEvents
2828import GUI.EventsView
@@ -117,7 +117,7 @@ constructUI :: IO UIEnv
117117constructUI = failOnGError $ do
118118
119119 builder <- Gtk. builderNew
120- Gtk. builderAddFromFile builder =<< getDataFileName " threadscope.ui "
120+ Gtk. builderAddFromString builder $ ui
121121
122122 eventQueue <- Chan. newChan
123123 let post = postEvent eventQueue
Original file line number Diff line number Diff line change 1+ {-# LANGUAGE TemplateHaskell #-}
12module GUI.MainWindow (
23 MainWindow ,
34 mainWindowNew ,
@@ -10,12 +11,10 @@ module GUI.MainWindow (
1011
1112 ) where
1213
13- import Paths_threadscope
14-
15- -- Imports for GTK
1614import Graphics.UI.Gtk as Gtk
1715import qualified System.Glib.GObject as Glib
1816
17+ import GUI.DataFiles (loadLogo )
1918
2019-------------------------------------------------------------------------------
2120
@@ -146,8 +145,8 @@ mainWindowNew builder actions = do
146145
147146 ------------------------------------------------------------------------
148147
149- logoPath <- getDataFileName " threadscope.png "
150- windowSetIconFromFile mainWindow logoPath
148+ logo <- $ loadLogo
149+ set mainWindow [ windowIcon := Just logo ]
151150
152151 ------------------------------------------------------------------------
153152 -- Status bar functionality
Original file line number Diff line number Diff line change @@ -58,7 +58,11 @@ Executable threadscope
5858 containers >= 0.2 && < 0.6 ,
5959 deepseq >= 1.1 ,
6060 text < 1.3 ,
61- time >= 1.1 && < 1.9
61+ time >= 1.1 && < 1.9 ,
62+ bytestring < 0.11 ,
63+ file-embed < 0.1 ,
64+ template-haskell < 2.13 ,
65+ temporary >= 1.1 && < 1.3
6266 if os(osx)
6367 build-depends : gtk-mac-integration
6468
@@ -74,6 +78,7 @@ Executable threadscope
7478 GUI.Main,
7579 GUI.MainWindow,
7680 GUI.EventsView,
81+ GUI.DataFiles,
7782 GUI.Dialogs,
7883 GUI.SaveAs,
7984 GUI.Timeline,
You can’t perform that action at this time.
0 commit comments