diff options
author | Walter Bender <walter.bender@gmail.com> | 2011-10-18 20:24:06 (GMT) |
---|---|---|
committer | Walter Bender <walter.bender@gmail.com> | 2011-10-18 20:24:06 (GMT) |
commit | 2f0963e3d4c842a9f775100ccb27a20254eca13f (patch) | |
tree | 955a56985da836370f88cb5509e43f7f8dfd6cee /utils.py | |
parent | 919e8066884eb4a520d2ccae22847909df15f464 (diff) |
added custom ball combo box
Diffstat (limited to 'utils.py')
-rw-r--r-- | utils.py | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -11,6 +11,10 @@ # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. +import gtk + +from sugar.graphics.objectchooser import ObjectChooser + from StringIO import StringIO try: USING_JSON_READWRITE = False @@ -52,3 +56,23 @@ def json_dump(data): _io = StringIO() jdump(data, _io) return _io.getvalue() + + +def chooser(parent_window, filter, action): + """ Choose an object from the datastore and take some action """ + chooser = None + try: + chooser = ObjectChooser(parent=parent_window, what_filter=filter) + except TypeError: + chooser = ObjectChooser(None, parent_window, + gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT) + if chooser is not None: + try: + result = chooser.run() + if result == gtk.RESPONSE_ACCEPT: + dsobject = chooser.get_selected_object() + action(dsobject) + dsobject.destroy() + finally: + chooser.destroy() + del chooser |