Forum: Ruby Looking for good reads on Ruby TK GUI programming

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Harry T. (Guest)
on 2006-03-08 18:15
(Received via mailing list)
Hello,

Could anyone suggest any good examples, articles, books, etc. for Ruby
TK
GUI programming with particular emphasis on multi-screen/window GUI
applications? For example, someone is working on one window, clicks on a
button and another window 'takes-over the screen', they finish with that
one
and return to the previous window.

Thanks,

Harry
Hidetoshi NAGAI (Guest)
on 2006-03-09 04:22
(Received via mailing list)
From: "Harry T." <removed_email_address@domain.invalid>
Subject: Looking for good reads on Ruby TK GUI programming
Date: Thu, 9 Mar 2006 01:14:47 +0900
Message-ID: <200603081114464.SM03532@htruax>
> Could anyone suggest any good examples, articles, books, etc. for Ruby TK
> GUI programming with particular emphasis on multi-screen/window GUI
> applications? For example, someone is working on one window, clicks on a
> button and another window 'takes-over the screen', they finish with that one
> and return to the previous window.

Do you mean about such like as TkWindow#grab or TkWindow#focus?
Or usage of 'screen' option of TkToplevel widget?
Or again, how to control another {Ruby|Tcl}/Tk process on the
same or other machine with RemoteTkIp class?

Did you check samples in 'ext/tk/sample' directory
on your ruby source tree?
Harry T. (Guest)
on 2006-03-09 16:15
(Received via mailing list)
Hi,

I didn't check the source tree you mentioned, but I will, thanks.

I am looking for info on the routines needed to have a GUI that involves
more
Than one screen/window - I guess TKToplevel is one of them. Most of the
stuff I
Find is just the code being used with no explanation, the user is
assumed to
Know what it does. I am looking for something that explains the
routines.

I basically want to switch between one or more windows, each window
takes up
the
whole screen, the user would enter/view data in each window, basic GUI
stuff.

Thanks,

Harry
Gregor K. (Guest)
on 2006-03-09 16:49
(Received via mailing list)
ChrisH (Guest)
on 2006-03-09 17:05
(Received via mailing list)
Harry T. wrote:
> Hello,
>
> Could anyone suggest any good examples, articles, books, etc. for Ruby TK
> GUI programming ...

I haven't had a chance to check myself, but I understand the some of
the Perl/TK books are good if you can grok Perl.

cheers
Karl von Laudermann (Guest)
on 2006-03-09 17:39
(Received via mailing list)
Harry T. wrote:
> Hello,
>
> Could anyone suggest any good examples, articles, books, etc. for Ruby TK
> GUI programming with particular emphasis on multi-screen/window GUI
> applications?

No. And it's frustrating. The only Ruby/Tk tutorials I've been able to
find, including the Ruby/Tk chapter of the Pickaxe, just provide a few
simple examples, then tell you to go find some other Tk API
documentation and translate it in your head into Ruby/Tk. It took me
maybe two hours of Googling just to figure out how to programmatically
select some text in a TkText widget. (The answer is that TkText has a
concept called "tags", and you can apply any arbitrary tag to any range
of text in the widget, and to select some text you apply a predefined
tag called "sel" to the desired range using the tag_add() method.
Because a set_selection() method would have been too straightforward
and useful.)

It would be really nice if someone would write a definitive book on
developing GUI apps with Ruby/Tk. What I'm envisioning is a complete
guide on how to develop GUI apps using Tk, covering all necessary
concepts such as how to use most widgets (buttons, checkboxes, text
controls, menus, etc.), how to do modal and non-modal dialogs, how to
manage multiple windows, event handling, key shortcuts, etc. And it
would use Ruby and Ruby/Tk exclusively as the language and API for its
code samples. And of course include a complete Ruby/Tk API reference as
it's second half.

And if, say, the Pragmatic Programmers were to write such a book, that
would rock.
Harry T. (Guest)
on 2006-03-09 17:48
(Received via mailing list)
Karl,

I know what you mean. I have found several Perl/TK examples, but found
it
Difficult in discovering the translation to Ruby/TK. I guess I will go
and
Buy a good TK book on GUI programming and start there.

Harry
Hidetoshi NAGAI (Guest)
on 2006-03-09 18:46
(Received via mailing list)
From: "Harry T." <removed_email_address@domain.invalid>
Subject: Re: Looking for good reads on Ruby TK GUI programming
Date: Thu, 9 Mar 2006 23:12:58 +0900
Message-ID: <200603090912662.SM02816@htruax>
> I basically want to switch between one or more windows, each window takes up
> the
> whole screen, the user would enter/view data in each window, basic GUI
> stuff.

First of all, you'll have to clarify the design concept of your GUI.
# Probably, it will be clarified in your mind. ;-)

Do you mean the concept is such like as the following?
==========================================================================
require 'tk'

def window_setup(top)
  top.overrideredirect(true)
  top.geometry("#{top.winfo_screenwidth}x#{top.winfo_screenheight}+0+0")
  top.pack_propagate(false)
  TkFrame.new(top, :borderwidth=>2,
  :relief=>:ridge).pack(:expand=>:true)
end

Tk.root.lower # This is important. If all toplevel windows (not
iconified or
              # withdrawn) are set overrideredirect flags, the
application
              # may not be able to get keyboard focus. So, keep the root
              # widget under administration of window-manager, but put
it
              # lowest layer.

top0 = TkToplevel.new
top0_f = window_setup(top0)

top1 = TkToplevel.new
top1_f = window_setup(top1)

top2 = TkToplevel.new
top2_f = window_setup(top2)

Tk.update_idletasks
top0.raise

#-------------------------------------------------------------

v1 = TkVariable.new
v2 = TkVariable.new

#-------------------------------------------------------------
#  top2

TkLabel.new(top1_f, :text=>'edit STR1').pack
e1 = TkEntry.new(top1_f, :textvariable=>v1).pack(:side=>:left)
b1 = TkButton.new(top1_f, :text=>'OK',
                  :command=>proc{top0.raise}).pack(:side=>:left)

e1.bind('Return', proc{b1.invoke})

#-------------------------------------------------------------
#  top2

TkLabel.new(top2_f, :text=>'edit STR2').pack
e2 = TkEntry.new(top2_f, :textvariable=>v2).pack(:side=>:left)
b2 = TkButton.new(top2_f, :text=>'OK',
                  :command=>proc{top0.raise}).pack(:side=>:left)

e2.bind('Return', proc{b2.invoke})

#-------------------------------------------------------------
#  top0

TkFrame.new(top0_f){|f|
  TkLabel.new(f, :text=>'STR1:').pack(:side=>:left)
  l = TkLabel.new(f, :textvariable=>v1, :anchor=>:w,
                  :width=>25, :relief=>:sunken).pack(:side=>:left)
  b = TkButton.new(f, :text=>'edit', :command=>proc{
                     top1.raise
                     e1.focus # or e1.focus(true) (if 'force' flag is
required)
                   }).pack(:side=>:left)
  l.bind('ButtonPress-1', proc{b.invoke})
}.pack

TkFrame.new(top0_f){|f|
  TkLabel.new(f, :text=>'STR2:').pack(:side=>:left)
  l = TkLabel.new(f, :textvariable=>v2, :anchor=>:w,
                  :width=>25, :relief=>:sunken).pack(:side=>:left)
  b = TkButton.new(f, :text=>'edit', :command=>proc{
                     top2.raise
                     e2.focus # or e2.focus(true) (if 'force' flag is
required)
                   }).pack(:side=>:left)
  l.bind('ButtonPress-1', proc{b.invoke})
}.pack

TkButton.new(top0_f, :text=>'QUIT', :command=>proc{exit}).pack

#-------------------------------------------------------------

Tk.mainloop
==========================================================================
Randy K. (Guest)
on 2006-03-09 18:46
(Received via mailing list)
On Wednesday 08 March 2006 09:21 pm, Hidetoshi NAGAI wrote:
> Do you mean about such like as TkWindow#grab or TkWindow#focus?
> Or usage of 'screen' option of TkToplevel widget?
> Or again, how to control another {Ruby|Tcl}/Tk process on the
> same or other machine with RemoteTkIp class?
>
> Did you check samples in 'ext/tk/sample' directory
> on your ruby source tree?

Sorry for piggybacking here, but I thought someone reading this thread
might
know--does Ruby TK have an HTML rendering "widget"?

Randy K.
Carl (Guest)
on 2006-03-09 19:04
(Received via mailing list)
Randy,

This thread linked below may be of interest to you:
http://groups.google.com/group/comp.lang.ruby/msg/...

Hope that helps,
Carl.
Hidetoshi NAGAI (Guest)
on 2006-03-09 19:20
(Received via mailing list)
From: "Karl von Laudermann" <removed_email_address@domain.invalid>
Subject: Re: Looking for good reads on Ruby TK GUI programming
Date: Fri, 10 Mar 2006 00:38:42 +0900
Message-ID: <removed_email_address@domain.invalid>
> It would be really nice if someone would write a definitive book on
> developing GUI apps with Ruby/Tk.

I wrote a resume for my Ruby/Tk seminar (at 2004/12/08;
based on Ruby 1.8.2-prevew).
It has about 2000 lines and refers about 150 exsamples.
(total line count of samples is about 5000 lines.)
Of course, it is not a complete manual of Ruby/Tk.
But I think it includes some key-points of Ruby/Tk.

Unfortunately, the text is witten in Japanese.
Does anyone translate it in English?
If someone is up for that, I'll send the text and the examples.
Hidetoshi NAGAI (Guest)
on 2006-03-09 19:35
(Received via mailing list)
From: Randy K. <removed_email_address@domain.invalid>
Subject: Does Ruby TK have an HTML rendering "widget"? (was Re: Looking
for good reads on Ruby TK GUI programming)
Date: Fri, 10 Mar 2006 01:45:31 +0900
Message-ID: <removed_email_address@domain.invalid>
> Sorry for piggybacking here, but I thought someone reading this thread might
> know--does Ruby TK have an HTML rendering "widget"?

One of such widget is "Tkhtml" (http://www.hwaci.com/sw/tkhtml/).
Another one is "scrolledhtml" widget included in [incr Widgets]
(http://incrtcl.sourceforge.net/iwidgets/).
Those Tk extensions are available on current Ruby/Tk.
If you use ActiveTcl binary package for your Ruby/Tk,
you'll be able to use those extentions already.
Harry T. (Guest)
on 2006-03-09 19:35
(Received via mailing list)
Thanks so much for the code. I think that is what I am looking for - I
need
to understand what the routines you have provided do and their
implications.
I will study them closely. My problem is, I can find some TK examples,
but
it is hard to find corresponding Ruby/TK coding for the examples.

You are correct about the 'mind clarification' thing, tough to explain
something when you do not really have the tool-set knowledge in the
first
place. But, we all start somewhere.

Here is a brief description of my application:

I am writing an Investment Manager application. This is comprised of a
View
Manager, a Program Manager, a Spend Manager, an Account Manager, and
perhaps
a Main Menu screen.

I am working on the View Manager right now. When started, it draws 12
months
on the screen starting with the current month - for example, right now
it
shows March 2006 up to February 2007. All of the days are button
widgets.
The View Manager will read a database file of spends in various
programs.
When it finds spends that are due to mature for the 12 month view, the
appropriate day will be highlighted in green, and a textual description
of
the spend will be displayed in a listbox at the bottom of the screen. I
am
also considering to have this info displayed when you press a particular
highlighted day button. At the right of the screen or at the bottom,
depending on the available screen area, a selection box will list the
programs currently invested in. One will be able to set the 12 month
view to
either all programs invested in or, it could show sub-sets of the
current
programs. Also viewable on the same screen will be a section that shows
the
money invested in each of the programs - a program status so to speak.

I haven't done this yet, but I would like the user to be able to select
either the View Manager screen, the Spend Manager screen, the Program
Manager screen or the Account Manager screen from a main screen that
comes
up when you start the program. Or perhaps, a way to select the screens
from
each of the manager screens. So from the View Manager screen, you could
choose to go to the Spend Manager screen, for example.

The Spend Manager screen would show a bunch of input text fields that
would
enable you to make a spend in one of the programs curently available. It
would also allow you to edit/delete a particular spend. The Account
Manager
Screen would have a bunch of input text fields that would enable you to
add/edit/delete an e-currency account in the current list - this is
where
the Spend Manager gets the info on what account is being used to fund
the
spend. The Program Manager would allow you to enter information into
various
text fields about a new investment program,
as well as edit/update current program info.

Obviously, all of this stuff cannot fit on one screen. So I want to
functionally break-up my application per screen. The View Manager is
almost
done, got the packing and class creation stuff down, but I do not have
the
Ruby TK know-how yet on how to jump between screens - however, your code
I
am sure will help.

Thanks again for your help,

Harry
Hidetoshi NAGAI (Guest)
on 2006-03-10 09:52
(Received via mailing list)
From: "Harry T." <removed_email_address@domain.invalid>
Subject: Re: Looking for good reads on Ruby TK GUI programming
Date: Fri, 10 Mar 2006 02:34:58 +0900
Message-ID: <200603091234113.SM03532@htruax>
> Obviously, all of this stuff cannot fit on one screen. So I want to
> functionally break-up my application per screen. The View Manager is almost
> done, got the packing and class creation stuff down, but I do not have the
> Ruby TK know-how yet on how to jump between screens - however, your code I
> am sure will help.

Is the 'screen' a physical (multi-display) screen? Or a logical one?
If you mean jump between physical screens, I think there is no way on
the standard Ruby/Tk.

On the workflow of your application, is each non-main screen modal
(before finising the work on the screen, it doesn't need to jump
to the other screen)? Or have to switch between non-main screens?
And how large are non-main screens against the physical screen?

If modal and not so large, I think, a dialog type of a non-main
screen is better.

If modal but very large, the way such like as my example is not bad.

If not modal and not so large, it is enough to control screens with
TkToplevel#raise/lower and focus.

If not modal but very large, a tab stype widget (e.g. tabnotebook
on [incr Tcl]) may be suitable.
Randy K. (Guest)
on 2006-03-13 19:19
(Received via mailing list)
On Thursday 09 March 2006 12:34 pm, Hidetoshi NAGAI wrote:
> One of such widget is "Tkhtml" (http://www.hwaci.com/sw/tkhtml/).
> Another one is "scrolledhtml" widget included in [incr Widgets]
> (http://incrtcl.sourceforge.net/iwidgets/).
> Those Tk extensions are available on current Ruby/Tk.
> If you use ActiveTcl binary package for your Ruby/Tk,
> you'll be able to use those extentions already.

Thanks!

I took a quick look at those, and they may be what I need.  (I was/am
considering khtml also, but I think one of these will have a shorter
learning
curve.)  One thing I want to be able to do is send HTML to them (rather
than
have them fetch a URL) and the sample code for TkHTML does exactly that!

I'm sure I'll have more questions as time goes by, but I'll mention two
that
spring to mind immediately (in case somebody can answer them easily):

   * I presume I can have multiple instances of the widget without
interfering
with each other?

   * In the application I'm hoping to build, I'll want to send
occasional
updates of the HTML (either append or clear and send new HTML) to an
instance
of the widget without needing to create a new instance (I don't want to
wait
for the widget to start again).  Possible?

Thanks again!
Randy K.
Hidetoshi NAGAI (Guest)
on 2006-03-13 20:35
(Received via mailing list)
From: Randy K. <removed_email_address@domain.invalid>
Subject: Re: Does Ruby TK have an HTML rendering "widget"?
Date: Tue, 14 Mar 2006 02:16:53 +0900
Message-ID: <removed_email_address@domain.invalid>
>    * I presume I can have multiple instances of the widget without
> interfering with each other?

I think so too.

>    * In the application I'm hoping to build, I'll want to send occasional
> updates of the HTML (either append or clear and send new HTML) to an instance
> of the widget without needing to create a new instance (I don't want to wait
> for the widget to start again).  Possible?

Tk::HTML_Widget#clear and Tk::HTML_Widget#parse(html_txt)
Randy K. (Guest)
on 2006-03-14 04:14
(Received via mailing list)
Wonderful!  Thank you very much!

Randy K.
This topic is locked and can not be replied to.