From 56b0fb8b6e01540f36b32236cdc6b064346bae6b Mon Sep 17 00:00:00 2001 From: root Date: Sat, 27 Jun 2009 14:09:11 +0000 Subject: fixed printscript.py fixed odftops filter added gtkunixprint dialog trimmed down some unnecessary code --- diff --git a/odftops-filter/odftops b/odftops-filter/odftops index cc63c22..9593e66 100644..100755 --- a/odftops-filter/odftops +++ b/odftops-filter/odftops @@ -9,11 +9,9 @@ fn="$6" #for our subshell convenience -sandbox1="${TMPDIR1:-/tmp}/tempcups.$$" -(umask 077 && mkdir "$sandbox1") || exit 1 - - # we are creating a dummy folder, which can take different file types. +sandbox1="${TMPDIR1:-/tmp}/cups-temp.$$" +(umask 077 && mkdir "$sandbox1") || exit 1 sandbox="${TMPDIR:-/tmp}/cups-odftops.$$" (umask 077 && mkdir "$sandbox") || exit 1 @@ -21,8 +19,7 @@ sandbox="${TMPDIR:-/tmp}/cups-odftops.$$" #The condition which checks whether our abiword is 2.6.6+ or 2.6.6- -$(abiword --to="$sandbox1/temp123.doc" "$fn") - +`abiword --to="$sandbox1/temp123.doc" "$fn"` > "$sandbox/errorinfo.txt" if [ "$?" -ne 0 ]; then @@ -37,30 +34,28 @@ then abiword --to="ps" "$fn1" - fn2="`echo "$fn1" | sed -e 's/odt$/ps/' `" - + fn2="$sandbox/temp123.ps" else #check if our version doesn't require an intermediate conversion, #if it does, do it - $(abiword --to="$sandbox1/temp123.ps" "$fn") + `abiword --to="$sandbox1/temp123.ps" "$fn"` > "$sandbox/errorinfo.txt" if [ "$?" -ne 0 ]; then - + abiword --to="$sandbox/temp123.ps" "$sandbox1/temp123.doc" - + fn2="$sandbox/temp123.ps" + else - - fn2="$sandbox1/temp123.ps" - fi - + fn2="$sandbox1/temp123.ps" + fi fi cat "$fn2" #remove the sandbox folder, for debugging purposes check by commenting the following line and see what is in the /tmp/ folder rm -rf $sandbox -rm -rf $sandbox1 +rm -rf $sandbox1 \ No newline at end of file diff --git a/printactivity.py b/printactivity.py index 2a72303..8d93d58 100644 --- a/printactivity.py +++ b/printactivity.py @@ -37,7 +37,8 @@ from sugar.datastore import datastore from sugar.graphics.objectchooser import ObjectChooser from printscript import serverConnection -from printtoolbar import PrintToolbar,DocumentToolbar, ReadToolbar, ViewToolbar +from printtoolbar import PrintToolbar, \ +ReadToolbar, ViewToolbar from glib import GError import atexit @@ -125,22 +126,11 @@ class ReadActivity(activity.Activity): self._print_toolbar = PrintToolbar(self._view) self._print_toolbar._pdf.connect('clicked',self._save_pdf) - self._print_toolbar._moodle.connect('clicked',self._send_to_moodle) - self._print_toolbar._moodle.props.sensitive = True + self._print_toolbar._USB.props.sensitive = True toolbox.add_toolbar(_('Print'), self._print_toolbar) self._print_toolbar.show() - self._document_toolbar = DocumentToolbar(self._view) - self._document_toolbar._open.connect('clicked',self._show_journal_object_picker) - self._document_toolbar._close.connect('clicked',self._close_file) - if self._document == None: - self._document_toolbar._open.props.sensitive = True - else: - self._document_toolbar._close.props.sensitive = True - toolbox.add_toolbar(_('Documents'), self._document_toolbar) - self._document_toolbar.show() - self._read_toolbar = ReadToolbar(self._view) toolbox.add_toolbar(_('Read'), self._read_toolbar) self._read_toolbar.show() @@ -229,9 +219,6 @@ class ReadActivity(activity.Activity): # uncomment this and adjust the path for easier testing #else: # self._load_document('file:///home/smcv/tmp/test.pdf') - def _close_file(self, button=None): - self._document_toolbar._close.props.sensitive = False - self.delete() def _show_journal_object_picker(self, button=None): """Show the journal object picker to load a document. @@ -301,8 +288,6 @@ class ReadActivity(activity.Activity): if not os.path.isfile(self._tempfile): os.link(file_path,self._tempfile) self._load_document('file://' + self._tempfile, file_path) - self._document_toolbar._open.props.sensitive = False - self._document_toolbar._close.props.sensitive = True # FIXME: This should obviously be fixed properly gobject.timeout_add(1000, self.__view_toolbar_needs_update_size_cb, None) @@ -311,27 +296,24 @@ class ReadActivity(activity.Activity): def _open_pdf(self, file_path, title, save=None): self._connection = serverConnection () atexit.register(self._delete_pdf) - self.pdf_file_path = self._connection._printPDF (CUPS_PDF, file_path) - sleep(.5) + self.pdf_file_path = self._connection._printPDF (CUPS_PDF, file_path, + title) + sleep(1) _logger.debug('PrintActivity._open_pdf: %s', self.pdf_file_path) + os.remove(self._tempfile) os.link(self.pdf_file_path, self._tempfile) filepathr = 'file://' + self._tempfile - + _logger.debug('PrintActivity._open_pdf: %s', filepathr) return filepathr def _delete_pdf(self, doit = True): - os.remove(self.pdf_file_path) - - def _send_to_moodle(self,host = None): - rpc_server = xmlrpclib.ServerProxy("http://localhost/~iwikiwi/moodle/mod/assignment/rpclib.php") - #rpc_server.transport.send_content(self.pdf_file_path) - #pdf_fd = xmlrpclib.Binary(open(self.pdf_file_path).read()) - #rpc_server.assignment.mnet_concatenate_strings_RPC_OK() - #_logger.debug('send to moodle %s',rpc_server.greeting('iwikiwi')) - _logger.debug('moodle login %s',rpc_server.login('iwikiwi','dbzdbz')) - #rpc_server.loadpdf(pdf_fd) - + try: + os.remove(self.pdf_file_path) + except OSError: + pass + + def _save_pdf (self,button, file_path=None, title=None): _logger.debug('the file path of temp is: %s', file_path) @@ -351,7 +333,7 @@ class ReadActivity(activity.Activity): fileObject.metadata['share-scope'] = act_meta['share-scope'] - fileObject.file_path = os.path.join(self.get_activity_root(), 'instance', '%i' % time.time()) #, 'instance', '%i' % time.time()) + fileObject.file_path = os.path.join(self.get_activity_root(), 'instance', '%i' % time.time()) _logger.debug('the file_path is %s',fileObject.file_path) # store the journal item os.link(self.pdf_file_path, fileObject.file_path) @@ -476,17 +458,22 @@ class ReadActivity(activity.Activity): """ try: + self._document = evince.factory_get_document(filepath) except GError: - self._document = self._open_pdf (file_path, self._jobject.metadata['title']) - _logger.debug('the file path is: %s', self._document) - self._document = evince.factory_get_document(self._document) + self._title = self._jobject.metadata['title'] + document = self._open_pdf(file_path, self._title) + _logger.debug('the file path is: %s', document) + self._document = evince.factory_get_document(document) self._print_toolbar._pdf.props.sensitive = True self._want_document = False self._view.set_document(self._document) self._read_toolbar.set_document(self._document) + self._print_toolbar.setTitlePath(self._title,self._tempfile) + + if not self.metadata['title_set_by_user'] == '1': info = self._document.get_info() if info and info.title: 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 + '\'' diff --git a/printtoolbar.py b/printtoolbar.py index 5f3ff5f..2132b16 100644 --- a/printtoolbar.py +++ b/printtoolbar.py @@ -27,7 +27,7 @@ from sugar.graphics.toolbutton import ToolButton from sugar.graphics.menuitem import MenuItem from sugar.graphics import iconentry from sugar.activity import activity -from printscript import serverConnection +from printscript import * @@ -36,14 +36,14 @@ class PrintToolbar(gtk.Toolbar): __gtype_name__= 'PrintToolbar' - def __init__(self, evince_view): + def __init__(self, evince_view, title=None, tempfile=None): gtk.Toolbar.__init__(self) - + self._evince_view = evince_view self._document = None - self._pdf = ToolButton() + self._pdf = ToolButton('document-save') self._pdf.set_tooltip(_('save-PDF')) self._pdf.props.sensitive = False self.insert(self._pdf, -1) @@ -55,38 +55,21 @@ class PrintToolbar(gtk.Toolbar): self.insert(self._moodle, -1) self._moodle.show() - - - - -class DocumentToolbar(gtk.Toolbar): - __gtype_name__= 'DocumentToolbar' - - - def __init__(self, evince_view): - gtk.Toolbar.__init__(self) - - self._evince_view = evince_view - self._document = None - + self._USB = ToolButton('printer') + self._USB.set_tooltip(_('printer')) + self._USB.props.sensitive = False + self.insert(self._USB, -1) + self._USB.show() - self._open = ToolButton() - self._open.set_tooltip(_('Open')) - self._open.props.sensitive = False - #self._open.connect('clicked', self._show_journal_object_picker) - self.insert(self._open, -1) - self._open.show() + self._USB.connect('clicked', self.printing) - self._close = ToolButton() - self._close.set_tooltip(_('Close')) - self._close.props.sensitive = False - #self._close.connect('clicked', self._close_a_doc) - self.insert(self._close, -1) - self._close.show() - - - - + def printing(self, widget): + printdialog = PrinterSetup(self._title, self._path) + + def setTitlePath(self, title, path): + self._title = title + self._path = path + class ReadToolbar(gtk.Toolbar): __gtype_name__ = 'ReadToolbar' -- cgit v0.9.1