I want to add a splitter to my program. I have 2 separately working python programs i.e. spltest.py with 2 panels and pnl_pos.pyold and combined them together to form pnl_pos.pynew. The splitter did not show up. There was:
“Gtk-WARNING **: 11:51:01.211: gtk_widget_size_allocate(): attempt to allocate widget with width -5 and height 17”.
I googled all over, found and tried wx.CallAfter() and evt.Skip() but in vain. Can anyone show me where the problem lies? Thank you very much.
pnl_pos.pynew (excerpt)
import wx
import string
from lc_mpos import *
import mpos_db
import config
import dlg_pos_addItem
import mpos_utility
import wx.lib.inspection
class POS_Panel(wx.Panel):
def __init__(self, parent, *args, **kwargs):
super(POS_Panel, self).__init__(parent, *args, **kwargs)
# Set the fonts for the panel
#------------------------------------------------------------------
font_1 = wx.Font(20, wx.SWISS, wx.NORMAL, wx.NORMAL)
font_2 = wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL)
font_3 = wx.Font(15, wx.SWISS, wx.NORMAL, wx.NORMAL)
font_4 = wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD)
font_5 = wx.Font(13, wx.SWISS, wx.NORMAL, wx.BOLD)
self.SetBackgroundColour(wx.WHITE)
# EndSizer will be the parent of vsizer1 and vsizer2
#------------------------------------------------------------------
splitter = wx.SplitterWindow(self, -1)
#self.later()
#splitter =wx.SplitterWindow(self, -1, style = wx.SP_LIVE_UPDATE)
panel1 = wx.Panel(splitter, -1)
#endSizer = wx.BoxSizer(wx.HORIZONTAL)
#------------------------------------------------------------------
# vsizer1 will be the parent of the left wx.Boxsizers
#------------------------------------------------------------------
vsizer1 = wx.BoxSizer(wx.VERTICAL)
vsizer1.Add((-1, 0))
#------------------------------------------------------------------
lbox1 = wx.BoxSizer(wx.HORIZONTAL)
self.title = wx.StaticText(self, -1, 'Point of Sale')
self.title.SetFont(font_1)
lbox1.Add(self.title, 0)
vsizer1.Add(lbox1, 0, wx.ALIGN_LEFT|wx.EXPAND|wx.ALL, 5)
#------------------------------------------------------------------
lbox2 = wx.BoxSizer(wx.HORIZONTAL)
self.search_label = wx.StaticText(self, -1, 'Search'+': ')
self.search_label.SetFont(font_2)
# self.search_bar = wx.TextCtrl(self, -1)
self.search_bar = wx.SearchCtrl(self, -1)
self.search_bar.ShowCancelButton(True)
self.search_bar.ShowSearchButton(False)
lbox2.Add(self.search_label, 0, wx.RIGHT|wx.TOP, 5)
lbox2.Add(self.search_bar, 1)
vsizer1.Add(lbox2, 0, wx.EXPAND|wx.RIGHT|wx.LEFT, 5)
vsizer1.Add((-1, 2))
#------------------------------------------------------------------
lbox3 = wx.BoxSizer(wx.HORIZONTAL)
self.product_lc = ProductLC(self, -1, style=wx.LC_REPORT|\
wx.LC_VRULES|wx.BORDER_DEFAULT)
lbox3.Add(self.product_lc, 1, wx.EXPAND)
vsizer1.Add(lbox3, 1, wx.EXPAND|wx.ALL, 5)
panel1.SetSizerAndFit(vsizer1)
panel2 = wx.Panel(splitter, -1)
#endSizer.Add(vsizer1, 4, wx.EXPAND|wx.RIGHT, 5)
#------------------------------------------------------------------
# vsizer2 will be the parent of the right wx.Boxsizers
#------------------------------------------------------------------
vsizer2 = wx.BoxSizer(wx.VERTICAL)
vsizer2.Add((-1, 30))
# size ------------------------------------------------------------------
rbox1 = wx.BoxSizer(wx.HORIZONTAL)
self.receipt_label = wx.StaticText(self, -1, 'Receipt')
self.receipt_label.SetFont(font_3)
self.receipt_num = wx.TextCtrl(self, -1, style = wx.TE_READONLY|\
wx.TE_CENTER)
rbox1.Add(self.receipt_label, 0, wx.TOP, 5)
rbox1.Add(self.receipt_num, 1, wx.LEFT|wx.RIGHT, 75)
vsizer2.Add(rbox1, 0, wx.EXPAND|wx.ALL, 5)
#------------------------------------------------------------------
rbox2 = wx.BoxSizer(wx.HORIZONTAL)
self.sepLine1 = wx.StaticLine(self, -1)
rbox2.Add(self.sepLine1, 1)
vsizer2.Add(rbox2, 0, wx.EXPAND|wx.LEFT|wx.RIGHT, 5)
#------------------------------------------------------------------
rbox3 = wx.BoxSizer(wx.HORIZONTAL)
self.receipt_lc = ReceiptLC(self, -1, style=wx.LC_REPORT|\
wx.LC_VRULES|wx.BORDER_DEFAULT|wx.LC_HRULES)
rbox3.Add(self.receipt_lc, 1, wx.EXPAND)
vsizer2.Add(rbox3, 4, wx.EXPAND|wx.ALL, 5)
#------------------------------------------------------------------
self.static_box = wx.StaticBox(self, -1, 'Sales Summary')
rbox4 = wx.StaticBoxSizer(self.static_box, wx.VERTICAL)
# subbox1 will hold the total label and amount
subbox1 = wx.BoxSizer(wx.HORIZONTAL)
self.subtotal_label = wx.StaticText(self, -1, 'Sub Total')
self.subtotal_label.SetFont(font_4)
self.subtotal_amount = wx.TextCtrl(self, -1,
style=wx.TE_READONLY|wx.TE_RIGHT)
self.subtotal_amount.SetFont(font_4)
subbox1.Add(wx.StaticText(self, -1, ''), 2)
subbox1.Add(self.subtotal_label, 2, wx.TOP|wx.RIGHT, 5)
subbox1.Add(self.subtotal_amount, 2)
rbox4.Add(subbox1, 0, wx.EXPAND|wx.ALL, 10)
#--#
subbox2 = wx.BoxSizer(wx.HORIZONTAL)
self.tax_label = wx.StaticText(self, -1, 'Sales Tax')
self.tax_amount = wx.TextCtrl(self, -1,
style=wx.TE_READONLY|wx.TE_RIGHT)
self.tax_label.SetFont(font_2)
self.tax_amount.SetFont(font_2)
subbox2.Add(wx.StaticText(self, -1, ''), 2)
subbox2.Add(self.tax_label, 2, wx.TOP|wx.RIGHT, 5)
subbox2.Add(self.tax_amount, 2)
rbox4.Add(subbox2, 0, wx.EXPAND|wx.LEFT|wx.RIGHT, 10)
#--#
subbox3 = wx.BoxSizer(wx.HORIZONTAL)
subbox3.Add(wx.StaticText(self, -1, ''), 2)
subbox3.Add(wx.StaticLine(self, -1), 4)
rbox4.Add(subbox3, 0, wx.EXPAND|wx.TOP, 10)
#--#
subbox4 = wx.BoxSizer(wx.HORIZONTAL)
self.total_label = wx.StaticText(self, -1, 'Total')
self.total_amount = wx.TextCtrl(self, -1,
style=wx.TE_READONLY|wx.TE_RIGHT)
self.total_label.SetFont(font_5)
self.total_amount.SetFont(font_5)
subbox4.Add(wx.StaticText(self, -1, ''), 2)
subbox4.Add(self.total_label, 2, wx.TOP|wx.RIGHT, 5)
subbox4.Add(self.total_amount, 2)
rbox4.Add(subbox4, 0, wx.EXPAND|wx.LEFT|wx.RIGHT, 10)
#--#s
vsizer2.Add(rbox4, 2, wx.EXPAND|wx.LEFT|wx.RIGHT|wx.BOTTOM, 5)
#------------------------------------------------------------------
rbox5 = wx.BoxSizer(wx.HORIZONTAL)
self.complete_btn = wx.Button(self, -1, "Complete Transaction",
size=(-1, 100))
self.complete_btn.SetFont(font_4)
self.cancel_btn = wx.Button(self, -1, "Cancel",
size=(-1, 100))
self.cancel_btn.SetFont(font_4)
rbox5.Add(self.cancel_btn, 1, wx.RIGHT, 10)
rbox5.Add(self.complete_btn, 2)
vsizer2.Add(rbox5, 0, wx.EXPAND|wx.LEFT|wx.RIGHT, 20)
vsizer2.Add((-1, 5))
panel2.SetSizerAndFit(vsizer2)
#Layout()
#------------------------------------------------------------------
#self.later()
splitter.SetMinimumPaneSize(20)
splitter.SplitVertically(panel1, panel2,-100)
#------------------------------------------------------------------
#endSizer.Add(vsizer2, 5, wx.EXPAND)
#self.SetSizer(endSizer)
self.Centre()
self.Layout()
self.Show(True)
#self.Maximize(True)
self.Bind(wx.EVT_SIZE, self.OnSize)
# Set up complimentary objects
#------------------------------------------------------------------
self.db = mpos_db.MPOS_DB()
self.config = config.Configuration()
self.c_symbol = self.config.cCurrency()[0]
self.c_dec = self.config.cCurrency()[1]
self.thous_sep = self.config.ThousandsSep()
#------------------------------------------------------------------
self.m1, self.t1, self.m2, self.t2, self.btn_l1 = '', '', '', '', ''
self.btn_l2, self.r_label, self.t_label = '', '', ''
self.Language()
#-----------------------------------------------------------------
self.PListRefresh()
self.SetReceiptNo()
self.SaleInfoSetup()
self.edit_mode = False
self.OnCancel(None)
# Bindings
#------------------------------------------------------------------
self.search_bar.Bind(wx.EVT_TEXT, self.OnSearch)
self.product_lc.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnSelect)
self.receipt_lc.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.OnRClick)
self.receipt_lc.Bind(wx.EVT_LEFT_DCLICK, self.OnEdit)
self.Bind(wx.EVT_BUTTON, self.OnComplete, self.complete_btn)
self.Bind(wx.EVT_BUTTON, self.OnCancel, self.cancel_btn)
self.search_bar.Bind(wx.EVT_SEARCHCTRL_CANCEL_BTN, self.OnSearchCancel)
#def later(self):
#splitter.SplitVertically(panel1, panel2, 0)
#wx.CallAfter(later)
def OnSize(self, evt):
evt.Skip()
# here you will change the sash positions to your liking
self.splitter.SetSashPosition(100,redraw = True)
self.splitter2.SetSashPosition(200,redraw = True)
#----------------------------------------------------------------------
# Function Definitions
spltest.py
import wx
class Mywin(wx.Frame):
def __init__(self, parent, title):
super(Mywin, self).__init__(parent, title = title,size = (350,300))
splitter = wx.SplitterWindow(self, -1)
#---------------------------------------------
###panel 1
panel1 = wx.Panel(splitter, -1)
b = wx.BoxSizer(wx.HORIZONTAL)
self.text = wx.TextCtrl(panel1,style = wx.TE_MULTILINE)
b.Add(self.text, 1, wx.EXPAND)
panel1.SetSizerAndFit(b)
#-------------------------------------------------
###panel 2
panel2 = wx.Panel(splitter, -1)
c = wx.BoxSizer(wx.HORIZONTAL)
self.text = wx.TextCtrl(panel2,style = wx.TE_MULTILINE)
c.Add(self.text, 1, wx.EXPAND)
#panel2.SetSizer
panel2.SetSizerAndFit(c)
###back to plitter
splitter.SplitVertically(panel1, panel2)
self.Centre()
self.Show(True)
ex = wx.App()
Mywin(None,'Splitter Demo')
ex.MainLoop()