简体   繁体   中英

wxPython change mouse cursor to notify a long running operation

I am building a Python program that searches things on a remote website. Sometimes the operation takes many seconds and I believe that the user will not notice the status bar message "Search Operation in progress". Therefore, I would like to change the mouse cursor to highlight that the program is still waiting for a result.

This is the method I am using:

def OnButtonSearchClick( self, event ):
        """
        If there is text in the search text, launch a SearchOperation.
        """
        searched_value = self.m_search_text.GetValue()

        if not searched_value:
            return

        # clean eventual previous results
        self.EnableButtons(False)
        self.CleanSearchResults()

        operations.SearchOperation(self.m_frame, searched_value)

I tried two different approaches, both before the last line:

  • wx.BeginBusyCursor()
  • self.m_frame.SetCursor(wx.StockCursor(wx.CURSOR_WAIT))

None of them are working.

I am using KDE under GNU/Linux. This does not work under Gnome, too

Any hints? Thank you

I asked Robin Dunn, the maker of wxPython about this, and it looks like this should work, but doesn't. However, if you call the panel's SetCursor(), it DOES work or so I'm told. Here's an example you can try:

import wx

########################################################################
class MyForm(wx.Frame):

    #----------------------------------------------------------------------
    def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY, "Tutorial")

        # Add a self.panel so it looks the correct on all platforms
        self.panel = wx.Panel(self, wx.ID_ANY)

        btn = wx.Button(self.panel, label="Change Cursor")
        btn.Bind(wx.EVT_BUTTON, self.changeCursor)
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(btn)
        self.panel.SetSizer(sizer)

    #----------------------------------------------------------------------
    def changeCursor(self, event):
        """"""
        myCursor= wx.StockCursor(wx.CURSOR_WAIT)
        self.panel.SetCursor(myCursor)


#----------------------------------------------------------------------
# Run the program
if __name__ == "__main__":
    app = wx.PySimpleApp()
    frame = MyForm().Show()
    app.MainLoop()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM