Sorry, I should have included a sample.
#!/usr/bin/python
import wx
from wx.lib import scrolledpanel as scrolled
class GUI(wx.Frame):
def init(self, parent):
wx.Frame.init(self, parent, size=(1024, 786))
tabs = wx.Notebook(self)
self.board = DrawingPanel(tabs)
tabs.AddPage(self.board, “Tab 1”)
box = wx.BoxSizer(wx.HORIZONTAL) # position windows side-by-side
box.Add(tabs, 2, wx.EXPAND)
self.SetSizer(box)
menu = wx.MenuBar()
_file = wx.Menu()
_file.Append(wx.ID_NEW, "Resize\tCtrl-R")
menu.Append(_file, "&File")
self.SetMenuBar(menu)
self.Bind(wx.EVT_MENU, self.show, id=wx.ID_NEW)
def show(self, e):
dlg = Resize(self)
dlg.ShowModal()
dlg.Destroy()
class DrawingPanel(wx.ScrolledWindow):
def init(self, tab):
wx.ScrolledWindow.init(self, tab)
self.virtual_size = (1000, 1000)
self.SetVirtualSizeHints(2, 2)
self.SetVirtualSize(self.virtual_size)
self.SetScrollRate(3, 3)
self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM) # no flicking on Windows!
self.SetBackgroundColour("White")
self.ClearBackground()
self.Bind(wx.EVT_PAINT, self.paint)
def paint(self, event):
dc = wx.AutoBufferedPaintDC(self)
dc.Clear()
dc.DrawText("Thing!", 100, 100)
class Resize(wx.Dialog):
“”"
Allows the user to resize a sheet’s canvas
“”"
def init(self, gui):
“”"
Two text controls for inputting the size, limited to integers only
using a Validator class
“”"
wx.Dialog.init(self, gui, title=“Resize Canvas”)
self.gui = gui
gap = wx.LEFT | wx.TOP | wx.RIGHT
width, height = self.gui.board.virtual_size
csizer = wx.GridSizer(cols=2, hgap=1, vgap=2)
self.hctrl = wx.TextCtrl(self)
self.wctrl = wx.TextCtrl(self)
csizer.Add(wx.StaticText(self, label="Width:"), 0, wx.TOP | wx.ALIGN_RIGHT, 10)
csizer.Add(self.wctrl, 1, gap, 7)
csizer.Add(wx.StaticText(self, label="Height:"), 0, wx.TOP | wx.ALIGN_RIGHT, 7)
csizer.Add(self.hctrl, 1, gap, 7)
self.hctrl.SetValue(str(height))
self.wctrl.SetValue(str(width))
self.okButton = wx.Button(self, wx.ID_OK, "&OK")
self.okButton.SetDefault()
self.cancelButton = wx.Button(self, wx.ID_CANCEL, "&Cancel")
btnSizer = wx.StdDialogButtonSizer()
btnSizer.Add(self.okButton, 0, wx.BOTTOM | wx.RIGHT, 5)
btnSizer.Add(self.cancelButton, 0, wx.BOTTOM | wx.LEFT, 5)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(csizer, 0, gap, 7)
sizer.Add((10, 10)) # Spacer.
btnSizer.Realize()
sizer.Add(btnSizer, 0, gap | wx.ALIGN_CENTRE, 5)
self.SetSizer(sizer)
self.okButton.Bind(wx.EVT_BUTTON, self.ok)
def ok(self, event):
"""
Set the virtual canvas size
"""
value = (int(self.wctrl.GetValue()), int(self.hctrl.GetValue()))
board = self.gui.board
board.virtual_size = value
board.SetVirtualSize(value)
#board.SetSize(value)
board.SetBackgroundColour("Grey")
board.ClearBackground()
self.Close()
class TestApp(wx.App):
def OnInit(self):
frame = GUI(None)
frame.Show(True)
return True
if name == ‘main’:
app = TestApp()
app.MainLoop()
Copy of sample.py (3.38 KB)