SearchBrowser
SearchBrowser
SearchBrowser[Optional[Verbatim[Dynamic][_,f_,___]|None,None]]:=DynamicModule[{currentQ="Qwant",searchType,searchResults,$searchTypes={"Web","Image","News","SocialMedia","Music","Video"},resultsPerPage=10,resultsPage=1,$so,performSearch},Framed[Pane[#,ImageSize({#*GoldenRatio,#}&@335),AppearanceElements{"ResizeArea"}],FrameMarginsNone,FrameStyleGray]&@Column[{Panel[Grid@List@{Spacer[2],Row[{Button[Dynamic[searchType],Appearance{"Default"Lookup[FrontEndResource["FEExpressions","TabAbuttingLeftRightNinePatchAppearance"],"Hover"]},EnabledFalse,FrameMargins{{10,10},{0,0}},ImageSize{Automatic,26},ImageMargins0],PopupMenu[Dynamic[searchType],$searchTypes,None,Button["",AppearanceFrontEndResource["NotebookTemplatingExpressions","ButtonDropdownRightAppearance"]],ImageSize{Automatic,24},ImageMargins0]}],EventHandler[InputField[Dynamic[currentQ],String],{"ReturnKeyDown":>CompoundExpression[resultsPage=1;performSearch[]],Method"Queued"}],Button["",resultsPage=1;performSearch[],AppearanceFunction[{"Default"->#,"Hover"Image[Darker[#,.5],"Byte","ColorSpace"->"RGB",Interleaving->True],"Pressed"Image[Lighter[#,.5],"Byte","ColorSpace"->"RGB",Interleaving->True]}]@ToExpression@FrontEndResource["FEBitmaps","SearchIcon"],ImageSizeAutomatic,Method"Queued"],Row[{Button["«",resultsPage--;performSearch[],AppearanceFrontEndResource["FEExpressions","TabAbuttingRightNinePatchAppearance"],EnabledDynamic[resultsPage>1],FrameMargins{{3,2},{2,2}},ImageSize{Automatic,17},Method"Queued"],InputField[Dynamic[resultsPage,Function[Set[resultsPage,Max@{IntegerPart[#],1}];performSearch[]],SynchronousUpdatingFalse],Number,FieldSize3,ImageSize{Automatic,15}],Button["»",resultsPage++;performSearch[],AppearanceFrontEndResource["FEExpressions","TabAbuttingLeftNinePatchAppearance"],FrameMargins{{3,2},{2,2}},ImageSize{Automatic,17},Method"Queued"]}],InputField[Dynamic[resultsPerPage,Function[Set[resultsPerPage,Min@{Max@{IntegerPart[#],1},10}];performSearch[]],SynchronousUpdatingFalse],Number,FieldSize3,ImageSize{Automatic,15}]},ImageSize{Full,Automatic},AppearanceLookup[FrontEndResource["FEExpressions","MoreLeftSetterNinePatchAppearance"],"Hover"],Alignment{Left,Center}],Pane[Dynamic[If[Length@{f}>1&&ListQ@f,Map[#[searchResults]&,f],f[searchResults]];Replace[searchResults,Except[_Dataset]""]],ImageSizeFull,ScrollbarsAutomatic,AppearanceElementsNone]}],Initialization(If[Length@PacletFind["ServiceConnection_Qwant"]===0,PacletInstall["ServiceConnection_Qwant","Site""https://www.wolframcloud.com/objects/b3m2a1.paclets/PacletServer"],If[!TrueQ@QwantWebBrowser`Private`$qwantUpdated,PacletUpdate["ServiceConnection_Qwant","Site""https://www.wolframcloud.com/objects/b3m2a1.paclets/PacletServer"];QwantWebBrowser`Private`$qwantUpdated=True;QwantWebBrowser`Private`$qwantUpdated//Protect]];performSearch=Function[If[!MatchQ[$so,ServiceObject],$so=ServiceConnect["Qwant"]];Set[searchResults,$so[searchType<>"Search","q"currentQ,"count"ToString@resultsPerPage,"offset"ToString@((resultsPage-1)*resultsPerPage)]]])];SearchBrowser[Verbatim[Dynamic][v_,___?OptionQ]]:=SearchBrowser[Dynamic[v,Set[v,#]&]]