【问题标题】:wxPython progress barwxPython 进度条
【发布时间】:2009-12-10 19:51:29
【问题描述】:

我不能使用wx.ProgressDialog,因为我需要在对话框中添加额外的内容(暂停按钮和有关当前正在处理的内容的信息)。是否有我可以在我自己的对话框中使用的仅用于进度条的控件?

我当然可以自己画一些简单的东西,但由于程序需要在 Mac OS X、Windows 和 Linux 上运行,如果进度条具有原生外观会更好。

【问题讨论】:

    标签: python wxpython


    【解决方案1】:

    【讨论】:

      【解决方案2】:

      您始终可以创建自己的 wx.Dialog 衍生产品并使用大小调整器,添加您需要的小部件。

      这是我的程序中的一个,例如:

      class ProgressDialog(wx.Dialog):
          """
          Shows a Progres Gauge while an operation is taking place. May be cancellable
          which is possible when converting pdf/ps
          """
          def __init__(self, gui, title, to_add=1, cancellable=False):
              """Defines a gauge and a timer which updates the gauge."""
              wx.Dialog.__init__(self, gui, title=title,
                                style=wx.CAPTION)
              self.gui = gui
              self.count = 0
              self.to_add = to_add
              self.timer = wx.Timer(self)
              self.gauge = wx.Gauge(self, range=100, size=(180, 30))
              sizer = wx.BoxSizer(wx.VERTICAL)
              sizer.Add(self.gauge, 0, wx.ALL, 10)
      
              if cancellable:
                  cancel = wx.Button(self, wx.ID_CANCEL, _("&Cancel"))
                  cancel.SetDefault()
                  cancel.Bind(wx.EVT_BUTTON, self.on_cancel)
                  btnSizer = wx.StdDialogButtonSizer()
                  btnSizer.AddButton(cancel)
                  btnSizer.Realize()
                  sizer.Add(btnSizer, 0, wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, 10)
      
              self.SetSizer(sizer)
              sizer.Fit(self)
              self.SetFocus()
      
              self.Bind(wx.EVT_TIMER, self.on_timer, self.timer)
              self.timer.Start(30)
      
      
          def on_timer(self, event):
              """Increases the gauge's progress."""
              self.count += self.to_add
              self.gauge.SetValue(self.count)
              if self.count > 100:
                  self.count = 0
      
      
          def on_cancel(self, event):
              """Cancels the conversion process"""
              # do whatever
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多