1
# PiTiVi , Non-linear video editor
5
# Copyright (c) 2005, Edward Hervey <bilboed@bilboed.com>
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.
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.
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.
23
Editor for aribtrary properties of timeline objects
27
from gettext import gettext as _
28
from gettext import ngettext
30
def get_widget_propvalue(widget):
32
""" returns the value of the given propertywidget """
33
# FIXME : implement the case for flags
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()
43
return widget.get_model()[widget.get_active()][1]
46
def make_property_widget(t, value=None):
47
""" Creates a Widget for the given element property """
50
widget.set_text(str(value))
51
elif (t in [int, float, long]):
52
widget = gtk.SpinButton()
54
widget.set_range(-(2**31), 2**31 - 1)
56
widget.set_range(float("-Infinity"),float("Infinity"))
58
widget.set_range(0.0, 2**64 - 1)
60
#widget.set_value(float(value))
61
elif (t == 'gboolean'):
62
widget = gtk.CheckButton()
64
widget.set_active(True)
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)
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])
78
# widget.set_active(selected)
80
widget = gtk.Label(repr(t))
81
widget.set_alignment(1.0, 0.5)
86
class DefaultPropertyEditor(gtk.Viewport):
88
def __init__(self, *args, **kwargs):
89
gtk.Viewport.__init__(self, *args, **kwargs)
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)
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))
108
# we may have a non-homogeneous set of objects selected
109
# so take the intersection of the properties they have in common
112
properties = set(i.next().__editable_properties__)
114
properties &= set(obj.__editable_properties__)
115
self._addWidgets(properties)
117
def _addWidgets(self, 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)
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