代码之家  ›  专栏  ›  技术社区  ›  mooware

从pygtk程序启动默认图像查看器

  •  1
  • mooware  · 技术社区  · 14 年前


    我该怎么做?

    3 回复  |  直到 14 年前
        1
  •  3
  •   avacariu    14 年前

    我不知道具体使用PyGTK,但是: xdg-open 打开一个文件的默认应用程序,这样运行类似的程序应该可以:

    import os
    os.system('xdg-open ./img.jpg')
    

    编辑: 我建议使用 subprocess 模块如注释中所示。我还不知道怎么用,所以我就用了 os.system 在示例中显示 xdg打开 .

        2
  •  3
  •   Havok    11 年前

    在GNU/Linux中使用 xdg-open open ,在Windows中使用 start . 另外,使用 subprocess

    这是我的实现,希望对你有所帮助: http://goo.gl/xebnV

    import sys
    import subprocess
    import webbrowser
    
    def default_open(something_to_open):
        """
        Open given file with default user program.
        """
        # Check if URL
        if something_to_open.startswith('http') or something_to_open.endswith('.html'):
            webbrowser.open(something_to_open)
            return 0
    
        ret_code = 0
    
        if sys.platform.startswith('linux'):
            ret_code = subprocess.call(['xdg-open', something_to_open])
    
        elif sys.platform.startswith('darwin'):
            ret_code = subprocess.call(['open', something_to_open])
    
        elif sys.platform.startswith('win'):
            ret_code = subprocess.call(['start', something_to_open], shell=True)
    
        return ret_code
    
        3
  •  2
  •   Community CDub    7 年前

    GTK(>=2.14)有 gtk_show_uri :

    gtk.show_uri(screen, uri, timestamp)
    

    gtk.show_uri(None, "file:///etc/passwd", gtk.gdk.CURRENT_TIME)
    

    相关的