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.
26
from glade import GladeWindow
28
def get_widget_propvalue(property, widget):
29
""" returns the value of the given propertywidget """
30
type_name = gobject.type_name(property.value_type)
31
if (type_name == 'gchararray'):
32
return widget.get_text()
33
if (type_name in ['guint64', 'gint64', 'gint', 'gulong']):
34
return widget.get_value_as_int()
35
if (type_name in ['gfloat']):
36
return widget.get_value()
37
if (type_name in ['gboolean']):
38
return widget.get_active()
41
def make_property_widget(element, property, value=None):
42
""" Creates a Widget for the given element property """
43
type_name = gobject.type_name(property.value_type)
45
value = element.get_property(property.name)
46
if (type_name == 'gchararray'):
48
widget.set_text(str(value))
49
elif (type_name in ['guint64', 'gint64', 'gint', 'gfloat', 'gulong']):
50
widget = gtk.SpinButton()
51
if type_name == 'gint':
52
widget.set_range(-(2**31), 2**31 - 1)
53
elif type_name == 'guint':
54
widget.set_range(0, 2**32 - 1)
55
elif type_name == 'gint64':
56
widget.set_range(-(2**63), 2**63 - 1)
57
elif type_name in ['gulong', 'guint64']:
58
widget.set_range(0, 2**64 - 1)
59
elif type_name == 'gfloat':
60
widget.set_range(0.0, 2**64 - 1)
62
widget.set_value(float(value))
63
elif (type_name == 'gboolean'):
64
widget = gtk.CheckButton()
66
widget.set_active(True)
68
widget = gtk.Label(type_name)
69
widget.set_alignment(1.0, 0.5)
71
if not property.flags & gobject.PARAM_WRITABLE:
72
widget.set_sensitive(False)
75
class GstElementSettingsWidget(gtk.VBox):
78
gtk.VBox.__init__(self)
80
def set_element(self, element, properties={}, ignore=['name']):
81
gst.info("element:%s, properties:%s" % (element, properties))
82
self.element = element
84
self.properties = {} #key:name, value:widget
85
self._add_widgets(properties)
87
def _add_widgets(self, properties):
88
props = [x for x in gobject.list_properties(self.element) if not x.name in self.ignore]
90
self.pack_start(gtk.Label("No properties..."))
93
table = gtk.Table(rows=len(props), columns=2)
94
table.set_row_spacings(5)
95
table.set_col_spacings(5)
96
table.set_border_width(5)
98
for property in props:
99
label = gtk.Label(property.nick)
100
label.set_alignment(0.0, 0.5)
101
widget = make_property_widget(self.element, property, properties.get(property.name))
102
table.attach(label, 0, 1, y, y+1, xoptions=gtk.FILL, yoptions=gtk.FILL)
103
table.attach(widget, 1, 2, y, y+1, yoptions=gtk.FILL)
104
self.properties[property] = widget
106
self.pack_start(table)
109
def get_settings(self):
110
""" returns the dictionnary of propertyname/propertyvalue """
112
for property, widget in self.properties.iteritems():
113
if not property.flags & gobject.PARAM_WRITABLE:
115
value = get_widget_propvalue(property, widget)
116
if not value == None:
117
d[property.name] = value
122
class GstElementSettingsDialog(GladeWindow):
123
glade_file = "elementsettingsdialog.glade"
125
def __init__(self, elementfactory, properties={}):
126
GladeWindow.__init__(self)
127
gst.debug("factory:%s, properties:%s" % (elementfactory, properties))
128
self.factory = elementfactory
129
self.element = self.factory.create("elementsettings")
131
gst.warning("Couldn't create element from factory %s" % self.factory)
132
self.desclabel = self.widgets["descriptionlabel"]
133
self.authlabel = self.widgets["authorlabel"]
134
self.properties = properties
137
def _fill_window(self):
138
# set title and frame label
139
self.window.set_title("Properties for " + self.factory.get_longname())
140
self.widgets["infolabel"].set_markup("<b>" + self.factory.get_longname() + "</b>")
141
self.desclabel.set_text(self.factory.get_description())
142
self.authlabel.set_text(string.join(self.factory.get_author().split(","), "\n"))
143
self.authlabel.set_justify(gtk.JUSTIFY_RIGHT)
144
self.widgets["elementsettings"].set_element(self.element, self.properties)
146
def get_settings(self):
147
""" returns the property/value dictionnary of the selected settings """
148
return self.widgets["elementsettings"].get_settings()