[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Ruby/TK Question

Kujawa, Greg

11/4/2004 5:09:00 PM

I am new to Ruby and trying to create a basic application using Tk.
Unfortunately I'm also new to this as well :-)

The application is for a survey. I have created an initial window where the
survey taker signs in. They select their name from a TkListbox object. When
they click on a TkButton object the sign in window exits and I record the
appropriate current selection of the listbox object.

My question is how would I go about creating a new window for taking survey
itself and still keep the saved selection of the listbox object? Is Tk
intended more for a single windowed application? I read about multi-tk and
was wondering if this might be the way to go. I want to create a new window
for the survey, record the takers responses and then clear their name off
the sign in list after they have completed things. That's why I want to
retain the sign in's selection for the lifetime of the application.

Here is my current code for the survey sign in below. Any pointers would be
appreciated!

require 'dbi'
require 'tk'

# connect to the SQL data source
dsn= 'DBI:ADO:Provider=SQLOLEDB;Data Source=mobile_tech;Initial
Catalog=CoreVals;Persist Security Info=False;Trusted_Connection=Yes;'

DBI.connect(dsn) do |dbh|

# select all employees that haven't completed the survey
dbh.execute("SELECT First+' '+MI+' '+Last FROM TblEmployee where Done=0
order by Last, First") do |sth|

# populate the returned recordset into an array
$employee = sth.fetch_all
end
end

# create a new window for the sign in using Tk
@root = TkRoot.new() {title 'Core Values Survey'}

listViewFrm = TkFrame.new(@root).pack(
'side'=>'left',
'padx'=>10,
'pady'=>10,
'fill'=>'both')

# Create a scrollbar for the employee listbox
scrollbar = TkScrollbar.new(listViewFrm).pack(
'side'=>'right',
'fill'=>'y')

# Create the listbox to hold all of the employees
$empListbox = TkListbox.new(listViewFrm) {
width 25
}.pack(
'fill'=>'y',
'expand'=>'true')

# Link the listbox to scrollbar
$empListbox.yscrollbar(scrollbar)

# Populate the listbox control with the employee recordset
$employee.each { |emp|
$empListbox.insert('end', emp)
}

# Add the sign in button
button = TkButton.new(@root) { text "Sign me in!"
command proc {
indexstr = $empListbox.curselection.to_s;
indexnum = indexstr.to_i;
$taker=$employee[indexnum].to_s;
p $taker;
exit
}
}
button.pack("side"=>"right")

Tk.mainloop



10 Answers

Michael DeHaan

11/4/2004 6:13:00 PM

0

I'd consider hiding the root window after the input is provided, so
that it stays around but you can't see it. Tk can definitely support
multiple windows, add as many as you like.

I've only done Perl/Tk to this point, so I can't give you the
ruby-specific syntax...

--MPD

On Fri, 5 Nov 2004 02:09:08 +0900, Kujawa, Greg
<greg.kujawa@diamondcellar.com> wrote:
> I am new to Ruby and trying to create a basic application using Tk.
> Unfortunately I'm also new to this as well :-)
>
> The application is for a survey. I have created an initial window where the
> survey taker signs in. They select their name from a TkListbox object. When
> they click on a TkButton object the sign in window exits and I record the
> appropriate current selection of the listbox object.
>
> My question is how would I go about creating a new window for taking survey
> itself and still keep the saved selection of the listbox object? Is Tk
> intended more for a single windowed application? I read about multi-tk and
> was wondering if this might be the way to go. I want to create a new window
> for the survey, record the takers responses and then clear their name off
> the sign in list after they have completed things. That's why I want to
> retain the sign in's selection for the lifetime of the application.
>
> Here is my current code for the survey sign in below. Any pointers would be
> appreciated!
>
> require 'dbi'
> require 'tk'
>
> # connect to the SQL data source
> dsn= 'DBI:ADO:Provider=SQLOLEDB;Data Source=mobile_tech;Initial
> Catalog=CoreVals;Persist Security Info=False;Trusted_Connection=Yes;'
>
> DBI.connect(dsn) do |dbh|
>
> # select all employees that haven't completed the survey
> dbh.execute("SELECT First+' '+MI+' '+Last FROM TblEmployee where Done=0
> order by Last, First") do |sth|
>
> # populate the returned recordset into an array
> $employee = sth.fetch_all
> end
> end
>
> # create a new window for the sign in using Tk
> @root = TkRoot.new() {title 'Core Values Survey'}
>
> listViewFrm = TkFrame.new(@root).pack(
> 'side'=>'left',
> 'padx'=>10,
> 'pady'=>10,
> 'fill'=>'both')
>
> # Create a scrollbar for the employee listbox
> scrollbar = TkScrollbar.new(listViewFrm).pack(
> 'side'=>'right',
> 'fill'=>'y')
>
> # Create the listbox to hold all of the employees
> $empListbox = TkListbox.new(listViewFrm) {
> width 25
> }.pack(
> 'fill'=>'y',
> 'expand'=>'true')
>
> # Link the listbox to scrollbar
> $empListbox.yscrollbar(scrollbar)
>
> # Populate the listbox control with the employee recordset
> $employee.each { |emp|
> $empListbox.insert('end', emp)
> }
>
> # Add the sign in button
> button = TkButton.new(@root) { text "Sign me in!"
> command proc {
> indexstr = $empListbox.curselection.to_s;
> indexnum = indexstr.to_i;
> $taker=$employee[indexnum].to_s;
> p $taker;
> exit
> }
> }
> button.pack("side"=>"right")
>
> Tk.mainloop
>
>


Hidetoshi NAGAI

11/5/2004 12:24:00 AM

0

Blink003

9/13/2009 11:03:00 PM

0


"Anne G" <ann.guille@gmail[antispam].com.invalid> a ?crit dans le message de
news: 4aad789d@ac-versailles.fr...
> Blink003 a ?crit :
>> "Alberic" <Albert@albert.hic> a ?crit dans le message de news:
>
>>> ... la r?action de celui qui d?clarait ici m?me* ? propos d'une gamine
>>> enceinte dont la m?re avait organis? l'avortement :
>
>
>> Organis? ? De quelle mani?re ?
>
> Ben... elle avait pris rendez-vous chez le m?decin, je dirais. Non ?
> En tout cas c'est ce que je ferais si ma fille de 9 ans ?tait enceinte.

Ben dans se cas elle n'avait qu'? se pr?senter. Organis? me semble que ?a
fait broche ? tricoter non ?


Anne G

9/13/2009 11:24:00 PM

0

Blink003 a ?crit :
> "Anne G" <ann.guille@gmail[antispam].com.invalid> a ?crit dans le message de
> news: 4aad789d@ac-versailles.fr...
>> Blink003 a ?crit :
>>> "Alberic" <Albert@albert.hic> a ?crit dans le message de news:

>>>> ... la r?action de celui qui d?clarait ici m?me* ? propos d'une gamine
>>>> enceinte dont la m?re avait organis? l'avortement :

>>> Organis? ? De quelle mani?re ?
>> Ben... elle avait pris rendez-vous chez le m?decin, je dirais. Non ?
>> En tout cas c'est ce que je ferais si ma fille de 9 ans ?tait enceinte.

> Ben dans se cas elle n'avait qu'? se pr?senter.

Se pr?senter o? ? ?a se passait en Am?rique du Sud, cette histoire-l?...
Je ne sais plus o?.

> Organis? me semble que ?a
> fait broche ? tricoter non ?

Sais pas. Il m'arrive d'organiser un rendez-vous chez le cardiologue
pour mon mari...

Fustigator

9/14/2009 11:02:00 AM

0

Vitae forma vocatur Anne G <ann.guille@gmail[antispam].com.invalid>,
die Sun, 13 Sep 2009 17:23:33 -0600, in littera
<4aad7ef9@ac-versailles.fr> in foro soc.culture.belgium(et aliis) vere
scripsit quod sequitur:

>Blink003 a ?crit :
>> "Anne G" <ann.guille@gmail[antispam].com.invalid> a ?crit dans le message de
>> news: 4aad789d@ac-versailles.fr...
>>> Blink003 a ?crit :
>>>> "Alberic" <Albert@albert.hic> a ?crit dans le message de news:
>
>>>>> ... la r?action de celui qui d?clarait ici m?me* ? propos d'une gamine
>>>>> enceinte dont la m?re avait organis? l'avortement :
>
>>>> Organis? ? De quelle mani?re ?
>>> Ben... elle avait pris rendez-vous chez le m?decin, je dirais. Non ?
>>> En tout cas c'est ce que je ferais si ma fille de 9 ans ?tait enceinte.
>
>> Ben dans se cas elle n'avait qu'? se pr?senter.
>
>Se pr?senter o? ? ?a se passait en Am?rique du Sud, cette histoire-l?...
>Je ne sais plus o?.
>
>> Organis? me semble que ?a
>> fait broche ? tricoter non ?
>
>Sais pas. Il m'arrive d'organiser un rendez-vous chez le cardiologue
>pour mon mari...

Il sent d?j?, le malheureux ?

Non pas ? cause de son coeur, que je lui souhaite vaillant,
mais bien s?r ? cause de la rosse qu'il a ?pous?.
--

Fusti

Anne G

9/14/2009 2:14:00 PM

0

Fustigator a ?crit :

> Il sent d?j?

H?h?... touch? profond, la vieille ordure...

alien

9/14/2009 2:30:00 PM

0

Anne G a ?crit :
> Fustigator a ?crit :
>
>> Il sent d?j?
>
> H?h?...

z'allez finir par sinistrer une petite culotte avec vos orgasmes ....

Fustigator

9/14/2009 10:13:00 PM

0

Vitae forma vocatur alien <alien999@gmail.com>, die Mon, 14 Sep 2009
16:29:42 +0200, in littera <4aae5379$0$2861$ba620e4c@news.skynet.be>
in foro soc.culture.belgium(et aliis) vere scripsit quod sequitur:

>Anne G a ?crit :
>> Fustigator a ?crit :
>>
>>> Il sent d?j?
>>
>> H?h?...
>
>z'allez finir par sinistrer une petite culotte avec vos orgasmes ....

MDR
--

Fusti

Fustigator

9/14/2009 10:13:00 PM

0

Vitae forma vocatur Anne G <ann.guille@gmail[antispam].com.invalid>,
die Mon, 14 Sep 2009 08:13:55 -0600, in littera
<4aae4fa5@ac-versailles.fr> in foro soc.culture.belgium(et aliis) vere
scripsit quod sequitur:

>Fustigator a ?crit :
>
>> Il sent d?j?
>
>H?h?... touch? profond, la vieille ordure...

Votre masochisme fait peine ? voir, ma vieille...
--

Fusti

alien

9/15/2009 4:37:00 AM

0

Anne G a ?crit :
> Fustigator a ?crit :
>> Vitae forma vocatur alien <alien999@gmail.com>, die Mon, 14 Sep 2009
>
>>> z'allez finir par sinistrer une petite culotte avec vos orgasmes ....
>
>> MDR
>
> Demandez toujours ? madame ce que sont les effets d'un orgasme f?minin,
> mais je doute qu'elle puisse vous r?pondre...