Commits

Jonathan Eunice committed 2ae50ee

cleaned up code, docs, setup, test

  • Participants
  • Parent commits 727ce01

Comments (0)

Files changed (4)

 The API is modeled on that of `xerox <http://pypi.python.org/pypi/xerox>`_,
 with simple ``copy()`` and ``paste()`` operations.  Think of
 ``paste()`` as pasting *into* your program and ``copy()`` as copying
-*from* your program.  
+*from* your program.
 
-If the API were more object-oriented, ``paste()`` would be something like
-``pasteboard.get_contents()`` and ``copy()`` would be something
-like ``pasteboard.set_contents()``.
+Alternative API
+===============
+
+If you prefer an object-oriented API to a functional one, use this::
+
+    from richxerox import pasteboard, dict_print
+    
+    print pasteboard.get_contents(format='html')    # paste
+    pasteboard.clear()                              # clear
+    pasteboard.set_contents(text="this is good!",   # copy
+                            html="this is <strong>good</strong>!")
+
+    dict_print(pasteboard.get_all_contents())       # pasteall
 
 Background
 ==========
 ``NSPasteboard`` class and ``UTI`` descriptors, and of how my programs will use
 the APIs.
 
+*Update* As of version 0.125, ``richxerox`` adds the object-oriented API
+previously only suggested in the documentation.
+
 Credits and References
 ======================
 

File richxerox.py

     pb = NSPasteboard.generalPasteboard()
     pb.clearContents()
 
+class Pasteboard(object):
+    """
+    A different way of packaging the copy/paste/clear functionality.
+    Came after the functional interface, so really is just a veneer on it.
+    """
+    
+    def available(self, *args, **kwargs):
+        return available(*args, **kwargs)
+    
+    def get_contents(self, *args, **kwargs):
+        return paste(*args, **kwargs)
+    
+    def get_all_contents(self, *args, **kwargs):
+        return pasteall(*args, **kwargs)
+    
+    def set_contents(self, *args, **kwargs):
+        return copy(*args, **kwargs)
+        
+    def clear(self, *args, **kwargs):
+        return clear(*args, **kwargs)
+
+
+pasteboard = Pasteboard()
 
 def dict_print(d, heading=None, wrap=True, **kwargs):
     """
             print '\n'.join(textwrap.wrap(item_text, **kwargs))
         else:
             print item_text
-    
-def demo_richxerox():
-    """
-    Let's try it out!
-    """
-    print available()
-    print paste()
-    dict_print(pasteall(), 'ALL CONTENTS')
-    
-    clear()
-    dict_print(pasteall(), 'AFTER CLEAR')
-    
-    copy(text="this is good!", html="this is <strong>good</strong>!")
-    dict_print(pasteall(), 'AFTER COPY')
-    
-if __name__ == '__main__':
-    demo_richxerox()
 #! /usr/bin/env python
 
 from setuptools import setup
+from decimal import Decimal
+import re
+
+def verno(s):
+    """
+    Update the version number passed in by extending it to the 
+    thousands place and adding 1/1000, then returning that result
+    and as a side-effect updating setup.py
+
+    Dangerous, self-modifying, and also, helps keep version numbers
+    ascending without human intervention.
+    """
+    d = Decimal(s)
+    increment = Decimal('0.001')
+    d = d.quantize(increment) + increment
+    dstr = str(d)
+    setup = open('setup.py', 'r').read()
+    setup = re.sub('verno\(\w*[\'"]([\d\.]+)[\'"]', 'verno("' + dstr + '"', setup)
+    open('setup.py', 'w').write(setup)
+    return dstr
+
 
 def linelist(text):
     """
 
 setup(
     name='richxerox',
-    version='0.12',
+    version=verno("0.126"),
     author='Jonathan Eunice',
     author_email='jonathan.eunice@gmail.com',
     description='copy/paste for Mac OS X for rich text (HTML/RTF) rather than plain text',
 from richxerox import *
 
 def test_clear():
+    print "\n\n--- test_clear() ---"
 
     clear()
     assert available() == []
     assert list(pasteall().keys()) == []
+    print "PASSED"
     
 def test_copypaste():
+    print "\n\n--- test_copypaste() ---"
+
     t0 = "this is good!"
     h0 = "this is <strong>good</strong>!"
 
     assert h == h0
     
     assert len(pasteall().keys()) == 2
+    print "PASSED"
+
+    
+def demo_richxerox():
+    """
+    Let's try it out!
+    """
+    print "\n\n--- demo_richxerox() ---"
+
+    print available()
+    print paste()
+    dict_print(pasteall(), 'ALL CONTENTS')
+    
+    clear()
+    dict_print(pasteall(), 'AFTER CLEAR')
+    
+    copy(text="this is good!", html="this is <strong>good</strong>!")
+    dict_print(pasteall(), 'AFTER COPY')
+    
+def demo_richxerox_oo():
+    print "\n\n--- demo_richxerox_oo() ---"
+    from richxerox import pasteboard
+    
+    
+    print pasteboard.get_contents(format='html')    # paste
+    pasteboard.clear()                              # clear
+    pasteboard.set_contents(text="this is good!",   # copy
+                            html="this is <strong>good</strong>!")
+    
+    dict_print(pasteboard.get_all_contents())       # pasteall
+
+    pb_text = pasteboard.get_contents(format='text')
+    
+    assert pb_text == "this is good!"
+    assert available() == pasteboard.available()
+    
     
 if __name__ == '__main__':
     test_clear()
-    test_copypaste()
+    test_copypaste()
+    demo_richxerox()
+    demo_richxerox_oo()