Skip to content

Instantly share code, notes, and snippets.

@yaqwsx
Created July 21, 2021 16:27
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 yaqwsx/ab2bfd0a0e097fcea9faf987fbab20ae to your computer and use it in GitHub Desktop.
Save yaqwsx/ab2bfd0a0e097fcea9faf987fbab20ae to your computer and use it in GitHub Desktop.
import wx
# Just something dummy so we have something to show
availableSections = {
"Layout": None,
"Source": None,
"Tabs": None,
"Cuts": None,
"Framing": None,
"Tooling": None,
"Fiducials": None,
"Text": None,
"Postprocessing": None,
"Debugging": None,
}
class DummyWidget():
def __init__(self, parent, name, parameter):
self.name = name
self.label = wx.StaticText(parent,
label=name,
size=wx.Size(200, -1),
style=wx.ALIGN_RIGHT)
self.widget = wx.StaticText(parent,
label="Value",
size=wx.Size(200, -1),
style=wx.ALIGN_LEFT)
class SectionGui():
def __init__(self, parent, name, section, onResize):
self.container = wx.CollapsiblePane(
parent, wx.ID_ANY, name, wx.DefaultPosition, wx.DefaultSize,
wx.CP_DEFAULT_STYLE)
self.container.Collapse(False)
self.container.GetPane().SetBackgroundColour(wx.Colour(76, 183, 240))
self.container.Bind(wx.EVT_COLLAPSIBLEPANE_CHANGED, onResize)
self.container.SetSizeHints(wx.DefaultSize, wx.DefaultSize)
self.container.GetPane().SetSizeHints(wx.DefaultSize, wx.DefaultSize)
self.itemGrid = wx.BoxSizer(wx.VERTICAL)
# Just to find out what's going on, show some buttons instead of
# the actual widget code below
for i in range(3):
btn = wx.Button(self.container.GetPane(), label=f"{name}{i}")
self.itemGrid.Add(btn, 0, wx.ALL | wx.EXPAND, 2)
# self.itemGrid = wx.FlexGridSizer(0, 2, 0, 0)
# self.itemGrid.AddGrowableCol(1)
# self.itemGrid.SetFlexibleDirection(wx.BOTH)
# self.itemGrid.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED)
# self.items = {
# name: DummyWidget(self.container.GetPane(), name, param)
# for name, param in section.items()
# }
# for widget in self.items.values():
# print(
# f"Adding a widget: {widget.name}; {widget.label}, {widget.widget}")
# self.itemGrid.Add(widget.label, 0, wx.ALL |
# wx.ALIGN_CENTER_VERTICAL | wx.EXPAND | wx.RIGHT, 5)
# self.itemGrid.Add(widget.widget, 0, wx.ALL |
# wx.ALIGN_CENTER_VERTICAL | wx.EXPAND | wx.RIGHT, 5)
self.container.GetPane().SetSizer(self.itemGrid)
self.onResize()
def onResize(self):
self.itemGrid.Layout()
self.container.GetPane().Fit()
self.container.Fit()
class PanelizeDialog(wx.Dialog):
def __init__(self, parent=None, board=None):
wx.Dialog.__init__(
self, parent, title='Specify which components to hide',
style=wx.DEFAULT_DIALOG_STYLE | wx.MAXIMIZE_BOX | wx.MINIMIZE_BOX | wx.RESIZE_BORDER)
self.SetSizeHints(wx.Size(400, 600), wx.Size(-1, 1000))
self.Bind(wx.EVT_CLOSE, self.OnCancel, id=self.GetId())
topMostBoxSizer = wx.BoxSizer(wx.VERTICAL)
self.scrollWindow = wx.ScrolledWindow(
self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.VSCROLL)
self.scrollWindow.SetScrollRate(5, 5)
self.scrollWindow.SetBackgroundColour(
wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHT))
sectionsSizer = wx.BoxSizer(wx.VERTICAL)
self.sections = {
name: SectionGui(self.scrollWindow, name, section,
lambda evt: self.OnResize())
for name, section in availableSections.items()
}
for section in self.sections.values():
sectionsSizer.Add(section.container, 0, wx.ALL | wx.EXPAND, 5)
self.scrollWindow.SetSizer(sectionsSizer)
topMostBoxSizer.Add(self.scrollWindow, 1, wx.EXPAND | wx.ALL, 5)
button_box = wx.BoxSizer(wx.HORIZONTAL)
cancelButton = wx.Button(self, label='Cancel')
self.Bind(wx.EVT_BUTTON, self.OnCancel, id=cancelButton.GetId())
button_box.Add(cancelButton, 1, wx.RIGHT, 10)
self.okButton = wx.Button(self, label='Panelize')
self.Bind(wx.EVT_BUTTON, self.OnCreate, id=self.okButton.GetId())
button_box.Add(self.okButton, 1)
topMostBoxSizer.Add(button_box, 0, wx.ALIGN_RIGHT |
wx.LEFT | wx.RIGHT | wx.BOTTOM, 20)
self.SetSizer(topMostBoxSizer)
self.OnResize()
def OnResize(self):
for section in self.sections.values():
section.onResize()
self.scrollWindow.FitInside()
self.Fit()
def OnCancel(self, event):
self.EndModal(0)
def OnCreate(self, event):
self.EndModal(1)
if __name__ == "__main__":
# Run test dialog
app = wx.App()
dialog = PanelizeDialog()
dialog.ShowModal()
app.MainLoop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment