From d8008d355415a3ea3084bb1ac119923000f2630e Mon Sep 17 00:00:00 2001 From: Rick Hennigan Date: Fri, 15 Nov 2024 13:34:00 -0500 Subject: [PATCH] Add an indeterminate progress bar to top of chat --- Source/Chatbook/ChatModes/UI.wl | 87 ++++++++++++++++++++++++-------- Source/Chatbook/ChatState.wl | 10 +++- Source/Chatbook/CommonSymbols.wl | 1 + 3 files changed, 77 insertions(+), 21 deletions(-) diff --git a/Source/Chatbook/ChatModes/UI.wl b/Source/Chatbook/ChatModes/UI.wl index 13d906f5..bcd37ac8 100644 --- a/Source/Chatbook/ChatModes/UI.wl +++ b/Source/Chatbook/ChatModes/UI.wl @@ -1812,30 +1812,77 @@ $trashButtonLabel := $trashButtonLabel = chatbookIcon[ "WorkspaceHistoryTrashI (* ::Section::Closed:: *) (*Global Progress Bar*) -(* TODO: *) -Grid[ +(* ::**************************************************************************************************************:: *) +(* ::Subsection::Closed:: *) +(*withWorkspaceGlobalProgress*) +withWorkspaceGlobalProgress // beginDefinition; +withWorkspaceGlobalProgress // Attributes = { HoldRest }; + +withWorkspaceGlobalProgress[ nbo_NotebookObject, eval_ ] := Enclose[ + Catch @ Module[ { attached }, + + attached = ConfirmMatch[ + AttachCell[ + nbo, + Cell[ + BoxData @ ToBoxes @ $workspaceChatProgressBar, + "WorkspaceChatProgressBar", + FontSize -> 0.1, + Magnification -> AbsoluteCurrentValue[ nbo, Magnification ] + ], + { Center, Top }, + Offset[ { 0, 1 }, { 0, 0 } ], + { Center, Top }, + RemovalConditions -> { "EvaluatorQuit" } + ], + _CellObject, + "Attached" + ]; + + WithCleanup[ eval, NotebookDelete @ attached ] + ], + throwInternalFailure +]; + +withWorkspaceGlobalProgress // endDefinition; + + +$workspaceChatProgressBar = With[ { + background = None, + colorCenter = RGBColor[ 0.27451, 0.61961, 0.79608, 1.0 ], + colorEdges = RGBColor[ 0.27451, 0.61961, 0.79608, 0.0 ], + duration = 3, + leftOffset = -0.5, + rightOffset = 1.5, + thickness = Thickness[ 1 ] + }, + Graphics[ { - Graphics[ - { - RGBColor[ "#449EF7" ], - Dynamic @ Rectangle[ - ImageScaled @ { Max[ 0, Clock[ { -0.5, 1.0 }, 3 ] ], 0 }, - ImageScaled @ { Min[ 1, Clock[ { 0.0, 1.5 }, 3 ] ], 1 } + thickness, + Dynamic @ TemplateBox[ + { Clock[ { leftOffset, 1.0 }, duration ], Clock[ { 0.0, rightOffset }, duration ] }, + "WorkspaceChatProgressBar", + DisplayFunction -> Function[ + LineBox[ + { + { #1, 0 }, + { (#1 + #2) / 2, 0 }, + { #2, 0 } + }, + VertexColors -> { colorEdges, colorCenter, colorEdges } ] - }, - AspectRatio -> Full, - Background -> RGBColor[ "#D1D1D1" ], - ImageSize -> { Full, 2 }, - PlotRangePadding -> None + ] ] - } - }, - Alignment -> { Center, Center }, - Frame -> None, - ItemSize -> { Automatic, 0 }, - Spacings -> { { 0, { }, 0 }, { 0, { }, 0 } } -] + }, + AspectRatio -> Full, + Background -> background, + ImageMargins -> 0, + ImageSize -> { Full, 4 }, + PlotRange -> { { 0, 1 }, Automatic }, + PlotRangePadding -> None + ] +]; (* ::**************************************************************************************************************:: *) (* ::Section::Closed:: *) diff --git a/Source/Chatbook/ChatState.wl b/Source/Chatbook/ChatState.wl index 802a29c5..3c1bbb54 100644 --- a/Source/Chatbook/ChatState.wl +++ b/Source/Chatbook/ChatState.wl @@ -160,7 +160,15 @@ withEvaluationCell // endDefinition; (*withEvaluationNotebook*) withEvaluationNotebook // beginDefinition; withEvaluationNotebook // Attributes = { HoldRest }; -withEvaluationNotebook[ nbo_NotebookObject, eval_ ] := Block[ { $evaluationNotebook = nbo }, eval ]; + +withEvaluationNotebook[ nbo_NotebookObject, eval_ ] := + Block[ { $evaluationNotebook = nbo }, + If[ TrueQ @ CurrentChatSettings[ nbo, "WorkspaceChat" ], + withWorkspaceGlobalProgress[ nbo, eval ], + eval + ] + ]; + withEvaluationNotebook // endDefinition; (* ::**************************************************************************************************************:: *) diff --git a/Source/Chatbook/CommonSymbols.wl b/Source/Chatbook/CommonSymbols.wl index c1ae1411..2cb0fdb3 100644 --- a/Source/Chatbook/CommonSymbols.wl +++ b/Source/Chatbook/CommonSymbols.wl @@ -310,6 +310,7 @@ BeginPackage[ "Wolfram`Chatbook`Common`" ]; `withChatState; `withChatStateAndFEObjects; `withToolBox; +`withWorkspaceGlobalProgress; `wlTemplateBoxes; `writeInlineChatOutputCell; `writeReformattedCell;