Jump to content
Sign in to follow this  
AzKay

_Define()

Recommended Posts

AzKay

I was bored, So I made this. Enjoy.

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Definition", 202, 242, 193, 115)
$Input1 = GUICtrlCreateInput("", 8, 8, 185, 21)
$Button1 = GUICtrlCreateButton("Define", 8, 32, 185, 17, 0)
$ListView1 = GUICtrlCreateEdit("", 8, 56, 185, 177, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$WS_HSCROLL,$WS_VSCROLL,$ES_READONLY))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            GUICtrlSetData($ListView1, "")
            $oRet = _Define(GUICtrlRead($Input1))
            If Not @error Then
                For $i = 1 To $oRet[0]
                    GUICtrlSetData($ListView1, $oRet[$i] & @CRLF, 1)
                Next
            Else
                GUICtrlSetData($ListView1, "No definition available" & @CRLF, 1)
            EndIf
    EndSwitch
WEnd

Func _Define($oWord)
    Local $oWordx, $oHTTP, $oWords
    $oHTTP = ObjCreate("Microsoft.XMLHTTP")
    $oHTTP.Open("GET", "http://www.google.com/search?hl=en&q=define:" & $oWord, False)
    $oHTTP.Send()
    $oWords = StringRegExp($oHTTP.ResponseText, "<font size=-1><li>(.*?)<br>", 3)
    For $i = 0 To UBound($oWords) -1
        If $oWords[$i] <> "Web Images Groups News Froogle Local more» Advanced Search Preferences Language Tools AdvertisingPrograms - About Google ©2005 Google." Then
            $oWordx = $oWordx & $oWords[$i] & "#"
        EndIf
    Next
    $oWordx = StringTrimRight($oWordx, 1)
    $oWordx = StringReplace($oWordx, "'", "'")
    $oWordx = StringReplace($oWordx, "&amp;", "&")
    $oWordx = StringReplace($oWordx, "<li>", "")
    $oWordx = StringReplace($oWordx, "&quot;", '"')
    $oWordx = StringReplace($oWordx, "&gt;", ">")
    $oWordx = StringReplace($oWordx, "&lt;", "<")
    $oWordx = StringReplace($oWordx, "&ndash;", "-")
    $oWordx = StringReplace($oWordx, "&" & "#39;", "'")
    If $oWordx <> "" Then
        $oWordx = StringSplit($oWordx, "#")
        Return $oWordx
    Else
        SetError(1)
        Return -1
    EndIf
EndFunc

FEEDBACK PL0x.

Oh, And feel free to add in more special characters.

EDIT::

Better example added.

Edited by AzKay

# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites
Nahuel

That actually looks useful.. but I can't get it to work. Could you post an example?

Share this post


Link to post
Share on other sites
AzKay

That has an example;

#include <Array.au3>

$oWord = "Google"
$oWord = _Define($oWord)
_ArrayDisplay($oWord)

# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites
martin

That has an example;

#include <Array.au3>

$oWord = "Google"
$oWord = _Define($oWord)
_ArrayDisplay($oWord)
Neat!

Here's one you missed

$oWordx = StringReplace($oWordx, "'", "'");inverted comma


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
AzKay

Neat!

Here's one you missed

$oWordx = StringReplace($oWordx, "'", "'");inverted comma

Added x3

# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites
martin

Added x3

I think the browser is converting the characters so you don't see the code in the post, so this is what needs to be in the code

$oWordx = StringReplace($oWordx, "&" & "#39;", "'");


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
AzKay

I think the browser is converting the characters so you don't see the code in the post, so this is what needs to be in the code

$oWordx = StringReplace($oWordx, "&" & "#39;", "'");

Ah, Makes sense. x3

# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites
AzKay

Anyone else find this useful?


# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites
Nahuel

This part was extremely useful for me:

Local $oWordx, $oHTTP, $oWords
    $oHTTP = ObjCreate("Microsoft.XMLHTTP")
    $oHTTP.Open("GET", "http://www.google.com/search?hl=en&q=define:" & $oWord, False)
    $oHTTP.Send()
    $oWords = StringRegExp($oHTTP.ResponseText, "<font size=-1><li>(.*?)<br>", 3)

I use it all the time, it's awesome.

Besides that, I made a script a while ago that would give you the definition of a word when the user highlights it and presses a key combination using your script. Unfortunately, I had a problem with my hd and lost everything (thank jebus some of my 'important' scripts were here) but you can figure out how it worked :)

-edit-

Look: http://www.autoitscript.com/forum/index.php?showtopic=51987

Edited by Nahuel

Share this post


Link to post
Share on other sites
AzKay

This part was extremely useful for me:

Local $oWordx, $oHTTP, $oWords
    $oHTTP = ObjCreate("Microsoft.XMLHTTP")
    $oHTTP.Open("GET", "http://www.google.com/search?hl=en&q=define:" & $oWord, False)
    $oHTTP.Send()
    $oWords = StringRegExp($oHTTP.ResponseText, "<font size=-1><li>(.*?)<br>", 3)

I use it all the time, it's awesome.

Besides that, I made a script a while ago that would give you the definition of a word when the user highlights it and presses a key combination using your script. Unfortunately, I had a problem with my hd and lost everything (thank jebus some of my 'important' scripts were here) but you can figure out how it worked :)

-edit-

Look: http://www.autoitscript.com/forum/index.php?showtopic=51987

Very nice :3

# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites
JSunn

I actually really like this - would be useful as a widget that runs on the desktop to provide a quick definition. Good job!

-John

Share this post


Link to post
Share on other sites
maqleod

two suggestions:

make the default action when enter is pressed while the cursor is in the input box to execute the define function

make the gui wider so it is easier to read, or at least make the gui resizable


[u]You can download my projects at:[/u] Pulsar Software

Share this post


Link to post
Share on other sites
Valuater

Cool, Kay!!!

8)


NEWHeader1.png

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  

×