def add_standard_buttons(self): controls = { 'progress': gimpui.ProgressBar( ), #gtk.ProgressBar() # is easier to use gimpui's built in bar than construct a new one 'help': Button({'label': '_Help'}), 'okay': Button({'label': '_Okay'}), 'close': Button({'label': '_Cancel'}), } self.widgets = dict(self.widgets.items() + controls.items()) self.container.add(self.widgets['progress']) if 'help_text' in self.widgets.keys(): self.container.add(self.widgets['help_text']) #self.add_buttons(gtk.STOCK_HELP, gtk.RESPONSE_HELP, gtk.STOCK_OK, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) #self.set_alternative_button_order((gtk.RESPONSE_OK, gtk.RESPONSE_CANCEL)) #self.set_default_response(gtk.RESPONSE_OK) separator = gtk.HSeparator() self.container.add(separator) widget_line = gtk.HBox(spacing=10, homogeneous=True) if 'help_text' in self.widgets.keys(): widget_line.add(self.widgets['help']) widget_line.add(self.widgets['okay']) widget_line.add(self.widgets['close']) self.container.add(widget_line)
def start_stream(img, layer): import pygtk pygtk.require('2.0') import gimpui import gtk progress = gimpui.ProgressBar() progress.show() run(img) return
if pf_type != PF_TEXT: wid.set_tooltip_text(tooltip_text) else: # Attach tip to TextView, not to ScrolledWindow wid.view.set_tooltip_text(tooltip_text) wid.show() wid.desc = desc edit_wids.append(wid) 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() # progress_label = gtk.Label() # progress_label.set_alignment(0.0, 0.5) # progress_label.set_ellipsize(pango.ELLIPSIZE_MIDDLE) # attrs = pango.AttrList() # attrs.insert(pango.AttrStyle(pango.STYLE_ITALIC, 0, -1)) # progress_label.set_attributes(attrs) # progress_vbox.pack_start(progress_label) # progress_label.show() dialog.show()
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
def showDialog(self): self.dialog = gimpui.Dialog("Multi export", "multi_export_dialog") self.table = gtk.Table(2, 4, True) self.table.set_homogeneous(True) self.table.set_row_spacings(5) self.table.set_col_spacings(5) self.table.show() #Config File label = gtk.Label(' '+_('Config File :')+' ') label.set_use_underline(True) label.show() self.table.attach(label, 0, 1, 0, 1) config_chooser_dialog = gtk.FileChooserDialog(title=_("Open a Yaml config file"), action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK)) config_chooser_dialog.set_default_response(gtk.RESPONSE_OK) filtre = gtk.FileFilter() filtre.set_name(_('Yaml config file')) #TODO : find the real(s) mime-type format filtre.add_mime_type('text/yaml') filtre.add_pattern("*.yaml") filtre.add_pattern("*.yml") config_chooser_dialog.add_filter(filtre) self.config_chooser = gtk.FileChooserButton(config_chooser_dialog) self.yaml_file = os.path.splitext(self.img.filename)[0]+'.yaml' #select yaml file on the same image directory if os.path.exists(self.yaml_file): self.config_chooser.set_filename(self.yaml_file) #else choose the path on image directory else: self.config_chooser.set_filename(os.path.dirname(self.img.filename)+'/*') self.config_chooser.show() self.table.attach(self.config_chooser, 1, 4, 0, 1) #Save Directory label = gtk.Label(' '+_('Save Directory :')+' ') label.set_use_underline(True) label.show() self.table.attach(label, 0, 1, 1, 2) chooser_dialog = gtk.FileChooserDialog(title=_('Open the destination directory'), action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER, buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK)) chooser_dialog.set_default_response(gtk.RESPONSE_OK) self.chooser = gtk.FileChooserButton(chooser_dialog) self.chooser.set_current_folder(os.path.dirname(self.img.filename)) self.chooser.show() self.table.attach(self.chooser, 1, 4, 1, 2) self.bar_progress = gimpui.ProgressBar() self.bar_progress.set_text(_('Processing ...')) self.dialog.vbox.hbox1 = gtk.HBox(False, 5) self.dialog.vbox.hbox1.show() self.dialog.vbox.pack_start(self.dialog.vbox.hbox1, False, False, 5) self.dialog.vbox.hbox1.pack_start(self.table, True, True, 5) self.dialog.vbox.hbox2 = gtk.HBox(False, 5) self.dialog.vbox.hbox2.show() self.dialog.vbox.pack_end(self.dialog.vbox.hbox2, False, False, 5) self.dialog.vbox.hbox2.pack_end(self.bar_progress, True, True, 5) self.bar_progress.show() cancel_button = self.dialog.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) ok_button = self.dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK) cancel_button.connect("clicked", self.cancel) ok_button.connect("clicked", self.validate) #progress self.process = gimp.progress_install(self.start_progress, self.end_progress,\ self.text_progress, self.value_progress) self.dialog.show() gtk.main()
def __init__(self, image): self.image = image self.dialog = gimpui.Dialog(PLUGIN_TITLE, None, None, 0, None, None) self.dialog.set_transient() self.dialog.set_default_size(850, 660) # self.dialog.set_size_request(850,660) self.dialog.set_border_width(8) dialog_position = retrieve_setting('dialog_position') if dialog_position is not None: self.dialog.move(*dialog_position) self.directory_chooser_label = gtk.Label() self.directory_chooser_label.set_markup( "<b>Choose output directory</b>") self.directory_chooser_label.set_alignment(0.0, 0.5) self.directory_chooser = gtk.FileChooserWidget( action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER) self.hbox_file_format = gtk.HBox(homogeneous=False) self.hbox_file_format.set_spacing(5) self.file_format_label = gtk.Label() self.file_format_label.set_markup("<b>File format:</b>") self.file_format_label.set_alignment(0.0, 0.5) self.file_format_label.set_size_request(100, -1) self.file_format_entry = gtk.Entry() self.file_format_entry.set_size_request(100, -1) self.file_format_error_icon = gtk.Image() self.file_format_error_icon.set_from_stock(gtk.STOCK_STOP, gtk.ICON_SIZE_BUTTON) self.file_format_error_message = gtk.Label() self.file_format_error_message.set_alignment(0.0, 0.5) self.hbox_file_format.pack_start(self.file_format_label, expand=False) self.hbox_file_format.pack_start(self.file_format_entry, expand=False) self.hbox_file_format.pack_start(self.file_format_error_icon, expand=False) self.hbox_file_format.pack_start(self.file_format_error_message, expand=False) self.hbox_export_options = gtk.HBox(homogeneous=False) self.export_options_layer_groups = gtk.CheckButton( "Treat layer groups as directories") self.export_options_ignore_invisible = gtk.CheckButton( "Ignore invisible layers") self.export_options_is_autocrop = gtk.CheckButton("Autocrop layers") self.export_options_use_image_size = gtk.CheckButton( "Use image size instead of layer size") self.hbox_export_options.pack_start(self.export_options_layer_groups) self.hbox_export_options.pack_start( self.export_options_ignore_invisible) self.hbox_export_options.pack_start(self.export_options_is_autocrop) self.hbox_export_options.pack_start(self.export_options_use_image_size) self.hbox_action_area = gtk.HBox(homogeneous=False) self.export_layers_button = gtk.Button(label="Export Layers") self.export_layers_button.set_size_request(110, -1) self.cancel_button = gtk.Button(label="Cancel") self.cancel_button.set_size_request(110, -1) self.progress_bar = gimpui.ProgressBar() # self.progress_bar = gtk.ProgressBar() self.hbox_action_area.set_spacing(8) self.hbox_action_area.set_border_width(8) self.hbox_action_area.pack_start(self.progress_bar, expand=True, fill=True) self.hbox_action_area.pack_end(self.export_layers_button, expand=False, fill=True) self.hbox_action_area.pack_end(self.cancel_button, expand=False, fill=True) self.dialog.vbox.set_spacing(3) self.dialog.vbox.pack_start(self.directory_chooser_label, expand=False, fill=False) self.dialog.vbox.pack_start(self.directory_chooser, padding=5) self.dialog.vbox.pack_start(self.hbox_file_format, expand=False, fill=False) self.dialog.vbox.pack_start(self.hbox_export_options, expand=False, fill=False) self.dialog.vbox.pack_start(self.hbox_action_area, expand=False, fill=False) self.dialog.connect("response", self.response) self.cancel_button.connect("clicked", self.cancel) self.export_layers_button.connect("clicked", self.export) # Assign last used values if last export was successful and # if there are any, otherwise use default values. selected_directory = retrieve_setting('output_directory') if selected_directory is not None: self.directory_chooser.set_current_folder(selected_directory) else: if self.image.uri is not None: self.directory_chooser.set_uri(self.image.uri) else: self.directory_chooser.set_current_folder( ExportLayersPlugin. PARAMS_DEFAULT_VALUES['output_directory']) self.file_format_entry.set_text( retrieve_setting( 'file_format', ExportLayersPlugin.PARAMS_DEFAULT_VALUES['file_format'])) self.export_options_layer_groups.set_active( retrieve_setting( 'layer_groups_as_directories', ExportLayersPlugin. PARAMS_DEFAULT_VALUES['layer_groups_as_directories'])) self.export_options_ignore_invisible.set_active( retrieve_setting( 'ignore_invisible', ExportLayersPlugin.PARAMS_DEFAULT_VALUES['ignore_invisible'])) self.export_options_is_autocrop.set_active( retrieve_setting( 'is_autocrop', ExportLayersPlugin.PARAMS_DEFAULT_VALUES['is_autocrop'])) self.export_options_use_image_size.set_active( retrieve_setting( 'use_image_size', ExportLayersPlugin.PARAMS_DEFAULT_VALUES['use_image_size'])) self.dialog.show_all() # Action area is unused, the dialog bottom would otherwise be filled with empty space. self.dialog.action_area.hide() self.display_label_error_message() self.progress_bar.set_visible(False)