Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/printscript.py
diff options
context:
space:
mode:
Diffstat (limited to 'printscript.py')
-rw-r--r--printscript.py96
1 files changed, 77 insertions, 19 deletions
diff --git a/printscript.py b/printscript.py
index 7c066c5..303aed2 100644
--- a/printscript.py
+++ b/printscript.py
@@ -1,5 +1,6 @@
#!/usr/bin/env python
-
+import gtk
+import gtkunixprint
import logging
import threading
import cups
@@ -11,9 +12,66 @@ import gtk
import os
import tempfile
import time
+import pygtk
_logger = logging.getLogger('print-activity:printscript')
+class PageSetup(gtk.Dialog):
+
+ def __init__(self, title=None,):
+ printDialog = gtkunixprint.PageSetupUnixDialog('Page Setup',
+ gtk.Window())
+ printDialog.show_all()
+ printDialog.connect('response',self.processResponse)
+
+ def processResponse(self, widget, settings):
+ _PAGE_SETUP = widget.get_page_setup()
+ widget.destroy()
+ return _PAGE_SETUP
+
+
+class PrinterSetup(gtk.Dialog):
+
+ def __init__(self,title, filepath):
+ printDialog = gtkunixprint.PrintUnixDialog('Printer Settings',
+ gtk.Window())
+ printDialog.show_all()
+ printDialog.connect('response',self.processResponse,title,filepath)
+
+ def processResponse(self, widget, settings,title,filepath):
+ _PRINT_SETTINGS = widget.get_settings()
+ _PRINTER = widget.get_selected_printer()
+ print _PRINTER.get_name()
+ widget.destroy()
+ pgSetup = self.getDefaultPageLayout()
+
+ if settings == -5:
+ PrintJobObj = PrintJob(title, _PRINTER,
+ _PRINT_SETTINGS,
+ pgSetup, filepath)
+
+ def getDefaultPageLayout(self,):
+ pgSetup = gtk.PageSetup()
+ return pgSetup
+
+
+
+
+class PrintJob:
+ def __init__(self, title=None,
+ printer=None,
+ settings=None,
+ page_setup=None,
+ file_path=None):
+
+ printJob = gtkunixprint.PrintJob(title,printer,
+ settings, page_setup)
+ printJob.set_source_file(file_path)
+ printJob.send(self.printDone)
+
+ def printDone(self, arg1, arg2, arg3):
+ pass
+
class serverConnection:
def __init__ (self, host=None, port=None, encryption=None, lock=False):
@@ -38,7 +96,7 @@ class serverConnection:
self._lock = lock
self._gui_event = threading.Event ()
self.jobid = []
- print self._server
+ #print self._server
def _connect (self,):
cups.setUser (self._use_user)
@@ -49,7 +107,7 @@ class serverConnection:
encryption=self._encryption)
except RuntimeError:
_logger.debug("check if cups server is functioning properly")
- print ('hey i messed up')
+ # print ('hey i messed up')
return 1
def _getTitle(self,_filepath):
@@ -57,17 +115,17 @@ class serverConnection:
return title
def _getPrintersList (self,):
- _dictPrinters = self._connection.getPrinters ()
+ self._dictPrinters = self._connection.getPrinters()
_thePrinters = self._dictPrinters.keys()
- return self._thePrinters
+ return _thePrinters
def _getPrinterURI (self, name):
- _dictPrinters = self._connection.getPrinters ()
+ self._dictPrinters = self._connection.getPrinters ()
_printerURI = self._dictPrinters[name]['device-uri']
- return self._printerURI
+ return _printerURI
def _getDefaultPrinter (self,):
- _defaultPrinter = self._connection.getDefault ()
+ self._defaultPrinter = self._connection.getDefault ()
return self._defaultPrinter
def _setPrintDevice (self, device = None, uri = None ):
@@ -95,14 +153,14 @@ class serverConnection:
for printer in theprinters:
if self._getPrinterURI(printer) == u'cups-pdf:/':
_printer = printer
- break
+
# Now we have the printer at hand
#lets open the config files and check the paths, and if user Directories are enabled
#Check for the paths, if a default $USER path exists, skip the condition and just use
#that if not go to user.dir, and also, that particular definition does not exist, use
#home dir, as it defaults to that
- print _printer
+ # print _printer
f = open('/etc/cups/cups-pdf.conf', 'r')
for line in f:
if line[0:3] == 'Out':
@@ -111,7 +169,7 @@ class serverConnection:
if self._location.find('${USER}') == -1: #Special Fedora case
desktop = os.getenv("HOME")+'/.config/user-dirs.dirs'
- print desktop
+ #print desktop
try:
f1 = open(desktop, 'r')
except IOError:
@@ -122,7 +180,7 @@ class serverConnection:
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"))
@@ -130,15 +188,15 @@ class serverConnection:
f1.close()
- print self._location
+ #print self._location
else:
self._location = self._location.replace('${USER}', os.getenv("USER"))
break #break to end 2nd for loop
- f.close()
- print _printer
- print _filename
- print _title
+
+ #print _printer
+ #print _filename
+ #print _title
self._connection.printFile (_printer, _filename, _title, {})
break # break to end 1st for loop
return self._location+'/'+_title+'.pdf'
@@ -196,5 +254,5 @@ class serverConnection:
#hello = serverConnection()
-#hello._printPDF('Cups-PDF','/home/iwikiwi/hello.odt','lolmax')
-
+#lol = hello._printPDF('Cups-PDF','/home/iwikiwi/lolmax.odt','lolmax')
+#print '\''+ lol + '\''