Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/SynthLab/SynthLabToolbars.py
blob: 6ec55cf1750dafdd068a5a6b5e9ded5b40bc7ec9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import gtk
import common.Config as Config

from sugar.graphics.toolbutton import ToolButton
from sugar.graphics.toggletoolbutton import ToggleToolButton
from sugar.graphics.radiotoolbutton import RadioToolButton
from gettext import gettext as _


def main_toolbar_common(toolbar, synthLab):

        def _button_factory(name='', toolbar=None, cb=None, arg=None,
                            tooltip=None, toggle=True):
            ''' Add a toggle button to a toolbar '''
            if toggle:
                button = ToggleToolButton(name)
            else:
                button = ToolButton(name)
            if cb is not None:
                if arg is None:
                    button.connect('clicked', cb)
                else:
                    button.connect('clicked', cb, arg)
            if toolbar is not None:
                toolbar.insert(button, -1)
            button.show()
            if tooltip is not None:
                button.set_tooltip(tooltip)
            return button

        def _insertSeparator(toolbar, x=1):
            for i in range(x):
                separator = gtk.SeparatorToolItem()
                separator.set_draw(False)
                toolbar.insert(separator, -1)
                separator.show()

        def _label_factory(label='', toolbar=None):
            ''' Add a label to a toolbar '''
            mylabel = gtk.Label(label)
            mytool = gtk.ToolItem()
            mytool.add(mylabel)
            mylabel.show()
            if toolbar is not None:
                toolbar.insert(mytool, -1)
            mytool.show()
            return mylabel

        def _slider_factory(toolbar=None, cb=None, tooltip=None):
            ''' Add a slider to a toolbar '''
            sliderAdj = gtk.Adjustment(2, .5, 30, .01, .01, 0)
            sliderAdj.connect("value_changed", cb)
            slider = gtk.HScale(adjustment=sliderAdj)
            slider.set_size_request(250,15)
            slider.set_inverted(False)
            slider.set_value_pos(gtk.POS_RIGHT)
            sliderTool = gtk.ToolItem()
            sliderTool.add(slider)
            sliderTool.show()
            tooltips = gtk.Tooltips()
            sliderTool.set_tooltip(tooltips, tooltip)
            toolbar.insert(sliderTool, -1)
            slider.show()
            return sliderAdj

        durationSliderLabel = _label_factory(label=_('Duration:  '),
                                             toolbar=toolbar)

        durationSliderAdj = _slider_factory(toolbar=toolbar,
                                            cb=synthLab.handleDuration,
                                            tooltip=_('Duration'))

        durationSliderLabelSecond = _label_factory(label=_(' s.'),
                                                   toolbar=toolbar)

        _insertSeparator(toolbar, 1)

        resetButton = _button_factory(
            name='edit-clear',
            toolbar=toolbar,
            cb=synthLab.handleReset,
            tooltip=_('Reset the worktable'),
            toggle=False)

        return durationSliderAdj


class mainToolbar(gtk.Toolbar):
    def __init__(self, toolbox, synthLab):
        gtk.Toolbar.__init__(self)

        self.durationSliderAdj = main_toolbar_common(self, synthLab)


class recordToolbar(gtk.Toolbar):
    def __init__(self, toolbox, synthLab):
        gtk.Toolbar.__init__(self)

        def _button_factory(name='', toolbar=None, cb=None, arg=None,
                            tooltip=None, toggle=True):
            ''' Add a toggle button to a toolbar '''
            if toggle:
                button = ToggleToolButton(name)
            else:
                button = ToolButton(name)
            if cb is not None:
                if arg is None:
                    button.connect('clicked', cb)
                else:
                    button.connect('clicked', cb, arg)
            if toolbar is not None:
                toolbar.insert(button, -1)
            button.show()
            if tooltip is not None:
                button.set_tooltip(tooltip)
            return button

        def _insertSeparator(x=1):
            for i in range(x):
                self.separator = gtk.SeparatorToolItem()
                self.separator.set_draw(False)
                self.insert(self.separator, -1)
                self.separator.show()

        self.toolbox = toolbox
        self.synthLab = synthLab

        if Config.FEATURES_LAB:
            self.synthRecButtons = []
            for i in range(6):
                j = i + 1
                self.synthRecButton.append(_button_factory(
                        name='rec%d' % (j),
                        toolbar=self,
                        cb=self.synthLab.recordSound,
                        arg=j,
                        tooltip=_('Record Synth sound into slot') + \
                            ' "lab%d"' % (j)))

        if False: #Config.FEATURES_OGG:
            # Disabled .ogg support until fixing #2669
            #RecordOgg button
            self.recordOggButton = _button_factory(
                name='record0',
                toolbar=self,
                cb=self.synthLab.recordOgg,
                tooltip=_('Record to ogg'))


class presetToolbar(gtk.Toolbar):
    def __init__(self,toolbox, synthLab):
        gtk.Toolbar.__init__(self)

        def _insertSeparator(x = 1):
            for i in range(x):
                self.separator = gtk.SeparatorToolItem()
                self.separator.set_draw(False)
                self.insert(self.separator,-1)
                self.separator.show()

        def _radio_button_factory(name='', toolbar=None, cb=None, arg=None,
                                  tooltip=None, group=None):
            ''' Add a radio button to a toolbar '''
            button = RadioToolButton(group=group)
            button.set_named_icon(name)
            if cb is not None:
                if arg is None:
                    button.connect('clicked', cb)
                else:
                    button.connect('clicked', cb, arg)
            if toolbar is not None:
                toolbar.insert(button, -1)
            button.show()
            if tooltip is not None:
                button.set_tooltip(tooltip)
            return button

        self.toolbox = toolbox
        self.synthLab = synthLab

        self.presetButton = []
        for i in range(10):
            j = i + 1
            if i == 0:
                self.presetButton.append(_radio_button_factory(
                        name='preset%d' % (j),
                        toolbar=self,
                        cb=self.synthLab.presetCallback,
                        arg=j,
                        tooltip=_('Preset') + ' %d' % (j),
                        group=None))
            else:
                self.presetButton.append(_radio_button_factory(
                        name='preset%d' % (j),
                        toolbar=self,
                        cb=self.synthLab.presetCallback,
                        arg=j,
                        tooltip=_('Preset') + ' %d' % (j),
                        group=self.presetButton[0]))