hsudoku 0.1.0.1 → 0.1.1.0
raw patch · 4 files changed
+25/−18 lines, 4 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- UserInterface: buildSudokuUI :: Text -> IO SudokuUI
+ UserInterface: buildSudokuUI :: IO SudokuUI
Files
- hsudoku.cabal +9/−4
- src/Hsudoku.hs +1/−1
- src/UserInterface.hs +14/−12
- test/UserInterfaceSpec.hs +1/−1
hsudoku.cabal view
@@ -1,5 +1,5 @@ name: hsudoku-version: 0.1.0.1+version: 0.1.1.0 synopsis: Sudoku game with a GTK3 interface description: This package realizes a graphical GTK3 sudoku game. Moreover it provides modules for loading and solving sudoku grids.@@ -15,10 +15,14 @@ cabal-version: >=1.10 Tested-with: GHC == 8.0.2 -extra-source-files: gui/hsudoku.ui- gui/icon.png,- gui/theme.css+extra-source-files: gui/hsudoku.ui+ , gui/icon.png+ , gui/theme.css +data-files: gui/hsudoku.ui+ , gui/icon.png+ , gui/theme.css+ source-repository head type: git location: git@github.com:marcelmoosbrugger/hsudoku.git @@ -32,6 +36,7 @@ , Sudoku.Solver , Sudoku.Loader + other-modules: Paths_hsudoku build-depends: base >=4.9 && <4.10 , text >=1.2 && <1.3
src/Hsudoku.hs view
@@ -20,7 +20,7 @@ main = do Gtk.init Nothing - ui <- buildSudokuUI "gui/hsudoku.ui"+ ui <- buildSudokuUI cellsBindHandlers (cells ui) (popover ui) numbersBindHandlers (numberButtons ui) (popover ui) on (inputClear ui) #clicked $ writePopoverRelativeCell (popover ui) $ blankval
src/UserInterface.hs view
@@ -32,17 +32,17 @@ , showMenu ) where +import Control.Concurrent (forkIO, threadDelay) import Control.Exception import Control.Monad.IO.Class import Data.GI.Base import qualified Data.Text as T import Data.Typeable import GI.Gtk-import Sudoku.Type+import Paths_hsudoku import Sudoku.Loader import Sudoku.Solver-import Control.Concurrent (forkIO, threadDelay)-+import Sudoku.Type -- | Thrown when 'castB' fails get an object. data BuilderCastException = UnknownIdException String deriving (Show, Typeable)@@ -57,7 +57,7 @@ type GameMenu = Widget -- | A type containing all handles of widgets necessary for the user interface.-data SudokuUI = SudokuUI { window :: Window +data SudokuUI = SudokuUI { window :: Window , menu :: GameMenu , gameButtons :: [Button] , cells :: Cells@@ -72,9 +72,10 @@ -- | Builds the sudoku-ui from a gui-file for which the path is given.-buildSudokuUI :: T.Text -> IO SudokuUI-buildSudokuUI guiFilePath = do- (window, builder) <- buildMainWindow "mainWindow" guiFilePath+buildSudokuUI :: IO SudokuUI+buildSudokuUI = do+ uiFile <- T.pack <$> getDataFileName "gui/hsudoku.ui"+ (window, builder) <- buildMainWindow "mainWindow" uiFile menu <- builderGetTyped builder "menu" Widget gameButtons <- builderGetsTyped builder gameButtonNames Button cells <- builderGetsTyped builder cellNames Button@@ -85,7 +86,7 @@ solveButton <- builderGetTyped builder "solveButton" Button checkButton <- builderGetTyped builder "checkButton" Button menuButton <- builderGetTyped builder "menuButton" Button- pure $ SudokuUI window menu gameButtons cells popover + pure $ SudokuUI window menu gameButtons cells popover numberButtons inputClear inputSolve solveButton checkButton menuButton @@ -99,7 +100,7 @@ -- | The ids of the buttons which start a new game gameButtonNames :: [T.Text]-gameButtonNames = map (T.pack . (++) "game" . show) [Easy ..] +gameButtonNames = map (T.pack . (++) "game" . show) [Easy ..] -- | Takes a builder and returns the object with a given name -- typed as a given gtype.@@ -122,7 +123,8 @@ builder <- builderNewFromFile path window <- builderGetTyped builder name Window on window #destroy mainQuit- windowAddCss window "gui/theme.css"+ cssFile <- T.pack <$> getDataFileName "gui/theme.css"+ windowAddCss window cssFile pure (window, builder) -- | Adds to a given window a css file for which the path is given.@@ -175,7 +177,7 @@ checkCell :: Cell -> IO Bool checkCell cell = do solution <- T.head <$> (toWidget cell >>= #getName)- actual <- T.head <$> #getLabel cell + actual <- T.head <$> #getLabel cell let isCorrect = actual == solution style <- #getStyleContext cell if not isCorrect@@ -258,4 +260,4 @@ #hide popover popover `set` [#relativeTo := menu] #show menu- +
test/UserInterfaceSpec.hs view
@@ -14,7 +14,7 @@ describe "buildSudokuUI" $ do it "should actually return a UI data-structure and not fail" $ do _ <- Gtk.init Nothing- ui <- buildSudokuUI "gui/hsudoku.ui"+ ui <- buildSudokuUI (length $ cells ui) `shouldSatisfy` (> 0) (length $ gameButtons ui) `shouldSatisfy` (> 0) (length $ numberButtons ui) `shouldSatisfy` (> 0)