Re: How do I disable mousewheel scrolling?
Lawrence Gray <[email protected]>
| Newsgroups | gmane.comp.python.wxpython |
|---|---|
| Message-ID | <CAJFU_KqsVty4M=8_KOi4zkKwdT9BchaB9qu0-Q_HyXv_YMxZXw@mail.gmail.com> |
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. [image: image.png] 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]> 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: > > > > 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] <[email protected]> *On > Behalf Of *Lawrence Gray > *Sent:* 19 June 2020 16:16 > *To:* [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]> 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] <[email protected]> *On > Behalf Of *Lawrence Gray > *Sent:* 18 June 2020 18:14 > *To:* [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]. > 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]. > 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]. > 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]. > 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]. 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.
image001.png
(image/png, 119.5 KB) - not displayed
image.png
(image/png, 17.2 KB) - not displayed