#!/usr/bin/env python import birchenv import birchscript import browser import re import os import os.path import sys # This script is called for files listed in .GDEmenus files # using openitem: # It chooses a viewer, depending on the file extension. # Mime might be the 'right' way to do this, but it's # immensly easier to just write a short script, and probably # more reliable. # In most cases the file extension tells us what to do with # the file. However, we also want to be able to correctly handle # a URL, so URL tells us if sys.argv[1] is a URL, rather than a local # file name. """ ensure that there are enough command line arguments to parse """ if len(sys.argv) < 2: print("Usage: chooseviewer.py (URL or FILE)"); exit(); if re.search('^http:|^https:|^ftp:|^ftps:', sys.argv[1]): EXT="html" else: EXT=os.path.splitext(sys.argv[1])[1].lower() if EXT in (".html", ".shtml", ".htm"): # -------- Web pages browser.forkbrowser(sys.argv[1]) elif EXT == ".pdf": # -------- PDF, PostScript birchscript.forkrun([birchenv.BL_PDFViewer, sys.argv[1]]) elif EXT == ".ps": birchscript.forkrun([birchenv.BL_PSViewer, sys.argv[1]]) elif EXT in (".gif", ".jpg", ".jpeg", ".png", ".bmp", ".tif", ".tiff"): # -------- Bitmap graphics birchscript.forkrun([birchenv.BL_ImageViewer, sys.argv[1]]) else: # -------- Default is text editor # Special code for text editors used by GDE and scripts called by GDE # Nedit crashes in some Linux systems due to libraries set in BIRCHLIBS. # nedit_wrapper unsets LD_LIBRARY_PATH before calling nedit. # gedit opens all files in a single window. gedit_wrapper.sh forces # gedit to open each file in different window. # choose_edit_wrapper.sh returns the name of the wrapper to use # for each editor, or just returns BL_TextEditor if there is no # wrapper. birchscript.forkrun([birchenv.BL_TextEditor, sys.argv[1]])