Is this heading in the right direction? RIght now I'm not getting any output
at all, but am wondering if this is basically the right idea.
Thanks,
Gabriel
import wx
class MyFrame(wx.Frame):
def __init__(self):
wx.Frameinit__(self, None, -1, 'Global Context', size=(250,500))
self.panel = wx.Panelinit__(self,parent,id, size=(250,500))
self.SetBackgroundColour("Red")
self.color = "White"
self.thickness = 1
self.pen = wx.Pen(self.color, self.thickness, wx.SLID)
size = self.GetClientSize()
self.buffer = wx.EmptyBitmap(size.width, size.height)
EVT_PAINT(self.buffer, self.onPaint)
def onPaint(self):
dc = wx.BufferedPaintDC(None, self.buffer)
self.PrepareDC(dc)
dc.SetBackground(wx.Brush(self.GetBackgroundColour ()))
dc.Clear()
dc.BeginDrawing()
dc.SetPen(self.pen)
dc.DrawText('hello world', 60,65)
dc.DrawLine(20,20,30,30)
dc.EndDrawing()
app = wx.PySimpleApp(redirect='True')
frm = MyFrame()
frm.SetSize((250,500))
frm.Show()
app.SetTopWindow(frm)
app.MainLoop()
7/11/06, Lanier, Paul <Paul.Lanier (AT) analog (DOT) comwrote:
Put the drawing in a EVT_PAINT handler and use a wx.PaintDC or
wx.BufferedPaintDC.
-Paul
*From:* Gabriel Murray [mailto:gabriel.murray (AT) gmail (DOT) com]
*Sent:* Tuesday, July 11, 2006 11:16 AM
*To:* wxPython-users (AT) lists (DOT) wxwidgets.org
*Subject:* [wxPython-users] Re: drawing lines
As a follow-up on this, I've changed the code slighly here, but am still
not able to get lines drawn to the screen. Am I using the wrong type of dc?
I've not tried to draw lines with wxPython before, so am really not sure.
class MyFrame(wx.Frame):
def __init__(self):
wx.Frameinit__(self, None, -1, 'Global Context',
size=(250,500))
self.panel = MyPanel(self,-1)
class MyPanel(wx.Panel):
def __init__(self, parent, id):
wx.Panelinit__(self, parent, id, size=(250,500))
self.sketch = SketchWindow(self,-1)
--
class SketchWindow(wx.Window):
def __init__(self, parent, ID):
wx.Windowinit__(self, parent, ID, size=(250,500))
self.SetBackgroundColour("Red")
self.color = "White"
self.thickness = 1
self.pen = wx.Pen(self.color, self.thickness, wx.SLID)
size = self.GetClientSize()
self.buffer = wx.EmptyBitmap(size.width, size.height)
dc = wx.BufferedDC(None, self.buffer)
self.PrepareDC(dc)
dc.SetBackground(wx.Brush(self.GetBackgroundColour ()))
dc.Clear()
dc.BeginDrawing()
coords = [(12,13,12,14), (12,14,12,15), (12,15,12,16),
(13,16,13,17), (14,17,14,18)]
dc.SetPen(self.pen)
dc.DrawText('hello world', 60,65)
for eachcoord in coords:
dc.DrawLine(*eachcoord)
dc.EndDrawing()
--
7/11/06, Gabriel Murray <gabriel.murray (AT) gmail (DOT) comwrote:
Hello,
I am trying to use wxPython to draw some simple lines but am not getting
the results that I want. In my user interface, when the user makes certain
actions I want a window to pop up which will have certain multi-coloured
bars displaying some information to them.
This is the code I have for that window, with some sample coordinates
put in there. I get the window with a white background but no line. Do I
need to refresh it somehow after the line is drawn?
Thanks,
Gabriel
--
class PopupFrame(wx.Frame):
def __init__(self):
wx.Frameinit__(self, None, -1, 'Status Windowt',
size=(300,250))
self.sketch = SketchWindow(self,-1)
--
class SketchWindow(wx.Window):
def __init__(self, parent, ID):
wx.Windowinit__(self, parent, ID)
self.SetBackgroundColour("White")
self.color = "Black"
self.thickness = 1
self.pen = wx.Pen(self.color, self.thickness, wx.SLID)
self.InitBuffer()
--
def InitBuffer(self):
size = self.GetClientSize()
self.buffer = wx.EmptyBitmap(size.width, size.height)
dc = wx.BufferedDC(None, self.buffer)
dc.SetBackground(wx.Brush(self.GetBackgroundColour ()))
dc.Clear()
self.DrawLines(dc)
self.reInitBuffer = False
--
def DrawLines(self, dc):
coords = [(12,13,12,14), (12,14,12,15), (12,15,12,16),
(13,16,13,17), (14,17,14,18)]
for eachcoord in coords:
dc.DrawLine(*eachcoord)
>
>
>