Hi,
I'm trying to write some code which will pop up a search box when a
user clicks on the taskbar icon.
However, at the moment, I can't get the app to be 'active', i.e.
accept keyboard input, when the user clicks on the taskbar.
A stripped down version of the code is below, I've looked through all
of the methods from wx.App, wx.Window, wx.TopLevelWindow and wx.Frame,
and can't get anything to bring the frame back to the front.
Does anyone come across this before/ know how to get this behaviour working?
Thanks,
Tom Woolway
···
---------------------------------------------------------
import wx
class MainFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent)
self.search = wx.SearchCtrl(self)
self.task_bar_icon = TaskBarIcon(self)
self.Show()
class TaskBarIcon(wx.TaskBarIcon):
"""
Adds a Task Bar Icon to the System Tray. Right clicking on this
will launch a menu, which will allow the user to close the application.
"""
def __init__(self, frame):
wx.TaskBarIcon.__init__(self)
self.frame = frame
# Bind to events
self.Bind(wx.EVT_TASKBAR_LEFT_UP, self.OnOpenMainWindow)
self.SetIcon(wx.Icon('icon.png', wx.BITMAP_TYPE_PNG), "Icon")
def OnOpenMainWindow(self, event):
self.frame.Show()
self.frame.SetFocus()
self.frame.search.SetFocus()
app = wx.App()
MainFrame(None)
app.MainLoop()