Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Tkx catch and selection

7 views
Skip to first unread message

Ken Preslan

unread,
Dec 6, 2012, 10:59:03 PM12/6/12
to tc...@perl.org
Hi all,

I'm trying to translate one of my programs from Perl/Tk to Perl/Tkx. I
want to be able to paste a text string into the program using the middle
mouse button under X11.

I've been using "$string = Tkx::selection('get')", which works most of the
time. However, if there there is no current selection, I get an ugly
pop-up error.

I solved this problem in Perl/Tk with catch:
Tk::catch { $string = $g_w_main->SelectionGet(); };

I assume this is just a mapping to Tcl's catch. So, I can do:
$string = Tkx::catch('selection get');

However, this just sets $string to the result of catch, a number. How do
I get the results of the 'selection get' assigned to a Perl variable?

Thanks!

--
Ken Preslan <k...@preslan.org>

Jeff Hobbs

unread,
Dec 9, 2012, 7:47:56 PM12/9/12
to Ken Preslan, tc...@perl.org
On 2012-12-06, at 7:59 PM, Ken Preslan <k...@preslan.org> wrote:
> I solved this problem in Perl/Tk with catch:
> Tk::catch { $string = $g_w_main->SelectionGet(); };
>
> I assume this is just a mapping to Tcl's catch. So, I can do:
> $string = Tkx::catch('selection get');
>
> However, this just sets $string to the result of catch, a number. How do
> I get the results of the 'selection get' assigned to a Perl variable?

This needs testing, but you want the multi-arg version of catch to get the result.

my $string;
if (Tkx::catch('selection get', \$string)) {
# error occurred
} else {
# $string should have result
}

Jeff

Jeff Hobbs

unread,
Dec 9, 2012, 9:00:23 PM12/9/12
to Ken Preslan, tc...@perl.org
On 2012-12-09, at 5:59 PM, Ken Preslan <k...@preslan.org> wrote:
> On Sun, Dec 09, 2012 at 04:47:56PM -0800, Jeff Hobbs wrote:
>> On 2012-12-06, at 7:59 PM, Ken Preslan <k...@preslan.org> wrote:
>>> However, this just sets $string to the result of catch, a number. How do
>>> I get the results of the 'selection get' assigned to a Perl variable?
>>
>> This needs testing, but you want the multi-arg version of catch to get the
>> result.
>> ...
>
> Excellent, that works well. Thank you!
>
> Is there documentation for this somewhere that I missed?

Only in the sense that Tcl's catch has a 1-arg and 2-arg form, and this uses the 2nd arg. Variables references from Perl get auto-transmogrified into tied Tcl vars.

Jeff

Ken Preslan

unread,
Dec 9, 2012, 8:59:02 PM12/9/12
to Jeff Hobbs, tc...@perl.org
On Sun, Dec 09, 2012 at 04:47:56PM -0800, Jeff Hobbs wrote:
> On 2012-12-06, at 7:59 PM, Ken Preslan <k...@preslan.org> wrote:
> > However, this just sets $string to the result of catch, a number. How do
> > I get the results of the 'selection get' assigned to a Perl variable?
>
> This needs testing, but you want the multi-arg version of catch to get the
> result.
> ...

Excellent, that works well. Thank you!

Is there documentation for this somewhere that I missed?

--
Ken Preslan <k...@preslan.org>

Ken Preslan

unread,
Dec 9, 2012, 10:50:49 PM12/9/12
to Jeff Hobbs, tc...@perl.org
Ah, ok Thanks!

--
Ken Preslan <k...@preslan.org>

0 new messages