Forum: Ruby-Gnome 2 Open a context menu with actions in TextView widget

4828d528e2e46f7c8160c336eb332836?d=identicon&s=25 Robert Heiler (shevegen)
on 2013-08-24 02:30

I have a question.

I have a window with three things - ScrolledWindow, TextBuffer and

I can select text just fine with my mouse.

Now I would like to press right mouse click on selection and popup a
small context menu, with entries that I wish to define on my own. I.e.
increase font size would be nice for the selection.

Does one of you have an idea how to get such a popup widget on right
3853dd5371ac1e094fc45d6c2aa0e459?d=identicon&s=25 Carlo E. Prelz (Guest)
on 2013-08-24 08:06
(Received via mailing list)
Subject: [ruby-gnome2-devel-en] Open a context menu with actions in
TextView widget
  Date: sab 24 ago 13 02:30:37 +0200

Quoting Marc Heiler (

> click?
You can trap signals for your textview: signal 'button-press-event' is
emitted when a mouse button is pressed, and 'button-release-event' is
emitted when the button is released.

So, if you have something like this:



you can add this:

et.signal_connect('button-press-event') do |tv,eb|
et.signal_connect('button-release-event') do |tv,eb|

This specific processing only takes place when the focus of the mouse
is within the textview.

The second parameter you receive when the signal is triggered is an
EventButton instance. Check if eb.button==3, and do whatever you need
to do.

Remember that the return value from the signal_connect block has
meaning. If you return true, it means you have made use of the signal,
and it does not need further processing. If you return false, the
signal is passed downwards.

So, if you want to do something on release of the third mouse button,
first avoid the window manager processing of the click as follows:

et.signal_connect('button-press-event') do |tv,eb|
  eb.button==3 ? true : false

Then do what you need to do at release

et.signal_connect('button-release-event') do |tv,eb|
  return false unless(eb.button==3)


def do_what_you_need

Hope this helps


  *         Se la Strada e la sua Virtu' non fossero state messe da
* K * Carlo E. Prelz -             che bisogno ci
  *               di parlare tanto di amore e di rettitudine?
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.