Peter Miller wrote:
> OK, I'm confused.
> How the heck do I get key press events sent to a PapyrusGtk::Viewport
> widget? Or to a registered Controller?
> I've tried Gtk::Window::add_events on the viewport,
> and I've tried set_focus_add_child on the scroll window.
> What am I doing wrong?
I hope you don't mind... I cc'd the users list so there is something
archived that others can refer to as well.
In short, most modern GUI toolkits wrap the view and the controller into
one object, and for GUI's it makes sense to me to keep the user
interaction tied to the display. But, with papyrus I wanted more of a
separation to allow for external events (such as the results of an
inference engine) to control the scenegraph.
So, while papyrus has the model (basically everything descending from
Renderable) and controllers, papyrusmm has the view (Viewport) _and_
In the case of the Viewport, it descends from Gtk::EventBox which makes
it the canonical GUI approach with combined view and controller. So,
there are two ways key presses could be handled:
(1) Extend PapyrusGtk::Viewport and connect Gtk::EventBox
signal_key_press_event() and signal_key_press_release() to your own key
handling methods. I would call this the pure Gtkmm approach.
(2) Extend Papyrus::Controller and provide your own implementations for
Controller::on_key_press() and Controller::on_key_release(). Then add
your controller to the viewport to get the Viewports events to flow into
The Papyrus::Controller was directly inspired by the Gdk events. The
main purpose in having a separate hierarchy is so that I didn't feel
absolutely tied to the Gdk/Gtk event model. I suppose you might say I
wanted the freedom to take it in any direction that I felt was
appropriate. However, to date I haven't really found a real need to
exercise that freedom. :)
Something I was just thinking about though... I haven't done anything
with the Gtk::EventBox sigmasks, so key press events might not flow
automatically. If that's the case it's a bug in papyrusmm since
automatically passing the key press events off to the controller is the
behavior I intended.
Unfortunately I don't have time to test it right now, but these should
provide more info:
Maybe start by subclassing Viewport and making sure that the EventBox is
getting the keypresses??? Maybe even a simple program outside papyrus?