1 # Copyright (C) 2009, Thomas Leonard
2 # See the README file for details, or visit http://0install.net.
6 from zeroinstall
.support
import tasks
7 from zeroinstall
.gtkui
import gtkutils
13 builderfile
= os
.path
.join(os
.path
.dirname(__file__
), 'zero-install.ui')
15 class Template(gtkutils
.Template
):
16 def __init__(self
, root
):
17 gtkutils
.Template
.__init
__(self
, builderfile
, root
)
19 class Dialog(gtk
.Dialog
):
21 gtk
.Dialog
.__init
__(self
)
22 self
.set_has_separator(False)
23 self
.set_position(gtk
.WIN_POS_CENTER
)
25 def add_mixed_button(self
, message
, stock
, response
):
26 button
= MixedButton(message
, stock
)
27 button
.set_flags(gtk
.CAN_DEFAULT
)
29 self
.add_action_widget(button
, response
)
33 class DialogResponse(tasks
.Blocker
):
35 def __init__(self
, dialog
):
36 tasks
.Blocker
.__init
__(self
, dialog
.get_title())
38 def response(d
, resp
):
42 a
= dialog
.connect('response', response
)
44 class ButtonClickedBlocker(tasks
.Blocker
):
45 def __init__(self
, button
):
46 tasks
.Blocker
.__init
__(self
, "Button click")
51 a
= button
.connect('clicked', lambda b
: self
.trigger())
53 def alert(parent
, message
, type = gtk
.MESSAGE_ERROR
):
54 if type == gtk
.MESSAGE_ERROR
:
58 gtkutils
.show_message_box(parent
, message
, type)
60 def MixedButton(message
, stock
, x_align
= 0.5, button
= None):
65 label
.set_text_with_mnemonic(message
)
66 label
.set_mnemonic_widget(button
)
68 image
= gtk
.image_new_from_stock(stock
, gtk
.ICON_SIZE_BUTTON
)
69 box
= gtk
.HBox(False, 2)
70 align
= gtk
.Alignment(x_align
, 0.5, 0.0, 0.0)
72 box
.pack_start(image
, False, False, 0)
73 box
.pack_end(label
, False, False, 0)