Skip to content

Instantly share code, notes, and snippets.

@chadcooper
Last active December 16, 2015 15:59
Show Gist options
  • Save chadcooper/5460273 to your computer and use it in GitHub Desktop.
Save chadcooper/5460273 to your computer and use it in GitHub Desktop.
Experimenting with building a cartesian-quadrant-like array of textboxes with a crosshair of lines separating them.
import wx
class MyPanel(wx.Panel):
def __init__(self, parent, _id):
wx.Panel.__init__(self, parent, _id)
self.SetBackgroundColour("white")
default_font = wx.Font(9, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)
self.SetFont(default_font)
self.nw_label = wx.StaticText(self, -1, "N of W", pos=(100, 100),
size=wx.DefaultSize)
self.tb_nw = wx.TextCtrl(self, -1, value="", pos=(110, 120),
size=(30, -1))
self.ne_label = wx.StaticText(self, -1, "N of E", pos=(160, 100),
size=wx.DefaultSize)
self.tb_ne = wx.TextCtrl(self, -1, value="", pos=(160, 120),
size=(30, -1))
self.se_label = wx.StaticText(self, -1, "S of E", pos=(160, 190),
size=wx.DefaultSize)
self.tb_se = wx.TextCtrl(self, -1, value="", pos=(160, 160),
size=(30, -1))
self.sw_label = wx.StaticText(self, -1, "S of W", pos=(100, 190),
size=wx.DefaultSize)
self.tb_sw = wx.TextCtrl(self, -1, value="", pos=(110, 160),
size=(30, -1))
self.Bind(wx.EVT_PAINT, self.OnPaint)
def OnPaint(self, evt):
"""set up the device context (DC) for painting"""
self.dc = wx.PaintDC(self)
self.dc.BeginDrawing()
self.dc.SetPen(wx.Pen("grey", style=wx.SOLID, width=2))
# Draw crosshair lines
self.dc.DrawLine(150, 90, 150, 210) # vert
self.dc.DrawLine(90, 150, 210, 150) # horiz
self.dc.EndDrawing()
del self.dc
app = wx.PySimpleApp()
frame = wx.Frame(None, -1, "Drawing stuff...", size=(300, 300))
MyPanel(frame, -1)
frame.Show(True)
app.MainLoop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment