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

« back to all changes in this revision

Viewing changes to pitivi/ui/sourcelist.py

* New upstream pre-release:
  + debian/control:
    - Update dependencies.
* debian/control:
  + Update Standards-Version to 3.8.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
import time
28
28
 
29
29
from urllib import unquote
 
30
from xml.sax.saxutils import escape
30
31
from gettext import gettext as _
31
32
from gettext import ngettext
32
33
 
35
36
from pitivi.ui.filelisterrordialog import FileListErrorDialog
36
37
from pitivi.configure import get_pixmap_dir
37
38
from pitivi.signalgroup import SignalGroup
38
 
from pitivi.stream import VideoStream, AudioStream, TextStream
 
39
from pitivi.stream import VideoStream, AudioStream, TextStream, \
 
40
        MultimediaStream
39
41
from pitivi.settings import GlobalSettings
40
42
from pitivi.utils import beautify_length
41
43
from pitivi.log.loggable import Loggable
88
90
            templ = ngettext("<b>Audio:</b> %d channel at %d <i>Hz</i> (%d <i>bits</i>)",
89
91
                    "<b>Audio:</b> %d channels at %d <i>Hz</i> (%d <i>bits</i>)",
90
92
                    stream.channels)
91
 
            try:
92
 
                templ = templ % (stream.channels, stream.rate, stream.width)
93
 
            except TypeError:
94
 
                import pdb; pdb.set_trace()
 
93
            templ = templ % (stream.channels, stream.rate, stream.width)
95
94
            return templ
96
95
 
97
96
        return _("<b>Unknown Audio format:</b> %s") % stream.audiotype
114
113
    raise NotImplementedError
115
114
 
116
115
def beautify_factory(factory):
117
 
    ranks = {VideoStream: 0, AudioStream: 1}
 
116
    ranks = {VideoStream: 0, AudioStream: 1, TextStream: 2, MultimediaStream: 3}
118
117
    def stream_sort_key(stream):
119
118
        return ranks[type(stream)]
120
119
 
121
120
    streams = factory.getOutputStreams()
122
121
    streams.sort(key=stream_sort_key)
123
 
    return ("<b>" + unquote(factory.displayname) + "</b>\n" +
 
122
    return ("<b>" + escape(unquote(factory.name)) + "</b>\n" +
124
123
        "\n".join((beautify_stream(stream) for stream in streams)))
125
124
 
126
125
class SourceList(gtk.VBox, Loggable):
247
246
        # Connect to project.  We must remove and reset the callbacks when
248
247
        # changing project.
249
248
        self.project_signals = SignalGroup()
250
 
        self._connectToProject(self.app.current)
 
249
        self.app.connect("new-project-created",
 
250
            self._newProjectCreatedCb)
251
251
        self.app.connect("new-project-loaded",
252
252
            self._newProjectLoadedCb)
253
253
        self.app.connect("new-project-failed",
298
298
 
299
299
        actiongroup = gtk.ActionGroup("sourcelistpermanent")
300
300
        actiongroup.add_actions(actions)
 
301
        actiongroup.get_action("ImportSources").props.is_important = True
301
302
        uiman.insert_action_group(actiongroup, 0)
302
303
 
303
304
        self.selection_actions = gtk.ActionGroup("sourcelistselection")
316
317
        self._removeSources()
317
318
 
318
319
    def _insertEndCb(self, unused_action):
 
320
        self.app.action_log.begin("add clip")
319
321
        timeline = self.app.current.timeline
320
322
        sources = self.app.current.sources
321
323
        start = timeline.duration
322
324
        for uri in self.getSelectedItems():
323
 
            factory = sources[uri]
 
325
            factory = sources.getUri(uri)
324
326
            source = timeline.addSourceFactory(factory)
325
327
            source.setStart(start)
326
328
            start += source.duration
 
329
        self.app.action_log.commit()
327
330
 
328
331
    def _getIcon(self, iconname, alternate):
329
332
        icontheme = gtk.icon_theme_get_default()
346
349
 
347
350
        """
348
351
        self.project_signals.connect(
349
 
            project.sources, "file_added", None, self._fileAddedCb)
 
352
            project.sources, "source-added", None, self._sourceAddedCb)
350
353
        self.project_signals.connect(
351
 
            project.sources, "file_removed", None, self._fileRemovedCb)
 
354
            project.sources, "source-removed", None, self._sourceRemovedCb)
352
355
        self.project_signals.connect(
353
356
            project.sources, "discovery-error", None, self._discoveryErrorCb)
354
 
        self.project_signals.connect(
355
 
            project.sources, "missing-plugins", None, self._missingPluginsCb)
 
357
        #self.project_signals.connect(
 
358
        #    project.sources, "missing-plugins", None, self._missingPluginsCb)
356
359
        self.project_signals.connect(
357
360
            project.sources, "ready", None, self._sourcesStoppedImportingCb)
358
361
        self.project_signals.connect(
464
467
        self.storemodel.append([thumbnail,
465
468
            beautify_factory(factory),
466
469
            factory,
467
 
            factory.name,
 
470
            factory.uri,
468
471
            duration])
469
472
        self._displayTreeView()
470
473
 
471
474
    # sourcelist callbacks
472
475
 
473
 
    def _fileAddedCb(self, unused_sourcelist, factory):
 
476
    def _sourceAddedCb(self, unused_sourcelist, factory):
474
477
        """ a file was added to the sourcelist """
475
478
        self._addFactory(factory)
476
479
 
477
 
    def _fileRemovedCb(self, unused_sourcelist, uri):
 
480
    def _sourceRemovedCb(self, sourcelist, uri, factory):
478
481
        """ the given uri was removed from the sourcelist """
479
482
        # find the good line in the storemodel and remove it
480
483
        model = self.storemodel
549
552
        selected.sort(reverse=True)
550
553
        for path in selected:
551
554
            uri = model[path][COL_URI]
552
 
            del self.app.current.sources[uri]
 
555
            self.app.current.sources.removeUri(uri)
553
556
 
554
557
    ## UI Button callbacks
555
558
 
569
572
            return
570
573
        path = paths[0]
571
574
        factory = model[path][COL_FACTORY]
572
 
        self.debug("Let's play %s", factory.name)
 
575
        self.debug("Let's play %s", factory.uri)
573
576
        self.emit('play', factory)
574
577
 
575
578
    _dragStarted = False
652
655
        factory = self.storemodel[path][COL_FACTORY]
653
656
        self.emit('play', factory)
654
657
 
655
 
    def _newProjectLoadedCb(self, unused_pitivi, project):
 
658
    def _newProjectCreatedCb(self, app, project):
656
659
        # clear the storemodel
657
660
        self.storemodel.clear()
658
661
        self._connectToProject(project)
659
 
        # synchronize the storemodel with the new project's sourcelist
660
 
        if project.loaded:
661
 
            for uri, factory in project.sources:
662
 
                self.log("loading uri %s", uri)
663
 
                self._addFactory(factory)
664
 
        else:
665
 
            if not self.infostub.showing:
666
 
                self.pack_start(self.infostub, expand=False)
667
 
                self.infostub.startingImport()
 
662
 
 
663
 
 
664
    def _newProjectLoadingCb(self, unused_pitivi, uri):
 
665
        if not self.infostub.showing:
 
666
            self.pack_start(self.infostub, expand=False)
 
667
            self.infostub.startingImport()
 
668
 
 
669
    def _newProjectLoadedCb(self, unused_pitivi, project):
 
670
        pass
668
671
 
669
672
    def _newProjectFailedCb(self, unused_pitivi, unused_reason,
670
673
        unused_uri):
742
745
        self.errors = []
743
746
        self.showing = False
744
747
        self._importingmessage = _("Importing clips...")
745
 
        self._errorsmessage = _("Error(s) occured while importing")
746
 
        self._errormessage = _("An error occured while importing")
 
748
        self._errorsmessage = _("Error(s) occurred while importing")
 
749
        self._errormessage = _("An error occurred while importing")
747
750
        self._makeUI()
748
751
 
749
752
    def _makeUI(self):