~timo-jyrinki/ubuntu/trusty/pitivi/backport_utopic_fixes

« back to all changes in this revision

Viewing changes to pitivi/ui/common.py

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2011-05-26 15:29:58 UTC
  • mfrom: (3.1.20 experimental)
  • Revision ID: james.westby@ubuntu.com-20110526152958-90je1myzzjly26vw
Tags: 0.13.9.90-1ubuntu1
* Resynchronize on Debian
* debian/control:
  - Depend on python-launchpad-integration
  - Drop hal from Recommends to Suggests. This version has the patch applied
    to not crash without hal.
* debian/patches/01_lpi.patch:
  - launchpad integration  
* debian/rules:
  - Use gnome.mk so a translation template is built

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
from urllib import unquote
7
7
from gettext import gettext as _
8
8
from gettext import ngettext
 
9
import gst
 
10
import gtk
9
11
 
10
12
GlobalSettings.addConfigSection("user-interface")
11
13
LAYER_HEIGHT_EXPANDED = 50
13
15
LAYER_SPACING = 15
14
16
TRACK_SPACING = 8
15
17
 
16
 
def pack_color_32(red, green, blue, alpha = 0xFFFF):
17
 
   red = red >> 8
18
 
   green = green >> 8
19
 
   blue = blue >> 8
20
 
   alpha = alpha >> 8
21
 
   return (red << 24 | green << 16 | blue << 8 | alpha)
22
 
 
23
 
def pack_color_64(red, green, blue, alpha = 0xFFFF):
24
 
   return (red << 48 | green << 32 | blue << 16 | alpha)
 
18
SPACING = 6
 
19
PADDING = 6
 
20
 
 
21
def pack_color_32(red, green, blue, alpha=0xFFFF):
 
22
    """Packs the specified 16bit color values in a 32bit RGBA value."""
 
23
    red = red >> 8
 
24
    green = green >> 8
 
25
    blue = blue >> 8
 
26
    alpha = alpha >> 8
 
27
    return (red << 24 | green << 16 | blue << 8 | alpha)
 
28
 
 
29
def pack_color_64(red, green, blue, alpha=0xFFFF):
 
30
    """Packs the specified 16bit color values in a 64bit RGBA value."""
 
31
    return (red << 48 | green << 32 | blue << 16 | alpha)
25
32
 
26
33
def unpack_color(value):
 
34
    """Unpacks the specified RGBA value into four 16bit color values.
 
35
 
 
36
    Args:
 
37
      value: A 32bit or 64bit RGBA value.
 
38
    """
27
39
    if not (value >> 32):
28
40
        return unpack_color_32(value)
29
41
    else:
30
42
        return unpack_color_64(value)
31
43
 
32
44
def unpack_color_32(value):
33
 
    red = (value >> 24); red = red | red << 8
34
 
    green = (value >> 16) & 0xFF; green = green | green << 8
35
 
    blue = (value >> 8) & 0xFF; blue = blue | blue << 8
36
 
    alpha = value & 0xFF; alpha = alpha | alpha << 8
 
45
    """Unpacks the specified 32bit RGBA value into four 16bit color values."""
 
46
    red = (value >> 24) << 8
 
47
    green = ((value >> 16) & 0xFF) << 8
 
48
    blue = ((value >> 8) & 0xFF) << 8
 
49
    alpha = (value & 0xFF) << 8
37
50
    return red, green, blue, alpha
38
51
 
39
52
def unpack_color_64(value):
 
53
    """Unpacks the specified 64bit RGBA value into four 16bit color values."""
40
54
    red = (value >> 48) & 0xFFFF
41
55
    green = (value >> 32) & 0xFFFF
42
56
    blue = (value >> 16) & 0xFFFF
44
58
    return red, green, blue, alpha
45
59
 
46
60
def unpack_cairo_pattern(value):
 
61
    """Transforms the specified RGBA value into a SolidPattern object."""
47
62
    red, green, blue, alpha = unpack_color(value)
48
63
    return cairo.SolidPattern(
49
64
        red / 65535.0,
52
67
        alpha / 65535.0)
53
68
 
54
69
def unpack_cairo_gradient(value):
 
70
    """Creates a LinearGradient object out of the specified RGBA value."""
55
71
    red, green, blue, alpha = unpack_color(value)
56
 
    ret = cairo.LinearGradient(0,0, 0, 50)
57
 
    ret.add_color_stop_rgba(50,
 
72
    gradient = cairo.LinearGradient(0, 0, 0, 50)
 
73
    gradient.add_color_stop_rgba(
 
74
        1.0,
58
75
        red / 65535.0,
59
76
        green / 65535.0,
60
77
        blue / 65535.0,
61
78
        alpha / 65535.0)
62
 
    ret.add_color_stop_rgba(0,
 
79
    gradient.add_color_stop_rgba(
 
80
        0,
63
81
        (red / 65535.0) * 1.5,
64
82
        (green / 65535.0) * 1.5,
65
83
        (blue / 65535.0) * 1.5,
66
84
        alpha / 65535.0)
67
 
    return ret
68
 
 
69
 
def beautify_factory(factory):
70
 
    ranks = {VideoStream: 0, AudioStream: 1, TextStream: 2, MultimediaStream: 3}
71
 
    def stream_sort_key(stream):
72
 
        return ranks[type(stream)]
73
 
 
74
 
    streams = factory.getOutputStreams()
75
 
    streams.sort(key=stream_sort_key)
76
 
    return ("<b>" + escape(unquote(factory.name)) + "</b>\n" +
77
 
        "\n".join((beautify_stream(stream) for stream in streams)))
78
 
 
79
 
def factory_name(factory):
80
 
    return escape(unquote(factory.name))
81
 
 
82
 
 
83
 
def beautify_stream(stream):
84
 
    if type(stream) == AudioStream:
85
 
        if stream.raw:
86
 
            templ = ngettext("<b>Audio:</b> %d channel at %d <i>Hz</i> (%d <i>bits</i>)",
87
 
                    "<b>Audio:</b> %d channels at %d <i>Hz</i> (%d <i>bits</i>)",
88
 
                    stream.channels)
89
 
            templ = templ % (stream.channels, stream.rate, stream.width)
90
 
            return templ
91
 
 
92
 
        return _("<b>Unknown Audio format:</b> %s") % stream.audiotype
93
 
 
94
 
    elif type(stream) == VideoStream:
95
 
        if stream.raw:
96
 
            if stream.framerate.num:
97
 
                templ = _("<b>Video:</b> %d x %d <i>pixels</i> at %.2f<i>fps</i>")
98
 
                templ = templ % (stream.par * stream.width , stream.height,
99
 
                        float(stream.framerate))
100
 
            else:
101
 
                templ = _("<b>Image:</b> %d x %d <i>pixels</i>")
102
 
                templ = templ % (stream.par * stream.width, stream.height)
103
 
            return templ
104
 
        return _("<b>Unknown Video format:</b> %s") % stream.videotype
105
 
 
106
 
    elif type(stream) == TextStream:
107
 
        return _("<b>Text:</b> %s") % stream.texttype
108
 
 
109
 
    raise NotImplementedError
 
85
    return gradient
110
86
 
111
87
def beautify_factory(factory):
112
88
    ranks = {VideoStream: 0, AudioStream: 1, TextStream: 2, MultimediaStream: 3}
170
146
    context.curve_to(x,y,x,y,x+r,y)             # Curve to A
171
147
    return
172
148
 
 
149
def model(columns, data):
 
150
    ret = gtk.ListStore(*columns)
 
151
    for datum in data:
 
152
        ret.append(datum)
 
153
    return ret
 
154
 
 
155
frame_rates = model((str, object), (
 
156
    (_("12 fps"), gst.Fraction(12.0, 1.0)),
 
157
    (_("15 fps"), gst.Fraction(15.0, 1.0)),
 
158
    (_("20 fps"), gst.Fraction(20.0, 1.0)),
 
159
    (_("23,976 fps"), gst.Fraction(24000.0, 1001.0)),
 
160
    (_("24 fps"), gst.Fraction(24.0, 1.0)),
 
161
    (_("25 fps"), gst.Fraction(25.0, 1.0)),
 
162
    (_("29,97 fps"), gst.Fraction(30000.0, 1001.0)),
 
163
    (_("30 fps"), gst.Fraction(30.0, 1.0)),
 
164
    (_("50 fps"), gst.Fraction(50.0, 1.0)),
 
165
    (_("59,94 fps"), gst.Fraction(60000.0, 1001.0)),
 
166
    (_("60 fps"), gst.Fraction(60.0, 1.0)),
 
167
    (_("120 fps"), gst.Fraction(120.0, 1.0)),
 
168
))
 
169
 
 
170
audio_rates = model((str, int), (
 
171
    (_("8 KHz"),   8000),
 
172
    (_("11 KHz"),  11025),
 
173
    (_("22 KHz"),  22050),
 
174
    (_("44.1 KHz"), 44100),
 
175
    (_("48 KHz"),  48000),
 
176
    (_("96 KHz"),  96000)
 
177
))
 
178
 
 
179
audio_depths = model((str, int), (
 
180
    (_("8 bit"),  8),
 
181
    (_("16 bit"), 16),
 
182
    (_("24 bit"), 24),
 
183
    (_("32 bit"), 32)
 
184
))
 
185
 
 
186
audio_channels = model((str, int), (
 
187
    (_("6 Channels (5.1)"), 6),
 
188
    (_("4 Channels (4.0)"), 4),
 
189
    (_("Stereo"), 2),
 
190
    (_("Mono"), 1)
 
191
))
 
192
 
 
193
def set_combo_value(combo, value, default_index=-1):
 
194
    model = combo.props.model
 
195
    for i, row in enumerate(model):
 
196
        if row[1] == value:
 
197
            combo.set_active(i)
 
198
            return
 
199
    combo.set_active(default_index)
 
200
 
 
201
def get_combo_value(combo):
 
202
    active = combo.get_active()
 
203
    return combo.props.model[active][1]
 
204