~ubuntu-branches/ubuntu/trusty/pitivi/trusty

« back to all changes in this revision

Viewing changes to pitivi/ui/defaultpropertyeditor.py

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2011-07-07 13:43:47 UTC
  • mto: (6.1.9 sid) (1.2.12)
  • mto: This revision was merged to the branch mainline in revision 32.
  • Revision ID: james.westby@ubuntu.com-20110707134347-cari9kxjiakzej9z
Tags: upstream-0.14.1
ImportĀ upstreamĀ versionĀ 0.14.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# PiTiVi , Non-linear video editor
2
 
#
3
 
#       ui/propertyeditor.py
4
 
#
5
 
# Copyright (c) 2005, Edward Hervey <bilboed@bilboed.com>
6
 
#
7
 
# This program is free software; you can redistribute it and/or
8
 
# modify it under the terms of the GNU Lesser General Public
9
 
# License as published by the Free Software Foundation; either
10
 
# version 2.1 of the License, or (at your option) any later version.
11
 
#
12
 
# This program is distributed in the hope that it will be useful,
13
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 
# Lesser General Public License for more details.
16
 
#
17
 
# You should have received a copy of the GNU Lesser General Public
18
 
# License along with this program; if not, write to the
19
 
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
 
# Boston, MA 02111-1307, USA.
21
 
 
22
 
"""
23
 
Editor for aribtrary properties of timeline objects
24
 
"""
25
 
 
26
 
import gtk
27
 
from gettext import gettext as _
28
 
from gettext import ngettext
29
 
 
30
 
def get_widget_propvalue(widget):
31
 
 
32
 
    """ returns the value of the given propertywidget """
33
 
    # FIXME : implement the case for flags
34
 
    t = type(widget)
35
 
 
36
 
    if (t == gtk.TextEntry):
37
 
        return widget.get_text()
38
 
    if (t == gtk.SpinButton):
39
 
        return widget.get_value()
40
 
    if (t == gtk.CheckButton):
41
 
        return widget.get_active()
42
 
    if t == gtk.ComboBox:
43
 
        return widget.get_model()[widget.get_active()][1]
44
 
    return None
45
 
 
46
 
def make_property_widget(t, value=None):
47
 
    """ Creates a Widget for the given element property """
48
 
    if (t == str):
49
 
        widget = gtk.Entry()
50
 
        widget.set_text(str(value))
51
 
    elif (t in [int, float, long]):
52
 
        widget = gtk.SpinButton()
53
 
        if t == int:
54
 
            widget.set_range(-(2**31), 2**31 - 1)
55
 
        elif t == long:
56
 
            widget.set_range(float("-Infinity"),float("Infinity"))
57
 
        elif t == float:
58
 
            widget.set_range(0.0, 2**64 - 1)
59
 
            widget.set_digits(5)
60
 
        #widget.set_value(float(value))
61
 
    elif (t == 'gboolean'):
62
 
        widget = gtk.CheckButton()
63
 
        if value:
64
 
            widget.set_active(True)
65
 
    #elif (t == tuple):
66
 
    #    model = gtk.ListStore(gobject.TYPE_STRING, prop.value_type)
67
 
    #    widget = gtk.ComboBox(model)
68
 
    #    cell = gtk.CellRendererText()
69
 
    #    widget.pack_start(cell, True)
70
 
    #    widget.add_attribute(cell, 'text', 0)
71
 
    #    idx = 0
72
 
    #    for key, val in prop.enum_class.__enum_values__.iteritems():
73
 
    #        gst.log("adding %s / %s" % (val.value_name, val))
74
 
    #        model.append([val.value_name, val])
75
 
    #        if val == value:
76
 
    #            selected = idx
77
 
    #        idx = idx + 1
78
 
    #    widget.set_active(selected)
79
 
    else:
80
 
        widget = gtk.Label(repr(t))
81
 
        widget.set_alignment(1.0, 0.5)
82
 
 
83
 
    return widget
84
 
 
85
 
 
86
 
class DefaultPropertyEditor(gtk.Viewport):
87
 
 
88
 
    def __init__(self, *args, **kwargs):
89
 
        gtk.Viewport.__init__(self, *args, **kwargs)
90
 
        self._properties = {}
91
 
        self._createUi()
92
 
 
93
 
    def _createUi(self):
94
 
        self.text = gtk.Label()
95
 
        self.table = gtk.Table(rows=1, columns=2)
96
 
        self.table.attach(self.text, 0, 2, 0, 1)
97
 
        self.table.set_row_spacings(5)
98
 
        self.table.set_col_spacings(5)
99
 
        self.table.set_border_width(5)
100
 
        self.add(self.table)
101
 
        self.show_all()
102
 
 
103
 
    def setObjects(self, objs):
104
 
        self.text.set_text(ngettext("Properties For: %d object",
105
 
                                    "Properties For: %d objects",
106
 
                                    len(objs)) % len(objs))
107
 
 
108
 
        # we may have a non-homogeneous set of objects selected
109
 
        # so take the intersection of the properties they have in common
110
 
        assert len(objs) > 0
111
 
        i = iter(objs)
112
 
        properties = set(i.next().__editable_properties__)
113
 
        for obj in i:
114
 
            properties &= set(obj.__editable_properties__)
115
 
        self._addWidgets(properties)
116
 
 
117
 
    def _addWidgets(self, props):
118
 
        if not props:
119
 
            self.text.set_text(_("No properties..."))
120
 
        for widget in self._properties.values():
121
 
            self.table.remove(widget)
122
 
        self.table.resize(len(props) + 1, 2)
123
 
        y = 1
124
 
        for name, type, minval, contrlbl in sorted(props):
125
 
            label = gtk.Label(_(name))
126
 
            label.set_alignment(0.0, 0.5)
127
 
            widget = make_property_widget(type)
128
 
            self.table.attach(label, 0, 1, y, y+1, xoptions=gtk.FILL, yoptions=gtk.FILL)
129
 
            self.table.attach(widget, 1, 2, y, y+1, yoptions=gtk.FILL)
130
 
            self._properties[name] = widget
131
 
        self.show_all()