Improve error handling
Checks the file extension before attempting to read the file. Also allow empty argument list.
This commit is contained in:
parent
9272ff32d4
commit
860e7af61d
13
Gtk.hs
13
Gtk.hs
@ -8,6 +8,7 @@ import Diagrams.Backend.Cairo.Internal
|
||||
import Graphics.UI.Gtk
|
||||
import Graphics.UI.Gtk.Windows.MessageDialog
|
||||
import System.Directory
|
||||
import Util
|
||||
|
||||
|
||||
-- |Handle the whole GTK gui.
|
||||
@ -126,12 +127,15 @@ showErrorDialog str = do
|
||||
|
||||
-- |Draws a Diagram which is built from a given file to
|
||||
-- the gtk DrawingArea.
|
||||
-- Prints an error dialog if no valid mesh file is found.
|
||||
drawDiag' :: (WidgetClass widget, RangeClass scale)
|
||||
=> FilePath
|
||||
-> widget
|
||||
-> scale
|
||||
-> IO ()
|
||||
drawDiag' fp da scale' = do
|
||||
drawDiag' fp da scale' =
|
||||
case cmpExt "obj" fp of
|
||||
True -> do
|
||||
mesh <- readFile fp
|
||||
dw <- widgetGetDrawWindow da
|
||||
adjustment <- rangeGetAdjustment scale'
|
||||
@ -140,10 +144,15 @@ drawDiag' fp da scale' = do
|
||||
(CairoOptions "" (Width 600) SVG False)
|
||||
(diagFromString (MkProp scaleVal) mesh)
|
||||
renderWithDrawable dw r
|
||||
False -> showErrorDialog "No valid Mesh file!"
|
||||
|
||||
|
||||
-- |Saves a Diagram which is built from a given file as an SVG.
|
||||
-- Prints an error dialog if no valid mesh file is found.
|
||||
saveDiag' :: FilePath -> IO ()
|
||||
saveDiag' fp = do
|
||||
saveDiag' fp =
|
||||
case cmpExt "obj" fp of
|
||||
True -> do
|
||||
mesh <- readFile fp
|
||||
renderCairo "out.svg" (Width 600) (diagFromString (MkProp 2) mesh)
|
||||
False -> showErrorDialog "No valid Mesh file!"
|
||||
|
Loading…
Reference in New Issue
Block a user