Exemplo n.º 1
0
def StartViewer (entry, key, stringuri, parent=None, document=None):

    if not is_interactive (): 	return

    from Pyblio.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
Exemplo n.º 2
0
 def update (self, entry):
     (day, month, year) = (None, None, None)
     
     text = string.strip (self.day.get_chars (0, -1)).encode ('latin-1')
     if text != '':
         try: day = int (text)
         except ValueError:
             Compat.error_dialog_parented (_("Invalid day field in date"),
                                             self.day.get_toplevel ())
             return -1
     
     text = string.strip (self.month.get_chars (0, -1)).encode ('latin-1')
     if text != '':
         try: month = int (text)
         except ValueError, err:
             Compat.error_dialog_parented (_("Invalid month field in date"),
                                             self.day.get_toplevel ())
             return -1
Exemplo n.º 3
0
 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
Exemplo n.º 4
0
    def update (self, database, entry):
        modified = False
        
        key = string.strip (self.key.get_text ())
        if key == '':
            self.entry.key = None
            modified = True
        else:
            if not key_re.match (key):
                Compat.error_dialog_parented (
                    _("Invalid key format"), self.w.get_toplevel ())
                return None

            key = Key.Key (database, key)

            if key != self.entry.key:
                if database.has_key (key):
                     Compat.error_dialog_parented (
                         _("Key `%s' already exists") % str (key.key),
                         self.w.get_toplevel ())
                     return None
                
                self.entry.key = key
                modified = True
                
        modified = self.type != self.entry.type or modified
        
        for item in self.content:
            try:
                result = item.update(self.entry)
                
            except UnicodeError:
                f = Types.get_field(item.field)
                
                Compat.error_dialog_parented(
                    _("The `%s' field contains a non Latin-1 symbol") %
                    f.name, self.w.get_toplevel())
                return None
            
            if result == -1: return None
            
            modified = result or modified

        modified |= self.lt_update()

        if not modified:
            fields = self.entry.keys()
            fields.sort()

            if fields != self.fields: modified = 1
        
        if modified:
            return self.entry
        
        return entry
Exemplo n.º 5
0
    if scheme == 'file' and not location:
	filename = path
	
    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]