473,399 Members | 3,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Disabling right click over wx.iehtmlWindow

Subsciber123
I have a window that I have created using Python Card that contains an wx.iehtmlWindow opject inside of it. Does anyone know how to disable right click and/or cause links that would open in new windows to open in the same window?

I am running Windows XP Home.

I am running ActiveState Python 2.4.

Anything that I have tried has done absolutely nothing, because I can't get the events from the wx.iehtmlWindow to filter them for right clicks.
Jan 18 '07 #1
12 4205
bartonc
6,596 Expert 4TB
I have a window that I have created using Python Card that contains an wx.iehtmlWindow opject inside of it. Does anyone know how to disable right click and/or cause links that would open in new windows to open in the same window?

I am running Windows XP Home.

I am running ActiveState Python 2.4.

Anything that I have tried has done absolutely nothing, because I can't get the events from the wx.iehtmlWindow to filter them for right clicks.
This should be the kind of idea to persue. In order to block an event, bind very high in the hierachy and don't call event.Skip(). You can test for conditions when you DO want the event to propagate and then call event.Skip()
Expand|Select|Wrap|Line Numbers
  1. #Boa:Frame:Frame1
  2.  
  3. import wx
  4. import wx.html
  5.  
  6. def create(parent):
  7.     return Frame1(parent)
  8.  
  9. [wxID_FRAME1, wxID_FRAME1HTMLWINDOW1, 
  10. ] = [wx.NewId() for _init_ctrls in range(2)]
  11.  
  12. class Frame1(wx.Frame):
  13.     def _init_ctrls(self, prnt):
  14.         # generated method, don't edit
  15.         wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt, pos=wx.Point(431, 243),
  16.                 size=wx.Size(400, 250), style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
  17.         self.SetClientSize(wx.Size(392, 223))
  18.  
  19.         self.htmlWindow1 = wx.html.HtmlWindow(id=wxID_FRAME1HTMLWINDOW1, name='htmlWindow1',
  20.                 parent=self, pos=wx.Point(88, 72), size=wx.Size(200, 100),
  21.                 style=wx.html.HW_SCROLLBAR_AUTO)
  22.         self.htmlWindow1.Bind(wx.EVT_LEFT_DOWN, self.OnHtmlWindow1LeftDown)
  23.  
  24.     def __init__(self, parent):
  25.         self._init_ctrls(parent)
  26.  
  27.     def OnHtmlWindow1LeftDown(self, event):
  28.         pass    #  this is here for demonstration ONLY.
  29.         #if IWantThisEvent:
  30.             #event.Skip()
  31.         #else:
  32.             #pass    # to block an event, simply don't call event.Skip()
  33.  
Jan 19 '07 #2
I suppose that my code will be a little different, seeing as I am using PythonCard, not BoaConstructor. All my child objects (except windows) are created using a resource file, and are stored in self.components.

My class would probably look more like:

Expand|Select|Wrap|Line Numbers
  1. import os
  2. from PythonCard import model  #don't worry about some of these: some are
  3. import wx                    #used in other parts of the program
  4. import thread
  5. from time import sleep
  6.  
  7. class window(model.Background):
  8.  
  9.     def on_initialize(self, event):
  10.         self.components.htmlDisplay.Bind(wx.EVT_LEFT_DOWN, 
  11.             self.on_htmlDisplay_leftDown) #bartonc's line modified
  12.  
  13.     def on_htmlDisplay_leftDown(self, event): #bartonc's function
  14.         if IWantThisEvent:
  15.             event.Skip()
  16.         else:
  17.             DoWhatever
  18.  
I haven't tested it yet, but it will probably work with these minor modifications.
Jan 19 '07 #3
Now that I've tested it, it doesn't work. There are no exceptions or anything. I switched the wx.EVT_LEFT_DOWN with wx.EVT_RIGHT_DOWN, and had the function that I bound print "blah". I didn't get any "blah"'s printed, and the context menu still worked in wx.iehtmlWindow. My guess is that wx.iehtmlWindow is catching the events (since it is an activex control of IE), and not putting the events through my program before evaluating them. Any ideas?
Jan 19 '07 #4
Just as an afterthought, maybe I could put a clear picture in front of it, and relay click events that I approve to the wx.iehtmlWindow. I have no idea how I would do this, though.
Jan 19 '07 #5
bartonc
6,596 Expert 4TB
Now that I've tested it, it doesn't work. There are no exceptions or anything. I switched the wx.EVT_LEFT_DOWN with wx.EVT_RIGHT_DOWN, and had the function that I bound print "blah". I didn't get any "blah"'s printed, and the context menu still worked in wx.iehtmlWindow. My guess is that wx.iehtmlWindow is catching the events (since it is an activex control of IE), and not putting the events through my program before evaluating them. Any ideas?
Don't know if
class window(model.Background):
is an event handler class, but if it is you might try binding to the window instead of the iehtmlWindow. It's worth a shot, anyway.
Jan 19 '07 #6
It may help for me to describe a little how PythonCard works (or at least how it is persieved to work).

model.Background is contained inside PythonCard.

PythonCard takes the file that you import it from (say, "window.py"), and any top level windows that you create uses the associated resource file (in this case, "window.rsrc.py") to create the windows with objects in them.

In a class, PythonCard does all the binding for you: all you have to do is create a function with a name of the form
"on_[name of object in window]_[name of event](self,event):"
or
"on_[name of event](self,event):"
for events bound to every object in the window.

For example, "on_htmlDisplay_documentComplete(self,event):"
gets called whenever htmlDisplay finishes loading a document.

I am not sure how to bind the entire window to an event, just how to bind every object in the window to an event (they are not the same thing).

Any suggestions would be helpful. I also recommend that you look into PythonCard yourself. Firstly, it makes creating windows really easy, and secondly, it will help you understand my problem better.
Jan 19 '07 #7
Okay, now I've gotten the chance to try to bind the window to an arbitrary function, and nothing happens:
Expand|Select|Wrap|Line Numbers
  1. import os
  2. from PythonCard import model  #don't worry about some of these: some are
  3. import wx                    #used in other parts of the program
  4. import thread
  5. from time import sleep
  6.  
  7. class window(model.Background):
  8.  
  9.     def on_initialize(self, event):
  10.         self.Bind(wx.EVT_LEFT_DOWN,   
  11.             self.on_htmlDisplay_leftDown)
  12.  
  13.     def on_htmlDisplay_leftDown(self, event):
  14.     print "leftDown event"
  15.     event.skip()
  16.  
There are no errors, but nothing is printed no matter where on the screen I click, or right click, or middle click, whatever.

I am thinking that the only solution is to put a clear image in front of it, and transfer click events that I approve of to the wx.iehtmlWindow.

If anybody has any ideas on how to do this, please let me know!
Jan 21 '07 #8
bartonc
6,596 Expert 4TB
Okay, now I've gotten the chance to try to bind the window to an arbitrary function, and nothing happens:
Expand|Select|Wrap|Line Numbers
  1. import os
  2. from PythonCard import model  #don't worry about some of these: some are
  3. import wx                    #used in other parts of the program
  4. import thread
  5. from time import sleep
  6.  
  7. class window(model.Background):
  8.  
  9.     def on_initialize(self, event):
  10.         self.Bind(wx.EVT_LEFT_DOWN,   
  11.             self.on_htmlDisplay_leftDown)
  12.  
  13.     def on_htmlDisplay_leftDown(self, event):
  14.     print "leftDown event"
  15.     event.skip()
  16.  
There are no errors, but nothing is printed no matter where on the screen I click, or right click, or middle click, whatever.

I am thinking that the only solution is to put a clear image in front of it, and transfer click events that I approve of to the wx.iehtmlWindow.

If anybody has any ideas on how to do this, please let me know!
I'd be curious to know if on_initialize() is truly being called. If it is, then the model.Background class is not handling events properly because this should work.
I'm near the end of a large project with a deadline looming. Otherwise I would take some time to prove my thoughts regarding PyCard.
Jan 21 '07 #9
A good article on how binding works in wxPython is located at:
http://wiki.wxpython.org/index.cgi/self.Bind_vs._self.button.Bind

To answer your query, on_initialize is being called; I know because there are many other things in there such that if it were not called, the program would come crashing to the ground.

According to that article, the more specific the binding is, the sooner it will be called on the hierarchy. For example:
Expand|Select|Wrap|Line Numbers
  1. self.Bind(wx.EVT_BUTTON, self.OnButton1, self.button)
  2. self.button.Bind(wx.EVT_BUTTON, self.OnButton2)
Given that code, if OnButton2 does not call event.Skip(), then OnButton1 will NEVER be called.

Apparently, the iehtmlWindow must be the highest point on the hierarchy, and is not calling event.Skip(). That is not surprising, considering that it is an activex control of Microsoft IE. Because why would Microsoft think that anybody using their program with an activex control would want to filter events [said with sarcasm ;)]?

The only thing that I can think of right now is something that I have suggested before. That would be to put a clear gif image in front of the iehtmlWindow, and relay click events that I approve of. I don't know how to do this, and anything easier would be great.
Jan 21 '07 #10
I thought of another alternative: unbind events from the wx.lib.iewin html window. That too did not work.
Jan 21 '07 #11
Hi Folk,

I have wondered as same as you and googled it. Found it how easy it is:

<body oncontextmenu='return false;'>

http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_10231945.html

Hope it helps
Jan 15 '08 #12
Hi Folk,

I have wondered as same as you and googled it. Found it how easy it is:

<body oncontextmenu='return false;'>

http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_10231945.html

Hope it helps
This would require writing a proxy that put this in every page, which would be unwieldy.
Anyway, this is no longer a problem, as I have moved onto bigger and better operating systems and bigger and better projects since then.
Sep 7 '08 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

20
by: dukeleto | last post by:
I know this is an annoying thing on some sites. I have set some images in an online gallery to have their own java po up window that is set to be the same size as the image. I would like to...
7
by: Robert | last post by:
Can I programmatically disable the right click context menu?
1
by: Todd7 | last post by:
I am writing a python program to load a pdf file into an IEHtmlWindow which displays it through adobe acrobat reader 7. Depending on the buttons the user clicks, the program moves it to another...
12
by: Nalaka | last post by:
Hi, I suddenly started getting a lot of errors from html validation (some CSS) so I followed the following instructions to disable it. If you'd rather not have these types of HTML validation...
6
by: emmajoh | last post by:
Hi I'm trying to disable IE contextmenu (on a right click) as I want to create my own. The problem is that since I've installed the latest version of the google desktop, the script doesn't...
0
by: gjzusenet | last post by:
Hi I've been using an IEHtmlWindow in my script with no problems, but it seems that for people with a clean installation of XP SP2 it fails like such: Traceback (most recent call last): File...
1
by: kebabkongen | last post by:
Hi, I'm working on a JavaScript that is enabling / disabling a select element according to whether a checkbox is selected or not. This works fine in Firefox, but in Internet Explorer (v 6.0.2900)...
5
by: hp_1981 | last post by:
Hi Is there anyway avoiding users to save my web pages? this idea came to my mind when I tried to save a web page, but in the middle of saving progress something like the following error...
1
by: Farsheed Ashouri | last post by:
Hi everyone. I create a little browser with wxpython and IEHtmlWindow. But I have a little problem here. When I press enter in the html page, The focus goes to another panel. Why this happens? I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.