diff options
Diffstat (limited to 'printactivity.py')
-rw-r--r-- | printactivity.py | 59 |
1 files changed, 23 insertions, 36 deletions
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: |