changeset 7:41bc59775872

wow, haven't committed changes in a long time.
author Atul Varma <varmaa@toolness.com>
date Sat, 27 Mar 2010 12:19:32 -0700
parents c41c4896c97e
children 4285e37bea69
files my-enso-commands.py
diffstat 1 files changed, 63 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/my-enso-commands.py	Wed Aug 20 11:10:05 2008 -0700
+++ b/my-enso-commands.py	Sat Mar 27 12:19:32 2010 -0700
@@ -58,10 +58,12 @@
     import AppKit
 
     pb = AppKit.NSPasteboard.generalPasteboard()
+    typestr = pb.availableTypeFromArray_([AppKit.NSTIFFPboardType,
+                                          AppKit.NSPICTPboardType])
     tiffbytes = None
-    if pb.availableTypeFromArray_([AppKit.NSTIFFPboardType]):
+    if typestr == AppKit.NSTIFFPboardType:
         tiffbytes = pb.dataForType_(AppKit.NSTIFFPboardType).bytes()
-    elif pb.availableTypeFromArray_([AppKit.NSPICTPboardType]):
+    elif typestr == AppKit.NSPICTPboardType:
         img = AppKit.NSImage.alloc().initWithPasteboard_(pb)
         tiffbytes = img.TIFFRepresentation().bytes()
 
@@ -74,6 +76,7 @@
         import Image
 
         datafile = _get_clipboard_img_datafile()
+
         if datafile:
             img = Image.open(datafile)
             return func(ensoapi, img)
@@ -353,7 +356,7 @@
 
         webbrowser.open( self._url_template % {"query" : query} )
 
-cmd_wiki = WebSearchCmd("http://en.wikipedia.org/wiki/%(query)s")
+cmd_wiki = WebSearchCmd("http://en.wikipedia.org/wiki/Special:Search?search=%(query)s")
 cmd_wowhead = WebSearchCmd("http://www.wowhead.com/?search=%(query)s")
 cmd_amaz = WebSearchCmd("http://www.amazon.com/exec/obidos/search-handle-url/index%%3Dblended%%26field-keywords%%3D%(query)s%%26store-name%%3Dall-product-search")
 cmd_yp = WebSearchCmd("http://local.google.com/local?sc=1&q=%(query)s&near=2418+washington+94115&btnG=Google+Search")
@@ -636,6 +639,18 @@
     os.remove(source_name)
     os.remove(output_name)
 
+def cmd_wow_firefox(ensoapi):
+    popen = subprocess.Popen(["/Users/varmaa/bin/wow-firefox"])
+
+def cmd_work_firefox(ensoapi):
+    popen = subprocess.Popen(["/Users/varmaa/bin/work-firefox"])
+
+def cmd_mozpics_firefox(ensoapi):
+    popen = subprocess.Popen(["/Users/varmaa/bin/mozpics-firefox"])
+
+def cmd_firefox(ensoapi):
+    popen = subprocess.Popen(["/Users/varmaa/bin/personal-firefox"])
+
 def cmd_nosetest(ensoapi):
     """
     runs nosetests on the selected region of python code.
@@ -684,6 +699,49 @@
     os.remove(source_name)
     os.remove(output_name)
 
+def cmd_markdown_to_html(ensoapi):
+    """
+    Converts the plaintext markdown selection to plaintext
+    HTML source.
+    """
+
+    import markdown2
+    text = ensoapi.get_selection().get("text", "")
+    html = markdown2.markdown(text)
+    ensoapi.set_selection({"text": html})
+
+def cmd_unquote(ensoapi):
+    """
+    Removes a '<' at the beginning of every line.
+    """
+
+    text = ensoapi.get_selection().get("text", "")
+    lines = ["%s\n" % line[2:]
+             for line in text.splitlines()
+             if line.startswith("> ")]
+    ensoapi.set_selection({"text": ''.join(lines)})
+    
+def cmd_quote(ensoapi):
+    """
+    Puts a '>' at the beginning of every line.
+    """
+
+    text = ensoapi.get_selection().get("text", "")
+    lines = ["> %s\n" % line
+             for line in text.splitlines()]
+    ensoapi.set_selection({"text": ''.join(lines)})
+
+def cmd_markdown(ensoapi):
+    """
+    Converts the plaintext markdown selection to rich text.
+    """
+
+    import markdown2
+    text = ensoapi.get_selection().get("text", "")
+    html = markdown2.markdown(text)
+    ensoapi.set_selection({"html": html,
+                           "text": text})
+
 def cmd_insert_html(ensoapi):
     ensoapi.set_selection( {"html":"<b>hi</b> <p>there</p>"} )
 
@@ -787,9 +845,7 @@
     ensoapi.set_selection({"text" : HTML_TEMPLATE})
 
 HTML_TEMPLATE = """\
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
-          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<html>
 <head>
   <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
   <link rel="stylesheet" type="text/css" media="all"
@@ -799,6 +855,6 @@
 <body>
 
 </body>
-<script type="text/javascript" src=""></script>
+<script src=""></script>
 </html>
 """