繁体   English   中英

wxPython更改鼠标光标以通知长时间运行的操作

[英]wxPython change mouse cursor to notify a long running operation

我正在构建一个在远程网站上搜索东西的Python程序。 有时操作需要很多秒钟,我相信用户不会注意到状态栏消息“正在搜索操作”。 因此,我想更改鼠标光标以突出显示程序仍在等待结果。

这是我使用的方法:

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)

我尝试了两种不同的方法,都在最后一行之前:

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

他们都没有工作。

我在GNU / Linux下使用KDE。 这在Gnome下也不起作用

任何提示? 谢谢

我问过wxPython的制造商Robin Dunn,看起来这应该有效,但事实并非如此。 但是,如果你调用面板的SetCursor(),它会工作,或者我告诉你。 以下是您可以尝试的示例:

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()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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