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

« back to all changes in this revision

Viewing changes to pitivi/ui/gstwidget.py

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2006-02-04 14:42:30 UTC
  • Revision ID: james.westby@ubuntu.com-20060204144230-9ihvyas6lhgn81k1
Tags: upstream-0.9.9.2
ImportĀ upstreamĀ versionĀ 0.9.9.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# PiTiVi , Non-linear video editor
 
2
#
 
3
#       ui/gstwidget.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
import string
 
23
import gobject
 
24
import gtk
 
25
import gst
 
26
from glade import GladeWindow
 
27
 
 
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()
 
39
    return None
 
40
 
 
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)
 
44
    if value == None:
 
45
        value = element.get_property(property.name)
 
46
    if (type_name == 'gchararray'):
 
47
        widget = gtk.Entry()
 
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)
 
61
            widget.set_digits(5)
 
62
        widget.set_value(float(value))
 
63
    elif (type_name == 'gboolean'):
 
64
        widget = gtk.CheckButton()
 
65
        if value:
 
66
            widget.set_active(True)
 
67
    else:
 
68
        widget = gtk.Label(type_name)
 
69
        widget.set_alignment(1.0, 0.5)
 
70
 
 
71
    if not property.flags & gobject.PARAM_WRITABLE:
 
72
        widget.set_sensitive(False)
 
73
    return widget
 
74
 
 
75
class GstElementSettingsWidget(gtk.VBox):
 
76
 
 
77
    def __init__(self):
 
78
        gtk.VBox.__init__(self)
 
79
 
 
80
    def set_element(self, element, properties={}, ignore=['name']):
 
81
        gst.info("element:%s, properties:%s" % (element, properties))
 
82
        self.element = element
 
83
        self.ignore = ignore
 
84
        self.properties = {} #key:name, value:widget
 
85
        self._add_widgets(properties)        
 
86
 
 
87
    def _add_widgets(self, properties):
 
88
        props = [x for x in gobject.list_properties(self.element) if not x.name in self.ignore]
 
89
        if not props:
 
90
            self.pack_start(gtk.Label("No properties..."))
 
91
            self.show_all()
 
92
            return
 
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)
 
97
        y = 0
 
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
 
105
            y += 1
 
106
        self.pack_start(table)
 
107
        self.show_all()
 
108
 
 
109
    def get_settings(self):
 
110
        """ returns the dictionnary of propertyname/propertyvalue """
 
111
        d = {}
 
112
        for property, widget in self.properties.iteritems():
 
113
            if not property.flags & gobject.PARAM_WRITABLE:
 
114
                continue
 
115
            value = get_widget_propvalue(property, widget)
 
116
            if not value == None:
 
117
                d[property.name] = value
 
118
        return d
 
119
                            
 
120
 
 
121
    
 
122
class GstElementSettingsDialog(GladeWindow):
 
123
    glade_file = "elementsettingsdialog.glade"
 
124
 
 
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")
 
130
        if not self.element:
 
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
 
135
        self._fill_window()
 
136
 
 
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)
 
145
 
 
146
    def get_settings(self):
 
147
        """ returns the property/value dictionnary of the selected settings """
 
148
        return self.widgets["elementsettings"].get_settings()
 
149