diff options
author | Vamsi Krishna Davuluri <iwikiwi@localhost.localdomain> | 2009-06-06 09:31:03 (GMT) |
---|---|---|
committer | Vamsi Krishna Davuluri <iwikiwi@localhost.localdomain> | 2009-06-06 09:31:03 (GMT) |
commit | 041a1b0eee66085676744d95d0696d6c119f985e (patch) | |
tree | 7b0814f093a3a4d687a1caa8f5e99e0c73b8fb54 /printactivity.py | |
parent | 4c0575525582fb583899a4ab87673208e9e8d465 (diff) |
No more temp files clutter; added atexit
Diffstat (limited to 'printactivity.py')
-rw-r--r-- | printactivity.py | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/printactivity.py b/printactivity.py index 33b584c..ae1e3cd 100644 --- a/printactivity.py +++ b/printactivity.py @@ -39,6 +39,7 @@ from sugar.graphics.objectchooser import ObjectChooser from printscript import serverConnection from printtoolbar import PrintToolbar,DocumentToolbar, ReadToolbar, ViewToolbar from glib import GError +import atexit _HARDWARE_MANAGER_INTERFACE = 'org.laptop.HardwareManager' _HARDWARE_MANAGER_SERVICE = 'org.laptop.HardwareManager' @@ -227,7 +228,7 @@ class ReadActivity(activity.Activity): 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. @@ -305,6 +306,7 @@ 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) _logger.debug('PrintActivity._open_pdf: %s', self.pdf_file_path) @@ -314,15 +316,18 @@ class ReadActivity(activity.Activity): return filepathr + def _delete_pdf(self, doit = True): + os.remove(self.pdf_file_path) + + + def _save_pdf (self,button, file_path=None, title=None): + _logger.debug('the file path of temp is: %s', file_path) - if file_path == None: - file_path = self.document.split('file://')[1] - _logger.debug('the file path of temp is: %s', file_path) if title == None: title = self._jobject.metadata['title'] - + fileObject = datastore.create() act_meta = self._jobject.metadata fileObject.metadata['title'] = title @@ -337,9 +342,9 @@ class ReadActivity(activity.Activity): fileObject.file_path = os.path.join(self.get_activity_root(), 'instance', '%i' % time.time()) #, 'instance', '%i' % time.time()) - + _logger.debug('the file_path is %s',fileObject.file_path) # store the journal item - os.link(file_path, fileObject.file_path) + os.link(self.pdf_file_path, fileObject.file_path) datastore.write(fileObject, transfer_ownership=True) _logger.debug('this is the new path: %s',fileObject.file_path) fileObject.destroy() @@ -466,6 +471,7 @@ class ReadActivity(activity.Activity): 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._print_toolbar._pdf.props.sensitive = True self._want_document = False self._view.set_document(self._document) |