Commit 144431ff authored by Scott Lembcke's avatar Scott Lembcke Committed by Scott Lembcke

Removed some unnecesary code. Clicking 'cancel' in the dialog will now

2006-07-21  Scott Lembcke <lemb0029@gnome.org>

        * gimp-lib/rubyfu.rb: Removed some unnecesary code. Clicking 'cancel' in
          the dialog will now work correctly. Interactive procedures that take
          no parameters don't trigger the dialog.

        * ext/rbgimpdialog.c: Added a enumeration popup widget. show_dialog()
          now takes an extra parameter for the menu name. The procedure name
          is used as the help_id, and the menu name is used in the dialog title.
          Parameter names now have a ':' appended to their labels.

        * plug-ins/test.rb: Added the new parameter type.
parent a6c827b8
2006-07-21 Scott Lembcke <lemb0029@gnome.org>
* gimp-lib/rubyfu.rb: Removed some unnecesary code. Clicking 'cancel' in
the dialog will now work correctly. Interactive procedures that take
no parameters don't trigger the dialog.
* ext/rbgimpdialog.c: Added a enumeration popup widget. show_dialog()
now takes an extra parameter for the menu name. The procedure name
is used as the help_id, and the menu name is used in the dialog title.
Parameter names now have a ':' appended to their labels.
* plug-ins/test.rb: Added the new parameter type.
2006-07-21 Scott Lembcke <lemb0029@gnome.org>
* ext/rbgimpdialog.c: Changed spacing, padding and alignment of the
......
......@@ -329,19 +329,6 @@ handle_string_types (VALUE param,
return widget;
}
static void
get_min_max_step(VALUE param,
VALUE *min,
VALUE *max,
VALUE *step)
{
VALUE range = rb_iv_get(param, "@range");
*step = rb_iv_get(param, "@step");
*min = rb_funcall(range, rb_intern("begin"), 0, NULL);
*max = rb_funcall(range, rb_intern("end"), 0, NULL);
}
static GtkWidget *
handle_int_types (VALUE param,
VALUE deflt,
......@@ -374,6 +361,17 @@ handle_int_types (VALUE param,
result->ptr = widget;
result->func = &get_toggle_int;
}
else if (subtypeid == rb_intern("enum"))
{
VALUE enum_name = rb_iv_get(param, "@enum");
GType enum_type = g_type_from_name(StringValuePtr(enum_name));
widget = gimp_enum_combo_box_new(enum_type);
gimp_int_combo_box_set_active(GIMP_INT_COMBO_BOX(widget),
defint);
result->ptr = widget;
result->func = &get_combo_box_int;
}
else
{
widget = NULL;
......@@ -383,6 +381,19 @@ handle_int_types (VALUE param,
return widget;
}
static void
get_min_max_step(VALUE param,
VALUE *min,
VALUE *max,
VALUE *step)
{
VALUE range = rb_iv_get(param, "@range");
*step = rb_iv_get(param, "@step");
*min = rb_funcall(range, rb_intern("begin"), 0, NULL);
*max = rb_funcall(range, rb_intern("end"), 0, NULL);
}
static GtkWidget *
handle_float_types (VALUE param,
VALUE deflt,
......@@ -428,7 +439,7 @@ handle_float_types (VALUE param,
else
{
widget = gtk_label_new("poo");
// rb_raise(rb_eTypeError, "Bad RubyFu::ParamDef float subtype.");
rb_raise(rb_eTypeError, "Bad RubyFu::ParamDef float subtype.");
}
return widget;
......@@ -523,8 +534,12 @@ make_table (VALUE params,
if (!rb_obj_is_kind_of(param, sGimpParamDef))
rb_raise(rb_eArgError, "Parameters must be of type Gimp::ParamDef");
VALUE dscr = rb_struct_aref(param, ID2SYM(id_dscr));
GtkWidget *label = gtk_label_new(StringValuePtr(dscr));
VALUE rbdscr = rb_struct_aref(param, ID2SYM(id_dscr));
gchar *dscr = g_strdup_printf("%s:", StringValuePtr(rbdscr));
GtkWidget *label = gtk_label_new(dscr);
g_free(dscr);
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
gtk_table_attach(GTK_TABLE(table), label, 0, 1, i, i+1,
GTK_FILL, GTK_FILL, 0, 0);
......@@ -562,11 +577,13 @@ collect_results (int num_results,
static VALUE
show_dialog (VALUE self,
VALUE rbname,
VALUE rbtitle,
VALUE rbprocname,
VALUE params)
{
GtkWidget *dialog, *table;
gchar *name = StringValuePtr(rbname);
gchar *procname = StringValuePtr(rbprocname);
gchar *title = g_strdup_printf("Ruby Fu: %s", StringValuePtr(rbtitle));
int num_results;
Result *results;
......@@ -574,15 +591,15 @@ show_dialog (VALUE self,
gtk_init(NULL, NULL);
gimp_ui_init ("ruby-fu", TRUE);
dialog = gimp_dialog_new(name, "ruby-fu",
NULL, 0,
gimp_standard_help_func, "FIXME",
dialog = gimp_dialog_new(title, "rubyfu", NULL, 0,
gimp_standard_help_func, procname,
/*GIMP_STOCK_RESET, RESPONSE_RESET,*/
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK,
NULL);
g_free(title);
gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), 12);
......@@ -600,5 +617,5 @@ show_dialog (VALUE self,
void Init_rubyfudialog(void)
{
VALUE mRubyFu = rb_define_module("RubyFu");
rb_define_module_function(mRubyFu, "dialog", show_dialog, 2);
rb_define_module_function(mRubyFu, "dialog", show_dialog, 3);
}
......@@ -5,6 +5,9 @@ module RubyFu
class ResultError < Exception
end
class Cancel < Exception
end
class ParamDef < Gimp::ParamDef
attr_reader :default, :subtype
......@@ -85,6 +88,13 @@ module RubyFu
value.instance_variable_set(:@step, step)
return value
end
def self.ENUM(name, desc, default, enum)
value = INT32(name, desc, default)
value.instance_variable_set(:@subtype, :enum)
value.instance_variable_set(:@enum, enum)
return value
end
end
class Procedure
......@@ -158,19 +168,23 @@ module RubyFu
end
def run_interactive(args)
args += RubyFu.dialog(@name, @params)
return run_noninteractive(args) if @params.empty?
interactive_args = RubyFu.dialog(@menulabel, @name, @params)
raise Cancel unless interactive_args
values = @function.call(*args)
args += interactive_args
return @function.call(*args)
end
def run_noninteractive(args, params)
def run_noninteractive(args)
nargs = args.length
nparams = params.length
nparams = @fullparams.length
unless nargs == nparams
raise(CallError, "Wrong number of arguments. (#{nargs} for #{nparams})")
end
values = @function.call(*args)
return @function.call(*args)
end
def run_last_vals(args)
......@@ -179,7 +193,7 @@ module RubyFu
warn "Last value mode not implemented, sending default params."
args += default_args
values = @function.call(*args)
return @function.call(*args)
end
def run(*args)
......@@ -197,7 +211,7 @@ module RubyFu
values = case runMode
when Gimp::RUN_INTERACTIVE: run_interactive(args)
when Gimp::RUN_NONINTERACTIVE: run_noninteractive(args, @fullparams)
when Gimp::RUN_NONINTERACTIVE: run_noninteractive(args)
when Gimp::RUN_WITH_LAST_VALS: run_last_vals(args)
end
......@@ -274,7 +288,9 @@ module RubyFu
return values
rescue CallError
PDB.gimp_message("A calling error has occured: #$!.message")
return [Gimp::Param.STATUS(PDB_CALLING_ERROR)]
return [Gimp::Param.STATUS(Gimp::PDB_CALLING_ERROR)]
rescue Cancel
return [Gimp::Param.STATUS(Gimp::PDB_CANCEL)]
rescue Exception
PDB.gimp_message "A #{$!.class} has occured: #{$!.message}\n#{$@.join("\n")}"
return [Gimp::Param.STATUS(Gimp::PDB_EXECUTION_ERROR)]
......
......@@ -223,11 +223,12 @@ RubyFu.register(
print 'Calling with too many params ... '
test_exception(ArgumentError){PDB.gimp_message(123, 123)}
##THIS CRASHES HORRIBLY. NOT SURE IF IT'S MY FAULT OR NOT.
# printf 'Calling error ... '
# test_exception(PDB::CallingError) do
# Gimp.run_procedure('ruby-fu-test-crash', [Gimp::Param.INT32(123)])
# end
#THIS CRASHES HORRIBLY. NOT SURE IF IT'S MY FAULT OR NOT.
#printf 'Calling error ... '
#test_exception(PDB::CallingError) do
# #Gimp.run_procedure('ruby-fu-test-crash', [Gimp::Param.INT32(123)])
# PDB.plug_in_script_fu_eval(Gimp::Interactive, '(ruby-fu-test-crash 123)')
#end
printf 'Exucution error ... '
test_exception(PDB::ExecutionError){PDB.ruby_fu_test_crash}
......@@ -287,6 +288,7 @@ RubyFu.register(
RubyFu::ParamDef.SLIDER('slider', 'SLIDER', 6, (1.5..9.1), 0.01),
RubyFu::ParamDef.STRING('string', 'STRING', 'string'),
RubyFu::ParamDef.COLOR('color', 'COLOR', Gimp::Rgb.new(1.0, 0.0, 0.0, 0.0)),
RubyFu::ParamDef.ENUM('enum', 'ENUM', 0, 'GimpBlendMode')
], #params
[] #results
) do|run_mode, *params|
......
......@@ -6,7 +6,11 @@ The color code has turned out to be sub-par, lots of room for improvment.
Signal handlers might need to be backed up. (see how the old one did this. Is it still necessary? Seems not.)
Read up on Gtk before working on any UI stuff.
Add a list type parameter.
Add a reset button to the interactive dialog.
Get widget resizing under control.
Console mode.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment