1 # Copyright (C) 2009, Thomas Leonard
2 # See the README file for details, or visit http://0install.net.
7 from zeroinstall
.support
import tasks
8 from zeroinstall
.gtkui
import gtkutils
14 gladefile
= os
.path
.join(os
.path
.dirname(__file__
), 'zero-install.glade')
16 class Template(gtkutils
.Template
):
17 def __init__(self
, root
):
18 gtkutils
.Template
.__init
__(self
, gladefile
, root
)
20 class Dialog(gtk
.Dialog
):
24 gtk
.Dialog
.__init
__(self
)
25 self
.set_has_separator(False)
26 self
.set_position(gtk
.WIN_POS_CENTER
)
28 def add_mixed_button(self
, message
, stock
, response
):
29 button
= MixedButton(message
, stock
)
30 button
.set_flags(gtk
.CAN_DEFAULT
)
32 self
.add_action_widget(button
, response
)
36 class DialogResponse(tasks
.Blocker
):
38 def __init__(self
, dialog
):
39 tasks
.Blocker
.__init
__(self
, dialog
.get_title())
41 def response(d
, resp
):
45 a
= dialog
.connect('response', response
)
47 class ButtonClickedBlocker(tasks
.Blocker
):
48 def __init__(self
, button
):
49 tasks
.Blocker
.__init
__(self
, "Button click")
54 a
= button
.connect('clicked', lambda b
: self
.trigger())
56 def alert(parent
, message
, type = gtk
.MESSAGE_ERROR
):
57 if type == gtk
.MESSAGE_ERROR
:
61 gtkutils
.show_message_box(parent
, message
, type)
63 def MixedButton(message
, stock
, x_align
= 0.5, button
= None):
68 label
.set_text_with_mnemonic(message
)
69 label
.set_mnemonic_widget(button
)
71 image
= gtk
.image_new_from_stock(stock
, gtk
.ICON_SIZE_BUTTON
)
72 box
= gtk
.HBox(False, 2)
73 align
= gtk
.Alignment(x_align
, 0.5, 0.0, 0.0)
75 box
.pack_start(image
, False, False, 0)
76 box
.pack_end(label
, False, False, 0)
82 def frame(page
, title
, content
, expand
= False):
85 label
.set_markup('<b>%s</b>' % title
)
86 frame
.set_label_widget(label
)
87 frame
.set_shadow_type(gtk
.SHADOW_NONE
)
88 if type(content
) in (str, unicode):
89 content
= gtk
.Label(content
)
90 content
.set_alignment(0, 0.5)
91 content
.set_selectable(True)
93 if hasattr(content
, 'set_padding'):
94 content
.set_padding(8, 4)
96 content
.set_border_width(8)
97 page
.pack_start(frame
, expand
, True, 0)