loop gtk

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

loop gtk

Alejandro
Hello,

I want to create a loop, my explanation is:

Using a text view, I will introduce values, one by one, and after pressing enter, the loop should compare the introduced value with the reference, but, I do not figure how to stablish the loop.

May you help?

Alejandro
_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: loop gtk

Grant McLean
Hi Alejandro

It can be a challenge to integrate procedural concepts like loops with
an event-driven environment like Gtk.  In fact, your GUI code will
already be running in a loop - processing events as they occur.  So what
you need to do is integrate your loop with the event loop.

I'm not completely clear on your requirement, but another way of looking
at it might be as a work queue.

If you have all the "values" that you want to process in an array, then
you could have a key_press_event handler that checks for the Enter key,
uses 'shift' to take the next value from the array, does whatever is
required and then returns.  Next time the key_press_event occurs the
handler will run again and get the next value from the array.
Eventually the array will be empty and the handler will have no work
left to do (perhaps you will pop up a message to the user at that
point).

Hope that helps

Regards
Grant

On Tue, 2013-08-13 at 11:52 -0500, Alejandro wrote:

> Hello,
>
> I want to create a loop, my explanation is:
>
> Using a text view, I will introduce values, one by one, and after
> pressing enter, the loop should compare the introduced value with the
> reference, but, I do not figure how to stablish the loop.
>
> May you help?
>
> Alejandro
> _______________________________________________
> gtk-perl-list mailing list
> [hidden email]
> https://mail.gnome.org/mailman/listinfo/gtk-perl-list


_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: loop gtk

Juergen Harms
Essentially, the loop you are looking for is already built into gtk: gtk
permanently runs its "event loop" when your application is idling - it
starts idling when you return form your "main" procedure (in which you
probably have done all drawing of your user interface).

When gtk detects an event - for instance the key_press-event mentioned
by Grant, it uses a callback mechanism to call the handler you have
declared, does what you have programmed into this handler, and than goes
back to idling and waits for further events.

If you are building up experience with gtk, it is important that you are
familiar with this way of handling the parallelism between your program
and "random" things like I/O that happen asynchoronously with respect to
your program - and that you conceive your application to profit from
this way of doing.

Good luck - Juergen
_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: loop gtk

Kevin Philp
In reply to this post by Alejandro
In event driven programming you link events with your procedures. In
your case the event sounds like its pressing the enter button. So you
need to link the "event" of pressing the enter button with your
procedure. Its been a while but I think the event is called something
like onkeypress - grab that event, check if its ENTER, process if it is,
if not just pass the event on down the line.

Kevin.


-----Original Message-----
From: Alejandro <[hidden email]>
To: GTK2-Perl List <[hidden email]>
Subject: loop gtk
Date: Tue, 13 Aug 2013 11:52:07 -0500

Hello,

I want to create a loop, my explanation is:

Using a text view, I will introduce values, one by one, and after
pressing enter, the loop should compare the introduced value with the
reference, but, I do not figure how to stablish the loop.

May you help?

Alejandro
_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list


_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: loop gtk

Alejandro
In reply to this post by Grant McLean
Hi Grant

Let me explain more.

The idea is to have a text view, in this view an operator will be entering data commin from an 2D barcode scanner. The idea is to compara the introduced data as soon the operator has finished introducing it. I cannot figure how to do it, I tough to use a perl thread to monitor the current data, check the matrix lenght and compare the last scanned data to a reference.

But if you have a better idea I will thank you very much, I attach the code until now.



El mié, 14-08-2013 a las 11:55 +1200, Grant McLean escribió:
Hi Alejandro

It can be a challenge to integrate procedural concepts like loops with
an event-driven environment like Gtk.  In fact, your GUI code will
already be running in a loop - processing events as they occur.  So what
you need to do is integrate your loop with the event loop.

I'm not completely clear on your requirement, but another way of looking
at it might be as a work queue.

If you have all the "values" that you want to process in an array, then
you could have a key_press_event handler that checks for the Enter key,
uses 'shift' to take the next value from the array, does whatever is
required and then returns.  Next time the key_press_event occurs the
handler will run again and get the next value from the array.
Eventually the array will be empty and the handler will have no work
left to do (perhaps you will pop up a message to the user at that
point).

Hope that helps

Regards
Grant

On Tue, 2013-08-13 at 11:52 -0500, Alejandro wrote:
> Hello,
> 
> I want to create a loop, my explanation is:
> 
> Using a text view, I will introduce values, one by one, and after
> pressing enter, the loop should compare the introduced value with the
> reference, but, I do not figure how to stablish the loop.
> 
> May you help?
> 
> Alejandro 
> _______________________________________________
> gtk-perl-list mailing list
> [hidden email]
> https://mail.gnome.org/mailman/listinfo/gtk-perl-list


_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list


_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list

verificador_tarjetas_C489_02.pl (14K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: loop gtk

Alejandro
In reply to this post by Juergen Harms
Hello Juergen

I will apreciate you can address me to now how to do it, I am new writing Perl-Gtk2 GUI apps. please check previously answered email, I attached the code.

El mié, 14-08-2013 a las 08:08 +0200, Juergen Harms escribió:
Essentially, the loop you are looking for is already built into gtk: gtk 
permanently runs its "event loop" when your application is idling - it 
starts idling when you return form your "main" procedure (in which you 
probably have done all drawing of your user interface).

When gtk detects an event - for instance the key_press-event mentioned 
by Grant, it uses a callback mechanism to call the handler you have 
declared, does what you have programmed into this handler, and than goes 
back to idling and waits for further events.

If you are building up experience with gtk, it is important that you are 
familiar with this way of handling the parallelism between your program 
and "random" things like I/O that happen asynchoronously with respect to 
your program - and that you conceive your application to profit from 
this way of doing.

Good luck - Juergen
_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list


_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: loop gtk

Alejandro
In reply to this post by Kevin Philp
Hello Kevin,

I previously answered email attaching my code, the idea is to enter data in a text view and compare line by line as it is entering to a reference.

El mié, 14-08-2013 a las 09:25 +0100, Kevin Philp escribió:
In event driven programming you link events with your procedures. In
your case the event sounds like its pressing the enter button. So you
need to link the "event" of pressing the enter button with your
procedure. Its been a while but I think the event is called something
like onkeypress - grab that event, check if its ENTER, process if it is,
if not just pass the event on down the line.

Kevin.


-----Original Message-----
From: Alejandro <[hidden email]>
To: GTK2-Perl List <[hidden email]>
Subject: loop gtk
Date: Tue, 13 Aug 2013 11:52:07 -0500

Hello,

I want to create a loop, my explanation is:

Using a text view, I will introduce values, one by one, and after
pressing enter, the loop should compare the introduced value with the
reference, but, I do not figure how to stablish the loop.

May you help?

Alejandro 
_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list




_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: loop gtk

Alejandro
I found how to use the timing events using AnyEvent Module, it works like a charm thanks.

have a nice day


El mié, 14-08-2013 a las 11:18 -0500, Alejandro escribió:
Hello Kevin,

I previously answered email attaching my code, the idea is to enter data in a text view and compare line by line as it is entering to a reference.

El mié, 14-08-2013 a las 09:25 +0100, Kevin Philp escribió:
In event driven programming you link events with your procedures. In
your case the event sounds like its pressing the enter button. So you
need to link the "event" of pressing the enter button with your
procedure. Its been a while but I think the event is called something
like onkeypress - grab that event, check if its ENTER, process if it is,
if not just pass the event on down the line.

Kevin.


-----Original Message-----
From: Alejandro <[hidden email]>
To: GTK2-Perl List <[hidden email]>
Subject: loop gtk
Date: Tue, 13 Aug 2013 11:52:07 -0500

Hello,

I want to create a loop, my explanation is:

Using a text view, I will introduce values, one by one, and after
pressing enter, the loop should compare the introduced value with the
reference, but, I do not figure how to stablish the loop.

May you help?

Alejandro 
_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list





_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list