Home > Archive > PerlTk > January 2005 > Tk::Text menus
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| greymaus@yahoo.com 2005-01-16, 3:57 pm |
| When you create a Scrolled("Text:.. widget, it has a floating menu,
with "File", "Edit", etc. Is there any way to use these menu's from
one's own program (as in , how do you get the co-ords of text
highlighted with a mouse?)
--
greymaus
97.025% of statistics are wrong
| |
|
| On Sun, 16 Jan 2005 19:12:09 +0000, greymaus wrote:
> When you create a Scrolled("Text:.. widget, it has a floating menu, with
> "File", "Edit", etc. Is there any way to use these menu's from one's own
> program (as in , how do you get the co-ords of text highlighted with a
> mouse?)
Yes, the default Button3 binding (sometimes called a context menu), right?
Happens I just did something similar:
Since you're using a Scrolled('Text'...), you need to get the real Text widget
with:
my $sw = $text->Subwidget('scrolled'); # get the scrolled widget
then you can get the menu with:
my $menu = $sw->menu; # see perldoc Tk::Text
at which point you may add, delete, and all the other Tk::Menu things you might
want to do.
You may also want to reorder the binding something like:
$sw->bindtags([$sw, ref $sw, $sw->toplevel, 'all']); # re-order bindings so
# our subs are called first
and put a $widget->break in your button handler.
For selection co-ords, seems like you should be able to get the Text co-ords
with a $text->tagRanges('sel') request (but I haven't tried it). On the other
hand, once you get full control over the menu, you may not really need the
selection co-ords - just use the 'sel' tag directly?
Regards,
plugh
| |
| greymaus@yahoo.com 2005-01-17, 8:56 am |
| On Sun, 16 Jan 2005 18:00:10 -0800, plugh wrote:
> On Sun, 16 Jan 2005 19:12:09 +0000, greymaus wrote:
>
>
> Yes, the default Button3 binding (sometimes called a context menu), right?
> Happens I just did something similar:
>
> Since you're using a Scrolled('Text'...), you need to get the real Text widget
> with:
> my $sw = $text->Subwidget('scrolled'); # get the scrolled widget
>
> then you can get the menu with:
> my $menu = $sw->menu; # see perldoc Tk::Text
>
> at which point you may add, delete, and all the other Tk::Menu things you might
> want to do.
>
> You may also want to reorder the binding something like:
> $sw->bindtags([$sw, ref $sw, $sw->toplevel, 'all']); # re-order bindings so
> # our subs are called first
>
> and put a $widget->break in your button handler.
>
> For selection co-ords, seems like you should be able to get the Text co-ords
> with a $text->tagRanges('sel') request (but I haven't tried it). On the other
> hand, once you get full control over the menu, you may not really need the
> selection co-ords - just use the 'sel' tag directly?
>
> Regards,
>
> plugh
Thanks!
--
greymaus
97.025% of statistics are wrong
|
|
|
|
|