diff options
author | iwikiwi <iwikiwi@localhost.localdomain> | 2009-06-30 06:30:26 (GMT) |
---|---|---|
committer | iwikiwi <iwikiwi@localhost.localdomain> | 2009-06-30 06:30:26 (GMT) |
commit | 1d5d2e992192d79d6e90dd13da4a566bc9cc66ef (patch) | |
tree | d5b11b525c68ecee3af4c99327cbdd8dc31e324b /printscript.py | |
parent | 56b0fb8b6e01540f36b32236cdc6b064346bae6b (diff) |
A gtk version of printscript.py; A cups verion of printscript.py, final version of printerdeviceicon, allworking
Diffstat (limited to 'printscript.py')
-rw-r--r-- | printscript.py | 69 |
1 files changed, 56 insertions, 13 deletions
diff --git a/printscript.py b/printscript.py index 303aed2..eb7f064 100644 --- a/printscript.py +++ b/printscript.py @@ -30,9 +30,44 @@ class PageSetup(gtk.Dialog): return _PAGE_SETUP + +class JustPrint: + + def __init__(self, title, filepath): + self.printSettings = gtk.PrintSettings() + #self.printSettings. + self.pgSetup = gtk.PageSetup() + printerEnumerationObj = EnumeratePrinters() + self.printerObj = printerEnumerationObj.getPrinter()[1] + 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)),]) + + def setPrinter(self, printer): + self.printerObj = printer + +class EnumeratePrinters: + + def __init__(self,): + self.cups = serverConnection() + self.cups._connect() + self.printerList = self.cups._getPrintersList() + #self.cups.close() + + def getPrinter(self,): + return self.printerList + class PrinterSetup(gtk.Dialog): - def __init__(self,title, filepath): + def __init__(self, title, filepath): printDialog = gtkunixprint.PrintUnixDialog('Printer Settings', gtk.Window()) printDialog.show_all() @@ -41,7 +76,7 @@ class PrinterSetup(gtk.Dialog): def processResponse(self, widget, settings,title,filepath): _PRINT_SETTINGS = widget.get_settings() _PRINTER = widget.get_selected_printer() - print _PRINTER.get_name() + #print _PRINTER.get_name() widget.destroy() pgSetup = self.getDefaultPageLayout() @@ -148,9 +183,10 @@ class serverConnection: # we require our script to not look up the editable names of the printing devices, # but look up the unchangeable URI of the printer, so we do this: - theprinters = self._getPrintersList () + theprinters = self._getPrintersList() self._location = '' for printer in theprinters: + #print printer if self._getPrinterURI(printer) == u'cups-pdf:/': _printer = printer @@ -174,7 +210,8 @@ class serverConnection: f1 = open(desktop, 'r') except IOError: - _logger.debug("$DESKTOP isn't defined, so going to home directory") + _logger.debug("$DESKTOP isn't defined,\ + so going to home directory") self._location = os.getenv("HOME") f1.close() else: @@ -182,8 +219,10 @@ class serverConnection: for line in f1: # 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")) + self._location = line[15:].rsplit('\n', + 1)[0].strip('= "') + self._location = self._location.replace('$HOME', + os.getenv("HOME")) break @@ -191,15 +230,17 @@ class serverConnection: #print self._location else: - self._location = self._location.replace('${USER}', os.getenv("USER")) + self._location = self._location.replace('${USER}', + os.getenv("USER")) break #break to end 2nd for loop - #print _printer - #print _filename - #print _title - self._connection.printFile (_printer, _filename, _title, {}) - break # break to end 1st for loop - return self._location+'/'+_title+'.pdf' + self._connection.printFile (_printer, _filename, _title, {}) + # break to end 1st for loop + return self._location+'/'+_title+'.pdf' + + + def _print_Printer(self, filename, title, printer): + self._connection.printFile (printer, filename, title, {}) def _printtoPrinter (self,_filename, _title=None): if _title == None: @@ -209,6 +250,7 @@ class serverConnection: self._connection.printFile (printer, _filename, _title, {}) return True return False + def _selectDefaultPrinter (self,_printer): self._connection.setDefault(_printer) @@ -252,6 +294,7 @@ class serverConnection: +#printer = JustPrint('lolmax','/home/iwikiwi/lolmax.odt') #hello = serverConnection() #lol = hello._printPDF('Cups-PDF','/home/iwikiwi/lolmax.odt','lolmax') |