如何在 Threepenny-gui 0.6 中重新加载更新的文件?
How to reload updated file in Threepenny-gui 0.6?
Threepenny-gui 变更日志 (https://hackage.haskell.org/package/threepenny-gui-0.6.0.1/changelog) 内容如下:"The functions loadFile and loadDirectory have been removed, as I felt that the jsStatic option is sufficient for most use cases."
我的问题是:我们如何在没有 loadFile 的情况下重新加载在执行期间更新的图像?
对于 Threepenny-gui 0.5,我使用了以下代码:
redraw :: UI.Element -> IORef CompTree -> (Maybe Vertex) -> UI ()
redraw img treeRef mcv
= do tree <- UI.liftIO $ readIORef treeRef
UI.liftIO $ writeFile ".Hoed/debugTree.dot" (shw $ summarize tree mcv)
UI.liftIO $ system $ "dot -Tpng -Gsize=9,5 -Gdpi=100 .Hoed/debugTree.dot "
++ "> .Hoed/wwwroot/debugTree.png"
url <- UI.loadFile "image/png" ".Hoed/wwwroot/debugTree.png"
UI.element img # UI.set UI.src url
当我使用 Threepenny-gui 0.6 将 jsStatic
设置为 Just "./.Hoed/wwwroot"
时,以下代码(显然)导致我的 GUI 仅显示应用程序启动时已经存在的初始图像:
redraw :: UI.Element -> IORef CompTree -> (Maybe Vertex) -> UI ()
redraw img treeRef mcv
= do tree <- UI.liftIO $ readIORef treeRef
UI.liftIO $ writeFile ".Hoed/debugTree.dot" (shw $ summarize tree mcv)
UI.liftIO $ system $ "dot -Tpng -Gsize=9,5 -Gdpi=100 .Hoed/debugTree.dot "
++ "> .Hoed/wwwroot/debugTree.png"
UI.element img # UI.set UI.src "static/debugTree.png"
return ()
Threepenny-gui 0.5 的完整代码在这里:https://github.com/MaartenFaddegon/Hoed/blob/master/Debug/Hoed/DemoGUI.hs
(此处为作者。)显然,我在删除这些功能时没有考虑您的用例。 :-) 如果你愿意,我可以把它们加回去,可以在 github?
上提出问题
JavaScript 端有多种方法可以在某个 URL 重新加载文件。例如,参见问题 "Refresh image with a new one at the same url".
Threepenny-gui 变更日志 (https://hackage.haskell.org/package/threepenny-gui-0.6.0.1/changelog) 内容如下:"The functions loadFile and loadDirectory have been removed, as I felt that the jsStatic option is sufficient for most use cases."
我的问题是:我们如何在没有 loadFile 的情况下重新加载在执行期间更新的图像?
对于 Threepenny-gui 0.5,我使用了以下代码:
redraw :: UI.Element -> IORef CompTree -> (Maybe Vertex) -> UI ()
redraw img treeRef mcv
= do tree <- UI.liftIO $ readIORef treeRef
UI.liftIO $ writeFile ".Hoed/debugTree.dot" (shw $ summarize tree mcv)
UI.liftIO $ system $ "dot -Tpng -Gsize=9,5 -Gdpi=100 .Hoed/debugTree.dot "
++ "> .Hoed/wwwroot/debugTree.png"
url <- UI.loadFile "image/png" ".Hoed/wwwroot/debugTree.png"
UI.element img # UI.set UI.src url
当我使用 Threepenny-gui 0.6 将 jsStatic
设置为 Just "./.Hoed/wwwroot"
时,以下代码(显然)导致我的 GUI 仅显示应用程序启动时已经存在的初始图像:
redraw :: UI.Element -> IORef CompTree -> (Maybe Vertex) -> UI ()
redraw img treeRef mcv
= do tree <- UI.liftIO $ readIORef treeRef
UI.liftIO $ writeFile ".Hoed/debugTree.dot" (shw $ summarize tree mcv)
UI.liftIO $ system $ "dot -Tpng -Gsize=9,5 -Gdpi=100 .Hoed/debugTree.dot "
++ "> .Hoed/wwwroot/debugTree.png"
UI.element img # UI.set UI.src "static/debugTree.png"
return ()
Threepenny-gui 0.5 的完整代码在这里:https://github.com/MaartenFaddegon/Hoed/blob/master/Debug/Hoed/DemoGUI.hs
(此处为作者。)显然,我在删除这些功能时没有考虑您的用例。 :-) 如果你愿意,我可以把它们加回去,可以在 github?
上提出问题JavaScript 端有多种方法可以在某个 URL 重新加载文件。例如,参见问题 "Refresh image with a new one at the same url".