简体   繁体   English

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

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

I am building a Python program that searches things on a remote website. 我正在构建一个在远程网站上搜索东西的Python程序。 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() wx.BeginBusyCursor()
  • self.m_frame.SetCursor(wx.StockCursor(wx.CURSOR_WAIT)) self.m_frame.SetCursor(wx.StockCursor(wx.CURSOR_WAIT))

None of them are working. 他们都没有工作。

I am using KDE under GNU/Linux. 我在GNU / Linux下使用KDE。 This does not work under Gnome, too 这在Gnome下也不起作用

Any hints? 任何提示? Thank you 谢谢

I asked Robin Dunn, the maker of wxPython about this, and it looks like this should work, but doesn't. 我问过wxPython的制造商Robin Dunn,看起来这应该有效,但事实并非如此。 However, if you call the panel's SetCursor(), it DOES work or so I'm told. 但是,如果你调用面板的SetCursor(),它会工作,或者我告诉你。 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()

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

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