Disabling right click over wx.iehtmlWindow

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Subsciber123
    New Member
    • Nov 2006
    • 87

    Disabling right click over wx.iehtmlWindow

    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.
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Originally posted by 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.
    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()
    Code:
    #Boa:Frame:Frame1
    
    import wx
    import wx.html
    
    def create(parent):
        return Frame1(parent)
    
    [wxID_FRAME1, wxID_FRAME1HTMLWINDOW1, 
    ] = [wx.NewId() for _init_ctrls in range(2)]
    
    class Frame1(wx.Frame):
        def _init_ctrls(self, prnt):
            # generated method, don't edit
            wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt, pos=wx.Point(431, 243),
                    size=wx.Size(400, 250), style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
            self.SetClientSize(wx.Size(392, 223))
    
            self.htmlWindow1 = wx.html.HtmlWindow(id=wxID_FRAME1HTMLWINDOW1, name='htmlWindow1',
                    parent=self, pos=wx.Point(88, 72), size=wx.Size(200, 100),
                    style=wx.html.HW_SCROLLBAR_AUTO)
            self.htmlWindow1.Bind(wx.EVT_LEFT_DOWN, self.OnHtmlWindow1LeftDown)
    
        def __init__(self, parent):
            self._init_ctrls(parent)
    
        def OnHtmlWindow1LeftDown(self, event):
            pass    #  this is here for demonstration ONLY.
            #if IWantThisEvent:
                #event.Skip()
            #else:
                #pass    # to block an event, simply don't call event.Skip()

    Comment

    • Subsciber123
      New Member
      • Nov 2006
      • 87

      #3
      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:

      Code:
      import os
      from PythonCard import model  #don't worry about some of these: some are
      import wx                    #used in other parts of the program
      import thread
      from time import sleep
      
      class window(model.Background):
      
          def on_initialize(self, event):
              self.components.htmlDisplay.Bind(wx.EVT_LEFT_DOWN, 
                  self.on_htmlDisplay_leftDown) #bartonc's line modified
      
          def on_htmlDisplay_leftDown(self, event): #bartonc's function
              if IWantThisEvent:
                  event.Skip()
              else:
                  DoWhatever
      I haven't tested it yet, but it will probably work with these minor modifications.
      Last edited by Subsciber123; Jan 19 '07, 04:20 AM. Reason: I mislabeled something

      Comment

      • Subsciber123
        New Member
        • Nov 2006
        • 87

        #4
        Now that I've tested it, it doesn't work. There are no exceptions or anything. I switched the wx.EVT_LEFT_DOW N with wx.EVT_RIGHT_DO WN, 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?

        Comment

        • Subsciber123
          New Member
          • Nov 2006
          • 87

          #5
          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.

          Comment

          • bartonc
            Recognized Expert Expert
            • Sep 2006
            • 6478

            #6
            Originally posted by Subsciber123
            Now that I've tested it, it doesn't work. There are no exceptions or anything. I switched the wx.EVT_LEFT_DOW N with wx.EVT_RIGHT_DO WN, 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.Ba ckground):
            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.

            Comment

            • Subsciber123
              New Member
              • Nov 2006
              • 87

              #7
              It may help for me to describe a little how PythonCard works (or at least how it is persieved to work).

              model.Backgroun d 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 _documentComple te(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.

              Comment

              • Subsciber123
                New Member
                • Nov 2006
                • 87

                #8
                Okay, now I've gotten the chance to try to bind the window to an arbitrary function, and nothing happens:
                Code:
                import os
                from PythonCard import model  #don't worry about some of these: some are
                import wx                    #used in other parts of the program
                import thread
                from time import sleep
                
                class window(model.Background):
                
                    def on_initialize(self, event):
                        self.Bind(wx.EVT_LEFT_DOWN,   
                            self.on_htmlDisplay_leftDown)
                
                    def on_htmlDisplay_leftDown(self, event):
                	print "leftDown event"
                	event.skip()
                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!
                Last edited by Subsciber123; Jan 21 '07, 05:48 AM. Reason: I omitted something

                Comment

                • bartonc
                  Recognized Expert Expert
                  • Sep 2006
                  • 6478

                  #9
                  Originally posted by Subsciber123
                  Okay, now I've gotten the chance to try to bind the window to an arbitrary function, and nothing happens:
                  Code:
                  import os
                  from PythonCard import model  #don't worry about some of these: some are
                  import wx                    #used in other parts of the program
                  import thread
                  from time import sleep
                  
                  class window(model.Background):
                  
                      def on_initialize(self, event):
                          self.Bind(wx.EVT_LEFT_DOWN,   
                              self.on_htmlDisplay_leftDown)
                  
                      def on_htmlDisplay_leftDown(self, event):
                  	print "leftDown event"
                  	event.skip()
                  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.Backgroun d 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.

                  Comment

                  • Subsciber123
                    New Member
                    • Nov 2006
                    • 87

                    #10
                    A good article on how binding works in wxPython is located at:


                    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:
                    Code:
                    self.Bind(wx.EVT_BUTTON, self.OnButton1, self.button)
                    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.

                    Comment

                    • Subsciber123
                      New Member
                      • Nov 2006
                      • 87

                      #11
                      I thought of another alternative: unbind events from the wx.lib.iewin html window. That too did not work.

                      Comment

                      • hieuhan
                        New Member
                        • Jan 2008
                        • 1

                        #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

                        Comment

                        • Subsciber123
                          New Member
                          • Nov 2006
                          • 87

                          #13
                          Originally posted by hieuhan
                          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.

                          Comment

                          Working...