4 Simple directory chooser GUI. Useful for embedding in GUI programms.
10 class StockButton(gtk
.Button
):
11 def __init__(self
, label
=None, stock
=None, use_underline
=True, icon_size
=None):
12 if stock
is not None and stock
in gtk
.stock_list_ids():
15 stock_tmp
= gtk
.STOCK_ABOUT
16 super(self
.__class
__, self
).__init
__(stock
=stock_tmp
, use_underline
=use_underline
)
18 self
.set_markup(label
)
21 elif stock
not in gtk
.stock_list_ids():
23 if icon_size
is not None:
24 self
.set_icon(stock
, icon_size
)
25 def __get_children(self
):
26 align
= self
.get_children()[0]
27 hbox
= align
.get_children()[0]
28 return hbox
.get_children()
29 def set_label(self
, label
):
30 x
, lbl
= self
.__get
_children
()
32 def set_markup(self
, label
):
33 x
, lbl
= self
.__get
_children
()
35 def set_icon(self
, icon
, size
=gtk
.ICON_SIZE_BUTTON
):
36 img
, x
= self
.__get
_children
()
39 img
.props
.visible
= False
41 img
.set_from_icon_name(icon
, size
)
42 img
.props
.visible
= True
44 img
.set_from_pixbuf(icon
)
45 img
.props
.visible
= True
48 dialog
= gtk
.FileChooserDialog("Select a Directory", None, gtk
.FILE_CHOOSER_ACTION_SAVE
, (gtk
.STOCK_CANCEL
, gtk
.RESPONSE_CANCEL
, gtk
.STOCK_OK
, gtk
.RESPONSE_OK
))
49 dialog
.set_action(gtk
.FILE_CHOOSER_ACTION_SELECT_FOLDER
)
50 button_cwd
= StockButton(label
="Working Dir", stock
=gtk
.STOCK_JUMP_TO
)
51 dialog
.add_action_widget(button_cwd
, gtk
.RESPONSE_NO
)
55 response
= dialog
.run()
56 if response
== gtk
.RESPONSE_NO
:
57 dialog
.set_current_folder(os
.getcwd())
60 if response
== gtk
.RESPONSE_OK
:
61 print dialog
.get_filename()