Add more new Python code snippets

This commit is contained in:
Robin Dunn
2022-05-17 19:49:31 -07:00
parent 04cc18fbe8
commit eb04a7db0b
6 changed files with 65 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
# Create the combo control using its default ctor.
combo = wx.ComboCtrl()
# Create the custom main control using its default ctor too.
someMainWindow = SomeWindow()
# Set the custom main control before creating the combo.
combo.SetMainControl(someMainWindow)
# And only create it now: wx.TextCtrl won't be unnecessarily
# created because the combo already has a main window.
combo.Create(panel, wx.ID_ANY, wx.EmptyString)
# Finally create the main window itself, now that its parent was
# created.
someMainWindow.Create(combo, ...)

View File

@@ -0,0 +1,12 @@
listctrl = wx.ListCtrl(...)
for i in range(3):
listctrl.InsertColumn(i, wx.String.Format("Column %d", i))
order = [ 2, 0, 1]
listctrl.SetColumnsOrder(order)
# Now listctrl.GetColumnsOrder() will return order and
# listctrl.GetColumnIndexFromOrder(n) will return order[n] and
# listctrl.GetColumnOrder() will return 1, 2 and 0 for the column 0, 1 and 2
# respectively.

View File

@@ -0,0 +1,9 @@
def OnColClick(self, event):
col = event.GetColumn()
if col == -1:
return # clicked outside any column.
ascending = self.GetUpdatedAscendingSortIndicator(col)
self.SortItems(self.MyCompareFunction, ascending)
self.ShowSortIndicator(col, ascending)

View File

@@ -0,0 +1,12 @@
# In a frame's __init__
...
panel = wx.Panel(self)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(...)
sizer.Add(...)
panel.SetSizer(sizer)
# Use the panel sizer to set the initial and minimal size of the
# frame to fit its contents.
sizer.SetSizeHints(self)

View File

@@ -0,0 +1,3 @@
if wx.html2.WebView.IsBackendAvailable(wx.html2.WebViewBackendEdge):
# Do whatever you need to do when the Edge backend is available

View File

@@ -0,0 +1,12 @@
xrc_data = ... # Retrieve it from wherever.
xmlDoc = wx.xml.XmlDocument(io.BytesIO(xrc_data))
if not xmlDoc.IsOk():
... handle invalid XML here ...
return
if not wx.XmlResource.Get().LoadDocument(xmlDoc):
... handle invalid XRC here ...
return
... use the just loaded XRC as usual ...