diff options
Diffstat (limited to 'printscript.py')
-rwxr-xr-x[-rw-r--r--] | printscript.py | 59 |
1 files changed, 39 insertions, 20 deletions
diff --git a/printscript.py b/printscript.py index eb7f064..3695b25 100644..100755 --- a/printscript.py +++ b/printscript.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +# -*- coding: utf-8 -*- import gtk import gtkunixprint import logging @@ -38,31 +39,44 @@ class JustPrint: #self.printSettings. self.pgSetup = gtk.PageSetup() printerEnumerationObj = EnumeratePrinters() - self.printerObj = printerEnumerationObj.getPrinter()[1] + self.printerObj = printerEnumerationObj.getPrinters()[0] self._title = title self._filepath = filepath def printIt(self,): - cups = serverConnection() - cups._connect() - cups._print_Printer(self._filepath, self._title, self.printerObj) - #cups.close() - def setRange(self, textstring): - start, end = textstring.split('-',1) - self.printSettings.set_page_ranges([(int(start),int(end)),]) + printJob = PrintJob(self._title, self.printerObj, + self.printSettings, + self.pgSetup, self._filepath) + + def setRange(self, rangeList): + start = rangeList[0] + end = rangeList[1] + self.printSettings.set_page_ranges([(start-1,end-1,),]) + _logger.debug('the page ranges %s',self.printSettings.get_page_ranges()) + self.printSettings.set_print_pages(gtk.PRINT_PAGES_RANGES) def setPrinter(self, printer): self.printerObj = printer + + def getPrintSettings(self,): + return self.printSettings class EnumeratePrinters: def __init__(self,): - self.cups = serverConnection() - self.cups._connect() - self.printerList = self.cups._getPrintersList() - #self.cups.close() + self.printerList = [] + self.count = 0 + + loop = gtkunixprint.enumerate_printers(self.function,data=None, + wait=True) + + def function(self, printer, data=None): + #if printer.get_name() != _('Cups-PDF'): + _logger.debug(printer.get_name()) + self.printerList.append(printer) - def getPrinter(self,): + + def getPrinters(self,): return self.printerList class PrinterSetup(gtk.Dialog): @@ -205,7 +219,7 @@ class serverConnection: if self._location.find('${USER}') == -1: #Special Fedora case desktop = os.getenv("HOME")+'/.config/user-dirs.dirs' - #print desktop + #print "hello" try: f1 = open(desktop, 'r') except IOError: @@ -213,16 +227,17 @@ class serverConnection: _logger.debug("$DESKTOP isn't defined,\ so going to home directory") self._location = os.getenv("HOME") - f1.close() + _logger.debug('this is location 1 %s',self._location) else: self._location = os.getenv("HOME") for line in f1: - # print line[0:15] + #print line[0:15] if line[0:15] == 'XDG_'+folder+'_DIR': self._location = line[15:].rsplit('\n', 1)[0].strip('= "') self._location = self._location.replace('$HOME', os.getenv("HOME")) + _logger.debug('this is location2 %s',self._location) break @@ -233,10 +248,14 @@ class serverConnection: self._location = self._location.replace('${USER}', os.getenv("USER")) break #break to end 2nd for loop - - self._connection.printFile (_printer, _filename, _title, {}) - # break to end 1st for loop - return self._location+'/'+_title+'.pdf' + _logger.debug('this is location3 %s',self._location) + _title = _title.replace(")","_") + _title = _title.replace("(","_") + _title = _title.replace(" ","_") + self._connection.printFile (_printer, _filename, _title, {}) + + + return self._location + '/'+_title + '.pdf' def _print_Printer(self, filename, title, printer): |