# Optionparser to gui automation?

**URL:** <https://www.ruby-forum.com/t/optionparser-to-gui-automation/132782>\
**Category:** Ruby\
**Created:** [March 24, 2008, 6:09pm UTC](https://www.ruby-forum.com/t/optionparser-to-gui-automation/132782 "2008-03-24T18:09:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![scorintha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/278dde/32.png) [@scorintha](https://www.ruby-forum.com/u/scorintha)\
**Post date:** [March 24, 2008, 6:09pm UTC](https://www.ruby-forum.com/t/optionparser-to-gui-automation/132782/1 "2008-03-24T18:09:12Z")

</div>

I’m looking to support functionality like follows:

1. You start a ruby program with commandline arguments (in a standard  
optionparser kind of way)…
2. If you do not provide any, a GUI pops up, asking you for things  
that  
would otherwise be on the commandline.
3. Ideally, this is automated with semi-sane defaults for the gui  
view.

I would expect that there might be some sort of optionparser extension  
that  
might do this but googling has not helped me out so far…

Does anybody know of anything like this?

mark

---

<div class="post-metadata">

**Author:** ![scorintha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/278dde/32.png) [@scorintha](https://www.ruby-forum.com/u/scorintha)\
**Post date:** [March 24, 2008, 8:51pm UTC](https://www.ruby-forum.com/t/optionparser-to-gui-automation/132782/2 "2008-03-24T20:51:41Z")

</div>

You’re probably looking for something like this:

[ruby-doc.org/stdlib/libdoc/optparse/rdoc/](http://ruby-doc.org/stdlib/libdoc/optparse/rdoc/)

HTH,  
Dana M.

---

<div class="post-metadata">

**Author:** ![scorintha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/278dde/32.png) [@scorintha](https://www.ruby-forum.com/u/scorintha)\
**Post date:** [March 25, 2008, 12:48am UTC](https://www.ruby-forum.com/t/optionparser-to-gui-automation/132782/3 "2008-03-25T00:48:33Z")

</div>

What I’m after is something like a decorator on top of optionparser that  
will create a gui for those who are averse to specifying commandline  
arguments.

By way of example, boolean options might show up as checkboxes.

mark

On Mon, Mar 24, 2008 at 12:50 PM, Dana M.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![scorintha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/278dde/32.png) [@scorintha](https://www.ruby-forum.com/u/scorintha)\
**Post date:** [March 25, 2008, 7:48am UTC](https://www.ruby-forum.com/t/optionparser-to-gui-automation/132782/4 "2008-03-25T07:48:01Z")

</div>

Hi,

At Tue, 25 Mar 2008 02:07:54 +0900,  
Mark N. wrote in [ruby-talk:295532]:

> I’m looking to support functionality like follows:
> 
> 1. You start a ruby program with commandline arguments (in a standard  
> optionparser kind of way)…
> 2. If you do not provide any, a GUI pops up, asking you for things that  
> would otherwise be on the commandline.
> 3. Ideally, this is automated with semi-sane defaults for the gui view.
> 
> I would expect that there might be some sort of optionparser extension that  
> might do this but googling has not helped me out so far…

I had had similar idea at the time made it first, but haven’t  
implemented nor heard about something like it.

---

<div class="post-metadata">

**Author:** ![scorintha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/278dde/32.png) [@scorintha](https://www.ruby-forum.com/u/scorintha)\
**Post date:** [March 25, 2008, 1:21pm UTC](https://www.ruby-forum.com/t/optionparser-to-gui-automation/132782/5 "2008-03-25T13:21:30Z")

</div>

Ah, I’m sorry, I misunderstood what part of the question you were not  
aware of. I know there are Qt and GTK toolkits for Ruby, though I’ve  
tried neither. I’m looking forward to playing with the Qt one though,  
because Qt is a blast.

> **[Ruby Howto: Graphical User Interface](https://arachnoid.com/ruby/RubyGUIProject/)**
>
> How to design a GUI interface for your Ruby program..

-Dana

---

<div class="post-metadata">

**Author:** ![scorintha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/278dde/32.png) [@scorintha](https://www.ruby-forum.com/u/scorintha)\
**Post date:** [March 25, 2008, 8:31pm UTC](https://www.ruby-forum.com/t/optionparser-to-gui-automation/132782/6 "2008-03-25T20:31:21Z")

</div>

On Mar 24, 7:07 pm, Mark N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> might do this but googling has not helped me out so far…
> 
> Does anybody know of anything like this?

Hi,

A while ago, I had been trying to do something similar, but not  
exactly. 🙂

I’ve looked at this at a different angle: let’s say we have some  
command-line utility with lots of options and we’d like to provide a  
GUI. My idea was that as we can simply map GUI elements into command  
line parameters, we can have a parser to read parameters from command  
line and fill the GUI.

I’ve implemented a bit of this for my gtk-fortune project back while.  
You might be interested to check out these:

[http://gtk-fortune.rubyforge.org/svn/trunk/](http://gtk-fortune.rubyforge.org/svn/trunk/)  
[http://gtk-fortune.rubyforge.org/svn/trunk/cmdgui](http://gtk-fortune.rubyforge.org/svn/trunk/cmdgui)

The relevant code is only in the trunk as I think it’s still not in a  
shape for a release or separate project and I hadn’t touched it in  
quite a while…

Please note, that in my approach I assumed that GUI is hand-made, not  
generated, as this allows for “rich” options dialogs like “disable  
that input field if this checkbox is cleared”, etc. Nonetheless, it  
should work with a generated GUI as well. 😉

Also, I’ve used my own limited command-line parser–it should be  
possible to replace it with some widely used one.

---

<div class="post-metadata">

**Author:** ![scorintha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/278dde/32.png) [@scorintha](https://www.ruby-forum.com/u/scorintha)\
**Post date:** [March 25, 2008, 1:38pm UTC](https://www.ruby-forum.com/t/optionparser-to-gui-automation/132782/7 "2008-03-25T13:38:56Z")

</div>

Mark N. wrote:

> I’m looking to support functionality like follows:

Haven’t heard of anything that automatically generates a GUI dialog from  
command line options. But there are various libraries that make it easy  
to generate dialogs from scripts. You tell it that you want the user to  
enter a String with a default and so one.

There’s Dialog ([dialog - display dialog boxes from scripts | Hightek.org](http://hightek.org/dialog/)) which is not exactly a GUI  
but it’s a familiar interface. (Ruby wrapper here  
[http://rdialog.rubyforge.org/](http://rdialog.rubyforge.org/))

Or there’s Zenity ([Projects/Zenity - GNOME Wiki!](http://live.gnome.org/Zenity)). If you are on Ubuntu  
try typing:

$ zenity --entry

and see what happens. From Ruby you could call out to that through  
%x{zenity --entry} and interpret the output.

Or Zerenity is a port of zenity to Ruby-Gnome2 so it is easily callable  
from Ruby.  
[http://code.google.com/p/zerenity/](http://code.google.com/p/zerenity/)

I haven’t tried these much, but there should be something there that you  
could make work.

best,  
Dan

---

<div class="post-metadata">

**Author:** ![scorintha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/278dde/32.png) [@scorintha](https://www.ruby-forum.com/u/scorintha)\
**Post date:** [March 25, 2008, 8:35pm UTC](https://www.ruby-forum.com/t/optionparser-to-gui-automation/132782/8 "2008-03-25T20:35:33Z")

</div>

On Mar 25, 9:27 pm, Alex S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’ve implemented a bit of this for my gtk-fortune project back while.  
> You might be interested to check out these:
> 
> [http://gtk-fortune.rubyforge.org/svn/trunk/](http://gtk-fortune.rubyforge.org/svn/trunk/)  
> [http://gtk-fortune.rubyforge.org/svn/trunk/cmdgui](http://gtk-fortune.rubyforge.org/svn/trunk/cmdgui)

Yeah, one more thing:

Without having to read the code, the following might be insightful:

@cmdgui = CmdGUI::Glade.new(@glade,  
{ “-s” =\> “short\_quotes\_radiobutton”,  
“-l” =\> “long\_quotes\_radiobutton”,  
“-n” =\> [“custom\_length\_spinbutton”,

“custom\_length\_checkbutton”],  
“-o” =\>  
“offensive\_quotes\_checkbutton”,  
“-c” =\>  
“show\_cookie\_file\_checkbutton” },  
@cmdline)
