Sign in to follow this  
Followers 0
nerdgerl

Personal Encyclopedia/Dictionary

2 posts in this topic

#1 ·  Posted (edited)

Okay, I made this some time ago and forgot how I did it honestly. Surely there's some borrowed code in there somewhere, but essentially the program lets you make and use your own Encyclopedia/Dictionary. It uses two text files: 1 text file stores the terms and the other stores their corresponding meanings. The line positions of the terms and meanings must match or the things that you look up won't make sense.

I built this because I wanted to use my Palm's Encyclopedia Britannica on my desktop. The data file was huge and I was worried that AutoIT would never sift though all of it. I was silly enough to try this with an ini file, but there's an apparent limit of entries that I wasn't aware of. So I converted the encyclopedia to text and separated the entries (terms) from their descriptions (meanings) and put them into two separate files. Someone else's code gave me the idea to try it this way and it worked! The large file size doesn't seem to bother AutoIt, as it's pretty damn fast -- the descriptions (meanings) file I use is 16.3MB.

So anyway, I'm not even about to upload the encyclopedia but I put some functions in there that will let you add your own stuff. Of course you could always try it with a tiny dictionary. Click SAVE to save changes to an entry (term) - click ADD to add one. The back/forward navigation functions are weak - but kind of interesting once you get some massive data in there. That is, interesting in the way that you get what you didn't really ask for.

CODE
;Sources:

#include <GUIConstants.au3>

#include <file.au3>

#include <Array.au3>

#include <GuiEdit.au3>

Dim $Pos = 0

$Form = GUICreate("My Encyclopedia", 462, 386, -1, -1)

GUICtrlCreateLabel("Find:", 6, 10, 27, 17)

GUICtrlSetFont(-1, 9, 800, "", "Arial")

$Input = GUICtrlCreateInput("", 34, 7, 336, 21)

GUICtrlSetFont(-1, 9, 800, "", "Arial")

$Search = GUICtrlCreateButton("Search", 380, 7, 75, 23, $BS_DEFPUSHBUTTON)

GUICtrlSetFont(-1, 9, 800, "", "Arial")

$Edit = GUICtrlCreateEdit("", 6, 36, 448, 325, $ES_AUTOVSCROLL + $WS_VSCROLL)

GUICtrlSetFont(-1, 12, 400, "", "Arial")

;MENUBAR

$filemenu = GUICtrlCreateMenu("&File")

$filesave = GUICtrlCreateMenuitem("&Save Entry", $filemenu)

$fileadd = GUICtrlCreateMenuitem("&Add Entry", $filemenu)

$fileexit = GUICtrlCreateMenuitem("&Exit", $filemenu)

$navmenu = GUICtrlCreateMenu("&Navigate")

$Back = GUICtrlCreateMenuitem("&Back", $navmenu)

$Forward = GUICtrlCreateMenuitem("&Foward", $navmenu)

GUISetState(@SW_SHOW)

;Readin terms ahead of time

If FileExists("meanings.txt") Then

;Do nothing

Else

FileWrite("meanings.txt","meaning")

EndIf

If FileExists("terms.txt") Then

;Do nothing

Else

FileWrite("terms.txt","term")

EndIf

Dim $aRecords

If Not _FileReadToArray("terms.txt", $aRecords) Then

MsgBox(4096, "Error", " Error reading log to Array error:" & @error)

Exit

EndIf

HotKeySet("^f", "GoForward")

HotKeySet("^b", "GoBack")

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE Or $msg = $fileexit

ExitLoop

Case $msg = $fileadd

ToolTip("Adding Entry...", @DesktopWidth / 2, (@DesktopHeight / 2) - 30, "", "", 2)

FileWriteLine("terms.txt", GUICtrlRead($Input) & " ")

FileWriteLine("meanings.txt", GUICtrlRead($Edit))

ToolTip("")

Case $msg = $filesave

ToolTip("Saving Entry...", @DesktopWidth / 2, (@DesktopHeight / 2) - 30, "", "", 2)

_ReplaceStringInFile("terms.txt", FileReadLine("terms.txt", $Pos), GUICtrlRead($Input) & " ")

_ReplaceStringInFile("meanings.txt", FileReadLine("meanings.txt", $Pos), GUICtrlRead($Edit))

ToolTip("")

Case $msg = $Search

$sType = ''

Local $aSel = _GUICtrlEditGetSel($Edit)

If $aSel = -1 Then Return SetError(1, 0, -1)

Local $sText = StringMid(GUICtrlRead($Edit), $aSel[1] + 1, ($aSel[2] - $aSel[1]))

If $sText = "" Then

ToolTip("Searching For Term...", @DesktopWidth / 2, (@DesktopHeight / 2) - 30, "", "", 2)

For $x = 1 To $aRecords[0]

$Pos = _ArraySearch($aRecords, GUICtrlRead($Input) & " ", 0, 0, 0, True)

If $Pos = -1 Then

GUICtrlSetData($Edit, "Not Found")

GUICtrlSetData($Input, "")

ExitLoop

Else

GUICtrlSetData($Input, FileReadLine("terms.txt", $Pos))

GUICtrlSetData($Edit, FileReadLine("meanings.txt", $Pos))

ExitLoop

EndIf

Next

ToolTip("")

Else

ToolTip("Searching For Term...", @DesktopWidth / 2, (@DesktopHeight / 2) - 30, "", "", 2)

For $x = 1 To $aRecords[0]

$Pos = _ArraySearch($aRecords, $sText & " ", 0, 0, 0, True)

If $Pos = -1 Then

GUICtrlSetData($Edit, "Not Found")

GUICtrlSetData($Input, "")

ExitLoop

Else

GUICtrlSetData($Input, FileReadLine("terms.txt", $Pos))

GUICtrlSetData($Edit, FileReadLine("meanings.txt", $Pos))

ExitLoop

EndIf

Next

ToolTip("")

EndIf

Case $msg = $Back

GoBack()

Case $msg = $Forward

GoForward()

EndSelect

WEnd

Func GoForward()

$Pos = $Pos + 1

GUICtrlSetData($Input, FileReadLine("terms.txt", $Pos))

GUICtrlSetData($Edit, FileReadLine("meanings.txt", $Pos))

EndFunc ;==>GoForward

Func GoBack()

$Pos = $Pos - 1

GUICtrlSetData($Input, FileReadLine("terms.txt", $Pos))

GUICtrlSetData($Edit, FileReadLine("meanings.txt", $Pos))

EndFunc ;==>GoBack

Oh I forgot. If you highlight a word in the bottom window - and then click the search button - the program will attempt to find it in the terms and meanings files. Gotta be careful with highlighting though. This particular function doesn't remove highlighted spaces or punctuation (yet).

Edited by nerdgerl

My AutoIT's:[topic="53958"]Personal Encyclopedia/Dictionary[/topic][topic="46311"]MS Access (Style) Database[/topic]"Some people are born on third base and go through life thinking they hit a triple."

Share this post


Link to post
Share on other sites



I tried a couple terms, seems to work pretty well. Thanks for sharing. Didn't see any bugs so far and I am using windows XP SP2. :)

Edit:Sorry Typo

Share this post


Link to post
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
Sign in to follow this  
Followers 0