home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / pyshared / GnomeCodecInstall / Main.py next >
Encoding:
Python Source  |  2009-03-17  |  3.7 KB  |  112 lines

  1. # -*- coding: utf-8 -*-
  2. # Copyright (c) 2008 Sebastian Dr√∂ge <sebastian.droege@collabora.co.uk>, GPL
  3.  
  4. import sys
  5. import gtk
  6. import gettext
  7. from gettext import gettext as _
  8. import re
  9.  
  10. # from gst.pbutils - copied to avoid overhead of the import
  11. (INSTALL_PLUGINS_SUCCESS,
  12.  INSTALL_PLUGINS_NOT_FOUND,
  13.  INSTALL_PLUGINS_ERROR,
  14.  INSTALL_PLUGINS_PARTIAL_SUCCESS,
  15.  INSTALL_PLUGINS_USER_ABORT) = range(5)
  16.  
  17. class Request(object):
  18.   def __init__(self, major, minor, app, descr, kind, caps=None, feature=None):
  19.     self.major = major
  20.     self.minor = minor
  21.     self.application = app
  22.     self.description = descr
  23.     self.gstkind = kind      # decoder, encoder, urisink, urisource, ...
  24.     self.caps = caps
  25.     self.feature = feature
  26.  
  27. def parse_arguments(args):
  28.   regex = re.compile("^gstreamer\|([0-9])+\.([0-9]+)\|(.+)\|(.+)\|([a-z]+)-(.*)[|]?")
  29.   requests = []
  30.   gst_init = False
  31.   major = 0
  32.   minor = 0
  33.   for arg in args:
  34.     match = regex.search(arg)
  35.     if not match:
  36.       continue
  37.     try:
  38.       r_major = int(match.group(1))
  39.       r_minor = int(match.group(2))
  40.       if not gst_init:
  41.         import pygst
  42.     pygst.require("%d.%d" % (r_major, r_minor))
  43.     import gst
  44.     gst_init = True
  45.     major = r_major
  46.     minor = r_minor
  47.       elif r_major != major or r_minor != minor:
  48.         return None
  49.     except ValueError:
  50.       continue
  51.  
  52.     if match.group(5) == "decoder" or match.group(5) == "encoder":
  53.       try:
  54.         requests.append(Request(major, minor, match.group(3), match.group(4), match.group(5), caps=gst.Caps(match.group(6))))
  55.       except TypeError:
  56.         continue
  57.     elif match.group(5) == "urisource" or match.group(5) == "urisink" or match.group(5) == "element":
  58.       requests.append(Request(major, minor, match.group(3), match.group(4), match.group(5), feature=match.group(6)))
  59.     else:
  60.       continue
  61.   return requests
  62.  
  63. def main(args):
  64.   gettext.textdomain("gnome-codec-install")
  65.   gettext.bindtextdomain("gnome-codec-install")
  66.  
  67.   requests = parse_arguments(args)
  68.  
  69.   try:
  70.     icon = gtk.icon_theme_get_default().load_icon("gnome-codec-install", 32, 0)
  71.   except:
  72.     icon = None
  73.   if icon:
  74.     gtk.window_set_default_icon(icon)
  75.  
  76.   if requests == None or len(requests) == 0:
  77.     sys.stderr.write("invalid commandline '%s'\n" % (args))
  78.     dlg = gtk.MessageDialog(None, gtk.DIALOG_MODAL,
  79.                             gtk.MESSAGE_ERROR, gtk.BUTTONS_OK,
  80.                             _("Invalid commandline"))
  81.     dlg.format_secondary_text(_("The parameters passed to the application "
  82.                                 "had an invalid format. Please file a bug!\n\n"
  83.                 "The parameters were:\n%s") % ("\n".join(map(str, args))))
  84.     dlg.set_title(_("Invalid commandline"))
  85.     dlg.run()
  86.     dlg.destroy()
  87.     exit(INSTALL_PLUGINS_ERROR)
  88.   else:
  89.     dlg = gtk.MessageDialog(None, gtk.DIALOG_MODAL,
  90.                             gtk.MESSAGE_QUESTION, gtk.BUTTONS_CANCEL,
  91.                             _("Search for suitable plugin?"))
  92.     dlg.format_secondary_text(_("The required software to play this "
  93.                               "file is not installed. You need to install "
  94.                               "suitable plugins to play "
  95.                               "media files. Do you want to search for a plugin "
  96.                               "that supports the selected file?\n\n"
  97.                               "The search will also include software which is not "
  98.                               "officially supported."))
  99.     btn = dlg.add_button(_("_Search"), gtk.RESPONSE_YES)
  100.     btn.grab_focus()
  101.     dlg.set_title(_("Search for suitable plugin?"))
  102.     res = dlg.run()
  103.     dlg.destroy()
  104.     while gtk.events_pending():
  105.       gtk.main_iteration()
  106.     if res != gtk.RESPONSE_YES:
  107.       exit(INSTALL_PLUGINS_USER_ABORT)
  108.     import MainWindow
  109.     window = MainWindow.MainWindow(requests)
  110.     exit(window.main())
  111.  
  112.