Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Tk programmatically monitor change in Listbox

by Marshall (Canon)
on Jan 06, 2020 at 09:42 UTC ( [id://11111039]=note: print w/replies, xml ) Need Help??


in reply to Tk (Tcl::Tk) programmatically monitor change in Listbox

Your code which I simplified below works fine.

How would @list get modified? That is the real question here.
You don't show any code for that.
Do you want a right-click menu to add/delete? Do you want an Add/Delete menu bar?

Adding a new element to the listbox means that

my @list = ( "a", "b", "c", "d", "e", "f" );
has been modified. Perhaps:
my @list = ( "a", "b", "c", "d", "e", "f","g" ); or perhaps ( "a", "b", "NEW", "c", "d", "e", "f" ) or perhaps ( "a", "b", "c")

I would be thinking of just deleting all element in the Listbox
and then re-insert the new elements from this modified list.
That is one way to change the contents of a Listbox.

It would be very helpful if you could describe what the user is
going to do that results in a different displayed Listbox contents?

I think there is a wrong thought model here. If you change the Listbox,
then you know you did that. Call the update Listbox routine. Or perhaps
the window with list box, fetches new data every time is is displayed.
My last thought would be a timed update every x seconds.

================================= use strict; use warnings; use Tk; my $mw = MainWindow->new(); my $lbox = $mw->Listbox()->pack(); my @list = ( "a", "b", "c", "d", "e", "f" ); $lbox->insert('end', @list ); $lbox->selectionSet('2'); #default starting selection in the box,"c" $lbox->bind('<<ListboxSelect>>', sub{warn "new ListBox element selecte +d!\n"} ); MainLoop;

Replies are listed 'Best First'.
Re^2: Tk programmatically monitor change in Listbox
by IB2017 (Pilgrim) on Jan 06, 2020 at 10:45 UTC

    The user will add a new element (or a set of elements) to the set of elements displayed in the Listbox. This is done programmatically. The list can be recreated with no problem at any time. The problem is that this operation is done programmatically in Tcl (embedded in Perl) through Tcl.pm/Tcl::Tk inside a

    $int->Eval();#Tcl code which adds the element to the Listbox goes here

    Unfortunately, me and my collegue were not able to find a way to call a Perl subrutine from inside the Eval code at the moment of adding the new element (I guess it is not possible at all). This is the reason why I am searching for an alternative to call this subrutine when the set of elements changes. It goeas without saying that for the meoment we can not substitute the Tcl code with Perl code, which would make this operation superfluous.

    The original code posted in this thread is in Tk because I want(ed) to find a solution to my proposed approach - which is indipendent to Tcl.

      Do you need the exact changes made or do you only care about the final state? If the latter, you could simply read back the Listbox contents after the $int->Eval(); returns and call a Perl handler there.

        Unfortunately the $int->Eval(); is run upon external events (user interacting with the UI)

      The original code posted in this thread is in Tk because I want(ed) to find a solution to my proposed approach - which is indipendent to Tcl.

      Here is a rule of thumb, whenever you're 100% sure the boundary you're crossing isn't relevant, but you can't write the solution -- the boundary is critical.

      Tcl::Tk needs to be in your title to attract Courage/VKON

        Thanks for the comment. The colleague originally working on this function already posted a question regarding the possibility to call a Perl subroutine from $int->Eval(); on the tcltk@perl.org group. It seems it is possible to run Perl code from within $int->Eval(); with the Tcl command ::perl::Eval, however not a Perl subroutine that lives outside the $int->Eval();. Since I have 0 knowledge of Tcl and no experience in "language bridging", I was hoping to solve the issue simply by monitoring the change in the Listbox state/values. There are a couple of suggestion in other answers here that I am now examining.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11111039]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2024-03-28 10:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found