topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday December 26, 2024, 10:37 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Last post Author Topic: FScript Javascript SDK - Write FARR plugins in javascript and more.  (Read 113723 times)

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
The following worked a little bit better for me -- though I didn't end up seeing onBeginSearch getting invoked.

What I used:

  • Python 2.6.x (ActiveState)
  • FScript.dll version 1.13.0.0 (at least that's what I saw via the properties dialog box in explorer)
  • FARR 2.48.0.1
  • Windows XP

Uncommenting the last line shows that some bits seem to work for me.

Ah, I also have a vague memory that czb had a Python plugin -- may be asking him might shed some light on the matter.  I think a thread w/ the plugin mentioned in it says something about it being discontinued, but he still seems to have a page for it:

http://czb.dcmembers.com/TodoTXT.html

Code: Python [Select]
  1. displayname = "TESTPython"
  2. versionstring = "0.0.1"
  3. releasedatestring = "March 2nd, 2009"
  4. author = "Author"
  5. updateurl = ""
  6. homepageurl = ""
  7. shortdescription = "TESTPython"
  8. longdescription = "Python Test Plugin, you know?"
  9. readmestring = ""
  10. iconfilename = "FScript.ico"
  11. aliasstr = "ttt"
  12. regexstr = ""
  13. regexfilterstr = ""
  14. keywordstr = ""
  15. scorestr = "300"
  16.  
  17. # type
  18. UNKNOWN = 0
  19. FILE = 1
  20. FOLDER = 2
  21. ALIAS = 3
  22. URL = 4
  23. PLUGIN = 5
  24. CLIP = 5
  25. # Postprocessing
  26. IMMEDIATE_DISPLAY = 0
  27. ADDSCORE = 1
  28. MATCH_AGAINST_SEARCH = 2
  29. # search state constants
  30. STOPPED = 0
  31. SEARCHING = 1
  32.  
  33. def onSearchBegin(querykey, explicit, queryraw, querynokeyword):
  34.   FARR.setStrValue("DisplayAlertMessage", "woohoo")
  35.   FARR.setState(querykey, SEARCHING) #start search
  36.   #   return result to farr (queryID, title, path, icon, entrytype=FILE, resultpostprocessing=2, score=300)
  37.   FARR.emitResult(querykey, "python TITLE", "python PATH", iconfilename, ALIAS, IMMEDIATE_DISPLAY, 5000)
  38.   FARR.setState(querykey, STOPPED) #stopped search
  39.  
  40. # the following seems to work
  41. #FARR.setStrValue("DisplayAlertMessage", "loaded python test plugin")
« Last Edit: March 02, 2009, 12:54 AM by ewemoa »

ecaradec

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 410
    • View Profile
    • Blog & Projects
    • Read more about this member.
    • Donate to Member
You  can get the lastest FScript version at http://e.craft.free.fr/farr/FScript/ . The last one is 1.15 currently.
Blog & Projects : Blog | Qatapult | SwiffOut | FScript

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Thanks for the info concerning 1.15 :)

The following works for me - I haven't tested in-depth, but my suspicion about what made things work out is the signature for onSearchBegin -- I added a couple of more parameters after looking at the "Available Callbacks" section of:

  http://e.craft.free....rr/FScript/help.html

Code: Python [Select]
  1. displayname = "TESTPython"
  2. versionstring = "0.0.1"
  3. releasedatestring = "March 2nd, 2009"
  4. author = "Author"
  5. updateurl = ""
  6. homepageurl = ""
  7. shortdescription = "TESTPython"
  8. longdescription = "Python Test Plugin, you know?"
  9. readmestring = ""
  10. iconfilename = "FScript.ico"
  11. aliasstr = "ttt"
  12. regexstr = ""
  13. regexfilterstr = ""
  14. keywordstr = ""
  15. scorestr = "300"
  16.  
  17. # type
  18. UNKNOWN = 0
  19. FILE = 1
  20. FOLDER = 2
  21. ALIAS = 3
  22. URL = 4
  23. PLUGIN = 5
  24. CLIP = 5
  25. # Postprocessing
  26. IMMEDIATE_DISPLAY = 0
  27. ADDSCORE = 1
  28. MATCH_AGAINST_SEARCH = 2
  29. # search state constants
  30. STOPPED = 0
  31. SEARCHING = 1
  32.  
  33. def onInit(currentDirectory):
  34. #  FARR.setStrValue("DisplayAlertMessage", "onInit")
  35.   return
  36.  
  37. def onSearchBegin(querykey, explicit, queryraw, querynokeyword,
  38.                   modifierstring, triggermethod):
  39. #  FARR.setStrValue("DisplayAlertMessage", "onSearchBegin")
  40.   if not explicit:
  41.     return
  42.   FARR.setState(querykey, SEARCHING) #start search
  43.   #   return result to farr (queryID, title, path, icon, entrytype=FILE, resultpostprocessing=2, score=300)
  44.   FARR.emitResult(querykey, "python TITLE", "python PATH", iconfilename, ALIAS, IMMEDIATE_DISPLAY, 5000)
  45.   FARR.setState(querykey, STOPPED) #stopped search
  46.  
  47. def onSetStrValue(name, value):
  48. #  FARR.setStrValue("DisplayAlertMessage", "onSetStr: " + name + " " + value)
  49.   return
  50.  
  51. # the following seems to work
  52. #FARR.setStrValue("DisplayAlertMessage", "loaded python test plugin")

ChrisVN

  • Participant
  • Joined in 2009
  • *
  • default avatar
  • Posts: 7
    • View Profile
    • Donate to Member
Thanks for the tips so far.

I will try the newest version of FScript and I will also try to get TodoTXT running.
I don't like the idea of downgrading to Python v2.x - but if we are running out of ideas I will also test this one.

Any other suggestions?
chris

ChrisVN

  • Participant
  • Joined in 2009
  • *
  • default avatar
  • Posts: 7
    • View Profile
    • Donate to Member
Thanks again

Tonight I will try out the suggested signature for onSearchBegin:
def onSearchBegin(querykey, explicit, queryraw, querynokeyword,
                  modifierstring, triggermethod):


chris

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
I tried uninstalling Python 2.6.x and installing Python 3.x -- didn't seem to work here [1], but may be other people will experience differently.

There's a bit at:

  http://activestate.com/activepython/python3/

that says:

Many 3rd-party modules and extensions that you may depend upon may not yet be available for Python 3. [Currently this includes the Python for Windows (pywin32) extensions that are a default part of ActivePython on Windows.] As a result you may want to continue to use Python 2 for the time being. However, you can safely install both ActivePython 2.6 and ActivePython 3.0 side-by-side on your computer so that you can experiment with Python 3 while still using Python 2 for your current code.
Python 3.0 is Python's future, however the Python 2.x line will continue to see new releases for some time to allow for a long and smooth transition. ActivePython 2.6 is the latest ActivePython 2.x release.

Perhaps the part in bold-face is related...

Ah, I didn't mention this earlier, but my sense of the corrupt text was that this happens if some of certain variables (e.g. releasedatestring) are not defined.


[1] I didn't even notice the plugin appearing...

ChrisVN

  • Participant
  • Joined in 2009
  • *
  • default avatar
  • Posts: 7
    • View Profile
    • Donate to Member
[1] I didn't even notice the plugin appearing...
This is exactly what happend to me at first.
(I don't know what has changed that the plugin finally showed up)

-> Seems like I will have to work with Python v2.6

But I will also try this at first:
Ah, I didn't mention this earlier, but my sense of the corrupt text was that this happens if some of certain variables (e.g. releasedatestring) are not defined.

ChrisVN

  • Participant
  • Joined in 2009
  • *
  • default avatar
  • Posts: 7
    • View Profile
    • Donate to Member
Special thanks to ewemoa - 2 of your tips did the trick  :D

Trick #1: Python v3 is NOT working
After installing Python 2.6 the plug-in showed up in the list

Trick #2: Python requires the whole signature for onSearchBegin
Even though the java script samples don't use the whole signature, python seems to need all parameters including "modifierstring" and "triggermethod"

A big 'thank you' for the useful tips
now I can go on and experience the new possibilities.

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Great to hear it's working  :Thmbsup:

ecaradec

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 410
    • View Profile
    • Blog & Projects
    • Read more about this member.
    • Donate to Member
ChrisVN : Thank you for sharing your findings.  :Thmbsup:
Blog & Projects : Blog | Qatapult | SwiffOut | FScript

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
A side note -- I compared checksums of the FScript.dll (1.15) mentioned in this thread:

  http://e.craft.free.fr/farr/FScript/
  SHA-1: 5f71f21959139002bb022d0c7ae9d0f1edc83ca6

to that of the one (also comes up as 1.15?) included in CZBFSubScript.zip in the following thread:

  https://www.donation...ex.php?topic=16942.0
  SHA-1: 96bba6cb3480025bc7e357cc143eec2c0b4f7605

I suspected the files were different after failing to get the socket stuff to work with the former one.

ecaradec

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 410
    • View Profile
    • Blog & Projects
    • Read more about this member.
    • Donate to Member
I have  probably done several build of the 1.15 version. However (if I didn't screw up ), they should be equivalent. Visual Studio probably add informations specific to the time of the build, or something like that, causing sha1 to be different.

Blog & Projects : Blog | Qatapult | SwiffOut | FScript

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Thanks for the clarification.

I think it is worth noting that at least one of them (the former one mentioned in my earlier post) doesn't appear to support the FARR.newTCPSocket().  If you don't mind, perhaps you could update that one or confirm whether it supports FARR.newTCPSocket().

ecaradec

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 410
    • View Profile
    • Blog & Projects
    • Read more about this member.
    • Donate to Member
Hum, there is probably two 1.15 version, which is not very cool. I'm making an automated build for future version, so that this kind of issues would not occur anymore. You are probably safe to use the 1.15 version with socket support. As I remember, it should be the only difference between the two versions.
Thank you for reporting the issue.
Blog & Projects : Blog | Qatapult | SwiffOut | FScript

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Thanks for the clarification -- I am happy to be using the version with socket support (and it is nice to hear from the creator that that's probably ok ;) ).

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
I am starting to experiment more with writing plugins using Python.

My experience so far is that I do not know how to become aware of at least one type of runtime difficulty.  Specifically, I do not know that the plugin has aborted execution due to an exception being raised.  Tracking down relevant lines in the source code can become a chore with no hints!

Does any one have any ideas (other than wrap every function call body in try/except) about how to be alerted about runtime exceptions?  Any chance that FScript could make a stacktrace available (or may be it does already and I don't know where to look)?

For comparison, when this type of thing occurs for a JavaScript plugin, I am alerted by my local installation of MS Script Debugger...I went looking for something similar for Python, but so far I have not been successful in locating anything.

I hope someone has some good ideas regarding this situation :)

Edit: catch -> except ... oops ;)
« Last Edit: March 20, 2009, 12:58 AM by ewemoa »

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
At the moment, I'm taking the wrap function bodies approach -- as an example, an onInit might look like:

Code: Python [Select]
  1. def onInit(currentDirectory):
  2.   try:
  3.     # XXX
  4.     1 / 0
  5.   except:
  6.     type, value, tb = sys.exc_info()
  7.     FARR.setStrValue("DisplayAlertMessage", repr(traceback.format_exception(type, value, tb)))

This is assuming something like the following also in an appropriate location in the code:

Code: Python [Select]
  1. import sys, traceback

DisplayAlertMessage is a bit tight on space, so I'm considering alternatives.  Perhaps bring up some browser window?  It'd be neat to display the stack trace, but also perhaps load the source for the file with the problem and highlight the problematic line.  Mmm, how to do that...

Doing this for each function sounds painful so I'm thinking of writing some code to appropriately "instrument" certain functions -- may be just the plugin entry points.  This code could then be placed so that it runs when the plugin is first loaded.

Any reflections?

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
I've made something using Python's decorators.  I have the following code near the beginning of a plugin:

Code: Python [Select]
  1. import sys, traceback, pprint
  2.  
  3. # "advice" -- quick-and-dirty wrapping/instrumenting code
  4. #
  5. # to use, place @around before a function definition line.
  6. # for example, for a function f:
  7. #
  8. #   @around
  9. #   def f(arg1):
  10. #     print arg1
  11. #
  12. # based on code at:
  13. #   http://livingcode.org/2009/aspect-oriented-python
  14. def around(fn):
  15.   def wrapped(*args, **kws):
  16.     try:
  17.       return fn(*args, **kws)
  18.     except:
  19.       import pprint
  20.       xtype, value, tb = sys.exc_info()
  21.       trace = traceback.format_exception(xtype, value, tb)
  22.       tracestr = pprint.pformat(trace)
  23.       efname = plugindir() + "\\exception.txt"
  24.       f = open(efname, "w")
  25.       f.write(tracestr)
  26.       f.close()
  27.       FARR.setStrValue("launch", "notepad.exe " + efname)
  28.   return wrapped

Then example usage for onInit might be:

Code: Python [Select]
  1. @around
  2. def onInit(currentDirectory):
  3.   FARR.setStrValue("DisplayAlertMessage", "Know any perfect numbers?")
  4.   # XXX
  5.   1 / 0

That is, just place "@around" on the line preceding the first line of a function definition -- assuming you want the function in question "wrapped".

The basic idea seems ok -- but using "launch" w/ "showhtml" isn't working out so well for plugin reloads.  Looks like FARR quickly goes on to display the result of the plugins reloading so I don't get enough time to read the stack trace...

Edit: It's a bit ugly, but now the code writes exception information to a temporary file within the plugin directory and opens it using notepad.
« Last Edit: March 22, 2009, 06:29 AM by ewemoa »

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,916
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: FScript Javascript SDK - Write FARR plugins in javascript and more.
« Reply #68 on: December 25, 2009, 11:06 PM »
Do we have a python and ruby example somewhere?

ecaradec

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 410
    • View Profile
    • Blog & Projects
    • Read more about this member.
    • Donate to Member
Re: FScript Javascript SDK - Write FARR plugins in javascript and more.
« Reply #69 on: December 26, 2009, 09:49 AM »
Yep, debugging in python or ruby suck. the activescript binding of python and ruby is limited to running script but not debugging them, and the debugging support is required to get correct error lines, etc... May be there is somewhere a debuggable active script implementation of python ?
Once you have a good understanding on what FARR pass as parameters and order of methods call, you can try running plugins standalone and integrate them as FARR plugin at the end. Not the solution I'd like but it helps.
Blog & Projects : Blog | Qatapult | SwiffOut | FScript

relipse

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 127
  • I love Jesus. Coding in PHP primarily.
    • View Profile
    • See my GitHub
    • Read more about this member.
    • Donate to Member
Can someone help me write a plugin? I don't understand any of the example plugins.

I want to write a plugin that lets you automatically search google when you press a hotkey (for example alt+g) with whatever text is being shown.

I also want to write a plugin that lets me find a particular window that is open since i always have about 20-25
For example you open FARR type w <window name> and it will jump to that open window (faster than alt-tab if you know what you are looking for)

Jim
Ex C++Builder coder, current PHP coder, and noob Qt Coder

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,916
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Jim,

The Fprocs plugin should solve your second request -- there is also an alt-tab like plugin somewhere but i can't find it.

As for a plugin that automatically searches google when you press a hotkey -- that's an interesting idea.. i can think of a couple of ways that could ALMOST be done without using a plugin.. Perhaps it would be useful if i added some more options to the hotkey configuration in FARR to support NON-GLOBAL local hotkeys..

Vurbal

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 653
  • Mostly harmless
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: FScript Javascript SDK - Write FARR plugins in javascript and more.
« Reply #72 on: October 16, 2013, 02:08 AM »
Since mouser wasn't sure about this when I asked him earlier I'll add it to this thread instead.

Does anyone know if it's possible to call functions from a fscript plugin script via a html document rendered in FARR? My immediate inclination is to think it's not but that's not really even an educated guess. I honestly don't understand enough about how fscript works to really wrap my brain around the question.
I learned to say the pledge of allegiance
Before they beat me bloody down at the station
They haven't got a word out of me since
I got a billion years probation
- The MC5

Follow the path of the unsafe, independent thinker. Expose your ideas to the danger of controversy. Speak your mind and fear less the label of ''crackpot'' than the stigma of conformity.
- Thomas J. Watson, Sr

It's not rocket surgery.
- Me


I recommend reading through my Bio before responding to any of my posts. It could save both of us a lot of time and frustration.

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Re: FScript Javascript SDK - Write FARR plugins in javascript and more.
« Reply #73 on: October 16, 2013, 06:41 AM »
Not sure if I'm following and I don't have much FARR context in my head, but If you mean something like:

1. User takes some action which leads to a plugin getting FARR to display some HTML (generated by the plugin say)
2. User clicks on a link or button in the HTML
3. The plugin executes some code in response

Then IIUC the answer is "yes".

An example of this type of situation is in the CommandPromptHere plugin.

Look in the file named callbacks/onSetStrValue.js for the following code path:

  onSetStrValue ->
    handleStartConfig ->
      displayConfigHTML ->
        buildConfigHTML

buildConfigHTML generates HTML which is displayed by FARR.

Within that generated HTML is a FORM element with an action that begins with "farr://pscommand".  When a user submits the associated form, the plugin gets called by FARR's pscommand mechanism.  Specifically, the plugin handles this request via onSetStrValue in callbacks/onSetStrValue.js:

  onSetStrValue ->
    handleConfig

Does that help at all?

Vurbal

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 653
  • Mostly harmless
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: FScript Javascript SDK - Write FARR plugins in javascript and more.
« Reply #74 on: October 16, 2013, 06:54 AM »
Does that help at all?

I'll have to look closer when I have some time but at first glance it appears to be exactly what I was looking for!

Thanks!
I learned to say the pledge of allegiance
Before they beat me bloody down at the station
They haven't got a word out of me since
I got a billion years probation
- The MC5

Follow the path of the unsafe, independent thinker. Expose your ideas to the danger of controversy. Speak your mind and fear less the label of ''crackpot'' than the stigma of conformity.
- Thomas J. Watson, Sr

It's not rocket surgery.
- Me


I recommend reading through my Bio before responding to any of my posts. It could save both of us a lot of time and frustration.