[Kde-bindings] Ruby, sendEvent and KDE

Stefan Champailler champailler at octalis.com
Wed Oct 19 17:25:47 UTC 2005


Hi Richard,

Thank you for answering ! As you can see from my previous messages 
I've made some progress and I'm now heading to complete my goal.

As a side note, if I want to simulate a click, it is for example, to 
simulate a click on some JavaScript controlled elements or to make 
sure I have the mouse cursor positioned on the link so I can take a 
picture (very helpful in tutorials)... So there _are_ good reasons 
to simulate real mouse movements even though the KHTML part does 
provide openURL(xxx) functions !

Also, for those who followed my other thread, I'm now thinking of 
decoupling my code in two ruby scripts connected by DCOP. This way I 
achieve "multithreading" or parallel processing, even though I use 
Qt components and KDE event loops... Ain't clean but will probably 
work..

Cheers !

stF

> On Friday 14 October 2005 18:13, Stefan Champailler wrote:
> > Dear All,
> >
> > I'm now facing a problem with sendEvent. The deal is this : I
> > have a KDE::HTMLPart in a KDE::MainWindow that I use as a web
> > browser. I'd like to simulate a mouse cursor move over on
> > particular place on the view of the browser and a mouse click
> > there. For example, open the www.kde.org and click on the
> > "announcement" link.
>
> Surely what you actually want to do is to find out which URL is
> selected under the mouse, and open it? I think the
> KHTMLPart/BrowserExtension apis allow you to do that. I don't
> think you need to simulate mouse events.
>
> -- Richard
>
> > I've written a piece of code that so far can display the browser
> > and move the mouse cursor on the link I want :
> >
> >         p = Qt::Point.new(30,30)
> >         p_global = self.mapToGlobal(p)
> >         Qt::Cursor.setPos( p_global)
> >         KDE::Application::kApplication.processEvents()
> >
> > The next thing I want to do is the "click". So I do :
> >
> >         current_widget =
> > KDE::Application::kApplication.widgetAt( p_global)
> >         mouseEvent( current_widget, Qt::Event::MouseButtonPress,
> > p, p_global, Qt::RightButton, 0)
> >         mouseEvent( current_widget,
> > Qt::Event::MouseButtonRelease, p, p_global, Qt::RightButton, 0)
> >
> >
> > with
> >
> >     def mouseEvent( target, type, pos, global_pos,button, state)
> >         res = Qt::Application::sendEvent( target,
> >             Qt::MouseEvent.new( type, target.rect().center(),
> > button, state))
> >         puts "Cant send event to target" if !res
> >     end
> >
> >
> > problem is the sendEvent always returns false and the click
> > never occurs.
> >
> > If I add an event filter I can see that the events I'm sending
> > arrives to the widget.
> >
> > I've been coding ruby/qt/korundum for 2 days so far so I'm quite
> > newbie... I'va also checked Qt Test Lib from TrollTech but I
> > think I do things like them. The big difference is that to
> > simplify my code (i.e. no good reason :)), all this code is part
> > of the MainWindow object :
> >
> > class MainWindow < KDE::MainWindow
> >
> > which I use like this :
> >
> > a = KDE::Application.new()
> > window = MainWindow.new( "Tutorial - p4", a )
> > window.resize( 1200, 800 )
> > a.setTopWidget( window)
> > window.show
> > a.exec
> >
> >
> > help would be much appreciated !
> >
> > Stefan
> >
> > _______________________________________________
> > Kde-bindings mailing list
> > Kde-bindings at kde.org
> > https://mail.kde.org/mailman/listinfo/kde-bindings
>
> _______________________________________________
> Kde-bindings mailing list
> Kde-bindings at kde.org
> https://mail.kde.org/mailman/listinfo/kde-bindings
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-bindings/attachments/20051019/9816a7c7/attachment.sig>


More information about the Kde-bindings mailing list