def save_document (self, * arg): if self.data.key is None: self.save_document_as () return file = self.data.key.url [2] if not self.modification_check (): return Utils.set_cursor (self.w, 'clock') try: try: self.data.update (self.selection.sort) except (OSError, IOError), error: Utils.set_cursor (self.w, 'normal') self.w.error (_("Unable to save `%s':\n%s") % (str (self.data.key), str (error))) return except: etype, value, tb = sys.exc_info () traceback.print_exception (etype, value, tb) Utils.set_cursor (self.w, 'normal') self.w.error (_("An internal error occured during saving\nTry to Save As...")) return Utils.set_cursor (self.w, 'normal') # get the current modification date self.modification_date = os.stat (file) [stat.ST_MTIME] self.update_status (0) return
def save_document (self, * arg): if self.data.key is None: self.save_document_as () return file = self.data.key.url [2] if not self.modification_check (): return Utils.set_cursor (self.w, 'clock') try: try: self.data.update (Sort.Sort([Sort.KeySort()])) except (OSError, IOError), error: Utils.set_cursor (self.w, 'normal') Utils.error_dialog_s(_(u"Unable to save “%s”:\n%s") % (str (self.data.key), str (error))) return except: etype, value, tb = sys.exc_info () traceback.print_exception (etype, value, tb) Utils.set_cursor (self.w, 'normal') Utils.error_dialog_s(_(u"An internal error occurred during saving\nTry to Save As…")) return Utils.set_cursor (self.w, 'normal') # get the current modification date self.modification_date = os.stat (file) [stat.ST_MTIME] self.update_status (0) return
def close_document_request (self): answer = self.confirm () # remove autosave object with closing if answer and self.source_id: gobject.source_remove (self.source_id) # remove old autosave file if answer and self.data.key: if self.data.key.url [0] == 'file': old_file = self.data.key.url [2] old_auto_save = os.path.join (os.path.dirname (old_file), 'x-pyblio-save-' + os.path.basename (old_file)) if os.path.exists (old_auto_save): try: os.remove (old_auto_save) except (OSError, IOError), error: Utils.set_cursor (self.w, 'normal') self.w.error (_("Unable to remove autosave file `%s':\n%s") % (str (old_auto_save), str (error))) return
def close_document_request (self): answer = self.confirm () # remove autosave object with closing if answer and self.source_id: gobject.source_remove (self.source_id) # remove old autosave file if answer and self.data.key: if self.data.key.url [0] == 'file': old_file = self.data.key.url [2] old_auto_save = os.path.join (os.path.dirname (old_file), 'x-pyblio-save-' + os.path.basename (old_file)) if os.path.exists (old_auto_save): try: os.remove (old_auto_save) except (OSError, IOError), error: Utils.set_cursor (self.w, 'normal') Utils.error_dialog_s(_(u"Unable to remove autosave file “%s”:\n%s") % (str (old_auto_save), str (error))) return
def open_document (self, url, how = None, no_name = False): Utils.set_cursor (self.w, 'clock') orig_url = Fields.URL (url) url = orig_url.get_url () restore = False if orig_url.url [0] == 'file': name = orig_url.url [2] auto_save = os.path.join (os.path.dirname (name), 'x-pyblio-save-' + os.path.basename (name)) if os.path.exists (auto_save): mod_date = os.stat (name) [stat.ST_MTIME] mod_date_auto = os.stat (auto_save) [stat.ST_MTIME] if mod_date < mod_date_auto: restore = Utils.Callback (_("An autosave file was found which is newer than the original file.\nDo you want to restore it?"), self.w).answer () if restore: url = auto_save try: data = Open.bibopen (url, how = how) except (Exceptions.ParserError, Exceptions.FormatError, Exceptions.FileError, Exceptions.DateError), error: Utils.set_cursor (self.w, 'normal') Utils.error_dialog (_("Open error"), error, parent = self.w) return
def display(self, iterator): # clear the access table self.access = [] Utils.set_cursor(self.w, 'clock') self.model.clear() for entry in iterator: row = [] i = 0 for f in self.fields: row.append(i) i = i + 1 if f == '-key-': row.append((str(entry.key.key)).decode('latin-1')) elif f == '-type-': row.append(str(entry.type.name)) ## ascii elif f == '-author/editor-': row.append( userformat.author_editor_format(entry).decode( 'latin-1')) elif f == '-author/title-': row.append( userformat.author_title_format(entry).decode( 'latin-1')) elif entry.has_key(f): if Types.get_field(f).type == Fields.AuthorGroup: text = join(map(lambda a: str(a.last), entry[f]), ', ') elif Types.get_field(f).type == Fields.Date: text = str(entry[f].year) else: text = str(entry[f]) row.append(text.decode('latin-1')) else: row.append('') if True: row.append(i) if Resource.is_viewable(entry): row.append(self.gvpixbuf) else: row.append(None) iter = self.model.append() apply(self.model.set, [iter] + row) self.access.append(entry) entry = iterator.next() Utils.set_cursor(self.w, 'normal') return
# remove the old autosave object if self.data.key is not None and self.source_id: gobject.source_remove (self.source_id) # remove old autosave file if exists if self.data.key: if self.data.key.url [0] == 'file': old_file = self.data.key.url [2] old_auto_save = os.path.join (os.path.dirname (old_file), 'x-pyblio-save-' + os.path.basename (old_file)) if os.path.exists (old_auto_save): try: os.remove (old_auto_save) except (OSError, IOError), error: Utils.set_cursor (self.w, 'normal') self.w.error (_("Unable to remove autosave file `%s':\n%s") % (str (old_auto_save), str (error))) return Utils.set_cursor (self.w, 'normal') if no_name: data.key = None self.data = data if restore: # restore the original url internally, # and change the document status
def display (self, iterator): # clear the access table self.access = [] Utils.set_cursor (self.w, 'clock') self.model.clear () for entry in iterator: row = [] i = 0 for f in self.fields: row.append (i) i = i + 1 if f == '-key-': row.append ((str (entry.key.key)).decode ('latin-1')) elif f == '-type-': row.append (str (entry.type.name)) ## ascii elif f == '-author/editor-': row.append (userformat.author_editor_format (entry).decode ('latin-1')) elif f == '-author/title-': row.append (userformat.author_title_format (entry).decode ('latin-1')) elif entry.has_key (f): if Types.get_field (f).type == Fields.AuthorGroup: text = join (map (lambda a: str (a.last), entry [f]), ', ') elif Types.get_field (f).type == Fields.Date: text = str (entry [f].year) else: text = str (entry [f]) row.append (text.decode ('latin-1')) else: row.append ('') if True: row.append (i) if Resource.is_viewable (entry): row.append (self.gvpixbuf) else: row.append (None) iter = self.model.append () apply (self.model.set, [iter] + row) self.access.append (entry) entry = iterator.next () Utils.set_cursor (self.w, 'normal') return
# remove the old autosave object if self.data.key is not None and self.source_id: gobject.source_remove (self.source_id) # remove old autosave file if exists if self.data.key: if self.data.key.url [0] == 'file': old_file = self.data.key.url [2] old_auto_save = os.path.join (os.path.dirname (old_file), 'x-pyblio-save-' + os.path.basename (old_file)) if os.path.exists (old_auto_save): try: os.remove (old_auto_save) except (OSError, IOError), error: Utils.set_cursor (self.w, 'normal') Utils.error_dialog_s(_(u"Unable to remove autosave file “%s”:\n%s") % (str (old_auto_save), str (error))) return Utils.set_cursor (self.w, 'normal') if no_name: data.key = None self.data = data if restore: # restore the original url internally, # and change the document status