[pitivi] ui.sourcelist.py, ui.common.py: move beautify_* functions to ui.common.py



commit 8600a662f73908172e528b6b420ebf99f6de358c
Author: Brandon Lewis <brandon_lewis berkeley edu>
Date:   Tue Jul 28 15:09:35 2009 -0700

    ui.sourcelist.py, ui.common.py: move beautify_* functions to ui.common.py

 pitivi/ui/common.py     |   91 +++++++++++++++++++++++++++++++++++++++++++++++
 pitivi/ui/sourcelist.py |   45 +----------------------
 2 files changed, 93 insertions(+), 43 deletions(-)
---
diff --git a/pitivi/ui/common.py b/pitivi/ui/common.py
index 8d2f8fd..de30341 100644
--- a/pitivi/ui/common.py
+++ b/pitivi/ui/common.py
@@ -1,5 +1,11 @@
 from pitivi.settings import GlobalSettings
 import cairo
+from pitivi.stream import VideoStream, AudioStream, TextStream, \
+        MultimediaStream
+from xml.sax.saxutils import escape
+from urllib import unquote
+from gettext import gettext as _
+from gettext import ngettext
 
 GlobalSettings.addConfigSection("user-interface")
 LAYER_HEIGHT_EXPANDED = 50
@@ -59,3 +65,88 @@ def unpack_cairo_gradient(value):
         (blue / 65535.0) * 1.5,
         alpha / 65535.0)
     return ret
+
+def beautify_factory(factory):
+    ranks = {VideoStream: 0, AudioStream: 1, TextStream: 2, MultimediaStream: 3}
+    def stream_sort_key(stream):
+        return ranks[type(stream)]
+
+    streams = factory.getOutputStreams()
+    streams.sort(key=stream_sort_key)
+    return ("<b>" + escape(unquote(factory.name)) + "</b>\n" +
+        "\n".join((beautify_stream(stream) for stream in streams)))
+
+def factory_name(factory):
+    return escape(unquote(factory.name))
+
+
+def beautify_stream(stream):
+    if type(stream) == AudioStream:
+        if stream.raw:
+            templ = ngettext("<b>Audio:</b> %d channel at %d <i>Hz</i> (%d <i>bits</i>)",
+                    "<b>Audio:</b> %d channels at %d <i>Hz</i> (%d <i>bits</i>)",
+                    stream.channels)
+            templ = templ % (stream.channels, stream.rate, stream.width)
+            return templ
+
+        return _("<b>Unknown Audio format:</b> %s") % stream.audiotype
+
+    elif type(stream) == VideoStream:
+        if stream.raw:
+            if stream.framerate.num:
+                templ = _("<b>Video:</b> %d x %d <i>pixels</i> at %.2f<i>fps</i>")
+                templ = templ % (stream.par * stream.width , stream.height,
+                        float(stream.framerate))
+            else:
+                templ = _("<b>Image:</b> %d x %d <i>pixels</i>")
+                templ = templ % (stream.par * stream.width, stream.height)
+            return templ
+        return _("<b>Unknown Video format:</b> %s") % stream.videotype
+
+    elif type(stream) == TextStream:
+        return _("<b>Text:</b> %s") % stream.texttype
+
+    raise NotImplementedError
+
+def beautify_factory(factory):
+    ranks = {VideoStream: 0, AudioStream: 1, TextStream: 2, MultimediaStream: 3}
+    def stream_sort_key(stream):
+        return ranks[type(stream)]
+
+    streams = factory.getOutputStreams()
+    streams.sort(key=stream_sort_key)
+    return ("<b>" + escape(unquote(factory.name)) + "</b>\n" +
+        "\n".join((beautify_stream(stream) for stream in streams)))
+
+def factory_name(factory):
+    return escape(unquote(factory.name))
+
+
+def beautify_stream(stream):
+    if type(stream) == AudioStream:
+        if stream.raw:
+            templ = ngettext("<b>Audio:</b> %d channel at %d <i>Hz</i> (%d <i>bits</i>)",
+                    "<b>Audio:</b> %d channels at %d <i>Hz</i> (%d <i>bits</i>)",
+                    stream.channels)
+            templ = templ % (stream.channels, stream.rate, stream.width)
+            return templ
+
+        return _("<b>Unknown Audio format:</b> %s") % stream.audiotype
+
+    elif type(stream) == VideoStream:
+        if stream.raw:
+            if stream.framerate.num:
+                templ = _("<b>Video:</b> %d x %d <i>pixels</i> at %.2f<i>fps</i>")
+                templ = templ % (stream.par * stream.width , stream.height,
+                        float(stream.framerate))
+            else:
+                templ = _("<b>Image:</b> %d x %d <i>pixels</i>")
+                templ = templ % (stream.par * stream.width, stream.height)
+            return templ
+        return _("<b>Unknown Video format:</b> %s") % stream.videotype
+
+    elif type(stream) == TextStream:
+        return _("<b>Text:</b> %s") % stream.texttype
+
+    raise NotImplementedError
+
diff --git a/pitivi/ui/sourcelist.py b/pitivi/ui/sourcelist.py
index 918e6a9..0f7083b 100644
--- a/pitivi/ui/sourcelist.py
+++ b/pitivi/ui/sourcelist.py
@@ -27,7 +27,6 @@ import os
 import time
 
 from urllib import unquote
-from xml.sax.saxutils import escape
 from gettext import gettext as _
 from gettext import ngettext
 
@@ -40,6 +39,8 @@ from pitivi.stream import VideoStream, AudioStream, TextStream, \
         MultimediaStream
 from pitivi.settings import GlobalSettings
 from pitivi.utils import beautify_length
+from pitivi.ui.common import beautify_factory, factory_name, \
+    beautify_stream
 from pitivi.log.loggable import Loggable
 from pitivi.sourcelist import SourceListError
 
@@ -85,48 +86,6 @@ ui = '''
 INVISIBLE = gtk.gdk.pixbuf_new_from_file(os.path.join(get_pixmap_dir(), 
     "invisible.png"))
 
-def beautify_stream(stream):
-
-    if type(stream) == AudioStream:
-        if stream.raw:
-            templ = ngettext("<b>Audio:</b> %d channel at %d <i>Hz</i> (%d <i>bits</i>)",
-                    "<b>Audio:</b> %d channels at %d <i>Hz</i> (%d <i>bits</i>)",
-                    stream.channels)
-            templ = templ % (stream.channels, stream.rate, stream.width)
-            return templ
-
-        return _("<b>Unknown Audio format:</b> %s") % stream.audiotype
-
-    elif type(stream) == VideoStream:
-        if stream.raw:
-            if stream.framerate.num:
-                templ = _("<b>Video:</b> %d x %d <i>pixels</i> at %.2f<i>fps</i>")
-                templ = templ % (stream.par * stream.width , stream.height,
-                        float(stream.framerate))
-            else:
-                templ = _("<b>Image:</b> %d x %d <i>pixels</i>")
-                templ = templ % (stream.par * stream.width, stream.height)
-            return templ
-        return _("<b>Unknown Video format:</b> %s") % stream.videotype
-
-    elif type(stream) == TextStream:
-        return _("<b>Text:</b> %s") % stream.texttype
-
-    raise NotImplementedError
-
-def beautify_factory(factory):
-    ranks = {VideoStream: 0, AudioStream: 1, TextStream: 2, MultimediaStream: 3}
-    def stream_sort_key(stream):
-        return ranks[type(stream)]
-
-    streams = factory.getOutputStreams()
-    streams.sort(key=stream_sort_key)
-    return ("<b>" + escape(unquote(factory.name)) + "</b>\n" +
-        "\n".join((beautify_stream(stream) for stream in streams)))
-
-def factory_name(factory):
-    return escape(unquote(factory.name))
-
 class SourceList(gtk.VBox, Loggable):
     """ Widget for listing sources """
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]