Jump to content



Photo

Xamp Spell Check


  • Please log in to reply
1 reply to this topic

#1 jfcby

jfcby

    Geek Problem Solver In The Making...

  • Active Members
  • PipPipPipPipPipPip
  • 327 posts

Posted 11 January 2010 - 08:04 PM

Hi,

I was looking for a spell checker for a program that I'm scripting and did not find a suitable one for my purposes. Below is the "Xamp Spell Check" script that I put together with the help from AutoIt3 forum script examples, members, and the help file. As I add other features to the code I'll update it here.

Suggestions to improve the script will be appreciated.

Need to figure out how to:
1. Check mispelled word once by going to next word.
2. Ignore or skip word if no change is desired.
3. Integrate ASpell

Original Post: 1/11/2010

Plain Text         
#include <GuiConstantsEx.au3> #include <EditConstants.au3> #include <GuiEdit.au3> #include <WindowsConstants.au3> #include <array.au3> #include <GuiListBox.au3> #include <StaticConstants.au3> #include <IE.au3> #cs###########################################################################################################     Title:  XampSpellCheck Version 1.0.1     By:     James F Cooper (AKA: Frankie Cooper & JFCBY)     Date:   January 11, 2010     Update: January 13, 2009     Description:         This spell check was designed for learning purposes and to add into another project         I'm working on. I posted it for future reference and maybe for others to learn from.                 I got help from AutoIT3 Forum members, example scripts, and Help File to put this script together.         Need to figure out how to do:         1. Check mispelled word once by going to next word.         2. Ignore or skip word if no change is desired. #ce############################################################################################################ Global $msg, $i Global $iC = 0 Global $cStatus[5], $cColor[5], $cLabel3 $hWidth = 395 $hHeight = 425 $hLeft = $hWidth / 2 $hTop = $hHeight / 2 $hGUI = GUICreate("Xamp Spell Check", $hWidth, $hHeight, (@DesktopWidth / 2) - $hLeft, (@DesktopHeight / 2) - $hTop)     $Label1 = GUICtrlCreateLabel("Editor", 5, 1, 100, 15)     GUICtrlSetFont(-1, 9, 600)          $Edit1 = GUICtrlCreateEdit("Coutn and splel checker test time to check and procses.", 5, 25, 385, 350, _         BitOR($ES_AUTOVSCROLL, $ES_MULTILINE, $ES_NOHIDESEL, $ES_WANTRETURN))         $Button1 = GUICtrlCreateButton("Spell Check", 325, 380)     GUISetState(@SW_SHOW) ;Create ChildGUI & Center in Main GUI:  parent width/2 minus the child's width/2 $cWidth = 250 $cHeight = 250              $cLeft = $hWidth / 2 - $cWidth / 2 $cTop = $hHeight /2 - $cHeight / 2 $cGUI = GUICreate("Spell Check", $cWidth, $cHeight, $cLeft, $cTop, Default, BitOR($WS_EX_MDICHILD, $WS_EX_TOOLWINDOW), $hGUI)     $cLabel1 = GUICtrlCreateLabel("Original Text:", 5, 5, 75, 20)     $cLabel2 = GUICtrlCreateLabel("Replace With:", 5, 30, 75, 20)       $cInput1 = GUICtrlCreateInput("", 100, 5, 145, 20)     GUICtrlSetState(-1, $GUI_DISABLE)   ; the label is in disable state     $cInput2 = GUICtrlCreateInput("", 100, 30, 145, 20)     $cListBox1 = GUICtrlCreateList("", 5, 55, 155, 200)     $cButton1 = GUICtrlCreateButton("Replace", 170, 65, 75, 20)     $cButton2 = GUICtrlCreateButton("Ignore", 170, 85, 75, 20)      $cButton3 = GUICtrlCreateButton("Close", 170, 225, 75, 20)     GUICtrlCreateGroup("Status", 170, 110, 75, 50)              $cStatus[1] = "Complete"         $cStatus[2] = "Input"         $cStatus[3] = "Working"         $cColor[1] = "0x009A31"     ; Green         $cColor[2] = "0xFFFF00"     ; Yellow         $cColor[3] = "0xAD0000"     ; Red         $cLabel3 = GUICtrlCreateLabel("", 172, 130, 70, 15, $SS_CENTER)             GUICtrlSetBkColor(-1, $cColor[3])           GUICtrlCreateGroup("", -99, -99, 1, 1)  ;close group     GUISetState(@SW_HIDE, $cGUI) $nOffset = 1 While 1     $Msg = GUIGetMsg()     Select         Case $Msg = $GUI_EVENT_CLOSE             Exit                 Case $Msg = $Button1                         ;Show Child GUI                 _cStatus1()             GUISetState(@SW_SHOW, $cGUI)             _SpellCheck()             While 1                 $aMsg = GUIGetMsg(1)                 If $aMsg[1] = $cGUI Then ; Check we are getting messages from the child                     Switch $aMsg[0]                         Case $GUI_EVENT_CLOSE, $cButton3                             GUISetState(@SW_HIDE, $cGUI)    ;GUIDelete($cGUI)                             $iC = 0                             _ResetFields()                             ExitLoop                         Case $cButton1      ; Replace                                                       $text = StringReplace(GUICtrlRead($Edit1), GUICtrlRead($cInput1), GUICtrlRead($cInput2))                                                        GUICtrlSetData($Edit1, $text)                                                       _ResetFields()                             _cStatus1()                             _SpellCheck()                                                   Case $cButton2      ; Ignore ;~                          MsgBox(0, "Note:", "Haven't figured out how to setup yet!")                             _ResetFields()                                                      _cStatus1()                             _SpellCheck()                                                       Case $cListBox1                             GUICtrlSetData($cInput2, _GUICtrlListBox_GetText($cListBox1, _GUICtrlListBox_GetCurSel($cListBox1)))                                                EndSwitch                 EndIf             WEnd     EndSelect WEnd Func _SpellCheck()     ;     ;Select individual word.     $array = StringRegExp(GUICtrlRead($Edit1), "[\s\.:;,]*([a-zA-Z0-9-_]+)[\s\.:;,]*", 3, $nOffset)         If @error = 0 Then         $nOffset = @extended     Else         ;ExitLoop     EndIf         ; Select word in Edit1     Local $sText = GUICtrlRead($Edit1)     Local $iTextLen = StringLen($sText)     Local $from = 1 ; we search from here in edit text     Local $ist      ; where we found the start of the word     Local $iL           If $iC >= 0 And $iC <= UBound($array) - 1 Then              $oIE = _IECreate("<a href='http://dictionary.reference.com/search?q=' class='bbc_url' title='External link' rel='nofollow external'>http://dictionary.reference.com/search?q="</a> & $array[$iC], 0, 0)         $oTable = _IETableGetCollection($oIE, 0)         ConsoleWrite(@CRLF & "Word Spell = " & $array[$iC] & @CRLF)         $oDiv = _IEGetObjByClass ($oIE, "dym")         $iePropertyGet = _IEPropertyGet($oDiv, "innertext")         $sTrimRight = StringRight($iePropertyGet, StringLen($iePropertyGet) - 13)         $result = StringLeft($sTrimRight, StringLen($sTrimRight) - 1)               If IsObj($oTable) Then                        $ar = _IETableWriteToArray($oTable, True)                       If $ar[0][0] = "Dictionary:" Then                               $ist = StringInStr($sText,$array[$iC],0,1,$from,$iTextLen) - 1                 $from = $ist + StringLen($array[$iC])                 _GUICtrlEdit_SetSel($Edit1,$ist,$ist+StringLen($array[$iC]))                                        ; Insert Misspelled Word into $cInput1                 GuiCtrlSetData($cInput1, $array[$iC])                 ; Insert Misspelled Word into $cInput2                 GuiCtrlSetData($cInput2, $result)                 ; Load Word Options into $cListBox1                             GuiCtrlSetData($cListBox1, "")                 For $i = 0 To UBound($ar) -1                   $ar2 = $ar[$i][0]                                 GUICtrlSetData($cListBox1, $ar2)               Next               _cStatus2()             Else                                _IEQuit($oIE)                 $iC = $iC + 1                 _SpellCheck()             EndIf         EndIf               _IEQuit($oIE)         $iC = $iC + 1           Else                _ResetFields()         _cStatus3()     EndIf         EndFunc     ;==>_SpellCheck Func _ResetFields()     ;     GUICtrlSetData($cInput1, "")     GUICtrlSetData($cInput2, "")     GUICtrlSetData($cListBox1, "") EndFunc     ;==>_ResetFields Func _cStatus1()     ;     GUICtrlSetData($cLabel3, $cStatus[3])     GUICtrlSetBkColor($cLabel3, $cColor[3]) EndFunc     ;==>_cStatus Func _cStatus2()     ;     GUICtrlSetData($cLabel3, $cStatus[2])     GUICtrlSetBkColor($cLabel3, $cColor[2]) EndFunc     ;==>_cStatus Func _cStatus3()     ;     GUICtrlSetData($cLabel3, $cStatus[1])     GUICtrlSetBkColor($cLabel3, $cColor[1]) EndFunc     ;==>_cStatus



Learning to write scripts,
jfcby

########################################################################################
Updates

1/13/2009
1. Figured out and implemented checked mispelled word once.
2. Figured out and implemented ignore/skip word.
3. Added status control for user. (Green=Complete, Yellow=Input, red=Working)


1/12/2009
Clean up code and added code to insert "Did you mean word" into input box.

########################################################################################

Edited by jfcby, 13 January 2010 - 05:46 PM.

Determined -- Devoted -- DeliveredMake your mind up -- to seriously apply yourself -- accomplishing the desired results._____________________________________________________________________________________A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB_____________________________________________________________________________________Learning to write scripts...WMP Resumer | InstaPro Launcher | XampLabel Styles | XampPause - "HotKeySet" | XampCounter | XampSpellCheck Forum References Remembered...5 Tips better coder by: Omar AlBadri (AKA - Volly) | AutoIT3/SciTE - USB by: MadSc13ntist | XSkin.au3 GUI by: Valuater AutoIT MVP | Helpful Collection Autoit Scripts: Maintained By: Volly | Windows Help 101 By: beerman & othersMy WebsitesCoopersBarnYard.com | Frankie-Cooper.me





#2 jfcby

jfcby

    Geek Problem Solver In The Making...

  • Active Members
  • PipPipPipPipPipPip
  • 327 posts

Posted 13 January 2010 - 04:52 PM

Hi,

Updated first post with additions and corrections to the "Xamp Spell Check".

1. Figured out how to and implemented into the script so that it will check mispelled word once.
2. Figured out how to and implemented into the script so that it will ignore/skip word.
3. Added a status label indicator so that the user would know what input is needed. (Green = Complete, Yellow = Input, Red = Working)

Learning to write scripts,
jfcby
Determined -- Devoted -- DeliveredMake your mind up -- to seriously apply yourself -- accomplishing the desired results._____________________________________________________________________________________A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB_____________________________________________________________________________________Learning to write scripts...WMP Resumer | InstaPro Launcher | XampLabel Styles | XampPause - "HotKeySet" | XampCounter | XampSpellCheck Forum References Remembered...5 Tips better coder by: Omar AlBadri (AKA - Volly) | AutoIT3/SciTE - USB by: MadSc13ntist | XSkin.au3 GUI by: Valuater AutoIT MVP | Helpful Collection Autoit Scripts: Maintained By: Volly | Windows Help 101 By: beerman & othersMy WebsitesCoopersBarnYard.com | Frankie-Cooper.me




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users