RazmjenaVjestina
EnsoExtensions: Revision 1

Napisao sam nekoliko dodatnih funkcija za Enso Launcher.[BR]
http://www.humanized.com[BR]
U potpunosti je ekstenzibilan app sa bilo kojim jezikom, [BR]
moj language of choice je python.
Ovo nikako nije sve, svaki dan se igram sa novim stvarima i [BR]
mjenjati ću sadržaj kako budem mjenjao kod.

Evo kako to izgleda za sada:

{{{
import xmlrpclib
import socket
from SimpleXMLRPCServer import SimpleXMLRPCServer
import threading
import webbrowser

socket.setdefaulttimeout( 10.0 )

class MyEnsoExtension:
    def __init__( self ):
        self.enso = xmlrpclib.ServerProxy( "http://127.0.0.1:11374" )
 

    def callCommand( self, commandName, postfix ):
        if commandName == "leetify":
            selectedText = self.enso.getUnicodeSelection()
            returnText = selectedText.replace('i','1',).replace('a','4').replace('e','3')
            returnText = returnText.replace('I','1').replace('o','0').replace('O','0')
            returnText = returnText.replace('t','7').replace('T','7')
            if returnText:
                self.enso.setUnicodeSelection( returnText, "leetify" )
            else:
                self.enso.displayMessage('<p>No text selection!</p>')
        elif commandName == "amazon {keyword}":
            self.enso.displayMessage('<p>Searching Amazon for \"'+ postfix + '\"...</p>')
            url = 'http://www.amazon.com/s?ie=UTF8&keywords=' + postfix + '&index=blended'
            webbrowser.open(url)
        elif commandName == "sms {name}":
            # do something here
            self.enso.displayMessage('<p>\"'+self.enso.getUnicodeSelection()+'\"\
sent to '+postfix.upper()+'</p>')
        elif commandName == "camel":
            selectedText = self.enso.getUnicodeSelection()
            if selectedText:
                returnText = ''
                for word in selectedText.split():
                    returnText += word.capitalize()
                self.enso.setUnicodeSelection(returnText,'camel')
            else:
                self.enso.displayMessage('<p>No text selection!</p>')
        else:
            raise AssertionError( "Unknown command name: %s" % \
                                   commandName )
        return True

def runMyExtensionServer():
    rpcServer = SimpleXMLRPCServer( ("127.0.0.1", 11375) )
    # We set the socket timeout to permit the server to be killed.
    rpcServer.socket.settimeout( 1.0 )
    rpcServer.register_instance( MyEnsoExtension() )
    rpcServer.serve_forever()

  1. Start the XML-RPC server

serverThread = threading.Thread( target = runMyExtensionServer )
serverThread.setDaemon( True )
serverThread.start()

  1. Register with Enso.

enso = xmlrpclib.ServerProxy( "http://127.0.0.1:11374" )
enso.registerCommand(
    "http://127.0.0.1:11375",
    "leetify",
    "Leetifies your currently selected text",
    "<p>This command transforms the current" \
    "text selection to the leet version of "\
    "that text.</p>",
    "none"
    )

enso.registerCommand(
    'http://127.0.0.1:11375',
    'amazon {keyword}',
    'Searches Amazon for keyword',
    '<p>This command will search Amazon '\
    'for the keyword.</p>',
    'arbitrary'
    )

enso.registerCommand(
    'http://127.0.0.1:11375',
    'sms {name}',
    'Sends SMS to {name} via VIP WebSMS',
    '<p>This command will look up a number by name '\
    'from the preset phonebook and send an SMS '\
    'to that number/person using the VIP WebSMS service.</p>',
    'bounded'
    )
enso.setCommandValidPostfixes('http://127.0.0.1:11375',
                              'sms {name}',
                             'marija', 'test','erik','mum' )

enso.registerCommand(
    "http://127.0.0.1:11375",
    "camel",
    "Transforms your currently selected text to CamelCase",
    "<p>This command transforms the current" \
    "text selection to the CamelCase version of "\
    "that text, removing whitespaces.</p>",
    "none"
    )

try:
    print "press enter to exit."
    raw_input()
finally:
    enso.unregisterCommand( "http://127.0.0.1:11375", "leetify" )
    enso.unregisterCommand( "http://127.0.0.1:11375", "amazon {keyword}" )
    enso.unregisterCommand( "http://127.0.0.1:11375", "sms {name}" )
    enso.unregisterCommand( "http://127.0.0.1:11375", "camel" )
}}}