예제 #1
0
 def on_treeview_row_activated(self, treeview, path, column):
     (model, iter) = treeview.get_selection().get_selected()
     filename = model.get(iter, 1)[0]
     application = gnomevfs.mime_get_default_application(
         gnomevfs.get_mime_type(gnomevfs.make_uri_from_input(filename)))
     if application:
         subprocess.Popen(str.split(application[2]) + [filename])
예제 #2
0
def launchApplicationByUrl(url, mimeType):
    """Launches an application in the background for
    displaying a url which is of a specific mimeType
    @param url: the url to display
    @param mimeType: the mime type of the content
    """
    try:
        import gnomevfs
    except ImportError:
        gnomevfs = None

    try:
        from win32com.shell import shell as win32shell
    except ImportError:
        win32shell = None

    try:
        import gio
    except ImportError:
        gio = None

    if gio:
        app = gio.app_info_get_default_for_type(mimeType, True)
        if not app:
            return
        args = '%s %s' % (app.get_executable(), url)
        executable = None
        shell = True
    elif gnomevfs:
        app = gnomevfs.mime_get_default_application(mimeType)
        if not app:
            return
        args = '%s %s' % (app[2], url)
        executable = None
        shell = True
    elif win32shell:
        assoc = win32shell.AssocCreate()
        ext = _EXTENSIONS.get(mimeType)
        if ext is None:
            return
        assoc.Init(0, '.' + ext)
        args = assoc.GetString(0, _ASSOCSTR_COMMAND)
        executable = assoc.GetString(0, _ASSOCSTR_EXECUTABLE)
        args = args.replace("%1", url)
        args = args.replace("%L", url)
        shell = False
    else:
        return

    import subprocess
    subprocess.Popen(args, executable=executable,
                     shell=shell)
예제 #3
0
파일: mime_info.py 프로젝트: kisp/oyepa-git
    def getApps(self, filename): # returns a tuple (default app, [list of other apps]) that are registered as able to open this file; 'apps' in this context are App objects; in case of error, returns (None, [])

        defaultApp, otherApps = None, []

        mimeType = self._getMimeType(filename)

        if mimeType:

            if self.DESK_ENV == GNOME:

                # in the future [since gnomevfs is deprecated], this should be done using
                # import gio
                # gio.app_info_get_all_for_type(mimeType)

                # both of these gnomevfs functions return tuples, where the element in [1] is the app name and [2] is the command to execute

                defaultAppInfo = gnomevfs.mime_get_default_application(mimeType)

                if defaultAppInfo: # if we got something

                    defaultApp = App(defaultAppInfo[1], defaultAppInfo[2])

                    otherApps = [App(app[1], app[2]) for app in gnomevfs.mime_get_all_applications(mimeType) ]

            elif self.DESK_ENV == KDE:

                kdeMimeTrader = KMimeTypeTrader.self()

                defaultAppInfo = kdeMimeTrader.preferredService(mimeType)

                if defaultAppInfo:

                    defaultApp = App( unicode(defaultAppInfo.desktopEntryName()) , unicode(defaultAppInfo.exec_()) ) # unicode()s since funky PyQt "QString" strings are returned...

                    otherApps = [ App(unicode(s.desktopEntryName()), unicode(s.exec_()) ) for s in kdeMimeTrader.query(mimeType) ]

            else: # need to use our own file type -> app mapping...

                # XXX code from before

                pass

            otherApps = filter(lambda a: a.cmd != defaultApp.cmd, otherApps) # make sure we don't include the default app into the list of OTHER apps...
            pass

        for app in [defaultApp] + otherApps: # at least KDE sometimes stores the cmd to execute with a placeholder ('%U', '%f') at the end to indicate where the filename should go; we remove that

            if app.cmd.split()[-1].startswith('%'): app.cmd = ' '.join( app.cmd.split()[:-1] ) + ' '
            pass

        return defaultApp, otherApps
예제 #4
0
def launchApplicationByUrl(url, mimeType):
    """Launches an application in the background for
    displaying a url which is of a specific mimeType
    @param url: the url to display
    @param mimeType: the mime type of the content
    """
    try:
        import gnomevfs
    except ImportError:
        gnomevfs = None

    try:
        from win32com.shell import shell as win32shell
    except ImportError:
        win32shell = None

    try:
        import gio
    except ImportError:
        gio = None

    if gio:
        app = gio.app_info_get_default_for_type(mimeType, True)
        if not app:
            return
        args = '%s %s' % (app.get_executable(), url)
        executable = None
        shell = True
    elif gnomevfs:
        app = gnomevfs.mime_get_default_application(mimeType)
        if not app:
            return
        args = '%s %s' % (app[2], url)
        executable = None
        shell = True
    elif win32shell:
        assoc = win32shell.AssocCreate()
        ext = _EXTENSIONS.get(mimeType)
        if ext is None:
            return
        assoc.Init(0, '.' + ext)
        args = assoc.GetString(0, _ASSOCSTR_COMMAND)
        executable = assoc.GetString(0, _ASSOCSTR_EXECUTABLE)
        args = args.replace("%1", url)
        args = args.replace("%L", url)
        shell = False
    else:
        return

    import subprocess
    subprocess.Popen(args, executable=executable, shell=shell)
예제 #5
0
def get_meta_info(filename):
	try:
		file_mimetype = gnomevfs.get_mime_type(filename)
	except:
		return False
	
	ret = {}
	ret['mime'] = file_mimetype
	ret['default_app'] = gnomevfs.mime_get_default_application(file_mimetype)
	ret['other_apps'] = gnomevfs.mime_get_all_applications(file_mimetype)
	if len(ret['other_apps']) > 0:
		del ret['other_apps'][0]
	ret ['description'] = gnomevfs.mime_get_description(file_mimetype)
	return ret
예제 #6
0
def get_default_application_for_files(files):
    id_comum = None
    for file in files:
        mime = gnomevfs.get_file_mime_type(file)
        if not mime:
          return None

        app = gnomevfs.mime_get_default_application(mime)
        if not app:
          return None

        if id_comum == None:
            id_comum = app[0]
        elif app[0] != id_comum:
            return None
    return gnomevfs.mime_application_new_from_id(id_comum)
예제 #7
0
def get_default_application_for_files(files):
    id_comum = None
    for file in files:
        mime = gnomevfs.get_file_mime_type(file)
        if not mime:
          return None
        # Query the MIME database for the default Bonobo component to be activated to view files of MIME type mime_type
        app = gnomevfs.mime_get_default_application(mime)
        if not app:
          return None

        if id_comum == None:
            id_comum = app[0]
        elif app[0] != id_comum:
            return None
    return ApplicationInfo(gnomevfs.mime_application_new_from_id(id_comum))
예제 #8
0
파일: utils.py 프로젝트: ywwg/penguintv
def desktop_has_file_handler(filename):
	"""Returns true if the desktop has a file handler for this
		filetype."""
	if is_kde():
		# If KDE can't handle the file, we'll use kfmclient exec to run the file,
		# and KDE will show a dialog asking for the program
		# to use anyway.
		return True
	else:
		if HAS_GNOMEVFS:
			# Otherwise, use GNOMEVFS to find the appropriate handler
			handler = gnomevfs.mime_get_default_application(gnomevfs.get_mime_type(urllib.quote(str(filename)))) #PA fix #Nerdist fix, urllib prefers strings over unicode
			if handler is not None:
				return True
			return False
		else: #FIXME: olpc doesn't know what the f**k... pretend yes and let error get caught later
			return True
예제 #9
0
def desktop_has_file_handler(filename):
    """Returns true if the desktop has a file handler for this
		filetype."""
    if is_kde():
        # If KDE can't handle the file, we'll use kfmclient exec to run the file,
        # and KDE will show a dialog asking for the program
        # to use anyway.
        return True
    else:
        if HAS_GNOMEVFS:
            # Otherwise, use GNOMEVFS to find the appropriate handler
            handler = gnomevfs.mime_get_default_application(
                gnomevfs.get_mime_type(urllib.quote(str(filename)))
            )  #PA fix #Nerdist fix, urllib prefers strings over unicode
            if handler is not None:
                return True
            return False
        else:  #FIXME: olpc doesn't know what the f**k... pretend yes and let error get caught later
            return True
예제 #10
0
파일: utils.py 프로젝트: ywwg/penguintv
def get_play_command_for(filename):
	known_players={ 'totem':'--enqueue',
					'xine':'--enqueue',
					'mplayer': '-enqueue',
					'banshee': '--enqueue'}

	if is_kde():
		try:
			mime_magic = kio.KMimeMagic()
			mimetype = str(mime_magic.findFileType(filename).mimeType())
			#mimetype = str(kio.KMimeType.findByPath(filename).defaultMimeType())
			service = kio.KServiceTypeProfile.preferredService(mimetype,"Application")
			if service is None: #no service, so we use kfmclient and kde should launch a helper window
				logging.info("unknown type, using kfmclient")
				return "kfmclient exec "
			full_qual_prog = str(service.exec_()).replace("%U","").strip()
		except:
			logging.info("error getting type, using kfmclient")
			return "kfmclient exec "
	else: #GNOME -- notice how short and sweet this is in comparison :P
		if HAS_GNOMEVFS:
			try:
				mimetype = gnomevfs.get_mime_type(urllib.quote(filename)) #fix for penny arcade filenames
				full_qual_prog = gnomevfs.mime_get_default_application(mimetype)[2]
			except:
				logging.info("unknown type, using gnome-open")
				return "gnome-open "
		else:
			# :(
			return "echo "
	try:
		path, program = os.path.split(full_qual_prog)
	except:
		program = full_qual_prog

	if known_players.has_key(program):
		return full_qual_prog+" "+known_players[program]
	return full_qual_prog
예제 #11
0
	def on_current_file_button_clicked (self, widget):
		application = gnomevfs.mime_get_default_application (gnomevfs.get_mime_type(gnomevfs.make_uri_from_input(self.filename)))
		if application:
			subprocess.Popen (str.split (application[2]) + [self.filename])
예제 #12
0
def open_file_watch(f):
    """ Open a file with the correct application (mime). """
    mime_type = gnomevfs.get_mime_type(f)
    application = gnomevfs.mime_get_default_application(mime_type)
    os.system(application[2] + " \"" + f + "\" &")
예제 #13
0
 def open_url(self, url):
   mime_type = gnomevfs.get_mime_type(url)
   application = gnomevfs.mime_get_default_application(mime_type)
   os.system(application[2] + ' "' + url + '" &')
예제 #14
0
 def launch_edit_file(self, path):
     uri = gnomevfs.get_uri_from_local_path(path) 
     app = gnomevfs.mime_get_default_application("text/plain")
     self.__launch_vfsmimeapp(app, uri)
예제 #15
0
 def on_current_file_button_clicked(self, widget):
     application = gnomevfs.mime_get_default_application(
         gnomevfs.get_mime_type(gnomevfs.make_uri_from_input(
             self.filename)))
     if application:
         subprocess.Popen(str.split(application[2]) + [self.filename])
예제 #16
0
	def on_treeview_row_activated (self, treeview, path, column):
		(model, iter) = treeview.get_selection ().get_selected ()
		filename = model.get (iter, 1)[0]
		application = gnomevfs.mime_get_default_application (gnomevfs.get_mime_type(gnomevfs.make_uri_from_input(filename)))
		if application:
			subprocess.Popen (str.split (application[2]) + [filename])
예제 #17
0
 def launch_edit_file(self, path):
     uri = gnomevfs.get_uri_from_local_path(path)
     app = gnomevfs.mime_get_default_application("text/plain")
     self.__launch_vfsmimeapp(app, uri)
예제 #18
0
    def getApps(
        self, filename
    ):  # returns a tuple (default app, [list of other apps]) that are registered as able to open this file; 'apps' in this context are App objects; in case of error, returns (None, [])

        defaultApp, otherApps = None, []

        mimeType = self._getMimeType(filename)

        if mimeType:

            if self.DESK_ENV == GNOME:

                # in the future [since gnomevfs is deprecated], this should be done using
                # import gio
                # gio.app_info_get_all_for_type(mimeType)

                # both of these gnomevfs functions return tuples, where the element in [1] is the app name and [2] is the command to execute

                defaultAppInfo = gnomevfs.mime_get_default_application(
                    mimeType)

                if defaultAppInfo:  # if we got something

                    defaultApp = App(defaultAppInfo[1], defaultAppInfo[2])

                    otherApps = [
                        App(app[1], app[2])
                        for app in gnomevfs.mime_get_all_applications(mimeType)
                    ]

            elif self.DESK_ENV == KDE:

                kdeMimeTrader = KMimeTypeTrader.self()

                defaultAppInfo = kdeMimeTrader.preferredService(mimeType)

                if defaultAppInfo:

                    defaultApp = App(
                        unicode(defaultAppInfo.desktopEntryName()),
                        unicode(defaultAppInfo.exec_())
                    )  # unicode()s since funky PyQt "QString" strings are returned...

                    otherApps = [
                        App(unicode(s.desktopEntryName()), unicode(s.exec_()))
                        for s in kdeMimeTrader.query(mimeType)
                    ]

            else:  # need to use our own file type -> app mapping...

                # XXX code from before

                pass

            otherApps = filter(
                lambda a: a.cmd != defaultApp.cmd, otherApps
            )  # make sure we don't include the default app into the list of OTHER apps...
            pass

        for app in [
                defaultApp
        ] + otherApps:  # at least KDE sometimes stores the cmd to execute with a placeholder ('%U', '%f') at the end to indicate where the filename should go; we remove that

            if app.cmd.split()[-1].startswith('%'):
                app.cmd = ' '.join(app.cmd.split()[:-1]) + ' '
            pass

        return defaultApp, otherApps