Jump to content

Word Cloud


picea892
 Share

Recommended Posts

Just a quick demonstration on how to make a wordcloud. This is a very simple approach using labels. I used the date stamp of the .doc in the recent files folder as an example. If you do not have any .doc in the recent files folder than you will need to tweak the script to work for you.

#include <Array.au3>
#Include <File.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
Global $path=@UserProfileDir&"\Recent"
Opt("GUIOnEventMode", 1)
Global $sFileExt = "doc"
Global $filelist=getfiles($sFileExt)
$gui=GUICreate("cloud",@desktopwidth,@desktopheight-132,0,0)
GUISetOnEvent($GUI_EVENT_CLOSE, "close")
$left=100
$down=100
If $filelist[0][0] > 0 Then
    redim $filelist[$filelist[0][0]][6]
Else
    MsgBox(0,"Warning","No files of type = "& $sFileExt & " Found in the recent files list please use another file type")
    Exit
EndIf
for $i = 1 to $filelist[0][0]-1
    $sized=_GetTextSize($filelist[$i][0], $filelist[$i][4], "Arial",0)
    if IsArray($sized) then
    $filelist[$i][5]=GUICtrlCreateLabel($filelist[$i][0],$left,$down,$sized[0],$sized[1])
    GUICtrlSetFont(-1,$filelist[$i][4])
    GUICtrlSetOnEvent(-1,"runner")
    if $left>=800 Then
        $down=$down+30
        $left=100
    Else
        $left=$left+$sized[0]
    EndIf
    EndIf
Next

GUISetState()

While 1
sleep(100)
WEnd

Func getfiles($ext="")

    $tfiles=_FileListToArray($path)
        dim $files[$tfiles[0]][5]
    _ArraySort($tfiles,0,1)
    $files[0][0]=0

for $i = 1 to $tfiles[0]-1
    if $ext="" or $ext=StringMid($tfiles[$i],StringLen($tfiles[$i])-6,3) then
        $files[0][0]=$files[0][0]+1
        if StringRight($tfiles[$i],3) = "lnk" then
            $files[$files[0][0]][0]=StringLeft($tfiles[$i],StringLen($tfiles[$i])-8)
        Else
            $files[$files[0][0]][0]=$tfiles[$i]
        EndIf
        $files[$files[0][0]][1]=FileGetTime($path&"\"&$tfiles[$i],2,1)
        $files[$files[0][0]][2]=FileGetSize($path&"\"&$tfiles[$i])
        $files[$files[0][0]][3]=$tfiles[$i]
    EndIf
Next
;_ArrayDisplay($files)
$sorted=$files
_ArraySort($sorted, 0, 1,$files[0][0],1)
$spread=$files[0][0]/4
for $i=1 to $sorted[0][0]
    for $j=1 to $files[0][0]
        if $sorted[$i][0]=$files[$j][0] then
            if $i<$spread then
                $files[$j][4]=8
            ElseIf $i<$spread*2 Then
                $files[$j][4]=12
            ElseIf $i<$spread*3 then
                $files[$j][4]=16
            ElseIf $i<$spread*4 then
                $files[$j][4]=20
            EndIf
            ExitLoop
        EndIf
    Next
Next
return $files
EndFunc

Func _GetTextSize($nText, $iFontSize = 8.5, $sFont = 'Microsoft Sans Serif', $iFontAttributes = 0)
    ;Author: Bugfix
    ;Modified: funkey
    If $nText = '' Then Return
    Local $hGUI = GUICreate("Textmeter by Bugfix")
    _GDIPlus_Startup()
    Local $hFormat = _GDIPlus_StringFormatCreate(0)
    Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
    Local $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize, $iFontAttributes, 3)
    Local $tLayout = _GDIPlus_RectFCreate(15, 171, 0, 0)
    Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $nText, $hFont, $tLayout, $hFormat)
    Local $iWidth = Ceiling(DllStructGetData($aInfo[0], "Width"))
    Local $iHeight = Ceiling(DllStructGetData($aInfo[0], "Height"))
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
    Local $aSize[2] = [$iWidth, $iHeight]
    Return $aSize
EndFunc ;==>_GetTextSize

func runner()
    for $i= 1 to $filelist[0][0]-1
        if @GUI_CtrlId =$filelist[$i][5] then ShellExecute($path&"\"&$filelist[$i][3])
    Next
EndFunc

func close()
    exit
EndFunc
Edited by picea892
Link to comment
Share on other sites

Hi Playlet. You must not have any .doc in your recently used folder. I added a checker (first post) for if there are no files of the type searched for so it won't error out anymore.

To make it work in your case. You can change the this line from

Global $filelist=getfiles("doc")

to this

Global $filelist=getfiles()

or any other extension you are looking for.

Edited by picea892
Link to comment
Share on other sites

Sounds great but I'm getting this error:

...\Desktop\word cloud original.au3 (13) : ==> Array variable subscript badly formatted.:
redim $filelist[$filelist[0][0]][6]
redim $filelist[^ ERROR

take note of 'If you do not have any .doc in the recent files folder than you will need to tweak the script to work for you.'

ive modified it to grab the error try changing the line

Global $sFileExt = "doc" ; finds .doc ext
to
Global $sFileExt = "txt" ; finds .txt ext

here's the modified version of the script that deals with not having any of the ext type

#include <Array.au3>
#Include <File.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
Global $path=@UserProfileDir&"\Recent"
Opt("GUIOnEventMode", 1)
Global $sFileExt = "doc"
Global $filelist=getfiles($sFileExt)
$gui=GUICreate("cloud",@desktopwidth,@desktopheight-132,0,0)
GUISetOnEvent($GUI_EVENT_CLOSE, "close")
$left=100
$down=100
If $filelist[0][0] > 0 Then
    redim $filelist[$filelist[0][0]][6]
Else
    MsgBox(0,"Warning","No files of type = "& $sFileExt & " Found in the recent files list please use another file type")
    Exit
EndIf
for $i = 1 to $filelist[0][0]-1
    $sized=_GetTextSize($filelist[$i][0], $filelist[$i][4], "Arial",0)
    if IsArray($sized) then
    $filelist[$i][5]=GUICtrlCreateLabel($filelist[$i][0],$left,$down,$sized[0],$sized[1])
    GUICtrlSetFont(-1,$filelist[$i][4])
    GUICtrlSetOnEvent(-1,"runner")
    if $left>=800 Then
        $down=$down+30
        $left=100
    Else
        $left=$left+$sized[0]
    EndIf
    EndIf
Next

GUISetState()

While 1
sleep(100)
WEnd

Func getfiles($ext="")

    $tfiles=_FileListToArray($path)
        dim $files[$tfiles[0]][5]
    _ArraySort($tfiles,0,1)
    $files[0][0]=0

for $i = 1 to $tfiles[0]-1
    if $ext="" or $ext=StringMid($tfiles[$i],StringLen($tfiles[$i])-6,3) then
        $files[0][0]=$files[0][0]+1
        if StringRight($tfiles[$i],3) = "lnk" then
            $files[$files[0][0]][0]=StringLeft($tfiles[$i],StringLen($tfiles[$i])-8)
        Else
            $files[$files[0][0]][0]=$tfiles[$i]
        EndIf
        $files[$files[0][0]][1]=FileGetTime($path&"\"&$tfiles[$i],2,1)
        $files[$files[0][0]][2]=FileGetSize($path&"\"&$tfiles[$i])
        $files[$files[0][0]][3]=$tfiles[$i]
    EndIf
Next
;_ArrayDisplay($files)
$sorted=$files
_ArraySort($sorted, 0, 1,$files[0][0],1)
$spread=$files[0][0]/4
for $i=1 to $sorted[0][0]
    for $j=1 to $files[0][0]
        if $sorted[$i][0]=$files[$j][0] then
            if $i<$spread then
                $files[$j][4]=8
            ElseIf $i<$spread*2 Then
                $files[$j][4]=12
            ElseIf $i<$spread*3 then
                $files[$j][4]=16
            ElseIf $i<$spread*4 then
                $files[$j][4]=20
            EndIf
            ExitLoop
        EndIf
    Next
Next
return $files
EndFunc

Func _GetTextSize($nText, $iFontSize = 8.5, $sFont = 'Microsoft Sans Serif', $iFontAttributes = 0)
    ;Author: Bugfix
    ;Modified: funkey
    If $nText = '' Then Return
    Local $hGUI = GUICreate("Textmeter by Bugfix")
    _GDIPlus_Startup()
    Local $hFormat = _GDIPlus_StringFormatCreate(0)
    Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
    Local $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize, $iFontAttributes, 3)
    Local $tLayout = _GDIPlus_RectFCreate(15, 171, 0, 0)
    Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $nText, $hFont, $tLayout, $hFormat)
    Local $iWidth = Ceiling(DllStructGetData($aInfo[0], "Width"))
    Local $iHeight = Ceiling(DllStructGetData($aInfo[0], "Height"))
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
    Local $aSize[2] = [$iWidth, $iHeight]
    Return $aSize
EndFunc ;==>_GetTextSize

func runner()
    for $i= 1 to $filelist[0][0]-1
        if @GUI_CtrlId =$filelist[$i][5] then ShellExecute($path&"\"&$filelist[$i][3])
    Next
EndFunc

func close()
    exit
EndFunc
GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
Link to comment
Share on other sites

Hi Playlet. I hope the below is the problem. In the recent files directory all the files are links. So.

document.doc.lnk

Textfile.txt.lnk

The function searches for 7-4 from the right in order to identify type. The files you copied over probably would not be in that structure. Anyways I hope this is the problem......

Maybe try searching for au3. I'm sure a couple of scripts will show up

Edited by picea892
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...