Skip to content

Instantly share code, notes, and snippets.

@StPanning

StPanning/ui.py Secret

Last active November 21, 2020 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StPanning/c0d26c8647401bd54e58407375df49c3 to your computer and use it in GitHub Desktop.
Save StPanning/c0d26c8647401bd54e58407375df49c3 to your computer and use it in GitHub Desktop.
wxPython Layout problems
import gettext
# end wxGlade
# begin wxGlade: extracode
import wx
# end wxGlade
class PlotCard(wx.Panel):
def __init__(self, *args, **kwds):
# begin wxGlade: PlotCard.__init__
kwds["style"] = kwds.get("style", 0) | wx.TAB_TRAVERSAL
wx.Panel.__init__(self, *args, **kwds)
self.SetSize((200, 100))
self.SetBackgroundColour(wx.Colour(50, 153, 204))
self.Layout()
# end wxGlade
# end of class PlotCard
class PlotBoard(wx.ScrolledWindow):
def __init__(self, *args, **kwds):
# begin wxGlade: PlotBoard.__init__
kwds["style"] = kwds.get("style", 0)
wx.ScrolledWindow.__init__(self, *args, **kwds)
self.SetMinSize((800, 600))
self.SetBackgroundColour(wx.Colour(90, 180, 142))
self.SetScrollRate(10, 10)
self.EnableScrolling(False, True)
sizer_2 = wx.WrapSizer(wx.HORIZONTAL)
self.SetSizer(sizer_2)
self.Layout()
self.Bind(wx.EVT_SIZE, self.OnSize, self)
# end wxGlade
def AddCard(self):
sizer: wx.WrapSizer = self.GetSizer()
box = PlotCard(self)
size = self.GetClientSize()
sizer.Add(box, flag=wx.FIXED_MINSIZE | wx.ALL, border=5)
self.SetVirtualSize(size)
self.Layout()
print("items: {}| size: {}".format(sizer.GetItemCount(), size))
def OnSize(self, event): # wxGlade: PlotBoard.<event_handler>
size = self.GetSize()
sizer_size = self.GetSizer().GetSize()
self.SetVirtualSize(size)
self.Layout()
print("Pane size: {} Sizer size {}".format(size, sizer_size))
event.Skip()
# end of class PlotBoard
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: MyFrame.__init__
kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.SetSize((800, 600))
self.SetTitle(_("frame"))
sizer_1 = wx.GridBagSizer(0, 0)
self.panel_1 = PlotBoard(self, wx.ID_ANY)
sizer_1.Add(self.panel_1, (0, 0), (1, 1), wx.EXPAND, 0)
self.button_1 = wx.Button(self, wx.ID_ADD, "")
sizer_1.Add(self.button_1, (1, 0), (1, 1), 0, 0)
sizer_1.AddGrowableRow(0)
sizer_1.AddGrowableCol(0)
self.SetSizer(sizer_1)
self.Layout()
self.Bind(wx.EVT_BUTTON, self.OnButtonAdd, self.button_1)
# end wxGlade
def OnButtonAdd(self, event): # wxGlade: MyFrame.<event_handler>
self.panel_1.AddCard()
# end of class MyFrame
class MyApp(wx.App):
def OnInit(self):
self.frame = MyFrame(None, wx.ID_ANY, "")
self.SetTopWindow(self.frame)
self.frame.Show()
return True
# end of class MyApp
if __name__ == "__main__":
gettext.install("app") # replace with the appropriate catalog name
app = MyApp(0)
app.MainLoop()
@StPanning
Copy link
Author

StPanning commented Nov 21, 2020

Platform linux/wxGTK (wxPython 4.01)
Action:

  • Add Elements with the '+ Add' Button

Expected behavior:

  • Wrap around horizontally if necessary
  • Show Vertical Scrollbar if necessary
  • Render each Element inside the visible/scrollable Area

Current behavior:

  • If the screen is very wide, elements are rendered off-screen
  • no scrollbars are shown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment