Пример #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
Пример #2
0
def StartViewer(entry, key, stringuri, parent=None, document=None):

    if not is_interactive(): return

    from Pyblio.GnomeUI import 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.push(document.context_id,
                                _(u"Determining Mime Type… "))

    try:
        mimetype = gio.content_type_guess(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(document.context_id)
        return
Пример #3
0
 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
Пример #4
0
    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
Пример #5
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:
         Utils.error_dialog_s(self.w.get_toplevel(),
                              _("Your text contains non Latin-1 symbols"))
         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
Пример #6
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:
         Utils.error_dialog_s(
             self.w.get_toplevel(),
             _("Your text contains non Latin-1 symbols"))
         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
Пример #7
0
    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,
                Exceptions.DateError), error:
            
            Utils.error_dialog (_("Open error"), error,
                                parent = self.w)
            return
Пример #8
0
    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,
                                                   parent=self.w).run ()

        if url is None: return

        try:
            iterator = Open.bibiter (url, how = how)
            
        except (Exceptions.ParserError,
                Exceptions.FormatError,
                Exceptions.FileError,
                Exceptions.DateError), error:
            
            Utils.error_dialog (_("Open error"), error,
                                parent = self.w)
            return
Пример #9
0
    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
Пример #10
0
    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
Пример #11
0
	
    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 (
Пример #12
0
    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 = gio.content_type_guess(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(document.context_id)
            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]
Пример #13
0
            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
Пример #14
0
            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"),
                                                   parent=self.w).run ()

        if url is None: return
        self.open_document (url, how)
        return