Programmatically set focus in TList on tab raise

Gunnar Strand <[email protected]> Fri, 19 Aug 2011 16:28:21 +0200
Newsgroups gmane.comp.lang.perl.tk
Message-ID <CAEsF1LsqOmbYfSfSSg068qHU=sD78p6tjc3TyTpADoSsZy2gxA@mail.gmail.com>
--===============3095079872460793701==
Content-Type: multipart/alternative; boundary=000e0cd47ab29aca5504aadc8a6e

--000e0cd47ab29aca5504aadc8a6e
Content-Type: text/plain; charset=ISO-8859-1

Hi list,

I have a DynaTabFrame with pages containing TLists. I want one entry in the
TList to be "active" whenever the tab is raised, just as if it had been
moved to by the directional keys (I do not want it to be selected). I have
tried the following in the -raisecmd callback by looking at the source of
TList ("$_[HEAP]->{menu}" is the TList instance).

sub menu_raised {
  warn "MENU RAISED";
  $_[HEAP]->{menu}->focus;
  $_[HEAP]->{menu}->anchorSet(0);
  $_[HEAP]->{menu}->see(0);
  #$_[HEAP]->{menu}->selection('clear');
  #$_[HEAP]->{menu}->selection('set' => 0);
  $_[KERNEL]->yield( 'menu_enter', $_[HEAP]->{menu}->cget('-current') );
}

Uncommenting the "selection" lines does not work either.

The code in TList which handles directional key presses looks like this:

sub DirKey
{
 my ($w,$dir) = @_;
 my $anchor = $w->info('anchor');

 my $new = (defined $anchor) ? $w->info($dir,$anchor) : 0;

 $w->anchorSet($new);
 $w->see($new);
}

Does anyone have any tips on how to do this? Do I need to resort to sending
a key event to the widget or is there a better way?

BR
Gunnar

--000e0cd47ab29aca5504aadc8a6e
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hi list,<div><br></div><div>I have a DynaTabFrame with pages containing TLi=
sts. I want one entry in the TList to be &quot;active&quot; whenever the ta=
b is raised, just as if it had been moved to by the directional keys (I do =
not want it to be selected). I have tried the following in the -raisecmd ca=
llback=A0by looking at the source of TList=A0(&quot;$_[HEAP]-&gt;{menu}&quo=
t; is the TList instance).</div>
<meta http-equiv=3D"content-type" content=3D"text/html; charset=3Dutf-8"><d=
iv><br></div><div><div><font class=3D"Apple-style-span" face=3D"&#39;courie=
r new&#39;, monospace">sub menu_raised {</font></div><div><font class=3D"Ap=
ple-style-span" face=3D"&#39;courier new&#39;, monospace">=A0 warn &quot;ME=
NU RAISED&quot;;</font></div>
<div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monosp=
ace">=A0 $_[HEAP]-&gt;{menu}-&gt;focus;</font></div><div><font class=3D"App=
le-style-span" face=3D"&#39;courier new&#39;, monospace">=A0 $_[HEAP]-&gt;{=
menu}-&gt;anchorSet(0);</font></div>
<div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monosp=
ace">=A0 $_[HEAP]-&gt;{menu}-&gt;see(0);</font></div><div><font class=3D"Ap=
ple-style-span" face=3D"&#39;courier new&#39;, monospace">=A0 #$_[HEAP]-&gt=
;{menu}-&gt;selection(&#39;clear&#39;);</font></div>
<div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monosp=
ace">=A0 #$_[HEAP]-&gt;{menu}-&gt;selection(&#39;set&#39; =3D&gt; 0);</font=
></div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;,=
 monospace">=A0 $_[KERNEL]-&gt;yield( &#39;menu_enter&#39;, $_[HEAP]-&gt;{m=
enu}-&gt;cget(&#39;-current&#39;) );</font></div>
<div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monosp=
ace">}</font></div><div><br></div></div><div>Uncommenting the &quot;selecti=
on&quot; lines does not work either.</div><div><br></div><div>The code in T=
List which handles directional key presses looks like this:</div>
<div><br></div><div><div><font class=3D"Apple-style-span" face=3D"&#39;cour=
ier new&#39;, monospace">sub DirKey</font></div><div><font class=3D"Apple-s=
tyle-span" face=3D"&#39;courier new&#39;, monospace">{</font></div><div><fo=
nt class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monospace">=A0=
my ($w,$dir) =3D @_;</font></div>
<div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monosp=
ace">=A0my $anchor =3D $w-&gt;info(&#39;anchor&#39;);</font></div><div><fon=
t class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monospace"><br>=
</font></div>
<div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monosp=
ace">=A0my $new =3D (defined $anchor) ? $w-&gt;info($dir,$anchor) : 0;</fon=
t></div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;=
, monospace"><br>
</font></div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new=
&#39;, monospace">=A0$w-&gt;anchorSet($new);</font></div><div><font class=
=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monospace">=A0$w-&gt;s=
ee($new);</font></div>
<div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monosp=
ace">}</font></div></div><div><br></div><div>Does anyone have any tips on h=
ow to do this? Do I need to resort to sending a key event to the widget or =
is there a better way?</div>
<div><br></div><div>BR</div><div>Gunnar</div>

--000e0cd47ab29aca5504aadc8a6e--

--===============3095079872460793701==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

--++**==--++**==--++**==--++**==--++**==--++**==--++**==
ptk mailing list
[email protected]
https://mailman.stanford.edu/mailman/listinfo/ptk


--===============3095079872460793701==--