RE: How do I disable mousewheel scrolling?
Steve Barnes <[email protected]>
| Newsgroups | gmane.comp.python.wxpython |
|---|---|
| Message-ID | <VI1PR03MB44795FBB85E6C74AAB246B399B960@VI1PR03MB4479.eurprd03.prod.outlook.com> |
Lawrence, Glad if I was able to help. In my example OnMW had a signature of def OnMW(self, evt): because it was defined as a class member on the window. If you need to handle more event types and given that you have a lot of controls that need the same behaviour you might wish to consider sub-classing the wx.Choice control to a control type that has these handlers built in. It might be worth you investing in one of Mike Driscoll’s books on wxPython – they are very good, if not cheap, https://www.amazon.com/Michael-Driscoll/e/B00KQZVUHG/ref=dp_byline_cont_ebooks_1 or reading his blog at https://www.blog.pythonlibrary.org/ Disclosure: I do have minor credits for proofreading or bug fixes in some of the books but have no financial interest. Have a great time & enjoy wxPython! Steve From: [email protected] <[email protected]> On Behalf Of Lawrence Gray Sent: 21 June 2020 06:11 To: [email protected] Subject: Re: [wxPython-users] How do I disable mousewheel scrolling? Thank you, Steve, I have things working now. But maybe not entirely as you described. Here is the code now... [cid:[email protected]] but, the definition of the handler 'onMW' is not quite what you suggested. [cid:[email protected]] The definition is not 'def name(self, evt):' as you can see. With the 'self' parameter I get the following non-fatal error: TypeError: OnMW() missing 1 required positional argument: 'evt' I am still trying to digest all of the information in your last reply. Thanks for the help. Of course, now I realize that I can have the same problem with the UP/DOWN arrow keys or even certain alphabetic key presses. If needed, I think a similar approach with KEY_EVENTS will handle that issue if needed. Regards -- ________________________________ Lawrence Gray ________________________________ On Sat, 20 Jun 2020 at 15:04, Steve Barnes <[email protected]<mailto:[email protected]>> wrote: Lawrence, The format is object.Bind(event_binder, handler_function) where the handler_function needs the signature def name(self, evt): and the actual events that match the binder will be passed in as the evt parameter. In your code below you need line 103 as: self.choice_1.Bind(wx.EVT_MOUSEWHEEL, utils.OnMW) # Note no parameters to the handler at this point The bind and caller mechanism handles the addition of the event parameter when an event is being handled and the code called. In your 103 below you are trying to bind the event to the result of calling utils.OnMW(self.choice_1, wx.EVT_MOUSEWHEEL) which will be None. The other thing to know is that wx.EVT_MOUSEWHEEL and the other wx.EVT_* items are not themselves events they are wx.core.PyEventBinder objects. To try to clarify: At bind time the handler is associated with a given objects/component event handling stack. When an event happens on any object that objects event handler stack is checked to see if it has a handler for that event. If it does that handler is called and if it ends with skip(True) or if there is no handler the objects parent control is passed the event. This continues until a handler is found that ends with skip(False) or the OS receives the event. Note that in this case we are talking parentage in the Windows terms rather than the code terms so the parent of choice_1 is self.panel_1 which has a parent of frame_1, . Quite a concept to get your head round – hope that helps. Steve Barnes From: [email protected]<mailto:[email protected]> <[email protected]<mailto:[email protected]>> On Behalf Of Lawrence Gray Sent: 20 June 2020 18:02 To: [email protected]<mailto:[email protected]> Subject: Re: [wxPython-users] How do I disable mousewheel scrolling? Again, thank you for your assistance. It seems so simple, I was able to replicate what you did in the example code for wxPython and I thought I understood what is going on. But I still keep running into the same roadblocks that I initially had trying to implement this in the first place. As suggested, I created a utility file containing the 'OnMW' method you defined and import this from the GUI file: import FS_utils AS utils From the postCode section of the Code panel for the control, in wxGlade, I inserted various code to 'Bind' the mousewheel event to the function in a manner that I believe replicates what you had done in the demo code. This is the relevant code generated by wxGlade. [cid:[email protected]] Hope this code snippet comes through. In line 101, I thought I would simply bind the event to the action needed, ie, skip the event. This fails with, "NameError: name 'event' is not defined" In line 102, in which I call the function 'OnMW' from the imported file, with parameters. As OnMW is not defined within the 'Frame' class, I thought it was necessary to pass something to the function. This fails in the same manner as line 101 In line 103, in which I think, but I'm not sure that I am passing the event explicitly to the function, also fails. File "D:\Lawrence Gray\My Documents\Python\Financial Summary\FS_utils.py", line 11, in OnMW evt.Skip(False) AttributeError: 'PyEventBinder' object has no attribute 'Skip' Should I simply define a function 'OnMW' within the Frame class to handle the event, or call the function in the utility file. In either case, when I try, it fails. AttributeError: 'MyFrame' object has no attribute 'OnMW' As for the "NameError's" above, in your example code from the wxPython demo, I don't see where the function 'OnMW' gets a value for the parameter 'evt', and yet this magic doesn't seem to happen in my code. Now, I am thoroughly befuddled. PS: Just at the last minute I noticed that I had this statement at the beginning of the file as part of my initial attempts to resolve the issue Could this be causing a problem? from wx import MouseEvent as ME Regards -- ________________________________ Lawrence Gray ________________________________ On Fri, 19 Jun 2020 at 13:40, Steve Barnes <[email protected]<mailto:[email protected]>> wrote: Lawrence, Event handling and such is a bit of a mystery for many people. The trick I think would be to have a handler something along the lines of: def NoMouseWheel(self, evt): """ Don't action the mousewheel """ evt.Skip(False) And for those controls, that when they have the focus you don’t wish mouse wheel to do anything, you do self.control.Bind(wx.EVT_MOUSEWHEEL, self. NoMouseWheel) on that control. wxGlade doesn’t seem to of heard of MOUSEWHEEL events yet ☹ In the demo code for wx.Choice I tried and sure enough the mousewheel changes the value when the choice has focus, but with the change below it doesn’t: [cid:[email protected]] You should be able to put the method into an import file, e.g. GUI_Utils.py, and handle this via the code tab for each of the controls. Hope that helps. Steve From: [email protected]<mailto:[email protected]> <[email protected]<mailto:[email protected]>> On Behalf Of Lawrence Gray Sent: 19 June 2020 16:16 To: [email protected]<mailto:[email protected]> Subject: Re: [wxPython-users] How do I disable mousewheel scrolling? Thank you for replying. That was actually my first thought but I couldn't implement it and still seem unable to do so. None of the wxPython demo programs provides the necessary insight for me. Event handling is still a mystery I am trying to come to grips with. If you could provide more detail, it would be greatly appreciated. As I am currently using wxGlade to generate the GUI code and trying to keep any business code separate from the GUI code I would ultimately prefer to implement a solution within the confines of the wxGlade project, but if that is not feasible, I will have to move out of my comfort zone. I am attaching my wxGlade project file and the code it generates for anyone so inclined to look at it. I am using wxGlade v0.9.6, python3.5.2 and wxPython4.0.3 Regards -- ________________________________ Lawrence Gray ________________________________ On Fri, 19 Jun 2020 at 05:08, Steve Barnes <[email protected]<mailto:[email protected]>> wrote: Rather than attempting to Disable mouse wheel scrolling you simply add a handler, to the controls that you don’t want to react to the mouse wheel, for EVT_MOUSEWHEEL which just does nothing. Then when those controls have focus nothing happens on mouse wheel events. Hope that helps. Steve Barnes From: [email protected]<mailto:[email protected]> <[email protected]<mailto:[email protected]>> On Behalf Of Lawrence Gray Sent: 18 June 2020 18:14 To: [email protected]<mailto:[email protected]> Subject: [wxPython-users] How do I disable mousewheel scrolling? I have created a simple application part of which incorporates a number (10) of choice elements in a horizontal sizer . These are displayed above a listCtrl and have their width resized to match the widths of the columns in the listCtrl. They effectively form headers for the listCtrl data. The selection in each choice box controls the disposition of the data in that column in subsequent processing. The selection list in all of the choice controls are identical. Some of the selection choices must be unique for the data presented in the listCtrl, ie. no two columns can have identical selections. Some selection choices are allowed multiple times and some selection choices are mutually exclusive. For example, if one column is labelled "Date", which logically should be unique for my purpose, and another column choice selection is set to "Date", the previous column is reset to the default value "--NA--", which means that column data is mow ignored. My problem is that when I make a choice selection in one column and inadvertently or purposely scroll the mouse wheel, the choice selections in other columns are quickly altered as the choice selection list is scrolled, creating havoc. My question is, how do I disable mouse wheel scrolling of the selection list, after making my selection? Is this to the best or only way to get around the problem? What about, after making a selection, altering the focus to the listCtrl, where scrolling of the mouse wheel would not matter? This is my first attempt at creating any GUI application. I am using wxPython in conjunction with wxGlade. Any advice is appreciated. Regards -- ________________________________ Lawrence Gray ________________________________ -- You received this message because you are subscribed to the Google Groups "wxPython-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]<mailto:[email protected]>. To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/CAJFU_KpgTZ-O8Rt5CTex%3DyEH0HA0xh_BO%2B6wpV_tKpscLaFZvg%40mail.gmail.com<https://groups.google.com/d/msgid/wxpython-users/CAJFU_KpgTZ-O8Rt5CTex%3DyEH0HA0xh_BO%2B6wpV_tKpscLaFZvg%40mail.gmail.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "wxPython-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]<mailto:[email protected]>. To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/VI1PR03MB447915C53481DA6B0FA968739B980%40VI1PR03MB4479.eurprd03.prod.outlook.com<https://groups.google.com/d/msgid/wxpython-users/VI1PR03MB447915C53481DA6B0FA968739B980%40VI1PR03MB4479.eurprd03.prod.outlook.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "wxPython-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]<mailto:[email protected]>. To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/CAJFU_KqJzhjH36ZpVU510rajKMn1sJwa7nbDgPMmosGA02LoxQ%40mail.gmail.com<https://groups.google.com/d/msgid/wxpython-users/CAJFU_KqJzhjH36ZpVU510rajKMn1sJwa7nbDgPMmosGA02LoxQ%40mail.gmail.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "wxPython-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]<mailto:[email protected]>. To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/VI1PR03MB4479B2B6BF64F8342688517F9B980%40VI1PR03MB4479.eurprd03.prod.outlook.com<https://groups.google.com/d/msgid/wxpython-users/VI1PR03MB4479B2B6BF64F8342688517F9B980%40VI1PR03MB4479.eurprd03.prod.outlook.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "wxPython-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]<mailto:[email protected]>. To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/CAJFU_KqsVty4M%3D8_KOi4zkKwdT9BchaB9qu0-Q_HyXv_YMxZXw%40mail.gmail.com<https://groups.google.com/d/msgid/wxpython-users/CAJFU_KqsVty4M%3D8_KOi4zkKwdT9BchaB9qu0-Q_HyXv_YMxZXw%40mail.gmail.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "wxPython-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]<mailto:[email protected]>. To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/VI1PR03MB447958A23727B0B1AD797E689B990%40VI1PR03MB4479.eurprd03.prod.outlook.com<https://groups.google.com/d/msgid/wxpython-users/VI1PR03MB447958A23727B0B1AD797E689B990%40VI1PR03MB4479.eurprd03.prod.outlook.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "wxPython-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]<mailto:[email protected]>. To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/CAJFU_Kr_THD%2B6v61Bd4mqLDZyE%2B54cdBX_kchzJzHWFYf1ov5A%40mail.gmail.com<https://groups.google.com/d/msgid/wxpython-users/CAJFU_Kr_THD%2B6v61Bd4mqLDZyE%2B54cdBX_kchzJzHWFYf1ov5A%40mail.gmail.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "wxPython-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/VI1PR03MB44795FBB85E6C74AAB246B399B960%40VI1PR03MB4479.eurprd03.prod.outlook.com.
image001.png
(image/png, 13 KB) - not displayed
image002.png
(image/png, 4.9 KB) - not displayed
image003.png
(image/png, 17.2 KB) - not displayed
image004.png
(image/png, 119.5 KB) - not displayed