wxPython.Panel refresh / redraw / update???

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • markwalker84
    New Member
    • Nov 2006
    • 11

    wxPython.Panel refresh / redraw / update???

    Hello everyone!

    Got a bit of a problem...

    Two of the panels on my program contain a number of check boxes. The exact number of which is determined by a pair of variables.

    I have recently implemented a Wizard which changes that number, as well as a save and load function to the program.

    I know the number of being altered in memory (i added a quick check button) but what i'm struggling with is how to refresh the panel with the new number of chek boxes... very confused!



    code time...

    Code:
    from Initials import *
    import wx
    import os
    from Wizard import *
    
    
    class MainFrame(wx.Frame):
        def __init__(self, parent, title):
            wx.Frame.__init__(self, parent, -1, title)
    
            icon = wx.Icon("icon.ico", wx.BITMAP_TYPE_ICO)
            self.SetIcon(icon)
    
    
            ### Create Main Panel & Sizer ###
            self.mainPanel = wx.Panel(self)
            self.mainPanel.SetBackgroundColour((225,245,255))
            mainSizer = wx.BoxSizer(wx.VERTICAL)
    
    
            ### IMPORT VARIABLES LIST FROM INITIALS.PY ###
            self.vars = VariablesData()
            self.variables = self.vars.GetVariables()
            
    
            ### Create Various Panels ###        
            self.titlePanel = TitlePanel(self.mainPanel, wx.HORIZONTAL, self.variables)
            self.controlPanel = ControlPanel(self.mainPanel, wx.HORIZONTAL, self.variables)
            self.actionPanel = ActionPanel(self.mainPanel, wx.HORIZONTAL, self.variables)
    
            
            self.CreatemenuBar()
            self.CreateStatusBar()
    
    
            mainSizer.Add(self.titlePanel.panel, 2, wx.ALIGN_LEFT | wx.EXPAND | wx.ALL, 5)
            mainSizer.Add(self.controlPanel.panel, 5, wx.EXPAND | wx.LEFT | wx.RIGHT, 5)
            mainSizer.Add(self.actionPanel.panel, 2, wx.EXPAND | wx.ALL, 5)
            
            self.mainPanel.SetSizer(mainSizer)
            mainSizer.Fit(self)                # Fit frame to neccessary size
            mainSizer.SetSizeHints(self)       # Prevents frame from getting smaller than min.
    
    .
    .
    .
    
    class NewPanel():
        def __init__(self, parent, Orientation, variables):
    
            self.variables = variables
    
            self.panel = wx.Panel(parent)
            self.sizer = wx.BoxSizer(Orientation)
    
            self.AddItems(self.variables)
    
            self.panel.SetSizer(self.sizer)
            self.sizer.Fit(self.panel)                # Fit frame to neccessary size
            self.sizer.SetSizeHints(self.panel)       # Prevents frame from getting smaller than min.
    
    .
    .
    .
    class ControlPanel(NewPanel):
    
        def AddItems(self, variables):
    
            self.variables = variables
    
            self.automaticPanel = AutomaticPanel(self.panel, wx.VERTICAL, variables)
            self.modePanel = ModePanel(self.panel, wx.VERTICAL, variables)
            self.manualPanel = ManualPanel(self.panel, wx.HORIZONTAL, variables)        
    
            self.sizer.Add(self.automaticPanel.panel, 6, wx.EXPAND)
            self.sizer.Add(self.modePanel.panel, 3, wx.EXPAND | wx.LEFT | wx.RIGHT, 5)
            self.sizer.Add(self.manualPanel.panel, 5, wx.EXPAND)
    .
    .
    .
    class ManualPanel(NewPanel):
    
        def AddItems(self, variables):
    
            self.variables = variables
            
            self.box = wx.StaticBox(self.panel, -1, 'Manual Control')
            self.box.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, False))
            self.sizer = wx.StaticBoxSizer(self.box, wx.HORIZONTAL)
    
            self.bristlePanel = BristlePanel(self.panel, wx.VERTICAL, variables)
            self.cylinderPanel = CylinderPanel(self.panel, wx.VERTICAL, variables)
    
            self.sizer.Add(self.bristlePanel.panel, 1, wx.EXPAND)
            self.sizer.Add(self.cylinderPanel.panel, 1, wx.EXPAND)
    
    
    
    class BristlePanel(NewPanel):
    
        def AddItems(self, variables):
    
            self.variables = variables
    
            self.bristleCheckBox = []
            
            for x in range(0, self.variables['bristles']):
                self.bristleCheckBox.insert(x, (wx.CheckBox(self.panel, -1, "Bristle %d" % (x+1))))
                self.sizer.Add(self.bristleCheckBox[x], 1, wx.ALIGN_CENTER_HORIZONTAL)        
    
    
    class CylinderPanel(NewPanel):
    
        def AddItems(self, variables):
    
            self.variables = variables
    
            self.cylinderCheckBox = []
            
            for x in range(0, self.variables['cylinders']):
                self.cylinderCheckBox.insert(x, (wx.CheckBox(self.panel, -1, "Cylinder %d" % (x+1))))
                self.sizer.Add(self.cylinderCheckBox[x], 1, wx.ALIGN_CENTER_HORIZONTAL)
    
    .
    .
    .
    
    
    
    class wxPyApp(wx.App):
        def OnInit(self):
            frame = MainFrame(None, "DPT - Sequence Driven Controller")
            self.SetTopWindow(frame)
            frame.Show(True)
            frame.Center(wx.BOTH)
            return True
            
    if __name__ == '__main__':          # Only runs if program is being executed, not imported
        app = wxPyApp(redirect=True)
        app.MainLoop()
    I know the NewPanel bit isnt the prettiest...

    Its the Bristle & Cylinder Panels im having the issue with


    Any help would be greatly appreciated!


    Thanks,


    Mark
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Have you tried calling self.Refresh()?
    I noticed earlier that you don't save the parent. I always assign
    self.parent = parent
    just in case I need to do something that acts on all the widgets in a frame.
    Or you can
    parent = self.GetParent( )

    There is also wxUpdate() to look at.

    Comment

    • markwalker84
      New Member
      • Nov 2006
      • 11

      #3
      Originally posted by bartonc
      Have you tried calling self.Refresh()?
      I noticed earlier that you don't save the parent. I always assign
      self.parent = parent
      just in case I need to do something that acts on all the widgets in a frame.
      Or you can
      parent = self.GetParent( )

      There is also wxUpdate() to look at.
      i tried self.Refresh() but it didnt seem to do much :-s

      where would i include the self.parent = parent line? and also - what exactly would that do? lol

      Ive got a sort of make-shift solution 1/2 working where i have a method which destroys all the frames within mainFrame and then another method rebuilds them, but for some reason it will only do this once. Try for a second time and it seems unable to cirrectly build the sizer information and places everything over the top of one another.


      Mark

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #4
        Originally posted by markwalker84
        i tried self.Refresh() but it didnt seem to do much :-s

        where would i include the self.parent = parent line? and also - what exactly would that do? lol

        Ive got a sort of make-shift solution 1/2 working where i have a method which destroys all the frames within mainFrame and then another method rebuilds them, but for some reason it will only do this once. Try for a second time and it seems unable to cirrectly build the sizer information and places everything over the top of one another.


        Mark
        I was thinking along the lines of
        self.parent.Upd ate()

        Comment

        • markwalker84
          New Member
          • Nov 2006
          • 11

          #5
          Originally posted by bartonc
          I was thinking along the lines of
          self.parent.Upd ate()
          ah... ok then... ill give that a whirl :-)


          Watch this space...


          mark

          Comment

          • bartonc
            Recognized Expert Expert
            • Sep 2006
            • 6478

            #6
            Originally posted by markwalker84
            ah... ok then... ill give that a whirl :-)


            Watch this space...


            mark
            This space? This thread?

            Comment

            • markwalker84
              New Member
              • Nov 2006
              • 11

              #7
              Originally posted by bartonc
              This space? This thread?
              Lol...

              Sorry - i got frustrated last night and just went to bed.

              Couldnt get it working :-(

              I know the variables are being updated as i created a push button -> change label to a variable test panel and it works fine. The problem is in actually re-building the panels... if that makes sense?


              ARGH!


              Mark

              Comment

              • bartonc
                Recognized Expert Expert
                • Sep 2006
                • 6478

                #8
                Originally posted by markwalker84
                Lol...

                Sorry - i got frustrated last night and just went to bed.

                Couldnt get it working :-(

                I know the variables are being updated as i created a push button -> change label to a variable test panel and it works fine. The problem is in actually re-building the panels... if that makes sense?


                ARGH!


                Mark
                If I get some time soon, I'll add a button to a panel dynamically so I know more about what you are going through.

                Comment

                • markwalker84
                  New Member
                  • Nov 2006
                  • 11

                  #9
                  Originally posted by bartonc
                  If I get some time soon, I'll add a button to a panel dynamically so I know more about what you are going through.
                  Much appreciated! Thanks :-)


                  Mark

                  Comment

                  • bartonc
                    Recognized Expert Expert
                    • Sep 2006
                    • 6478

                    #10
                    Originally posted by bartonc
                    If I get some time soon, I'll add a button to a panel dynamically so I know more about what you are going through.
                    The trick that I've decided to use is
                    Code:
                    self.thisButton.Hide()
                    on startup and
                    Code:
                    self.thisButton.Show()
                    when I want it visible.

                    The latter may work on a newly created object, as well.

                    Comment

                    • bartonc
                      Recognized Expert Expert
                      • Sep 2006
                      • 6478

                      #11
                      Originally posted by bartonc
                      The trick that I've decided to use is
                      Code:
                      self.thisButton.Hide()
                      on startup and
                      Code:
                      self.thisButton.Show()
                      when I want it visible.

                      The latter may work on a newly created object, as well.
                      And if you are trying to show one widget on top of an other:

                      In the constructor, let the bottom widget be created first. Then let that widget own the (be the parent of) the floater:[CODE=python]# in __init__()

                      self.grid1 = SingleRowGrid(i d=wxID_SEGMENTC OVERSHEETGRID1, name='grid1', parent=self,
                      pos=wx.Point(0, 0), size=wx.Size(60 2, 398), style=0)
                      self.grid1.Bind (wx.grid.EVT_GR ID_CELL_LEFT_CL ICK, self.OnGridCell LeftClick)

                      self.DatePicker = wx.DatePickerCt rl(id=wxID_SEGM ENTCOVERSHEETDA TEPICKER,
                      name='datePicke rCtrl1', parent=self.gri d1, pos=wx.Point(20 0, 31), size=wx.Size(10 0,
                      28),
                      style=wx.SIMPLE _BORDER | wx.DP_SHOWCENTU RY | wx.DP_DROPDOWN)
                      self.DatePicker .Raise()
                      self.DatePicker .Hide()[/CODE]Then, when you want the control shown:[CODE=python]#
                      def ActivateDatePic ker(self):
                      self.DatePicker .Refresh()
                      self.DatePicker .Update()

                      def OnDatePickerDat eChanged(self, event):
                      date = event.GetDate() .FormatDate()
                      self.DatePicker .Hide()
                      self.grid1.SetC ellValue(0, 0, date)
                      event.Skip()

                      def OnGridCellLeftC lick(self, event):
                      row = event.GetRow()
                      if row == 0:
                      self.DatePicker .Show()
                      wx.FutureCall(1 0, self.ActivateDa tePicker)
                      else:
                      self.DatePicker .Hide()
                      event.Skip()[/CODE]

                      Comment

                      Working...