2
# -*- coding: utf-8 -*-
5
# Copyright (C) 2007-2011 Tualatrix Chou <tualatrix@gmail.com>
6
# This program is free software: you can redistribute it and/or modify it
7
# under the terms of the GNU General Public License version 3, as published
8
# by the Free Software Foundation.
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranties of
12
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13
# PURPOSE. See the GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License along
16
# with this program. If not, see <http://www.gnu.org/licenses/>.
21
from gi.repository import GObject, Gtk, Gdk
23
class BaseDialog(Gtk.MessageDialog):
24
def __init__(self, **kwargs):
25
title = kwargs.pop('title', '')
26
message = kwargs.pop('message', '')
28
GObject.GObject.__init__(self, **kwargs)
34
self.set_content(message)
36
def set_title(self, title):
37
self.set_markup('<big><b>%s</b></big>' % title)
39
def set_content(self, message):
40
if self.get_property('text'):
41
self.format_secondary_markup(message)
43
self.set_markup(message)
49
def add_option_button(self, button):
50
'''Add an option button to the left. It will not grab the default response.'''
51
vbox = self.get_content_area()
52
hbuttonbox = vbox.get_children()[-1]
54
hbox = Gtk.HBox(spacing=12)
55
vbox.pack_start(hbox, False, False, 0)
56
vbox.remove(hbuttonbox)
58
new_hbuttonbox = Gtk.HButtonBox()
59
new_hbuttonbox.set_layout(Gtk.ButtonBoxStyle.START)
60
new_hbuttonbox.pack_start(button, True, True, 0)
62
hbox.pack_start(new_hbuttonbox, True, True, 0)
63
hbox.pack_start(hbuttonbox, True, True, 0)
65
hbuttonbox.get_children()[-1].grab_focus()
70
class ErrorDialog(BaseDialog):
71
def __init__(self, title='', message='', parent=None,
72
type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK):
73
BaseDialog.__init__(self, title=title, message=message,
74
parent=parent, message_type=type, buttons=buttons)