changeset 2:c28ae8f664ba

Removed a bunch of diagnostic or highly experimental commands. Also removed the PyXPCOM commands b/c I'm not running Enso on top of Firefox right now, but they're still stored in the repository for future use.
author Atul Varma <varmaa@toolness.com>
date Sun, 18 May 2008 00:31:26 -0700
parents 3924ba5f3621
children 9767abfe290b
files my-enso-commands.py
diffstat 1 files changed, 5 insertions(+), 219 deletions(-) [+]
line wrap: on
line diff
--- a/my-enso-commands.py	Sun May 18 00:25:03 2008 -0700
+++ b/my-enso-commands.py	Sun May 18 00:31:26 2008 -0700
@@ -10,36 +10,16 @@
 import logging
 from StringIO import StringIO
 
-def cmd_menu(ensoapi):
-    import AppKit
-    import Foundation
-
-    app = AppKit.NSApplication.sharedApplication()
-
-    mainMenu = AppKit.NSMenu.alloc().initWithTitle_("Main")
-    ensoMenu = AppKit.NSMenu.alloc().initWithTitle_("Boogy")
-
-    item = AppKit.NSMenuItem.alloc().init()
-    item.setTitle_("Boogy")
-    item.setSubmenu_(ensoMenu)
-    mainMenu.insertItem_atIndex_(item, 0)
-
-    app.setMainMenu_(mainMenu)
-    app.setServicesMenu_(ensoMenu)
-
-    app.registerServicesMenuSendTypes_returnTypes_(
-        [AppKit.NSStringPboardType],
-        []
-        )
-
-    ensoapi.display_message(str(app.mainMenu()))
-
 def cmd_define(ensoapi):
     import AppKit
 
     serviceName = "Look Up in Dictionary"
 
-    text = ensoapi.get_selection().get("text", "")
+    text = ensoapi.get_selection().get("text", "").strip()
+
+    if not text:
+        ensoapi.display_message("No text selection!")
+        return
 
     pb = AppKit.NSPasteboard.pasteboardWithName_("EnsoServiceContent")
 
@@ -54,169 +34,6 @@
     finally:
         pass
 
-def cmd_impersonate(ensoapi):
-    from xpcom import components
-
-    class MyEventHandler:
-        _com_interfaces_ = components.interfaces.nsIDOMEventListener
-
-        def __init__(self, corpus, author):
-            from nltk.probability import ConditionalFreqDist
-
-            cfd = ConditionalFreqDist()
-            prev_word = None
-            for word in corpus.words():
-                cfd[prev_word].inc(word)
-                prev_word = word
-
-            self._cfd = cfd
-            self._author = author
-            self._last_word = None
-
-        def handleEvent(self, event):
-            text = event.target.value[:event.target.selectionStart]
-            words = text.split()
-            if words and text[-1] == " ":
-                last_word = words[-1]
-                if last_word == self._last_word:
-                    return
-                self._last_word = last_word
-
-                #sorted = self._cfd[last_word].sorted()
-                suggestions = self._cfd[last_word].samples()
-                suggestions.sort(key=len, reverse=True)
-                suggestions = [sugg for sugg in suggestions
-                               if len(sugg) > 3]
-
-#                 if suggestions:
-#                     import random
-#                     suggestion = random.choice(suggestions)
-#                     cursor = event.target.selectionStart
-#                     event.target.value = event.target.value[:cursor] + suggestion + " " + event.target.value[cursor:]
-#                     cursor += len(suggestion) + 1
-#                     event.target.setSelectionRange(cursor, cursor)
-
-#                 suggestions = None
-                if suggestions:
-                    cc = components.classes
-                    asvc = cc["@mozilla.org/alerts-service;1"].getService(
-                        components.interfaces.nsIAlertsService
-                        )
-                    asvc.showAlertNotification(
-                        "http://www.mozilla.com/favicon.ico",
-                        "%s would say..." % self._author,
-                        ", ".join(suggestions[:10]),
-                        False,
-                        None,
-                        None,
-                        None,
-                        )
-
-    element = ensoapi.get_selection()["dom.element"]
-
-    #from nltk.corpus import gutenberg
-
-    #corpus, author = (gutenberg, "Project Gutenberg")
-    from nltk.corpus.reader.plaintext import PlaintextCorpusReader
-
-    corpus = PlaintextCorpusReader(
-        os.getenv("HOME"),
-        ["argon.txt"]
-        )
-    author = "Jim Theis"
-
-    element.addEventListener(
-        "keyup",
-         MyEventHandler(corpus, author),
-         False
-         )
-
-def cmd_extemporize(ensoapi):
-    element = ensoapi.get_selection().get("dom.element")
-
-    text = ""
-    if element:
-        text = element.value
-        words = text.split()
-        if words:
-            from nltk.corpus.reader.plaintext import PlaintextCorpusReader
-
-            corpus = PlaintextCorpusReader(
-                os.getenv("HOME"),
-                ["argon.txt"]
-                )
-
-            from nltk.probability import ConditionalFreqDist
-            import random
-
-            cfd = ConditionalFreqDist()
-            prev_word = None
-            for word in corpus.words():
-                cfd[prev_word].inc(word)
-                prev_word = word
-
-            last_word = words[-1]
-            new_words = []
-            for i in range(10):
-                potentials = cfd[last_word].samples()
-                if potentials:
-                    next_word = random.choice(potentials)
-                else:
-                    next_word = "Grignr"
-                new_words.append(next_word)
-                last_word = next_word
-            string = ""
-            for word in new_words:
-                if len(word) == 1 and not word.isalpha():
-                    string += "%s" % word
-                else:
-                    string += " %s" % word
-
-            element.value = text + string
-
-def getFuelApplication():
-    from xpcom import components
-    fuel_cls = components.classes["@mozilla.org/fuel/application;1"]
-    fuel_abs = fuel_cls.createInstance()
-    fuel_if = components.interfaces.fuelIApplication
-    return fuel_abs.queryInterface(fuel_if)
-
-def getXpcomObjInfo(thing):
-    thing._build_all_supported_interfaces_()
-    lines = []
-    for iname in thing._interface_names_:
-        methods = []
-        properties = []
-        for mname in thing._interface_names_[iname]._method_infos_:
-            if mname != "QueryInterface":
-                methods.append( "%s()" % mname )
-        for pname in thing._interface_names_[iname]._property_getters_:
-            properties.append( "%s" % pname )
-        lines.append("%s:" % iname)
-        if methods:
-            lines.extend(["  METHODS: %s" % ", ".join(methods)])
-        if properties:
-            lines.extend(["  PROPERTIES: %s" % ", ".join(properties)])
-    return "\n\n".join(lines)
-
-def cmd_info(ensoapi):
-    thing = getFuelApplication()
-    ensoapi.set_selection( {"text" : getXpcomObjInfo(thing)} )
-
-def cmd_highlight(ensoapi):
-    """
-    Highlights your current selection.
-    """
-
-    window = ensoapi.get_selection()["dom.window"]
-    document = window.document
-    sel = window.getSelection()
-    if sel.rangeCount >= 1:
-        range = sel.getRangeAt(0)
-        newNode = document.createElement("span")
-        newNode.style.background = "yellow"
-        range.surroundContents(newNode)
-
 def cmd_count_lines(ensoapi):
     seldict = ensoapi.get_selection()
     ensoapi.display_message( "Selection is %s lines." % 
@@ -387,21 +204,6 @@
             {"html":normal_template % text,
              "text":text} )
 
-def cmd_paste_html(ensoapi):
-    ensoapi.set_selection(
-        {"text":"u do not support html.",
-         "html":"<p>hai2u, <i>u support html</i>!</p>"}
-        )
-
-def cmd_get_pb_info(ensoapi):
-    import AppKit
-
-    pb = AppKit.NSPasteboard.generalPasteboard()
-
-    pbtypes = pb.types()
-    for string in pbtypes:
-        print "type: %s" % string
-
 def make_get_url_func(url):
     def get_url():
         import urllib2
@@ -967,22 +769,6 @@
 
 cmd_view.valid_args = KIRITSU_VIEWS
 
-def cmd_rest(ensoapi):
-    import sys
-
-    ensoapi.display_message( "please wait..." )
-    popen = subprocess.Popen(
-        [ sys.executable,
-          "-c", "import time;time.sleep(2.0)" ]
-        )
-    while popen.poll() is None:
-        yield
-    if popen.returncode == 0:
-        msg = "done!"
-    else:
-        msg = "an error occurred."
-    ensoapi.display_message( msg )
-
 def cmd_html_template(ensoapi):
     ensoapi.set_selection({"text" : HTML_TEMPLATE})