~timo-jyrinki/ubuntu/trusty/pitivi/backport_utopic_fixes

« back to all changes in this revision

Viewing changes to pitivi/dialogs/filelisterrordialog.py

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2014-04-05 15:28:16 UTC
  • mfrom: (6.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20140405152816-6lijoax4cngiz5j5
Tags: 0.93-3
* debian/control:
  + Depend on python-gi (>= 3.10), older versions do not work
    with pitivi (Closes: #732813).
  + Add missing dependency on gir1.2-clutter-gst-2.0 (Closes: #743692).
  + Add suggests on gir1.2-notify-0.7 and gir1.2-gnomedesktop-3.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Pitivi video editor
 
2
#
 
3
#       pitivi/dialogs/filelisterrordialog.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., 51 Franklin St, Fifth Floor,
 
20
# Boston, MA 02110-1301, USA.
 
21
 
 
22
"""
 
23
Dialog box listing files which had errors, and the reasons.
 
24
"""
 
25
 
 
26
from gi.repository import Gtk
 
27
import os
 
28
from gi.repository import Pango
 
29
 
 
30
from gettext import gettext as _
 
31
 
 
32
from urllib import unquote
 
33
from pitivi.configure import get_ui_dir
 
34
from pitivi.utils.signal import Signallable
 
35
from pitivi.utils.loggable import Loggable
 
36
 
 
37
 
 
38
class FileListErrorDialog(Signallable, Loggable):
 
39
    """ Dialog box for showing errors in a list of files """
 
40
    __signals__ = {
 
41
        'close': None,
 
42
        'response': ["something"]}
 
43
 
 
44
    def __init__(self, title, headline):
 
45
        Loggable.__init__(self)
 
46
        self.builder = Gtk.Builder()
 
47
        self.builder.add_from_file(os.path.join(get_ui_dir(),
 
48
            "filelisterrordialog.ui"))
 
49
        self.builder.connect_signals(self)
 
50
 
 
51
        self.window = self.builder.get_object("filelisterrordialog")
 
52
        self.window.set_modal(False)
 
53
        self.window.set_title(title)
 
54
 
 
55
        self.builder.get_object("headline").set_text(headline)
 
56
        self.errorvbox = self.builder.get_object("errorvbox")
 
57
 
 
58
    def addFailedFile(self, uri, reason=_("Unknown reason"), extra=None):
 
59
        """Add the given uri to the list of failed files. You can optionnaly
 
60
        give a string identifying the reason why the file failed to be
 
61
        discovered
 
62
        """
 
63
        self.debug("Uri: %s, reason: %s, extra: %s", uri, reason, extra)
 
64
        exp = self.__createFileExpander(uri, reason, extra)
 
65
        self.errorvbox.pack_start(exp, False, False, 0)
 
66
        if len(self.errorvbox.get_children()) < 3:
 
67
            exp.set_expanded(True)  # Let's save the user some clicks
 
68
        exp.show_all()
 
69
 
 
70
    @staticmethod
 
71
    def __createFileExpander(uri, reason, extra=None):
 
72
        if uri:
 
73
            if uri.startswith("file://"):
 
74
                uri = uri[7:]
 
75
            uri = uri.split('/')[-1]
 
76
            uri = unquote(uri)
 
77
            exp = Gtk.Expander(label=uri)
 
78
        else:
 
79
            exp = Gtk.Expander(label=reason)
 
80
 
 
81
        textbuffer = Gtk.TextBuffer()
 
82
        table = textbuffer.get_tag_table()
 
83
        boldtag = Gtk.TextTag()
 
84
        boldtag.props.weight = Pango.Weight.BOLD
 
85
        table.add(boldtag)
 
86
 
 
87
        end = textbuffer.get_end_iter()
 
88
        textbuffer.insert_with_tags(end, _("Problem:") + " ", boldtag)
 
89
 
 
90
        end = textbuffer.get_end_iter()
 
91
        textbuffer.insert(end, "%s\n" % reason)
 
92
 
 
93
        if extra:
 
94
            end = textbuffer.get_end_iter()
 
95
            textbuffer.insert_with_tags(end, _("Extra information:") + " ", boldtag)
 
96
 
 
97
            end = textbuffer.get_end_iter()
 
98
            textbuffer.insert(end, "%s\n" % extra)
 
99
 
 
100
        textview = Gtk.TextView(buffer=textbuffer)
 
101
        textview.set_wrap_mode(Gtk.WrapMode.WORD)
 
102
 
 
103
        exp.add(textview)
 
104
 
 
105
        return exp
 
106
 
 
107
    def isVisible(self):
 
108
        """ returns True if this dialog is currently shown """
 
109
        return self.window.get_property("visible")
 
110
 
 
111
    def destroy(self):
 
112
        """Destroy internal window"""
 
113
        self.window.destroy()
 
114
 
 
115
    ## Callbacks from glade
 
116
 
 
117
    def _closeCb(self, unused_dialog):
 
118
        """Emit the close signal"""
 
119
        self.emit('close')
 
120
 
 
121
    def _responseCb(self, unused_dialog, response):
 
122
        """Emit the response signal"""
 
123
        self.emit('response', response)