From: Masao M. <mu...@hi...> - 2002-07-23 05:53:46
|
Hi, On Thu, 11 Jul 2002 23:26:08 +0900 Masao Mutoh <mu...@hi...> wrote: > Hi, > > --------------------------------------- > > require 'gnome' > > Gtk::Window.new.set_title(ARGV[0]).show > > Gtk.main > > --------------------------------------- > > $ruby test.rb --help > > > > Certainly there is the possibility to add own arguments > > I don't know - do you? > > Hmm.... This is very difficult problem... > > I think it is better to implement Gnome#init which can > accept arguments. So the code is like as follows: I implemented it in CVS. *** NOTICE ****************************************************** Since next release, Ruby/GNOME Applications will have to call Gnome.init at first as follows: Gnome.init("your app name", "your app version") ***************************************************************** ------- Gnome.init initialize Gnome libraries and parse command line argument. So if you use Ruby/GNOME, you should call this at first. # sample/gnome-init-popt.rb is sample script for this. Sample: options = [ ["label", 'l', Gnome::POPT_ARG_STRING, "Hello World", "Set button label", "label"], ["width", 'w', Gnome::POPT_ARG_INT, 300, "Set window width", "width"], ["height", 'h', Gnome::POPT_ARG_INT, 200, "Set window height", "height"], ["border", 'b', Gnome::POPT_ARG_NONE, nil, "Remove window border"] ] args = Gnome.init("gnome-init-popt", "1.0", options) ---- * 1st parameter is application name, 2nd parameter is application version. * options is omissible. If you want to get command line parameter, you should use this. options format is: [long name, short name, type, default value, descrip, argsDescrip] (a)longName --label=hello --width=200, --height=100, --border. (b)shortName -l hello, -w 200, -h 100, -b (c)type Gnome::POPT_ARG_STRING means the option takes a string argument --label=hello Gnome::POPT_ARG_INT means the option takes an int argument --width=200 Gnome::POPT_ARG_NONE means the option is a simple switch, it takes no argument. (d)defaultValue If the option is not set in command line, this value is returned. When type is Gnome:POPT_ARG_NONE you can omit this. (e)description(omissible) describes an option. (f)argsDescrip(omissible) describes the argument to that option. Call the Ruby/GNOME application(like this sample) with --help, you can see: gnome-init-popt options -l, --label=label Set button label -w, --width=width Set window width -h, --height=height Set window height -b, --border Remove window border <<application name>> options -shortName, --longName=argsDescrip desciption * Return values Gnome.init return Hash value. There are two types of return value. 1st is option type, and other is no option type. ruby test.rb --label="Hello World" hoge fuga In this example, --label="Hello World" is option type, and hoge, fuga is no option type. option type can get value by longName. args["label"] #=> "Hello World". no option type get array by "args" args["args"] #=> ["hoge", "fuga"] "args" is reserved, so you can't use "args" for your own option. And POPT_ARGS is constatns of "args" So you can write as follows: args[Gnome::POPT_ARGS] #=> ["hoge", "fuga"] Cheers, -- .:% Masao Mutoh<mu...@hi...> |