I tried the reorder, no joy. The WIT did not reveal any obvious
smoking guns (at least, not to me :))
The wxMSW version is 2.8.9.1. The wxGTK version which works is
2.8.10.1.
···
================
'''
Wx Panel setup for calibrating a servo
'''
import wx
import wx.grid as wg
import wx.lib.mixins.inspection as wxInspector
#from angularInputPanel import AngularInputPanel
#from linearInputPanel import LinearInputPanel
class ServoPanel(wx.Panel):
'''
ServoPanel class derived from wx.Panel.
A panel with data input and plot areas. The user inputs servo
excitation measurements, presses the Calculate button and the
required cubic constants are calculated and data is plotted for
operator inspection.
'''
def __init__(self, parent, name = None, statusBar = None, conv =
None):
'''
Build the panel, initialize state variables.
'''
wx.Panel.__init__(self, parent, name = name)
self.parent = parent
self.statusBar = statusBar
self.k = None
self.inputMode = 'Angular'
self.first = True
self.panelBkGnd = wx.Colour(228, 172, 32)
self._buildLeftSide(conv)
self._buildRightSide()
self.mainSizer = wx.BoxSizer(wx.HORIZONTAL)
self.mainSizer.Add(self.leftPanel, 1, wx.ALL | wx.EXPAND, 1)
self.mainSizer.Add(self.rightPanel, 4, wx.ALL | wx.EXPAND, 1)
self.SetSizer(self.mainSizer)
self.Layout()
def _buildLeftSide(self, conv):
'''
Construct the data input side of the panel.
'''
self.leftPanel = wx.Panel(self, -1, name = 'Left')
self.leftPanel.SetBackgroundColour(self.panelBkGnd)
# create the static box & sizer
self.leftBox = wx.StaticBox(self.leftPanel, -1, 'Servo
Measurements',
name = 'Servo Measurements')
self.lsbSizer = wx.StaticBoxSizer(self.leftBox, wx.VERTICAL)
# create the input panels
#self.aip = AngularInputPanel(self.leftPanel, conv = conv)
self.aip = wx.Panel(self.leftPanel, -1, name = 'AIP - red')
self.aip.SetBackgroundColour(wx.Colour(128, 0, 0))
self.lsbSizer.Add(self.aip, 93, wx.ALL | wx.EXPAND, 2)
#self.lip = LinearInputPanel(self.leftPanel, conv = conv)
self.lip = wx.Panel(self.leftPanel, -1, name = 'LIP - blue')
self.lip.SetBackgroundColour(wx.Colour(0, 0, 128))
self.lip.Show(False)
self.lsbSizer.Add(self.lip, 93, wx.ALL | wx.EXPAND, 2)
# create the swap button
self.swapBtn = wx.Button(self.leftPanel, -1, 'Switch To Linear
Input',
name = 'Swap')
self.Bind(wx.EVT_BUTTON, self.onSwap, self.swapBtn)
self.lsbSizer.Add(self.swapBtn, 7, wx.ALL | wx.EXPAND, 2)
# create the calculate button
self.calcBtn = wx.Button(self.leftPanel, -1, 'Gonculate', name =
'Calc')
self.Bind(wx.EVT_BUTTON, self.onGonculate, self.calcBtn)
# create the panel sizer
self.leftSizer = wx.BoxSizer(wx.VERTICAL)
self.leftSizer.Add(self.lsbSizer, 93, wx.ALL | wx.EXPAND, 2)
self.leftSizer.Add(self.calcBtn, 7, wx.ALL | wx.EXPAND, 2)
self.leftPanel.SetSizer(self.leftSizer)
def _buildRightSide(self):
'''
Construct the graph side of the panel.
'''
self.rightPanel = wx.Panel(self, -1, name = 'Right')
self.rightPanel.SetBackgroundColour(self.panelBkGnd)
# create the plots box
self.rightBox1 = wx.StaticBox(self.rightPanel, -1, 'Data Plots',
name = 'Data Plots')
self.rsb1Sizer = wx.StaticBoxSizer(self.rightBox1, wx.VERTICAL)
self.plots = wx.Panel(self.rightPanel, -1, name = 'Dummy Plot')
self.plots.SetBackgroundColour(wx.Colour(96, 96, 96))
self.rsb1Sizer.Add(self.plots, 1, wx.ALL | wx.EXPAND, 1)
# create the coeff output
self.rightBox2 = wx.StaticBox(self.rightPanel, -1, 'Cubic Fit
Coefficients',
name = 'Cubic Fit Coefficients')
self.rsb2Sizer = wx.StaticBoxSizer(self.rightBox2, wx.HORIZONTAL)
f = wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD)
self.k_lbl = [None, None, None, None]
for i in range(4):
lbl = wx.StaticText(self.rightPanel, -1, 'K%d = ' % i,
style = wx.ALIGN_RIGHT, name = 'K%d Label' %
i)
lbl.SetFont(f)
self.rsb2Sizer.Add(lbl, 1, wx.ALL | wx.EXPAND, 1)
if self.k is None:
k_val = 0.0
else:
k_val = self.k[3 - i]
self.k_lbl[i] = wx.StaticText(self.rightPanel, -1, '%f' % k_val,
style = wx.ALIGN_LEFT, name = 'K
%d' % i)
self.rsb2Sizer.Add(self.k_lbl[i], 1, wx.ALL | wx.EXPAND, 1)
# create the panel sizer
self.rightSizer = wx.BoxSizer(wx.VERTICAL)
self.rightSizer.Add(self.rsb1Sizer, 93, wx.ALL | wx.EXPAND, 2)
self.rightSizer.Add(self.rsb2Sizer, 7, wx.ALL | wx.EXPAND, 2)
self.rightPanel.SetSizer(self.rightSizer)
def _errorMessage(self, msg):
'''
Display an error message in a modal dialog box.
'''
d = wx.MessageDialog(self, msg, 'Data Input Error',
wx.OK | wx.ICON_ERROR)
d.ShowModal()
d.Destroy()
def _testData(self):
'''
Create a test data set for verification of the class.
'''
pass
def getInputMode(self):
'''
Return the current input mode.
'''
return self.inputMode
def onGonculate(self, evt):
'''
Validate input, calculate the fit poly, generate the graphs.
'''
print 'onGonculate'
def onSwap(self, evt):
'''
Swap data input panels.
'''
print 'onSwap'
if self.inputMode == 'Angular':
self.aip.Show(False)
self.lip.Show(True)
self.swapBtn.SetLabel('Switch To Angular Input')
self.inputMode = 'Linear'
else:
self.aip.Show(True)
self.lip.Show(False)
self.swapBtn.SetLabel('Switch To Linear Input')
self.inputMode = 'Angular'
self.first = True
self.Layout()
class ServoFrame(wx.Frame):
'''
Test frame for the ServoPanel class.
'''
def __init__(self, doTest = False, name = 'Main Frame'):
'''
Create the custom frame and status bar.
Generate the ServoPanel test data if requested.
'''
wx.Frame.__init__(self, None, -1, 'ServoFrame', size = (1200,
760),
name = name)
self.statusBar = wx.StatusBar(self, -1, name = name + '
StatusBar')
self.statusBar.SetFieldsCount(2)
self.SetStatusBar(self.statusBar)
self.panel = ServoPanel(self, statusBar = self.statusBar,
name = 'Debug Panel')
if doTest:
self.panel._testData()
self.Bind(wx.EVT_CLOSE, self.onCloseWindow)
self.CenterOnScreen()
def onCloseWindow(self, event):
print 'ServoFrame onCloseWindow'
self.Destroy()
class ServoTestApp(wx.App, wxInspector.InspectionMixin):
'''
Test application for the ServoPanel class.
'''
def OnInit(self):
'''
Create the main window and insert the custom frame.
'''
self.Init() # Initialize the inspection tool
frame = ServoFrame(doTest = True, name = 'Debug Main Frame')
self.SetTopWindow(frame)
frame.Show(True)
return True
if __name__=='__main__':
'''
Run the test application class if directly executed.
'''
app = ServoTestApp(0)
app.MainLoop()
On Aug 24, 5:01 pm, Robin Dunn <ro...@alldunn.com> wrote:
Robin Dunn wrote:
> Todd wrote:
>> Hi -
>> I'm working on an app which uses one of two different input panels.
>> It works correctly on wxGTK on Gentoo, but fails on wxMSW. The
>> initial display is correct, but if I try to switch to the alternate
>> input panel, the input area is blank (it looks like a small window is
>> overiting part of the staticbox title).
>> On the left side of the main frame, I create a panel with a vertical
>> boxsizer that contains a button on the bottom and a vertical
>> staticboxsizer above. The staticboxsizer contains the two different
>> input panels and a "Swap" button; only one of the input panels is
>> visible at any given time. When the user clicks the "Swap" button, I
>> turn off one and turn on the other then call Layout() on the parent
>> panel. The two applicable code snippets are below. So, what am I
>> doing wrong?
> Besides not providing a complete runnable sample?
> (MakingSampleApps - wxPyWiki)
> Try creating the static box before you create the widgets that will
> appear to be within it. If that doesn't help then my guess is that
> there is some other window being created that is not being managed by a
> sizer or that has improper parentage. Try adding the WIT to your app so
> you can use it to find info about that window.
Opps, forgot the link:http://wiki.wxpython.org/Widget_Inspection_Tool
--
Robin Dunn
Software Craftsmanhttp://wxPython.org