def init_page_1 (self): self.fields1 = self.xml.get_widget('f_list_1') rend = gtk.CellRendererText() col = gtk.TreeViewColumn(_('Name'), rend, text = 0) self.fields1.append_column(col) rend = gtk.CellRendererText() col = gtk.TreeViewColumn(_('Type'), rend, text = 1) self.fields1.append_column(col) self.fm = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_PYOBJECT) self.sfm = gtk.TreeModelSort(self.fm) self.sfm.set_sort_column_id(2, gtk.SORT_ASCENDING) self.fields1.set_model(self.sfm) self.s1 = self.fields1.get_selection() self.s1.connect ('changed', self.list_1_select) self.fields = copy.copy (Config.get ('base/fields').data) for key, item in self.fields.iteritems(): self.fm.append((item.name, _typename [item.type], key, item)) self.name1 = self.xml.get_widget('name1') self.menu1 = self.xml.get_widget('type1') menu = gtk.Menu () self.menu1.set_menu (menu) self.menu_items = _typename.keys () for item in self.menu_items: Utils.popup_add (menu, _typename [item], self.select_menu, item) self.menu1.set_history (0) self.current_menu = self.menu_items [0] self.check()
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]), ', ') 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
def StartViewer (entry, key, stringuri, parent=None, document=None): if not is_interactive (): return from Legacy.GnomeUI import Compat, Utils uri = Fields.URL (stringuri) scheme, location, path, parameters, query, fragment = uri.url fileuri = uri.get_url () if uri.invalid or uri.inexact: message = Utils.Callback ( _("Warning: This URL is marked as Invalid or Approximate: %s\nContinue?") % fileuri) if not message.answer (): return if document: document.statusbar.set_status (_("Determining Mime Type ... ")) try: mimetype = Compat.get_mime_type (fileuri) except RuntimeError, mesg: Utils.error_dialog(_("Cannot determine mime type for item %s ") % entry.key.key, _("URL in question is: %s\n" "You should check the url or path given for errors.\n" "Details: %s") % (fileuri, mesg)) if document: document.statusbar.pop () return
def __init__ (self, parent = None): Utils.GladeWindow.__init__ (self, parent) # Fill the output format drop-down menu menu = gtk.Menu () self._w_menu.set_menu (menu) outlist = Autoload.available ('output') outlist.sort () for avail in outlist: Utils.popup_add (menu, avail, self._menu_select, avail) self._w_menu.set_history (0) self.menu_item = outlist [0] self._w_style_entry.set_default_path (FormatDialog.style) self._w_style.set_text (FormatDialog.style) if FormatDialog.output: self._w_output_entry.set_default_path (FormatDialog.output) self._w_output.set_text (FormatDialog.output) self._w_format.show () return
def update_content(self, entry, text): if text[0] == "@" and hasattr(entry, "set_native"): try: entry.set_native(self.field, string.lstrip(text[1:])) except Exceptions.ParserError, msg: Utils.error_dialog(_("Error in native string parsing"), str(msg)) return -1 return 1
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 update(self, database, entry): """Updates and returns the new entry.""" new = None text = self.buff.get_text(self.buff.get_start_iter(), self.buff.get_end_iter()) try: text = text.encode("latin-1") except UnicodeError: Compat.error_dialog_parented(_("Your text contains non Latin-1 symbols"), self.w.get_toplevel()) return None try: new = self.database.create_native(text) except Exceptions.ParserError, msg: Utils.error_dialog(_("Error in native string parsing"), str(msg)) return None
def merge_database (self, * arg): ''' add all the entries of another database to the current one ''' # get a new file name (url, how) = FileSelector.URLFileSelection (_("Merge file"), has_auto = True).run () if url is None: return try: iterator = Open.bibiter (url, how = how) except (Exceptions.ParserError, Exceptions.FormatError, Exceptions.FileError), error: Utils.error_dialog (_("Open error"), error, parent = self.w) 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 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), error: Utils.set_cursor (self.w, 'normal') Utils.error_dialog (_("Open error"), error, parent = self.w) return
def __init__ (self, parent = None): Utils.GladeWindow.__init__ (self, parent) # the tree model contains a string that explains the query, # and a python object representing the actual query. self._model = gtk.TreeStore (str, gobject.TYPE_PYOBJECT) self._w_tree.set_model (self._model) # the view does not display the python column, of course. col = gtk.TreeViewColumn ('field', gtk.CellRendererText (), text = 0) self._w_tree.append_column (col) self._w_tree.expand_all () # The root of the search tree is the full database self._model.append (None, (_("Full database"), None)) # Monitor the selected items self._selection = self._w_tree.get_selection () self._selection.connect ('changed', self.selection) # fill the combo containing the available fields self._w_field.set_popdown_strings ([' - any field - '] + list (Config.get ('gnome/searched').data) + [' - type - ', ' - key - ']) # connect a menu to the right button self.menu = gtk.Menu () self.delete_button = Utils.popup_add (self.menu, _("Delete"), self.search_delete) self.menu.show () # We are set up. self.show () return
errors = errors + msg.errors while entry: self.data.add (entry) while 1: try: entry = iterator.next () break except Exceptions.ParserError, msg: errors = errors + list (msg.errors) continue self.redisplay_index (1) if errors: Utils.error_dialog (_("Merge status"), string.join (errors, '\n'), parent = self.w) return def ui_open_document (self, * arg): ''' callback corresponding to "Open" ''' if not self.confirm (): return # get a new file name (url, how) = FileSelector.URLFileSelection (_("Open file")).run () if url is None: return self.open_document (url, how) return
elif mimetype in ['text/html', 'text/plain']: filename = fileuri else: filename, headers = urllib.urlretrieve (fileuri) if mimetype == 'application/x-gzip': try: tempname = os.tmpnam () os.system ("gzip -d < %s >%s" %(filename, tempname)) filename = tempname mimetype = Compat.get_mime_type (filename) except RuntimeError, mesg: Utils.error_dialog (_("IOError for item %s: cannot uncompress resource.") % entry.key.key, _("URL: %s\nDetails: %s") % (filename, mesg)) if document: document.statusbar.pop () return viewers = [ item [1] for item in Config.get (config_viewers).data if item [0] == mimetype] or [ item [1] for item in Config.get (config_viewers).data if item [0].endswith ('/*') and item [0] [:-2] == mimetype1] if viewers: cmd = viewers [0] command = userexit.resource_viewer_setup (