Gauge shennanigans, reloaded

Hello Ray,

just use a panel over the frame... usually is a good practice to put controls
on a Panel, instead that directly in a frame (there are exceptions, however).
I have tried the code below and it works (XP, 2.6.0.0, 2.3.4)

HTH.

Andrea.

import wx
import time

class MainFrame (wx.Frame):

    def __init__ (self, parent, id=-1, title='Default Frame Title',
                  size=(200, 150), pos=(100, 75)):

        wx.Frame.__init__ (self, parent, id, title=title, size=size, pos=pos)
        panel = wx.Panel(self, -1)

        self.SetBackgroundColour ( (225, 225, 245) )

## wx.StaticText (self, -1, '', (50, 15)) # This cannot be eliminated
!

        barlen = 300; barhgt = 25
        g1 = wx.Gauge (panel, -1, 50, (50, 50), (barlen, barhgt))

        self.CenterOnScreen()
        self.Show (True)

···

#-----------------------------#

        count = 0
        while (True):

            g1.SetValue (count)

            count += 1
            if count >= 50: count = 0

            wx.Yield ()
            time.sleep (0.05)

        #end while

    #end def __init__

#end class MainFrame

if __name__ == '__main__':

    myApp = wx.PySimpleApp()
    myFrame = MainFrame (None, -1, 'Progress Bar Gauge Demo (modified)',

                         size=(400, 150), pos=(0, 0))
    myApp.MainLoop()

#end if

andrea_gavana@tin.it wrote:

Hello Ray,

just use a panel over the frame... usually is a good practice to put controls
on a Panel, instead that directly in a frame (there are exceptions, however).
I have tried the code below and it works (XP, 2.6.0.0, 2.3.4)

Just to clairify a bit, the reason it sized funny before is because if frames have only one child and no sizer then they will automatically size that child to fill the client area of the frame. By adding the panel then you are letting the frame do that trick with the panel and then you are free to do brute-force positioning/sizing of the controls on the panel if that is the way you want to handle it.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

I ended up using it in a status bar, where I would have liked it to fill up the vertical extent. Of course, it wouldn't
and did follow the height parameter. BTW, did you notice all the wierd effects - the app close button was disabled
and it was impossible the move the frame ! It is a very strange widget, probably written badly.

Ray

andrea_gavana@tin.it wrote:

···

Hello Ray,

just use a panel over the frame... usually is a good practice to put controls
on a Panel, instead that directly in a frame (there are exceptions, however).
I have tried the code below and it works (XP, 2.6.0.0, 2.3.4)

HTH.

Andrea.

import wx
import time

class MainFrame (wx.Frame):

   def __init__ (self, parent, id=-1, title='Default Frame Title', size=(200, 150), pos=(100, 75)):

       wx.Frame.__init__ (self, parent, id, title=title, size=size, pos=pos)
       panel = wx.Panel(self, -1)
              self.SetBackgroundColour ( (225, 225, 245) )

## wx.StaticText (self, -1, '', (50, 15)) # This cannot be eliminated
!

       barlen = 300; barhgt = 25
       g1 = wx.Gauge (panel, -1, 50, (50, 50), (barlen, barhgt))

       self.CenterOnScreen()
       self.Show (True)

       #-----------------------------#

       count = 0
       while (True):

           g1.SetValue (count)

           count += 1
           if count >= 50: count = 0

           wx.Yield ()
           time.sleep (0.05)

       #end while

   #end def __init__

#end class MainFrame

if __name__ == '__main__':

   myApp = wx.PySimpleApp()
   myFrame = MainFrame (None, -1, 'Progress Bar Gauge Demo (modified)',

                        size=(400, 150), pos=(0, 0))
   myApp.MainLoop()

#end if

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Thanks. Now I know.

Ray

Robin Dunn wrote:

···

andrea_gavana@tin.it wrote:

Hello Ray,

just use a panel over the frame... usually is a good practice to put controls
on a Panel, instead that directly in a frame (there are exceptions, however).
I have tried the code below and it works (XP, 2.6.0.0, 2.3.4)

Just to clairify a bit, the reason it sized funny before is because if frames have only one child and no sizer then they will automatically size that child to fill the client area of the frame. By adding the panel then you are letting the frame do that trick with the panel and then you are free to do brute-force positioning/sizing of the controls on the panel if that is the way you want to handle it.