Writing an OO wrapper (UI)

N

Nit Khair

I am writing an app generator for ncurses-ruby.

While refactoring my apps, I find that the ncurses-ruby calls for any
object are still scattered in various switch cases - i.e. not reusable -
messy. I thus need to write a proper OO wrapper around ncurses-ruby
before I plunge deeper.

I need suggestions for what similar project I could study, so I go the
right way. I thought of Shoes, but read it's largely in C. There's wx
and Fxruby rubycocoa, qt, ... but they might be very large. Are there
some smallish projects that solve this kind of problem?
 
M

Martin DeMello

I am writing an app generator for ncurses-ruby.

While refactoring my apps, I find that the ncurses-ruby calls for any
object are still scattered in various switch cases - i.e. not reusable -
messy. I thus need to write a proper OO wrapper around ncurses-ruby
before I plunge deeper.

I need suggestions for what similar project I could study, so I go the
right way. I thought of Shoes, but read it's largely in C. There's wx
and Fxruby rubycocoa, qt, ... but they might be very large. Are there
some smallish projects that solve this kind of problem?

Could you paste in some of your switch/case code? It would suggest
what bits of it want to be object oriented. Some nice high level
projects atop C-ish bindings are WxSugar and RubyGame. Also look at
STFL for an existing high level layer atop ncurses, complete with ruby
bindings

http://www.clifford.at/stfl/

Another neat but sadly abandoned TUI project is jttuii:
http://freshmeat.net/projects/jttui/

martin
 
N

Nit Khair

Martin said:
Could you paste in some of your switch/case code? It would suggest
what bits of it want to be object oriented. Some nice high level
projects atop C-ish bindings are WxSugar and RubyGame. Also look at
STFL for an existing high level layer atop ncurses, complete with ruby
bindings

http://www.clifford.at/stfl/

Another neat but sadly abandoned TUI project is jttuii:
http://freshmeat.net/projects/jttui/

martin

Have been checking a lot of ncurses wrappers. Sadly, many ruby projects
that have not released any files, or seem abandoned. I am currently
installing a newt-ruby binding released in 2002. No activity since. No
writeup, screenshots etc.

e.g Yesterday I wrote a file pager with an OK Cancel button. This is a
tiny example compared to FIELD or FORM. Now I would like to be able to
just add a button in a few lines of code, and not have to cut-paste into
3 places and change names of form or window variables etc.

So when i am creating all the fields, prior to the form being created I
have these lines:

# create the Ok field
label = "OK"
width = label.length+2
field = FIELD.new(1, width, @footer_row, @cols-20, 0, 0)
field.field_opts_off(O_EDIT);
field.set_field_buffer(0, "[#{label}]")
field.set_field_just(JUSTIFY_CENTER);
field.user_object = label
@fields.push(field)

Later, in my getch() loop I have this:

when KEY_ENTER
name=@curr_field_name;
if name == "OK"
return multiline_format(@content, @fieldwidth)
elsif name == "Cancel"
return ""
end

In my field_init_hook, I check for field. When the button gets the
focus, I make it reverse video:
if ix != 0
@fields[ix].set_field_back(A_REVERSE)

When you tab out, (in the field_term_hook):

@fields[ix].set_field_back(A_NORMAL)

I have vague/distant memories of Swing programming, so I was having
thoughts that each field should have a handler installed in some array
for each event. The field_init and term hook just call that handler with
field and value, and the handler invokes the handler of that field, if
exists.

When i create a FIELD, it (should) installs its handlers. This includes
on_enter, on_exit, on_selection and should also wrap the label (in
ncurses printing a fields label is totally unrelated to the field, and
happens *after* the form and window is created). Now I don't want to get
overly complex and slow, for then one purpose of using text UI is
defeated.

So i really want to study a well-designed wrapper and see how the pros
do it.

I did look at wxSugar last night. Thanks for sharing your thoughts.
 
N

Nit Khair

Martin said:
Another neat but sadly abandoned TUI project is jttuii:
http://freshmeat.net/projects/jttui/

martin

Am going thru the jttui source. I like the way he has done buttons,
dialogs etc. For example:
bq=JTTWButton.new(d1, 'Quit Button', 3, 2, 11, 1, 'Quit') {
JTTui.addmessage nil, :close}

However, a little surprisingly he does not use anything from ncurses -
not even WINDOW, FORM, FIELD etc. So i am a bit lost. He has a C file,
jtcur.c which has this mysterious line:
* curses's Window stuff has been eliminated
* (IMHO it exist just because C programers don't have power
* of ruby to make it (or better) on their own :))

Can't figure out whether be bypasses curses altogether, although he
includes it in this one c file. Is he totally replacing curses ?

That said, I do not really like the text UI of jttui, or newt (similar
to the dialog command) - the popup/ dialogs etc. I tried out CDK too,
and did not like the widgets too.

I find alpine/pine's UI very pleasing and "clean". My app bases itself
on the pine look and feel - the same menu page, key labels at the bottom
of each screen, text messages and user input on the 3rd from last line
(instead of a popup/dialog).

However, i can learn a lot from jttui and other similar projects on how
i can make fields, labels, windows, panels easier to use, by making a
proper OO wrapper.
 
M

Martin DeMello

I find alpine/pine's UI very pleasing and "clean". My app bases itself
on the pine look and feel - the same menu page, key labels at the bottom
of each screen, text messages and user input on the 3rd from last line
(instead of a popup/dialog).

However, i can learn a lot from jttui and other similar projects on how
i can make fields, labels, windows, panels easier to use, by making a
proper OO wrapper.

As a fan of TUIs I'm looking forward to seeing your library :) You
might get some inspiration from sup and raggle too, though I've not
looked at the source of either.

martin
 
N

Nit Khair

Martin said:
As a fan of TUIs I'm looking forward to seeing your library :) You
might get some inspiration from sup and raggle too, though I've not
looked at the source of either.

martin

*dazed*
Can't believe I've missed these 2. I've googled "ruby curses" to death
and not come across these. Be assured I would have read each line of
code within a week!

Thanks and give me any more links you might have.

STFL looks great at layouting. However, it seems to create individual
screens and not apps. There's still a lot of code involved. I like the
HTML'ish way of layouting.
 
N

Nit Khair

Martin DeMello wrote:
You
might get some inspiration from sup and raggle too, though I've not
looked at the source of either.

martin

I hope it is not inappropriate to continue this disc here (since its
being mailed to a lot of people).

1. Looked at the source of sup. He does *not* use windows or panels at
all -- only stdscr. One comment from source (the others are
unprintable!):

## since we are currently only doing multiple full-screen modes,
## use stdscr for each window. once we become more sophisticated,
## we may need to use a new Ncurses::WINDOW
##

I had initially asked some questions on the bugs-ncurses list (this is
not ruby) and I had agreed with one person there that one should not use
stdscr *at all* but panels. Panel take care of updating and managing
themselves (in terms of which is on top etc) and when you delete a
panel, what's under it is automatically displayed.

That works excellently with me, since the menu calls other programs
which call others and then you come back ...
So I checked the source and (it seems) whenever a buffer is deleted, he
pops the last one and refreshes/displays that.

The only place he uses a field and form, is at the bottom, where he asks
for From, To, CC etc in the last line, and then invokes my $EDITOR. i
have only sent a mail using sup, not done anything else.

2. I then checked Raggle (not installed just looked at source). He only
uses Windows and not panels. So when a window is removed, it seems he
refreshes all the windows in $win (which is a global array for all
windows).

So my initial impression, is that these project are not ideal for
understanding how ncurses is to be used. However, i think sup would be
great for me to get ideas on how to allow customization of my app. The
sup "TextField" class takes into account history and completions which
could be useful someday.

3. I had checked Shoes some days back, it seems all the windowing code
is in the C compiled file.

----

Anyway, I am wondering if you (or anyone) could give me some inputs on
this problem i face.

A) I have my project files in a folder. The templates, the application
modules and runtime classes etc. In the *same* directory i create my
DSLS and then generate programs to run. Its becoming a mess.

If i use another working folder for my DSLs and output programs, the
requires will fail. How does one go about working on a project in one
location, and using it in another. (I do not want to place my project in
/opt/local/...site_ruby, while I am developing).

B) I have been looking through various projects, and I see one
structure:
Lets say the project is proj v 0.1

proj0.1 - lib/
-- proj.rb
-- proj/
--- x.rb, y.rb etc

Is there a place where this structure is explained? I understand that
proj.rb is a common module. Is this the name of the file that is
required. I would appreciate a link to some place where all this is
explained.
Thanks.
 
M

Martin DeMello

Martin DeMello wrote:
You

I hope it is not inappropriate to continue this disc here (since its
being mailed to a lot of people).

Not at all :) I took a look at your screenshots, looks pretty
promising. Are you going to be releasing the curses layer as a
standalone library?
So my initial impression, is that these project are not ideal for
understanding how ncurses is to be used. However, i think sup would be
great for me to get ideas on how to allow customization of my app. The
sup "TextField" class takes into account history and completions which
could be useful someday.

There are readline bindings for ruby too. And check out the excellent
Highline project.
3. I had checked Shoes some days back, it seems all the windowing code
is in the C compiled file.

Shoes is a GUI toolkit, anyway.
Anyway, I am wondering if you (or anyone) could give me some inputs on
this problem i face.

A) I have my project files in a folder. The templates, the application
modules and runtime classes etc. In the *same* directory i create my
DSLS and then generate programs to run. Its becoming a mess.

If i use another working folder for my DSLs and output programs, the
requires will fail. How does one go about working on a project in one
location, and using it in another. (I do not want to place my project in
/opt/local/...site_ruby, while I am developing).

In the first line of your code,

$LOAD_PATH << "/path/to/library"

You can use $: if you like (it's an alias for the same variable).
B) I have been looking through various projects, and I see one
structure:
Lets say the project is proj v 0.1

proj0.1 - lib/
-- proj.rb
-- proj/
--- x.rb, y.rb etc

Is there a place where this structure is explained? I understand that

I believe this was the convention used by setup.rb
[http://i.loveruby.net/en/projects/setup/]. Nowadays, I'd use one of
the gem packaging tools like hoe instead.

martin
 
N

Nit Khair

Martin said:
Not at all :) I took a look at your screenshots, looks pretty
promising. Are you going to be releasing the curses layer as a
standalone library?

First of all, I hope to *make* the OO layer over curses. Yes, it should
be standalone -- meaning not embedded or dependent on the rest of the
app code.

That's why I really began this thread.
There are readline bindings for ruby too. And check out the excellent
Highline project.

I have run through the samples. Its by JEG so the code should be the
best, esp for a newbie to learn from. Thanks for the other info and
link.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top