button double click causes freeze of GUI

34 views
Skip to first unread message

Sean Carter

unread,
Nov 15, 2022, 12:35:48 PM11/15/22
to wxPython-users
Hey everyone, just started playing with wxPython. Im using wxFormBuilder and visual studio for the code.

Got a little Gui working great, a button with up and down events, a slider , a check and a gauge.

But everytime i double click the button, it's likethe whole frame freezes, i can no long push the button, or move the slider. The gauge and check still update however

2 files - wxForm Gui (minus bind and code)

# -*- coding: utf-8 -*-

###########################################################################
## Python code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3)
## http://www.wxformbuilder.org/
##
## PLEASE DO *NOT* EDIT THIS FILE!
###########################################################################

import wx
import wx.xrc

###########################################################################
## Class MyFrame1
###########################################################################

class MyFrame1 ( wx.Frame ):

    def __init__( self, parent ):
        wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )

        self.SetSizeHints( wx.DefaultSize, wx.DefaultSize )

        gSizer1 = wx.GridSizer( 0, 2, 0, 0 )

        bSizer3 = wx.BoxSizer( wx.VERTICAL )

        self.m_button2 = wx.Button( self, wx.ID_ANY, u"Button", wx.DefaultPosition, wx.DefaultSize, 0 )
        bSizer3.Add( self.m_button2, 0, wx.ALL, 5 )

        self.m_slider2 = wx.Slider( self, wx.ID_ANY, 0, 0, 100, wx.DefaultPosition, wx.DefaultSize, wx.SL_HORIZONTAL )
        bSizer3.Add( self.m_slider2, 0, wx.ALL, 5 )


        gSizer1.Add( bSizer3, 1, wx.EXPAND, 5 )

        bSizer4 = wx.BoxSizer( wx.VERTICAL )

        self.m_radioBtn2 = wx.RadioButton( self, wx.ID_ANY, u"Light", wx.DefaultPosition, wx.DefaultSize, 0 )
        self.m_radioBtn2.SetValue( True )
        bSizer4.Add( self.m_radioBtn2, 0, wx.ALL, 5 )

        self.m_gauge1 = wx.Gauge( self, wx.ID_ANY, 100, wx.DefaultPosition, wx.DefaultSize, wx.GA_HORIZONTAL )
        self.m_gauge1.SetValue( 0 )
        bSizer4.Add( self.m_gauge1, 0, wx.ALL, 5 )


        gSizer1.Add( bSizer4, 1, wx.EXPAND, 5 )


        self.SetSizer( gSizer1 )
        self.Layout()

        self.Centre( wx.BOTH )

        # Connect Events
        self.m_button2.Bind( wx.EVT_LEFT_DCLICK, self.PB0_DC )

    def __del__( self ):
        pass


    # Virtual event handlers, override them in your derived class
    def PB0_DC( self, event ):
        event.Skip()

    def PB0_D( self, event ):
        event.Skip()

    def PB0_U( self, event ):
        event.Skip()

    def m_slider2OnSlider( self, event ):
        event.Skip()




Main file



from Gui import MyFrame1
import sys
import wx
import os
from pylogix import PLC

class f(MyFrame1):
    def __init__(self, parent):
        MyFrame1.__init__(self, parent)

       # Connect Event
        self.m_button2.Bind( wx.EVT_LEFT_DOWN, self.PB0_D )
        self.m_button2.Bind( wx.EVT_LEFT_UP, self.PB0_U )
        self.m_slider2.Bind( wx.EVT_SLIDER, self.m_slider2OnSlider )
        self.timer = wx.Timer(self)
        self.timer.Start(250)
        self.Bind(wx.EVT_TIMER, self.update, self.timer)
   
    def PB0_D( self, event ):
        clx.Write('buttons.0',1)
       
    def PB0_U( self, event ):
        clx.Write('buttons.0',0)

    def m_slider2OnSlider( self, event ):
        clx.Write('HMI_ANALOG_INPUT_CH1',self.m_slider2.Value)

    def update(self,event):
        IND0 = clx.Read('IND0')
        self.m_radioBtn2.SetValue(IND0.Value)
        CH1OUT = clx.Read('HMI_ANALOG_OUTPUT_CH1')
        self.m_gauge1.Value = int(CH1OUT.Value)
        self.Layout()
        self.Update()

def main():
    global clx
    clx = PLC('192.168.2.190',2)
    app = wx.App()
    frame = f(None)
    frame.Show()
    app.MainLoop()

if __name__ == '__main__':
    main()


ideas?

Dietmar Schwertberger

unread,
Nov 15, 2022, 2:32:08 PM11/15/22
to wxpytho...@googlegroups.com
When you post code, please make sure it does run, i.e. has no external
dependencies.

Even better, strip the sample down to a runnable minimal sample.

By doing so, often you find the problem yourself.

In your case, you would probably found that you have unused event
handlers in your Gui.py file but your actual handlers in the main file
are missing event.Skip().

You need to call event.Skip() inside your EVT_LEFT_UP handler.

Regards,

Dietmar

Tim Roberts

unread,
Nov 15, 2022, 4:02:48 PM11/15/22
to wxpytho...@googlegroups.com
Dietmar Schwertberger wrote:
>
> You need to call event.Skip() inside your EVT_LEFT_UP handler.

Right.  This is important, because the double-click detection is done as
part of the normal single-click handling.  If you don't let the standard
processing happen, it can't detect double-clicks.

The naming of the "Skip" method is one of the great disasters in the
history of wxWidgets.  It arguably should have had exactly the opposite
effect that it currently does, so that events were automatically
propagated unless you called "Skip".

--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

Dietmar Schwertberger

unread,
Nov 18, 2022, 2:59:12 PM11/18/22
to wxpytho...@googlegroups.com
Posting the same question on multiple platforms is not very nice and
will certainly decrease the number of answers you will receive in future.

Regards,

Dietmar

Reply all
Reply to author
Forward
0 new messages