为什么 Windows 中的 wxPython 中的菜单栏项会延迟,而 OS X 中的菜单栏项会立即出现?

发布于 2024-11-30 22:04:15 字数 3819 浏览 1 评论 0原文

请参阅下面的精简示例脚本。当我在 OS X 中运行它时,菜单栏的行为与您期望的完全一样。然而,在 Windows 中,“慢速”菜单项的渲染存在明显的延迟(在我的 2GHz Core 2 Duo 上约为 4 秒)。这感觉根本不对,让应用程序显示良好的旧(未响应)警告并不完全是您在菜单中单击后所期望的行为。

以前有人遇到过这个问题吗?我在 Windows 端做错了什么吗?

就版本而言,我使用最新的稳定版 2.8.12.1 和开发版 2.9.2.1 进行了测试,并且我运行的是 Python 2.7。

import wx
from operator import itemgetter
from itertools import groupby

class MainFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, title='Hello', size=(1150,700))
        self.panel = wx.Panel(self, -1)
        file_menu = wx.Menu()
        open_item = file_menu.Append(-1, 'Open Something')
        self.slow_menu = wx.Menu()
        another_menu = wx.Menu()
        another_item = another_menu.Append(-1, 'Something')
        more_menu = wx.Menu()
        more_item = more_menu.Append(-1, 'Else')
        self.menu_bar = wx.MenuBar()
        self.menu_bar.Append(file_menu, 'File')
        self.menu_bar.Append(self.slow_menu, 'Slow')
        self.menu_bar.Append(another_menu, 'Fake')
        self.menu_bar.Append(more_menu, 'Hello')
        self.SetMenuBar(self.menu_bar)
        self.setup_slow_menu()
        self.Bind(wx.EVT_CLOSE, self.OnClose)
    def OnClose(self, event):
        self.Destroy()
    def OnDud(self, event):
        pass
    def setup_slow_menu(self):
        names = """
        James    Christopher    Ronald        Mary    Lisa    Michelle
        John     Daniel  Anthony         Patricia     Nancy   Laura
        Robert   Paul     Kevin       Linda   Karen   Sarah
        Michael  Mark     Jason       Barbara     Betty   Kimberly
        William  Donald   Jeff        Elizabeth   Helen   Deborah
        David    George   Jennifer    Sandra
        Richard  Kenneth Maria    Donna
        Charles  Steven  Susan    Carol
        Joseph   Edward  Margaret     Ruth
        Thomas   Brian   Dorothy      Sharon""".split()
        some_data = ['red','blue','white','orange','brown']
        some_more_data = ['socks','pants','shirts','gloves','hats','red','blue','white','orange','brown']
        subs = ['Bla', 'Blabla']
        subsubs = []
        for name in names[:25]:
            subsubs.append((subs[0], name))
        for name in names[25:]:
            subsubs.append((subs[1], name))
        for sub in subs:
            sub_menu = wx.Menu()
            self.slow_menu.AppendMenu(-1, sub, sub_menu)
            for sub, subsub in [r for r in subsubs if r[0]==sub]:
                subsub_menu = wx.Menu()
                sub_menu.AppendMenu(-1, subsub, subsub_menu)
                for i in xrange(30):
                    subsubsub_menu = wx.Menu()
                    subsub_menu.AppendMenu(-1, str(i), subsubsub_menu)
                    for label in some_more_data:
                        menu_item = wx.MenuItem(subsubsub_menu, id=wx.NewId(), text=label)
                        subsubsub_menu.AppendItem(menu_item)
                        self.Bind(wx.EVT_MENU, self.OnDud, id=menu_item.GetId())
                for label in some_data:
                    menu_item = wx.MenuItem(subsub_menu, id=wx.NewId(), text=label)
                    subsub_menu.AppendItem(menu_item)
                    self.Bind(wx.EVT_MENU, self.OnDud, id=menu_item.GetId())
            for label in some_data:
                menu_item = wx.MenuItem(sub_menu, id=wx.NewId(), text=label)
                sub_menu.AppendItem(menu_item)
                self.Bind(wx.EVT_MENU, self.OnDud, id=menu_item.GetId())
        for label in some_data:
            menu_item = wx.MenuItem(self.slow_menu, id=wx.NewId(), text=label)
            self.slow_menu.AppendItem(menu_item)
            self.Bind(wx.EVT_MENU, self.OnDud, id=menu_item.GetId())

if __name__ == "__main__":
    app = wx.PySimpleApp()
    frame = MainFrame()
    frame.Show()
    app.MainLoop()

Please refer to the stripped down example script below. When I run this in OS X the menubar behaves exactly like you'd expect it to. In Windows however there is a noticeable lag (~4s on my 2GHz Core 2 Duo) of the rendering of the 'Slow' menu item. This doesn't feel right at all, to have an application show the good old (Not Responding) warning isn't exactly the behavior you'd expect after clicking around in a menu.

Has anyone run into this problem before? Am I doing something wrong on Windows side?

As far as versions go, I tested both with the latest stable, 2.8.12.1, and development, 2.9.2.1, and I am running Python 2.7.

import wx
from operator import itemgetter
from itertools import groupby

class MainFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, title='Hello', size=(1150,700))
        self.panel = wx.Panel(self, -1)
        file_menu = wx.Menu()
        open_item = file_menu.Append(-1, 'Open Something')
        self.slow_menu = wx.Menu()
        another_menu = wx.Menu()
        another_item = another_menu.Append(-1, 'Something')
        more_menu = wx.Menu()
        more_item = more_menu.Append(-1, 'Else')
        self.menu_bar = wx.MenuBar()
        self.menu_bar.Append(file_menu, 'File')
        self.menu_bar.Append(self.slow_menu, 'Slow')
        self.menu_bar.Append(another_menu, 'Fake')
        self.menu_bar.Append(more_menu, 'Hello')
        self.SetMenuBar(self.menu_bar)
        self.setup_slow_menu()
        self.Bind(wx.EVT_CLOSE, self.OnClose)
    def OnClose(self, event):
        self.Destroy()
    def OnDud(self, event):
        pass
    def setup_slow_menu(self):
        names = """
        James    Christopher    Ronald        Mary    Lisa    Michelle
        John     Daniel  Anthony         Patricia     Nancy   Laura
        Robert   Paul     Kevin       Linda   Karen   Sarah
        Michael  Mark     Jason       Barbara     Betty   Kimberly
        William  Donald   Jeff        Elizabeth   Helen   Deborah
        David    George   Jennifer    Sandra
        Richard  Kenneth Maria    Donna
        Charles  Steven  Susan    Carol
        Joseph   Edward  Margaret     Ruth
        Thomas   Brian   Dorothy      Sharon""".split()
        some_data = ['red','blue','white','orange','brown']
        some_more_data = ['socks','pants','shirts','gloves','hats','red','blue','white','orange','brown']
        subs = ['Bla', 'Blabla']
        subsubs = []
        for name in names[:25]:
            subsubs.append((subs[0], name))
        for name in names[25:]:
            subsubs.append((subs[1], name))
        for sub in subs:
            sub_menu = wx.Menu()
            self.slow_menu.AppendMenu(-1, sub, sub_menu)
            for sub, subsub in [r for r in subsubs if r[0]==sub]:
                subsub_menu = wx.Menu()
                sub_menu.AppendMenu(-1, subsub, subsub_menu)
                for i in xrange(30):
                    subsubsub_menu = wx.Menu()
                    subsub_menu.AppendMenu(-1, str(i), subsubsub_menu)
                    for label in some_more_data:
                        menu_item = wx.MenuItem(subsubsub_menu, id=wx.NewId(), text=label)
                        subsubsub_menu.AppendItem(menu_item)
                        self.Bind(wx.EVT_MENU, self.OnDud, id=menu_item.GetId())
                for label in some_data:
                    menu_item = wx.MenuItem(subsub_menu, id=wx.NewId(), text=label)
                    subsub_menu.AppendItem(menu_item)
                    self.Bind(wx.EVT_MENU, self.OnDud, id=menu_item.GetId())
            for label in some_data:
                menu_item = wx.MenuItem(sub_menu, id=wx.NewId(), text=label)
                sub_menu.AppendItem(menu_item)
                self.Bind(wx.EVT_MENU, self.OnDud, id=menu_item.GetId())
        for label in some_data:
            menu_item = wx.MenuItem(self.slow_menu, id=wx.NewId(), text=label)
            self.slow_menu.AppendItem(menu_item)
            self.Bind(wx.EVT_MENU, self.OnDud, id=menu_item.GetId())

if __name__ == "__main__":
    app = wx.PySimpleApp()
    frame = MainFrame()
    frame.Show()
    app.MainLoop()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

救赎№ 2024-12-07 22:04:15

我稍后将其发布到 wxPython 列表上,并得到了这个 回复。其实没什么问题,只是 XP 就是 XP 而已。

I posted this on the wxPython list later on, and got this reply. Nothing wrong really, just XP being XP that's all.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文