AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Tool tip dictionary
Goto page 1, 2  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
delta



Joined: 16 Feb 2005
Posts: 44

PostPosted: Thu Aug 25, 2005 1:08 pm    Post subject: Tool tip dictionary Reply with quote

There are some scripts around that automatically look up words on dictionary sites. I've always been reluctant to use those because I don't like it if the site I'm viewing is covered by another site. Nevertheless a dictionary is quite useful, so I tried my own script which uses (more or less) small tooltips.

It uses the site lookwayup.com because the entries there are quite short (good for tool tips without much formatting). Another reason is, that it has also Spanish, French and Portuguese dictionaries, which are now easier to include (but they need some more formatting though)

The script works as follows: Highlight a word or a phrase and click the middle mouse button. The last tool tip will vanish if you move the mouse a little (how much is specified in the variable mousetol, see comments in the script)

However, it is not perfect. Apart from cosmetic issues (tooltips are sometimes very wide, script could be improved (2 times GoTo! Shocked )) there is one thing: if there is too much data you can left click and see the next tool tip. Ideally that would be again the middle mouse button, but this is one locked, since it is the hotkey already. Moreover the left-click is passed through which is sometimes not desirable (e.g. if you marked a link)

Other than this the script works great for me. Comments welcome.

Code:
; _______________________________________________________
;
;    Usage: Highlight a word or a phrase and press
;           the middle mouse button to display a
;           translation retrieved from:
;                http://lookwayup.com/
;
; _______________________________________________________

#UseHook

; _______________________________________________________
;
;    mousetol:  The final tool tip will vanish if
;               the mouse is moved more then %moustol%
;               pixels away from the current position
; _______________________________________________________

mousetol = 3;

; _______________________________________________________
;
;    Some variables to shorten the scripts somewhat:
;       wordtypeshort: the letters used by lookwayup
;                      to mark certain wordtypes
;       wordtypelong : what the letters actual mean
;       typecount    : how many types do we have?
;
;    Note: If there should be types I have forgotten
;          the script will pop up a message box
;          displaying the missing letter. It can be
;          easily included in wordtypeshort and
;          wordtypelong.
; _______________________________________________________

wordtypeshort = vnarpocd
wordtypelong = verb|noun|adjective|adverb|preposition|pronoun|conjunction|determiner

tempfile = tooltipdic.ttd

StringLen, typecount, wordtypeshort

; _______________________________________________________
;
;    Variables to refine HTML Unicode which occurs
;    sometimes. If you should come about more than
;    those you can add them here.
; _______________________________________________________

replace = "|'
substitute = "'

offset = 0

return



; _______________________________________________________
;
;    Actual script start here
; _______________________________________________________

MButton::
   Begin:
   d =
   If offset = 0
   {
      temp = %clipboard%
      clipboard =
      Send, ^c

      If clipboard =
      {
         clipboard = %temp%
         temp =
         return
      }
      Else
      {
        lookup = %clipboard%
        clipboard = %temp%
        temp =
      }   
      ToolTip, Retrieving information on "%lookup%"...
   }
   Else
   {
      ToolTip, Retrieving more information on "%lookup%"...
      d = &d=%offset%
   }

   ; _______________________________________________________
   ;
   ;    Fetch dictionary entry
   ; _______________________________________________________

   FileDelete, %tempfile%
   URLDownloadToFile, http://lookwayup.com/lwu.exe//lwu/d?w=%lookup%%d%, %tempfile%
   
   IfNotExist, %tempfile%
   {
      ToolTip, Sorry`, connection timed out.`nTry again later.
      MouseGetPos, X, Y
      GoTo, ToolTipDelete
   }
   
   entry = 0
   more = 0
   
   ; _______________________________________________________
   ;
   ;    Prepare strings for different word types
   ; _______________________________________________________

   Loop, parse, wordtypelong, |
   {
      StringMid, type, wordtypeshort, %A_Index%, 1
      %type%_entry = %A_LoopField%`n
      If offset = 0
         %type%_count = 0
      %type%_found = 0
   }
   
   wordfound = yes
   Loop, Read, %tempfile%
   {
      IfInString, A_LoopReadLine, <h4>
      {
         StringTrimLeft, displayed, A_LoopReadLine, 4
         StringGetPos, trim, displayed, </h4>
         StringLeft, displayed, displayed, trim
         If offset > 0
            displayed = %displayed%%A_Space%(continued)
      }
      IfInString, A_LoopReadLine, colspan=2
         entry = 0
      IfInString, A_LoopReadLine, not found
         {
            wordfound = no
            break
         }
      If entry = 1
      {
         line = %A_LoopReadLine%
         IfNotEqual, line,
         {
            IfInString, line, VALIGN
            {
               StringRight, type, line, 2
               StringLeft, type, type, 1
               IfNotInString, wordtypeshort, %type%
                  MsgBox, Unsupported type (%type%) discovered!
            } 
            Else
            {
               StringGetPos, trim, line, <A HREF
               tofetch := trim - 1
               StringLeft, def, line, tofetch
               ++%type%_count
               %type%_found = 1
               temp := %type%_entry
               count := %type%_count
               %type%_entry = %temp%%count%.%A_Space%%def%`n
            }
         }
      }
      IfInString, A_LoopReadLine, CELLPADDING=1
         entry = 1
      IfInString, A_LoopReadLine, More senses
         more = 1
   }
   
   MouseGetPos, X, Y

   ; _______________________________________________________
   ;
   ;    Output any word type which was found
   ; _______________________________________________________

   
   full_entry = %displayed%`n
   If wordfound = yes
   {
     Loop, %typecount%
     {
        StringMid, type, wordtypeshort, %A_Index%, 1
        If %type%_found = 1
        {
           refd := refine(%type%_entry)
           full_entry = %full_entry%`n%refd%
        }
     }
     If more = 1
     {
        full_entry = %full_entry%`n>> left click to display more <<
        ++offset
     }
     ToolTip, %full_entry%
   }
   Else
     ToolTip, Sorry`, no match found.
   
   ; _______________________________________________________
   ; 
   ;    Wait for mouse movement to delete ToolTip.
   ;    If there is more to display also detect, if
   ;    the left mouse button is clicked.
   ; _______________________________________________________
 
   ToolTipDelete:
 
   Loop
   {
     MouseGetPos, Xn, Yn
     Sleep, 50
     If (Abs(X - Xn) > mousetol || Abs(Y - Yn) > mousetol)
        break
     If more = 1
     {
        GetKeyState, LB, LButton
        If LB = D
        {
           more = 0
           GoTo Begin                   ; Go back and start it all over again
                                        ; to display the next page
        }
     } 
   }
   offset = 0
   ToolTip
   
return



; _______________________________________________________

;    Replace HTML code with appropriate characters
;    (see beginning of the script for the strings
;     replace and substitute)
; _______________________________________________________

Refine(html)
{
   Global replace
   Global substitute

   Loop, parse, replace, |
   {
      StringMid, subs, substitute, %A_Index%, 1
      StringReplace, html, html, %A_LoopField%, %subs%, 1
   }
   return, html
}


Last edited by delta on Thu Aug 25, 2005 7:53 pm; edited 1 time in total
Back to top
View user's profile Send private message
delta



Joined: 16 Feb 2005
Posts: 44

PostPosted: Thu Aug 25, 2005 7:52 pm    Post subject: Reply with quote

As you might have noticed: the script exits if no text is selected. That's this part:
Code:
      If clipboard =
      {
         clipboard = %temp%
         temp =
         return
      }

To preserve most of the middle button functionality (in Opera it opens a link in a new tab in the background) without using an additional modifier I suggest you put a
Code:
         Send, {MButton}

right before the return.

(double post because of the longer time delay)
Back to top
View user's profile Send private message
freakkk



Joined: 29 Jul 2005
Posts: 179

PostPosted: Wed Aug 31, 2005 12:54 am    Post subject: Reply with quote

delta--
I think this script is absolutely awesome!! Although I don't have to regularly get definitions of words- its definately a good show piece to new scripters.. & a fresh creative idea. I think you should aim to try being able to highlight full sentences-- & utilize google translate to give you on the fly language translations.
Good job Very Happy
I'm a bit disappointed that no one has responded to your post.
_________________
.o0[ corey ]0o.
Back to top
View user's profile Send private message
webber



Joined: 25 Aug 2005
Posts: 129

PostPosted: Thu Sep 08, 2005 7:32 pm    Post subject: Reply with quote

This script doesn't seem to work. It only shows an empty tool tip.

Has anyone been able to make this work ?
________
Monaco


Last edited by webber on Fri Feb 11, 2011 4:54 am; edited 1 time in total
Back to top
View user's profile Send private message
garath



Joined: 24 Mar 2005
Posts: 398
Location: germany

PostPosted: Thu Sep 08, 2005 8:01 pm    Post subject: Reply with quote

Hmm, left-doubleclick will have the efffekt, that you lose the Highlight.
Right-doubleklick will open a menu.
Maybe, it will be better to use a special key, like F12 or something like that, or you use the right-klick, and look afterwards, if there is a rightklick the next second.


Yes, it is working,
replace MButton:: with RButton::
insert MouseClick, right
after Send, ^c


now the skript will dictionary with rightbutton, and you have the menu as usual
Back to top
View user's profile Send private message
webber



Joined: 25 Aug 2005
Posts: 129

PostPosted: Thu Sep 08, 2005 8:13 pm    Post subject: Reply with quote

I changed the button to right button but the script still does not do anything except show an empty tooltip.

It does not look up the word in the dictionary .
________
Buy Silver Surfer


Last edited by webber on Fri Feb 11, 2011 4:54 am; edited 1 time in total
Back to top
View user's profile Send private message
garath



Joined: 24 Mar 2005
Posts: 398
Location: germany

PostPosted: Thu Sep 08, 2005 8:34 pm    Post subject: Reply with quote

Try this little skript to test the lookup, maybe, you have an old version of AHK? but version 37 should be ok, don't know, hmm.


Code:

InputBox, word , Dictionary, Word to search:
URLDownloadToFile, http://lookwayup.com/lwu.exe//lwu/d?w=%word%, dict.htm
run, dict.htm
Back to top
View user's profile Send private message
webber



Joined: 25 Aug 2005
Posts: 129

PostPosted: Thu Sep 08, 2005 8:53 pm    Post subject: Reply with quote

running the latest and greatest but the file dict.htm is empty.

Question
________
Vaporizer affiliates


Last edited by webber on Fri Feb 11, 2011 4:54 am; edited 1 time in total
Back to top
View user's profile Send private message
garath



Joined: 24 Mar 2005
Posts: 398
Location: germany

PostPosted: Thu Sep 08, 2005 9:00 pm    Post subject: Reply with quote

hmm, is your IExplorer blocked?
Don't know the method of URLDownloadToFile, but I think, you have a problem with your firewall?

from the Helpfile:

Quote:

Internet Explorer 3 or greater must be installed for this function to work. Firewalls or the presence of multiple network adapters may cause this function to fail. Also, some websites may block such downloads.

The file is obtained from IE cache whenever possible. You might be able to force a (re)download from the Internet by supplying a fake cgi parameter, for example: "http://.../test.exe?fakeParam=42
Back to top
View user's profile Send private message
webber



Joined: 25 Aug 2005
Posts: 129

PostPosted: Thu Sep 08, 2005 9:05 pm    Post subject: Reply with quote

Quote:
IE blocked...


I don't think so . Using IE, if I just plug the url into the address bar, it goes through to the site and looks up the specified word.

I have firefox as my default browser, would that be the problem ?
________
Toyota Ar Engine Specifications


Last edited by webber on Fri Feb 11, 2011 4:54 am; edited 1 time in total
Back to top
View user's profile Send private message
garath



Joined: 24 Mar 2005
Posts: 398
Location: germany

PostPosted: Thu Sep 08, 2005 9:11 pm    Post subject: Reply with quote

sorry, don't know, I think, it uses a part of the IExporer, but I am no expert Confused
You can try to download something else, so you can see, if it depends on URLDownloadToFile or the comunication with this special site
Back to top
View user's profile Send private message
freakkk (as guest)
Guest





PostPosted: Fri Sep 09, 2005 2:41 am    Post subject: Reply with quote

webber-- check & see if autohotkey is blocked by your filewall. zonealarm asked permission the 1st time i ran it. if that doesn't get it working.. try compiling to its own exe and run it...

corey
Back to top
freakkk (as guest)
Guest





PostPosted: Fri Sep 09, 2005 2:44 am    Post subject: Reply with quote

ps-- per help file 'Internet Explorer 3 or greater must be installed for this function to work' for URLDownloadToFile. that doesn't mean it has to be your default browser though..
Back to top
webber



Joined: 25 Aug 2005
Posts: 129

PostPosted: Fri Sep 09, 2005 4:55 am    Post subject: Reply with quote

I have it working, it was a proxy problem

thanks for everyone's assistance.
________
Og Kush Marijuana


Last edited by webber on Fri Feb 11, 2011 4:54 am; edited 1 time in total
Back to top
View user's profile Send private message
delta



Joined: 16 Feb 2005
Posts: 44

PostPosted: Wed Sep 14, 2005 8:34 am    Post subject: Reply with quote

Thanks for the comments.

@freakkk:
You can already highlight whatever you want and pass it to the script. The script itself does not highlight anything. It will look up whatever is highlighted.

The google "translation" is a nice idea. Sometimes the first page of results is enough. Like a quick shot in the dark. Wink
But I think if you include a google search it will cut down the simplicity somewhat. I mean I see two versions: Either you have a tool tip google and tool tip dictionary as (more a less) separate scripts, then you have to define hotkeys for each of them and you have to decide for every word if you want it to be looked up in google or in lookwayup and it wouldn't be just middle click anymore.
The other version could be that you just get everything that could be found. But I think that will be too much information to grasp with one quick glance.
But maybe something like this would work: Look up whatever is hightlighted in lookwayup. If something is found then the user wanted a translation (as a rule of thumb) but if nothing is found present a googled search result list.

Hm, but then again, it seems there is not much interest in this script. Even I forgot the thread after no one had replied after some days.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group