dialog.set_transient() vbox = gtk.VBox(False, 12) vbox.set_border_width(12) dialog.vbox.pack_start(vbox) vbox.show() if blurb: if domain: try: (domain, locale_dir) = domain trans = gettext.translation(domain, locale_dir, fallback=True) except ValueError: trans = gettext.translation(domain, fallback=True) blurb = trans.ugettext(blurb) box = gimpui.HintBox(blurb) vbox.pack_start(box, expand=False) box.show() table = gtk.Table(len(params), 2, False) table.set_row_spacings(6) table.set_col_spacings(6) vbox.pack_start(table, expand=False) table.show() def response(dlg, id): if id == gtk.RESPONSE_OK: dlg.set_response_sensitive(gtk.RESPONSE_OK, False) dlg.set_response_sensitive(gtk.RESPONSE_CANCEL, False) params = []
def parameter_dialog( proc_name, run_func, # on OK button clicked, call with actual params paramdefs, # tuple, definitions of formal parameters defaults, # tuple of initial values: last used (persistent) or standard values # defaults is a misnomer, but commonly used. blurb = None, # displays blurb of plugin at top of dialog is_use_toggles=False, is_use_progress=True ): ''' Builds dialog to ask user for parameters. Runs inside a gtk event loop. Largely copied from gimpfu.interact() . Should be unified. Changes: made it a function with parameters added optional toggle button in each control (row of table) made the action func a parameter changed certain names: dialog => dlg (same widget, different names) changed certain names: params => paramdefs (more descriptive, formal parameter defs) made the progress bar optional Busted out table into separate class, taking tooltips with it. ''' ''' This is a call to libgimpui, via _gimpui.so (the Python binding), not gimpui.py. Uses libgimpui so that the dialog follows the Gimp theme, help policy, progress policy, etc. See libgimp/gimpui.c etc. ''' dialog = gimpui.Dialog(proc_name, 'python-fu', None, 0, None, proc_name, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK)) dialog.set_alternative_button_order((gtk.RESPONSE_OK, gtk.RESPONSE_CANCEL)) dialog.set_transient() vbox = gtk.VBox(False, 12) vbox.set_border_width(12) dialog.vbox.pack_start(vbox) vbox.show() # part 1: blurb if blurb: # see gimpfu.py for excised domain i8n code box = gimpui.HintBox(blurb) vbox.pack_start(box, expand=False) box.show() # part 2: table of parameters # added from gimpfu def enable_OK(direction): dialog.set_response_sensitive(gtk.RESPONSE_OK, direction) table = GimpParamWidget(vbox, dialog, paramdefs, defaults, is_use_toggles, enable_OK) # part 3: progress if is_use_progress: progress_vbox = gtk.VBox(False, 6) vbox.pack_end(progress_vbox, expand=False) progress_vbox.show() progress = gimpui.ProgressBar() progress_vbox.pack_start(progress) progress.show() def response(dlg, id): if id == gtk.RESPONSE_OK: dlg.set_response_sensitive(gtk.RESPONSE_OK, False) dlg.set_response_sensitive(gtk.RESPONSE_CANCEL, False) try: dialog.res = run_func(table.validate()) except param_widgets.EntryValueError: warning_dialog(dlg, _("Invalid input")) # WAS wid.desc here # dialog continues with OK and CANCEL insensitive? except Exception: dlg.set_response_sensitive(gtk.RESPONSE_CANCEL, True) error_dialog(dlg, proc_name) raise dlg.hide() dialog.connect("response", response) dialog.show() return dialog