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
33
Gtk.hs
33
Gtk.hs
@ -8,6 +8,7 @@ import Diagrams.Backend.Cairo.Internal
|
|||||||
import Graphics.UI.Gtk
|
import Graphics.UI.Gtk
|
||||||
import Graphics.UI.Gtk.Windows.MessageDialog
|
import Graphics.UI.Gtk.Windows.MessageDialog
|
||||||
import System.Directory
|
import System.Directory
|
||||||
|
import Util
|
||||||
|
|
||||||
|
|
||||||
-- |Handle the whole GTK gui.
|
-- |Handle the whole GTK gui.
|
||||||
@ -126,24 +127,32 @@ showErrorDialog str = do
|
|||||||
|
|
||||||
-- |Draws a Diagram which is built from a given file to
|
-- |Draws a Diagram which is built from a given file to
|
||||||
-- the gtk DrawingArea.
|
-- the gtk DrawingArea.
|
||||||
|
-- Prints an error dialog if no valid mesh file is found.
|
||||||
drawDiag' :: (WidgetClass widget, RangeClass scale)
|
drawDiag' :: (WidgetClass widget, RangeClass scale)
|
||||||
=> FilePath
|
=> FilePath
|
||||||
-> widget
|
-> widget
|
||||||
-> scale
|
-> scale
|
||||||
-> IO ()
|
-> IO ()
|
||||||
drawDiag' fp da scale' = do
|
drawDiag' fp da scale' =
|
||||||
mesh <- readFile fp
|
case cmpExt "obj" fp of
|
||||||
dw <- widgetGetDrawWindow da
|
True -> do
|
||||||
adjustment <- rangeGetAdjustment scale'
|
mesh <- readFile fp
|
||||||
scaleVal <- adjustmentGetValue adjustment
|
dw <- widgetGetDrawWindow da
|
||||||
let (_, r) = renderDia Cairo
|
adjustment <- rangeGetAdjustment scale'
|
||||||
(CairoOptions "" (Width 600) SVG False)
|
scaleVal <- adjustmentGetValue adjustment
|
||||||
(diagFromString (MkProp scaleVal) mesh)
|
let (_, r) = renderDia Cairo
|
||||||
renderWithDrawable dw r
|
(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.
|
-- |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' :: FilePath -> IO ()
|
||||||
saveDiag' fp = do
|
saveDiag' fp =
|
||||||
mesh <- readFile fp
|
case cmpExt "obj" fp of
|
||||||
renderCairo "out.svg" (Width 600) (diagFromString (MkProp 2) mesh)
|
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