468,110 Members | 1,505 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,110 developers. It's quick & easy.

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...

Expand|Select|Wrap|Line Numbers
  1.  
  2. from Initials import *
  3. import wx
  4. import os
  5. from Wizard import *
  6.  
  7.  
  8. class MainFrame(wx.Frame):
  9.     def __init__(self, parent, title):
  10.         wx.Frame.__init__(self, parent, -1, title)
  11.  
  12.         icon = wx.Icon("icon.ico", wx.BITMAP_TYPE_ICO)
  13.         self.SetIcon(icon)
  14.  
  15.  
  16.         ### Create Main Panel & Sizer ###
  17.         self.mainPanel = wx.Panel(self)
  18.         self.mainPanel.SetBackgroundColour((225,245,255))
  19.         mainSizer = wx.BoxSizer(wx.VERTICAL)
  20.  
  21.  
  22.         ### IMPORT VARIABLES LIST FROM INITIALS.PY ###
  23.         self.vars = VariablesData()
  24.         self.variables = self.vars.GetVariables()
  25.  
  26.  
  27.         ### Create Various Panels ###        
  28.         self.titlePanel = TitlePanel(self.mainPanel, wx.HORIZONTAL, self.variables)
  29.         self.controlPanel = ControlPanel(self.mainPanel, wx.HORIZONTAL, self.variables)
  30.         self.actionPanel = ActionPanel(self.mainPanel, wx.HORIZONTAL, self.variables)
  31.  
  32.  
  33.         self.CreatemenuBar()
  34.         self.CreateStatusBar()
  35.  
  36.  
  37.         mainSizer.Add(self.titlePanel.panel, 2, wx.ALIGN_LEFT | wx.EXPAND | wx.ALL, 5)
  38.         mainSizer.Add(self.controlPanel.panel, 5, wx.EXPAND | wx.LEFT | wx.RIGHT, 5)
  39.         mainSizer.Add(self.actionPanel.panel, 2, wx.EXPAND | wx.ALL, 5)
  40.  
  41.         self.mainPanel.SetSizer(mainSizer)
  42.         mainSizer.Fit(self)                # Fit frame to neccessary size
  43.         mainSizer.SetSizeHints(self)       # Prevents frame from getting smaller than min.
  44.  
  45. .
  46. .
  47. .
  48.  
  49. class NewPanel():
  50.     def __init__(self, parent, Orientation, variables):
  51.  
  52.         self.variables = variables
  53.  
  54.         self.panel = wx.Panel(parent)
  55.         self.sizer = wx.BoxSizer(Orientation)
  56.  
  57.         self.AddItems(self.variables)
  58.  
  59.         self.panel.SetSizer(self.sizer)
  60.         self.sizer.Fit(self.panel)                # Fit frame to neccessary size
  61.         self.sizer.SetSizeHints(self.panel)       # Prevents frame from getting smaller than min.
  62.  
  63. .
  64. .
  65. .
  66. class ControlPanel(NewPanel):
  67.  
  68.     def AddItems(self, variables):
  69.  
  70.         self.variables = variables
  71.  
  72.         self.automaticPanel = AutomaticPanel(self.panel, wx.VERTICAL, variables)
  73.         self.modePanel = ModePanel(self.panel, wx.VERTICAL, variables)
  74.         self.manualPanel = ManualPanel(self.panel, wx.HORIZONTAL, variables)        
  75.  
  76.         self.sizer.Add(self.automaticPanel.panel, 6, wx.EXPAND)
  77.         self.sizer.Add(self.modePanel.panel, 3, wx.EXPAND | wx.LEFT | wx.RIGHT, 5)
  78.         self.sizer.Add(self.manualPanel.panel, 5, wx.EXPAND)
  79. .
  80. .
  81. .
  82. class ManualPanel(NewPanel):
  83.  
  84.     def AddItems(self, variables):
  85.  
  86.         self.variables = variables
  87.  
  88.         self.box = wx.StaticBox(self.panel, -1, 'Manual Control')
  89.         self.box.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, False))
  90.         self.sizer = wx.StaticBoxSizer(self.box, wx.HORIZONTAL)
  91.  
  92.         self.bristlePanel = BristlePanel(self.panel, wx.VERTICAL, variables)
  93.         self.cylinderPanel = CylinderPanel(self.panel, wx.VERTICAL, variables)
  94.  
  95.         self.sizer.Add(self.bristlePanel.panel, 1, wx.EXPAND)
  96.         self.sizer.Add(self.cylinderPanel.panel, 1, wx.EXPAND)
  97.  
  98.  
  99.  
  100. class BristlePanel(NewPanel):
  101.  
  102.     def AddItems(self, variables):
  103.  
  104.         self.variables = variables
  105.  
  106.         self.bristleCheckBox = []
  107.  
  108.         for x in range(0, self.variables['bristles']):
  109.             self.bristleCheckBox.insert(x, (wx.CheckBox(self.panel, -1, "Bristle %d" % (x+1))))
  110.             self.sizer.Add(self.bristleCheckBox[x], 1, wx.ALIGN_CENTER_HORIZONTAL)        
  111.  
  112.  
  113. class CylinderPanel(NewPanel):
  114.  
  115.     def AddItems(self, variables):
  116.  
  117.         self.variables = variables
  118.  
  119.         self.cylinderCheckBox = []
  120.  
  121.         for x in range(0, self.variables['cylinders']):
  122.             self.cylinderCheckBox.insert(x, (wx.CheckBox(self.panel, -1, "Cylinder %d" % (x+1))))
  123.             self.sizer.Add(self.cylinderCheckBox[x], 1, wx.ALIGN_CENTER_HORIZONTAL)
  124.  
  125. .
  126. .
  127. .
  128.  
  129.  
  130.  
  131. class wxPyApp(wx.App):
  132.     def OnInit(self):
  133.         frame = MainFrame(None, "DPT - Sequence Driven Controller")
  134.         self.SetTopWindow(frame)
  135.         frame.Show(True)
  136.         frame.Center(wx.BOTH)
  137.         return True
  138.  
  139. if __name__ == '__main__':          # Only runs if program is being executed, not imported
  140.     app = wxPyApp(redirect=True)
  141.     app.MainLoop()
  142.  
  143.  
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
Nov 30 '06 #1
10 33054
bartonc
6,596 Expert 4TB
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.
Dec 1 '06 #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.
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
Dec 2 '06 #3
bartonc
6,596 Expert 4TB
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.Update()
Dec 2 '06 #4
I was thinking along the lines of
self.parent.Update()
ah... ok then... ill give that a whirl :-)


Watch this space...


mark
Dec 2 '06 #5
bartonc
6,596 Expert 4TB
ah... ok then... ill give that a whirl :-)


Watch this space...


mark
This space? This thread?
Dec 3 '06 #6
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
Dec 3 '06 #7
bartonc
6,596 Expert 4TB
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.
Dec 3 '06 #8
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
Dec 4 '06 #9
bartonc
6,596 Expert 4TB
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
Expand|Select|Wrap|Line Numbers
  1. self.thisButton.Hide()
on startup and
Expand|Select|Wrap|Line Numbers
  1. self.thisButton.Show()
when I want it visible.

The latter may work on a newly created object, as well.
Apr 15 '07 #10
bartonc
6,596 Expert 4TB
The trick that I've decided to use is
Expand|Select|Wrap|Line Numbers
  1. self.thisButton.Hide()
on startup and
Expand|Select|Wrap|Line Numbers
  1. 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:
Expand|Select|Wrap|Line Numbers
  1. # in __init__()
  2.  
  3.         self.grid1 = SingleRowGrid(id=wxID_SEGMENTCOVERSHEETGRID1, name='grid1', parent=self,
  4.                 pos=wx.Point(0, 0), size=wx.Size(602, 398), style=0)
  5.         self.grid1.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnGridCellLeftClick)
  6.  
  7.         self.DatePicker = wx.DatePickerCtrl(id=wxID_SEGMENTCOVERSHEETDATEPICKER,
  8.                 name='datePickerCtrl1', parent=self.grid1, pos=wx.Point(200, 31), size=wx.Size(100,
  9.                 28),
  10.                 style=wx.SIMPLE_BORDER | wx.DP_SHOWCENTURY | wx.DP_DROPDOWN)
  11.         self.DatePicker.Raise()
  12.         self.DatePicker.Hide()
Then, when you want the control shown:
Expand|Select|Wrap|Line Numbers
  1. #
  2.     def ActivateDatePicker(self):
  3.         self.DatePicker.Refresh()
  4.         self.DatePicker.Update()
  5.  
  6.     def OnDatePickerDateChanged(self, event):
  7.         date = event.GetDate().FormatDate()
  8.         self.DatePicker.Hide()
  9.         self.grid1.SetCellValue(0, 0, date)
  10.         event.Skip()
  11.  
  12.     def OnGridCellLeftClick(self, event):
  13.         row = event.GetRow()
  14.         if row == 0:
  15.             self.DatePicker.Show()
  16.             wx.FutureCall(10, self.ActivateDatePicker)
  17.         else:
  18.             self.DatePicker.Hide()
  19.             event.Skip()
Oct 10 '07 #11

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Ryan Moore | last post: by
2 posts views Thread by Kevin Chandler | last post: by
3 posts views Thread by citronelu | last post: by
1 post views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.