From Enso Wiki
[edit] Bugs / Comments
- There is a problem in importing Commands from commands. How can I solve it?
- This should be fixed in the download (The one that comes with ensoDebugCommandServer.py) Digitalxero 15:18, 31 January 2008 (PST)
- Should be noted it doesn't work with Python3 without a lot of tweaking. That one threw me for a bit :) --144.32.7.40 11:09, 21 January 2008 (PST)
- Considering Python3 is still in very early alpha, I would expect there to be issues Digitalxero 15:19, 31 January 2008 (PST)
- Using displayMessage("text") doesn't work under Enso 2.0 beta prototype. Following must be changed in base.py under displayMessage function:
replace:
return self.enso.displayMessage(u"<caption>" + text + u"</caption>")
with:
return self.enso.displayMessage(u"<p></p><caption>" + text + u"</caption>")
[edit] Comments
If you find this useful, horrible, or something in between let me know Digitalxero 14:32, 11 December 2007 (PST)
[edit] Builtin Commands
- reload commands
- This will reload all commands managed by the Command Server, allowing you to make changes to your commands without requiring you to restart the command server itself, or add new commands on the fly
- stop command server
- This will exit the Command Server and unregister all commands managed by it.
[edit] External Commands
- alarm - Schedule quick alarms in relative or absolute time
- convert - Used to convert a users text selection using Google's built-in converter
- length - Calculates the length of the selected text
- Mercurial - Commands to control the Mercurial DVCS (Distributed Version Control System)
- PC commands - Commands to lock, shutdown, log off and reboot your PC
- scicalc - Scientific Calculator
- sendto - Command to send files to a given email address
- ssh - Access to Putty sessions
- title case - Title Case Selected Text
- track - Track UPS & FedEx packages, as well as Flights.
- winamp - Winamp Controler
- WoW Search - World of Warcraft common website search options
[edit] Command API
- newCommand(commandName, commandMethod, commandDescription, commandHelp, postfixType="none", postfixList=[]) - This tells the Command Server to perform all the required junk to get your new command registered.
- commandName - The name of your command
- If your command is going to have variables you must have {string} at the end of your commandName
- Command names are all lower case, but the Command Server is smart enough that you can type then in any case
- commandMethod - This is the method of your commands class that should be called when you issue the command
- a command method must accept 1 paramater, which will be variable entered or an empty string
- commandDescription - A short text only description of your command
- commandHelp - HTML help message
- postfixType - The type of variable the user can enter. Can be none, bounded, or arbitrary
- postfixList - is a python list containing the acceptable variable names for a bounded postfixType command, it is not used otherwise
- newBoundedCommand(commandName, commandMethod, commandDescription, commandHelp, postfixList=[]) - An alias for newCommand(commandName, commandMethod, commandDescription, commandHelp, postfixType="bounded", postfixList=[])
- newArbitraryCommand(commandName, commandMethod, commandDescription, commandHelp) - An alias for newCommand(commandName, commandMethod, commandDescription, commandHelp, postfixType="arbitrary", postfixList=[])
- delCommand(commandName) - Remove a command
- commandName - The name of the command you wish to remove
- removeCommand(commandName) - An alias for delCommand(commandName)
- displayMessage(text, head="") - Wraps your message in the proper XML so you can just send text strings for the text and head parts
- text - The main body of your message. It gets wrapped in
<caption>text</caption>
- head - The header of your message. It gets wrapped in
<p>head</p>
- displayXMLMessage(xml) - Identical to the base enso command displayMessage. I changed the name to more clearly state that properly formated XML was required.
- getFileSelection() - Identical to the base enso command of the same name
- getUnicodeSelection() - Identical to the base enso command of the same name
- insertUnicodeAtCursor(text, fromCommand="") - Identical to the base enso command of the same name, except the fromCommand is not required
- text - The text you wish to insert at cursor
- fromCommand - Informational for error log tracking
- setUnicodeSelection(text, fromCommand="")- Identical to the base enso command of the same name, except the fromCommand is not required
- text - The text change the selection to
- fromCommand - Informational for error log tracking
[edit] Command Code example
from base import BaseCommand
import time
import urllib
import threading
class Command(BaseCommand):
def __init__(self, *args):
BaseCommand.__init__(self, *args)
self.newArbitraryCommand("test {string}", self._test, "Test Command", "No Help for you")
self.newBoundedCommand("order {food}",
self._orderFood,
"order some food.",
"<p>Allows you to order food.</p>",
["pizza", "lingonberries"]
)
self.newCommand("translate to swedish", #Name of the Command
self._translateToSwedish, #Method to be called when the command is issued
"Translates your current selection to Swedish.", #Short Description of the command
"<p>This command translates the current" \
"text selection to Swedish. Try it on this " \
"sentence.</p>" #HTML Help for the command
)
def _test(self, message):
self.displayMessage(message, "Message From The 'Test' Command")
def _translateToSwedish(self, postfix):
"""
Implementation of the 'translate to swedish' command.
"""
# URL of the Swedish translation web service.
URL = "http://www.cs.utexas.edu/users/jbc/bork/bork.cgi?"
# Call an Enso Developer Prototype API function to get the
# user's current unicode selection.
text = self.getUnicodeSelection()
if len(text) == 0:
# Use the Command Server API to display a
# transparent primary message to the end-user.
self.displayXMLMessage("<p>No text selected!</p>" )
else:
params = {"input": text, "type": "chef"}
params = urllib.urlencode(params)
# Note that we're making a network connection here, which
# could take a long time to complete. Ideally, this
# should be executed in a separate thread, and only if it
# takes longer than about 250 ms--the maximum wait time
# before end-users start clicking on things--should the
# Enso Extension print a primary message telling the
# end-user to "please wait". Furthermore, network errors
# should be caught and converted into primary messages
# informing the end-user. Actually implementing such
# behavior is left as an exercise for the reader.
translated = urllib.urlopen(URL, params).read()
translated = translated.decode("iso-8859-1")
urllib.urlcleanup()
# Use the Command Server API to replace the
# user's current unicode selection. The second parameter
# is the name of the command that is originating the
# change, for display purposes only. If the unicode
# selection can't be changed (e.g., because it is static
# text on a web page), then the text will automatically be
# inserted into Enso's put buffer for insertion at a later
# time by the user (via the 'put' command).
self.setUnicodeSelection(translated, "translate to swedish")
def _orderFood(self, foodName):
"""
Implementation of the 'order {food}' command.
"""
self.displayMessage(u"One moment please.", u"Ordering %s\u2026" % foodName)
def foodOrderConfirmation():
"""
Simple thread that fakes the ordering of food and displays
a primary message to the user when finished.
This shows that Command Server API calls can be
made from anywhere--not just from the context of a command
execution.
"""
time.sleep(3)
self.displayMessage(u"I didn't really order it, though.", u"%s ordered!" % foodName)
thread = threading.Thread(target = foodOrderConfirmation)
# Just in case we kill the Extension, we don't want to
# have to wait until the fake food ordering is complete. :)
thread.setDaemon(True)
thread.start()
[edit] Download
You can download the Command Server @ ensoCommandServer.zip
[edit] Automatically Starting Command Server
YtC7VC g9dR27dnaQkPp5sbn
[edit] Enso 2.0 'Learn as open' option
One easy way to start up command server is to create a windows shortcut to the target.
Enso 2.0 Launcher Beta can be found here: http://www.humanized.com/enso/beta/enso-20-launcher-prototype/
- Create a windows shortcut to the Command Server python script
- <python path>\pythonw25.exe <command server path>\ensoCommandServer.pyw
- Highlight the shortcut press <CAPLOCK> learn as command
- name the new command something relevant, I chose command server
Now to open command server you can use the Enso command command server
[edit] Registry
One way to setup Command Server to run after Enso has started is to add a new value to the registry.
Messing about in the registry can be dangerous to your computers health and you shouldn't do it if you don't know what you're doing!
Warnings aside, it's a pretty simple process:
- open regedit
- <winkey> -> run -> regedit
- Navigate to HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
- Note: By starting at HKEY_CURRENT_USER this will only affect the current user, not all users.
- At this point Enso should've already been installed on your machine. If this is the case you should see an entry for it here named HumanizedEnso.
- Create a new String Value
- Right click -> New -> String Value
- Name it HumanizedEnsoCmdServ
- Note: It's important to name our new Command Server entry so that it appears alphabetically AFTER the HumanizedEnso entry. Doing so ensures Command Server will load after the default Enso application does.
- double click on our new value HumanizedEnsoCmdServ
- In the Value Data field type in <p-path>\pythonw25.exe <cs-path>\ensoCommandServer.pyw where <p-path> is the path to Pythons' install directory and <cs-path> is the path to Command Server
- Example: c:\Python25\pythonw25.exe c:\MyEnso\command_server\ensoCommandServer.pyw
Now next time you login Command Server will automatically start, horray!