如何在状态栏区域放置进度条(仪表)并锁定gui大小

发布于 2024-12-12 06:27:40 字数 3166 浏览 0 评论 0原文

我正在使用 wxPython 搜索特定目录中的所有文件。当它搜索文件时,进度(文件数量)会发送到进度栏,只是为了提供一些背景信息。我想要做的是将进度条向下移动到框架底部,SetStatusText 通常显示名称。但是,当开始搜索时,我希望名称/文本被进度条替换。目前,当我尝试更改进度条的位置时,它仅在进度条的正上方可见。

其次,我想将 GUI 锁定在当前大小,这样窗口就无法调整大小。我查看了几个示例,但每个示例都以某种默认大小开始。我希望我的图形用户界面保持我给它的大小,因为按钮的显示方式保证了它的大小。这是 GUI 代码的样子:

class MyApp(wx.App):
    def OnInit(self):
        frame = MainWindow("ST v2.0.0", (50, 60), (458, 332))
        frame.Show()
        self.SetTopWindow(frame)
        return True



class MainWindow(wx.Frame):
    def __init__(self, pos, size, title):
        wx.Frame.__init__(self, None, -1, pos, size, title)


        panel = wx.Panel(self, wx.ID_ANY)
        panel.SetBackgroundColour('LIGHT GREY')
        toolbar = self.CreateToolBar()
        toolbar.Realize()
        menuFile = wx.Menu()
        menuFile.Append(1, "&About...")
        menuFile.AppendSeparator()
        menuFile.Append(2, "E&xit")
        menuBar = wx.MenuBar()
        menuBar.Append(menuFile, "&File")
        menu2 = wx.Menu()
        menu2.Append(wx.NewId(), "&Copy", "Copy in status bar")
        menu2.AppendSeparator()
        menu2.Append(wx.NewId(), "C&ut", "")
        menu2.AppendSeparator()
        menu2.Append(wx.NewId(), "Paste", "")
        menu2.AppendSeparator()
        menu2.Append(wx.NewId(), "&Options...", "Display Options")
        menuBar.Append(menu2, "&Edit")

        self.SetMenuBar(menuBar)
        self.CreateStatusBar()
        self.SetStatusText("Welcome to sQAST!")#can put connected here when logged in
        self.Bind(wx.EVT_MENU, self.OnAbout, id=1)
        self.Bind(wx.EVT_MENU, self.OnQuit, id=2)

        x = 100

        #Progress Gauge
        self.gauge = wx.Gauge(panel, -1, x ,pos=(180, 0), size=(-1, 20))



        #Close button
        self.button = wx.Button(panel, label="EXIT", pos=(229, 160), size=(229, 80))
        self.Bind(wx.EVT_BUTTON, self.OnQuit, self.button)
        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
        #Dispenser button
        self.button2 = wx.Button(panel, label="Serv 1", pos=(0, 160), size=(229, 80))
        self.Bind(wx.EVT_BUTTON, self.OnStartButton, self.button2)
        #Site Server
        self.button3 = wx.Button(panel, label="SERV 2", pos=(0, 80), size=(229, 80))
        self.Bind(wx.EVT_BUTTON, self.OnSiteservButton, self.button3)
        #Local Search
        self.button4 = wx.Button(panel, label="ABORT", pos=(229, 80), size=(229, 80))
        self.Bind(wx.EVT_BUTTON, self.OnAbortButton, self.button4)
        self.button4.Disable()
        self.shouldAbort = False 

这对我有用:

count = 0
    count2 = 0
    for afile in filelist:
        (head, filename) = os.path.split(afile)
        if afile.endswith(".log") or afile.endswith(".txt"):
            count2 += 1
            self.progress_bar.Show()
            wx.CallAfter(self.progress_bar.SetValue, count2)# This works ....

            f=ftp.open(afile, 'r')
            for i, line in enumerate(f.readlines()):
                result = regex.search(line)
                if self.shouldAbort:
                    return self.shouldAbort
                    break

I'm using wxPython to search all the files in a particular directory. As it searches the files, progress (number of files) is sent to the progress bar, just to give a little background. What I want to do is to move the progress bar down to the bottom of the frame where SetStatusText usually show a name. But, when a search is commenced, I would like the name/text to be replaced by the progress bar. Currently, when I try to change the position of the progress bar, it's only visible to right above the progress bar.

Secondly, I want to lock the gui at it's current size, so the window can't be resized. I looked at a few examples, but every one started at some default size. I want my gui to remain at the size that I give it because the way the buttons are displayed warrants it. Here is what the gui code looks like:

class MyApp(wx.App):
    def OnInit(self):
        frame = MainWindow("ST v2.0.0", (50, 60), (458, 332))
        frame.Show()
        self.SetTopWindow(frame)
        return True



class MainWindow(wx.Frame):
    def __init__(self, pos, size, title):
        wx.Frame.__init__(self, None, -1, pos, size, title)


        panel = wx.Panel(self, wx.ID_ANY)
        panel.SetBackgroundColour('LIGHT GREY')
        toolbar = self.CreateToolBar()
        toolbar.Realize()
        menuFile = wx.Menu()
        menuFile.Append(1, "&About...")
        menuFile.AppendSeparator()
        menuFile.Append(2, "E&xit")
        menuBar = wx.MenuBar()
        menuBar.Append(menuFile, "&File")
        menu2 = wx.Menu()
        menu2.Append(wx.NewId(), "&Copy", "Copy in status bar")
        menu2.AppendSeparator()
        menu2.Append(wx.NewId(), "C&ut", "")
        menu2.AppendSeparator()
        menu2.Append(wx.NewId(), "Paste", "")
        menu2.AppendSeparator()
        menu2.Append(wx.NewId(), "&Options...", "Display Options")
        menuBar.Append(menu2, "&Edit")

        self.SetMenuBar(menuBar)
        self.CreateStatusBar()
        self.SetStatusText("Welcome to sQAST!")#can put connected here when logged in
        self.Bind(wx.EVT_MENU, self.OnAbout, id=1)
        self.Bind(wx.EVT_MENU, self.OnQuit, id=2)

        x = 100

        #Progress Gauge
        self.gauge = wx.Gauge(panel, -1, x ,pos=(180, 0), size=(-1, 20))



        #Close button
        self.button = wx.Button(panel, label="EXIT", pos=(229, 160), size=(229, 80))
        self.Bind(wx.EVT_BUTTON, self.OnQuit, self.button)
        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
        #Dispenser button
        self.button2 = wx.Button(panel, label="Serv 1", pos=(0, 160), size=(229, 80))
        self.Bind(wx.EVT_BUTTON, self.OnStartButton, self.button2)
        #Site Server
        self.button3 = wx.Button(panel, label="SERV 2", pos=(0, 80), size=(229, 80))
        self.Bind(wx.EVT_BUTTON, self.OnSiteservButton, self.button3)
        #Local Search
        self.button4 = wx.Button(panel, label="ABORT", pos=(229, 80), size=(229, 80))
        self.Bind(wx.EVT_BUTTON, self.OnAbortButton, self.button4)
        self.button4.Disable()
        self.shouldAbort = False 

This worked for me:

count = 0
    count2 = 0
    for afile in filelist:
        (head, filename) = os.path.split(afile)
        if afile.endswith(".log") or afile.endswith(".txt"):
            count2 += 1
            self.progress_bar.Show()
            wx.CallAfter(self.progress_bar.SetValue, count2)# This works ....

            f=ftp.open(afile, 'r')
            for i, line in enumerate(f.readlines()):
                result = regex.search(line)
                if self.shouldAbort:
                    return self.shouldAbort
                    break

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

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

发布评论

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

评论(1

み青杉依旧 2024-12-19 06:27:40

有几种不同的方法可以做到这一点。我认为最简单的方法是使用EnhancedStatusBar小部件: http://wiki.wxpython.org/EnhancedStatusBar

但是,该线程还提到了一种使用普通 StatusBar 执行此操作的方法:http://wxpython-users.1045709.n5.nabble.com/Add-a-progressbar-in-a-statusbar-td2365269.html

至于使框架的大小“固定” ,尝试将其 SetSizeHints 设置为您想要的大小。

There are a couple of different ways to do this. I think the simplest is to just use the EnhancedStatusBar widget: http://wiki.wxpython.org/EnhancedStatusBar

However, this thread also mentions a way to do it with the normal StatusBar: http://wxpython-users.1045709.n5.nabble.com/Add-a-progressbar-in-a-statusbar-td2365269.html

As for making the Frame's size "fixed", try setting it's SetSizeHints to the size you want.

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