and, similarly, one may put some home-grown tooltip on the table columns…
import wx
GS = 'Do in', 'Rome', 'as', 'the', 'Romans', 'do'
BTN = ('button_1', 1), ('button_2', 0), ('button_3', 1)
COLUMNS = 'Label', 'Value'
class Gui(wx.Frame):
def __init__(self, parent):
super().__init__(parent, title='never repeat..')
self.frame_statusbar = self.CreateStatusBar()
vb = wx.BoxSizer(wx.VERTICAL)
panel = wx.Panel(self, wx.ID_ANY)
vb.Add(panel, 1, wx.EXPAND, 8)
self.SetSizer(vb)
# split horizontally
hbox = wx.BoxSizer(wx.HORIZONTAL)
splitter = wx.SplitterWindow(
panel, wx.ID_ANY,
style=wx.SP_LIVE_UPDATE | wx.SP_THIN_SASH)
hbox.Add(splitter, 1, wx.EXPAND)
panel.SetSizer(hbox)
panel1 = wx.Panel(splitter, wx.ID_ANY)
panel2 = wx.Panel(splitter, wx.ID_ANY)
splitter.SplitVertically(panel1, panel2, 500)
splitter.SetMinimumPaneSize(50) # no window should disappear
# text lines on the left
vbox = wx.BoxSizer(wx.VERTICAL)
gs = wx.GridSizer(1)
self.gs_ctrl = dict() # ctrl: row
self.gs_row = dict() # row: ctrl
for idx, entry in enumerate(GS):
gs.Add(wx.StaticText(panel1, wx.ID_ANY, entry))
tc = wx.TextCtrl(panel1)
self.gs_ctrl[tc.GetId()] = idx
self.gs_row[idx] = tc
gs.Add(tc, 0, wx.EXPAND)
vbox.Add(gs, 0, wx.EXPAND|wx.ALL, 8)
panel1.SetSizer(vbox)
# list on the right
vbox = wx.BoxSizer(wx.VERTICAL)
hdr = wx.StaticText(panel2, wx.ID_ANY, "My Stuff") # header
self.list = wx.ListView(panel2) # list
for col in COLUMNS:
self.list.AppendColumn(col)
self.list.Bind(wx.EVT_LIST_COL_DRAGGING, self.evt_col_width)
self.list.Bind(wx.EVT_SCROLLWIN_THUMBRELEASE, self.evt_scroll)
grp = wx.Window(panel2, size=(0, 1)) # buttons grip
grp.SetBackgroundColour(wx.BLUE)
grp.Bind(wx.EVT_ENTER_WINDOW, self.grip_btns)
hbox = wx.BoxSizer(wx.HORIZONTAL) # buttons
self.btn_ctrl = dict() # ctrl: pos
self.ctrl_btn = dict() # pos: ctrl
for idx, entry in enumerate(BTN):
btn = wx.Button(panel2, -1, entry[0])
hbox.Add(btn, entry[1], wx.EXPAND)
self.btn_ctrl[btn.GetId()] = idx
self.ctrl_btn[idx] = btn.GetId()
htt = self.update_htt(panel2) # header tooltips
self.fgs = wx.FlexGridSizer(1)
self.fgs.AddMany(
[hdr, (htt, 0, wx.EXPAND), (self.list, 0, wx.EXPAND),
(grp, 0, wx.EXPAND), (hbox, 0, wx.EXPAND)])
self.fgs.AddGrowableCol(0, 0)
self.fgs.AddGrowableRow(2, 0)
vbox.Add(self.fgs, 1, wx.EXPAND|wx.ALL, 8)
panel2.SetSizerAndFit(vbox)
vb.Fit(self)
self.grip_btns(None)
self.Show()
def evt_col_width(self, _, /):
self.update_htt()
self.fgs.Layout()
def evt_scroll(self, evt, /):
if evt.GetPosition():
self.list.Unbind(wx.EVT_LIST_COL_DRAGGING)
self.fgs.Hide(1)
else:
self.list.Bind(wx.EVT_LIST_COL_DRAGGING, self.evt_col_width)
self.fgs.Show(1)
evt.Skip()
def grip_btns(self, _, /):
if self.fgs.IsShown(4):
self.fgs.Hide(4)
else:
self.fgs.Show(4)
self.fgs.Layout()
def update_htt(self, panel=None, /):
if not panel:
hbox = self.fgs.GetChildren()[1].GetSizer()
panel = hbox.GetChildren()[0].GetWindow().GetParent()
hbox.Clear(delete_windows=True)
else:
hbox = wx.BoxSizer(wx.HORIZONTAL)
for col, entry in enumerate(COLUMNS):
win = wx.Window(
panel, -1, size=(self.list.GetColumnWidth(col), 3))
hbox.Add(win)
win.SetToolTip(f'tip for column "{entry}"')
win.SetBackgroundColour('light blue')
return hbox
if __name__ == "__main__":
app = wx.App()
app.TopWindow = Gui(None)
app.MainLoop()type or paste code here
there was a line missing…
ChuckM_od_grp_htt.py (4.4 KB)
and to care for changing column order as well: the extra sill is for a missing event, but with the proper sizer it’s fun to be a teeny-weeny bit creative…
ChuckM_od_grp_htt.py (4.7 KB)
and if you want to browse big data (until the mouse screams)
ChuckM_scrwin.py (10.5 KB)