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 _results (self): ''' Extract the current sorting settings ''' sort = [] for r in self._model: item, dir = r [2], r [3] # Only consider fields on which we sort if dir == 0: continue # Store the direction of sorting in each item if dir > 0: item.ascend = True else: item.ascend = False sort.append (item) if not sort: sort = None else: sort = Sort.Sort (sort) return sort
def sort_by_field (self, field): if field == '-key-': mode = Sort.KeySort () elif field == '-type-': mode = Sort.TypeSort () else: mode = Sort.FieldSort (field) # Check if we are toggling or changing cur = self.selection.sort if cur and len (cur.fields) == 1: cur = cur.fields [0] # We are still filtering according to the same field, # simply toggle the direction if cur == mode: mode.ascend = - cur.ascend self.selection.sort = Sort.Sort ([mode]) self.redisplay_index () return
def autosave (self, url, how): ''' autosave file as x-pyblio-save-filename ''' if self.data.key.url [0] != 'file': return False name = self.data.key.url [2] # create an autosave file save = os.path.join (os.path.dirname (name), 'x-pyblio-save-' + os.path.basename (name)) if self.changed: try: savefile = open (save, 'w') except (IOError, OSError), error: Utils.error_dialog_s(_("Error during autosaving:\n%s") % error [1]) return False iterator = Selection.Selection (sort = Sort.Sort([Sort.KeySort()])) Open.bibwrite (iterator.iterator (self.data.iterator ()), out = savefile, how = how, database=self.data) savefile.close ()
import sys from Pyblio import Selection, Sort how = sys.argv[2] if how == '': how = None a = bibopen(sys.argv[3], how) f = open(sys.argv[4], 'w') # write out in the key order sel = Selection.Selection(sort=Sort.Sort([Sort.KeySort()])) it = sel.iterator(a.iterator()) bibwrite(it, out=f, how=a.id)
if os.path.exists (url): if not Utils.Callback ( _(u"The file “%s” already exists.\nOverwrite it?") % url, parent = self.w).answer (): return try: file = open (url, 'w') except IOError, error: Utils.error_dialog_s(_("During opening:\n%s") % error [1]) return Utils.set_cursor (self.w, 'clock') iterator = Selection.Selection (sort = Sort.Sort([Sort.KeySort()])) Open.bibwrite (iterator.iterator (self.data.iterator ()), out = file, how = how, database=self.data) file.close () # 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 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))