changeset 8:19fd067db7ca

Added Windows support
author Ben Croston
date Mon, 15 Aug 2011 00:20:31 +0100
parents 0687a6666873
children 19a28a953f39
files README setup.py zebra.py
diffstat 3 files changed, 30 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/README	Sat Aug 13 08:37:53 2011 +0100
+++ b/README	Mon Aug 15 00:20:31 2011 +0100
@@ -1,10 +1,9 @@
 ============
-Zebra-0.0.1a
+Zebra-0.0.2a
 ============
 
 Note:
 
-- Windows support is not yet available but is currently being developed.
 - Mac OSX may already be supported but has not been tested
 
 Usage:
@@ -28,4 +27,3 @@
 
     z.output(commands)
        - Output EPL2 commands to the printer
-
--- a/setup.py	Sat Aug 13 08:37:53 2011 +0100
+++ b/setup.py	Mon Aug 15 00:20:31 2011 +0100
@@ -3,14 +3,15 @@
 from distutils.core import setup
 
 try:
-   from distutils.command.build_py import build_py_2to3 as build_py
+    from distutils.command.build_py import build_py_2to3 as build_py
 except ImportError:
-   from distutils.command.build_py import build_py
+    from distutils.command.build_py import build_py
 
 classifiers = ['Development Status :: 3 - Alpha',
                'Operating System :: Microsoft :: Windows',
                'Operating System :: Unix',
                'License :: OSI Approved :: MIT License',
+               'Programming Language :: Python',
                'Programming Language :: Python :: 2.7',
                'Programming Language :: Python :: 3',
                'Topic :: Printing']
@@ -19,17 +20,21 @@
 
 if sys.platform.lower().startswith('win'):
     requires = ['win32print']
+    try:
+        import win32print
+    except:
+        raise Exception('Requires the win32print module from the pywin32 package')
 else:
     requires = []
 
 setup(name             = 'zebra',
-      version          = '0.0.1a',
+      version          = '0.0.2a',
       py_modules       = ['zebra'],
       author           = 'Ben Croston',
       author_email     = 'ben@croston.org',
       maintainer       = 'Ben Croston',
       maintainer_email = 'ben@croston.org',
-#      url              = 'http://www.wyre-it.co.uk/zebra/',
+      url              = 'http://www.wyre-it.co.uk/zebra/',
       description      = 'A package to communicate with (Zebra) label printers using EPL2',
       long_description = long_description,
       platforms        = 'Windows, Unix',
--- a/zebra.py	Sat Aug 13 08:37:53 2011 +0100
+++ b/zebra.py	Mon Aug 15 00:20:31 2011 +0100
@@ -24,7 +24,22 @@
         p.stdin.close()
 
     def _output_win(self, commands):
-        raise Exception('Not yet implemented')
+        if self.queue == 'zebra_python_unittest':
+            print commands
+            return
+        if type(commands) != bytes:
+            commands = str(commands).encode()
+        hPrinter = win32print.OpenPrinter(self.queue)
+        try:
+            hJob = win32print.StartDocPrinter(hPrinter, 1, ('Label',None,'RAW'))
+            try:
+                win32print.StartPagePrinter(hPrinter)
+                win32print.WritePrinter(hPrinter, commands)
+                win32print.EndPagePrinter(hPrinter)
+            finally:
+                win32print.EndDocPrinter(hPrinter)
+        finally:
+            win32print.ClosePrinter(hPrinter)
     
     def output(self, commands):
         assert self.queue is not None
@@ -42,7 +57,10 @@
         return queues
 
     def _getqueues_win(self):
-        raise Exception('Not yet implemented')
+        printers = []
+        for (a,b,name,d) in win32print.EnumPrinters(win32print.PRINTER_ENUM_LOCAL):
+            printers.append(name)
+        return printers
 
     def getqueues(self):
         if sys.platform.lower().startswith('win'):