3
# pitivi/dialogs/filelisterrordialog.py
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., 51 Franklin St, Fifth Floor,
20
# Boston, MA 02110-1301, USA.
23
Dialog box listing files which had errors, and the reasons.
26
from gi.repository import Gtk
28
from gi.repository import Pango
30
from gettext import gettext as _
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
38
class FileListErrorDialog(Signallable, Loggable):
39
""" Dialog box for showing errors in a list of files """
42
'response': ["something"]}
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)
51
self.window = self.builder.get_object("filelisterrordialog")
52
self.window.set_modal(False)
53
self.window.set_title(title)
55
self.builder.get_object("headline").set_text(headline)
56
self.errorvbox = self.builder.get_object("errorvbox")
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
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
71
def __createFileExpander(uri, reason, extra=None):
73
if uri.startswith("file://"):
75
uri = uri.split('/')[-1]
77
exp = Gtk.Expander(label=uri)
79
exp = Gtk.Expander(label=reason)
81
textbuffer = Gtk.TextBuffer()
82
table = textbuffer.get_tag_table()
83
boldtag = Gtk.TextTag()
84
boldtag.props.weight = Pango.Weight.BOLD
87
end = textbuffer.get_end_iter()
88
textbuffer.insert_with_tags(end, _("Problem:") + " ", boldtag)
90
end = textbuffer.get_end_iter()
91
textbuffer.insert(end, "%s\n" % reason)
94
end = textbuffer.get_end_iter()
95
textbuffer.insert_with_tags(end, _("Extra information:") + " ", boldtag)
97
end = textbuffer.get_end_iter()
98
textbuffer.insert(end, "%s\n" % extra)
100
textview = Gtk.TextView(buffer=textbuffer)
101
textview.set_wrap_mode(Gtk.WrapMode.WORD)
108
""" returns True if this dialog is currently shown """
109
return self.window.get_property("visible")
112
"""Destroy internal window"""
113
self.window.destroy()
115
## Callbacks from glade
117
def _closeCb(self, unused_dialog):
118
"""Emit the close signal"""
121
def _responseCb(self, unused_dialog, response):
122
"""Emit the response signal"""
123
self.emit('response', response)