4 from zeroinstall
.support
import tasks
10 gladefile
= os
.path
.join(os
.path
.dirname(__file__
), 'zero-install.glade')
12 # Wrapped for glade widget tree that throws a sensible exception if the widget isn't found
14 def __init__(self
, root
):
15 self
.widgets
= gtk
.glade
.XML(gladefile
, root
)
18 def get_widget(self
, name
= None):
21 widget
= self
.widgets
.get_widget(name
)
22 assert widget
, "Widget '%s' not found in glade file '%s'" % (name
, gladefile
)
25 class Dialog(gtk
.Dialog
):
29 gtk
.Dialog
.__init
__(self
)
30 self
.set_has_separator(False)
31 self
.set_position(gtk
.WIN_POS_CENTER
)
33 def add_mixed_button(self
, message
, stock
, response
):
34 button
= MixedButton(message
, stock
)
35 button
.set_flags(gtk
.CAN_DEFAULT
)
37 self
.add_action_widget(button
, response
)
41 class DialogResponse(tasks
.Blocker
):
43 def __init__(self
, dialog
):
44 tasks
.Blocker
.__init
__(self
, dialog
.get_title())
46 def response(d
, resp
):
50 a
= dialog
.connect('response', response
)
52 def alert(parent
, message
, type = gtk
.MESSAGE_ERROR
):
53 if type == gtk
.MESSAGE_ERROR
:
57 box
= gtk
.MessageDialog(parent
, gtk
.DIALOG_DESTROY_WITH_PARENT
,
60 box
.set_position(gtk
.WIN_POS_CENTER
)
63 box
.connect('response', resp
)
66 def MixedButton(message
, stock
, x_align
= 0.5, button
= None):
71 label
.set_text_with_mnemonic(message
)
72 label
.set_mnemonic_widget(button
)
74 image
= gtk
.image_new_from_stock(stock
, gtk
.ICON_SIZE_BUTTON
)
75 box
= gtk
.HBox(False, 2)
76 align
= gtk
.Alignment(x_align
, 0.5, 0.0, 0.0)
78 box
.pack_start(image
, False, False, 0)
79 box
.pack_end(label
, False, False, 0)
85 def frame(page
, title
, content
, expand
= False):
88 label
.set_markup('<b>%s</b>' % title
)
89 frame
.set_label_widget(label
)
90 frame
.set_shadow_type(gtk
.SHADOW_NONE
)
91 if type(content
) in (str, unicode):
92 content
= gtk
.Label(content
)
93 content
.set_alignment(0, 0.5)
94 content
.set_selectable(True)
96 if hasattr(content
, 'set_padding'):
97 content
.set_padding(8, 4)
99 content
.set_border_width(8)
100 page
.pack_start(frame
, expand
, True, 0)