Python Forum
Stop Timer in Different Class - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: Stop Timer in Different Class (/thread-4291.html)



Stop Timer in Different Class - ian - Aug-06-2017

How can I add code in onStop of LeftPanel to stop the timer created in RightPanel?
Is it possible to stop it from in Frame class? Thanks.

import wx
import wx.html2 as webview

class LeftPanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent=parent)
        stopBtn = wx.Button(self, label="Stop Timer")
        stopBtn.Bind(wx.EVT_BUTTON, self.onStop)
    def onStop(self,event):
        print('Stop Timer')
class RightPanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent=parent)
        self.current = "http://wxPython.org"
        self.frame = self.GetTopLevelParent()
        self.titleBase = self.frame.GetTitle()
        sizer = wx.BoxSizer(wx.VERTICAL)
        self.wv = webview.WebView.New(self)
        sizer.Add(self.wv, 1, wx.EXPAND)
        self.SetSizer(sizer)
        self.wv.LoadURL(self.current)    
        self.timer = wx.PyTimer(self.Timer1)
        self.timer.Start(3000)
    def Timer1(self):
        print('3-second timer')
class Frame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, title="Stop Timer", size=(500, 300), pos = (500, 300))
        splitter = wx.SplitterWindow(self)
        leftP = LeftPanel(splitter)
        rightP = RightPanel(splitter)
        splitter.SplitVertically(leftP, rightP)
        splitter.SetMinimumPaneSize(200)
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(splitter, 1, wx.EXPAND)
        self.SetSizer(sizer)
if __name__ == "__main__":
    app = wx.App()
    win = Frame()
    win.CreateStatusBar()
    win.Show()
    app.MainLoop()