Im trying to test a system of created one main panel that will house the
wx.DC that will pass that DC to all the attached items and then they will
draw on that DC. With this system you should be able to attach a sub-panel
to it along with any items to that sub-panel as well so that you can have
objects move around.
I basically trying to figure out a good way to build and manage complex
alpha based interfaces by drawing all the items to the main DC by getting
pos and size from other items that are attached to the panel.
Ive got most of it working
as you can see from the attached py script,
but some reason, that is a mystery to me, when you scale the window up.
the item2(sub) is getting blocked by a white box. Im not sure where
this box is coming from and not really sure how to get rid of it.
Im fairly new to python and even newer to wxPython, if Im going around
my head to scratch my @$$ here please tell me
if there is a simpler way
then please let me know
Thanks in advanced
-Keith
#!/usr/bin/env python
# -*- coding: ISO-8859-1 -*-
# generated by wxGlade 0.4.1 on Thu Apr 13 21:27:13 2006
import wx
class PaintPanel(wx.Panel):
def __init__(self, parent, id, sub = 0, *args, **kwds):
wx.Panel.__init__(self, parent, id, *args, **kwds)
self.parent = parent
self.sub =sub
self.items = []
## sub = Not DC Panel
if self.sub:
self.parent.AddItem(self)
self.Hide()
else:
pass
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
def AddItem(self, item):
## Add Item
self.items.append(item)
def RemoveItem(self, item):
## Remove Item
for i in self.items:
if(i == item):
self.items.remove(i)
def RemoveAll(self):
## Remove All Items
self.items.clear()
def OnPaint(self, event):
self.sizeX, self.sizeY = self.GetSize()
print "position is: " + str(self.GetPosition())
print "size is: " + str(self.GetSize())
## Setup Double Buffer DC
buffer = wx.EmptyBitmap(self.sizeX, self.sizeY)
memDC = wx.MemoryDC()
memDC.SelectObject(buffer)
dc = wx.PaintDC(self)
self.PrepareDC(dc)
memDC.SetBackground(wx.Brush("White"))
memDC.Clear()
self.Draw(memDC, self.GetPosition())
## Copy DC from MemoryDC
dc.Blit(0, 0, self.sizeX, self.sizeY, memDC, 0, 0, wx.COPY, True)
## Clean Up The DC
del memDC
del dc
def Draw(self, dc, pos):
## Draw All Attached Items
for item in self.items:
item.Draw(dc, self.GetPosition())
def OnEraseBackground(self, event):
pass
class PaintItem:
def __init__(self, parent, id, name = ""):
self.parent = parent
self.name = name
self.parent.AddItem(self)
def Draw(self, dc, pos):
dc.SetTextForeground("BLUE")
dc.SetFont(wx.Font(50, wx.SWISS, wx.NORMAL, wx.BOLD))
dc.DrawText( self.name, pos[0], pos[1])
class TestFrame(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: MyFrame1.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.panel = PaintPanel(self, -1)
item1 = PaintItem(self.panel, -1, name = "main")
self.subPanel= PaintPanel(self.panel, -1, sub = 1)
item2 = PaintItem(self.subPanel, -1, name = "sub")
self.__set_properties()
self.__do_layout()
# end wxGlade
def __set_properties(self):
# begin wxGlade: MyFrame1.__set_properties
self.SetTitle("frame_2")
# end wxGlade
def __do_layout(self):
# begin wxGlade: MyFrame1.__do_layout
sizer_1 = wx.BoxSizer(wx.HORIZONTAL)
grid_sizer_1 = wx.FlexGridSizer(3, 3, 0, 0)
grid_sizer_1.Add((20, 20), 0, wx.EXPAND, 0)
grid_sizer_1.Add((20, 20), 0, wx.EXPAND, 0)
grid_sizer_1.Add((20, 20), 0, wx.EXPAND, 0)
grid_sizer_1.Add((20, 20), 0, wx.EXPAND, 0)
grid_sizer_1.Add(self.subPanel, 1, wx.EXPAND, 0)
grid_sizer_1.Add((20, 20), 0, wx.EXPAND, 0)
grid_sizer_1.Add((20, 20), 0, wx.EXPAND, 0)
grid_sizer_1.Add((20, 20), 0, wx.EXPAND, 0)
grid_sizer_1.Add((20, 20), 0, wx.EXPAND, 0)
grid_sizer_1.Fit(self.panel)
grid_sizer_1.SetSizeHints(self.panel)
grid_sizer_1.AddGrowableRow(0)
grid_sizer_1.AddGrowableRow(1)
grid_sizer_1.AddGrowableRow(2)
grid_sizer_1.AddGrowableCol(0)
grid_sizer_1.AddGrowableCol(1)
grid_sizer_1.AddGrowableCol(2)
self.panel.SetAutoLayout(True)
self.panel.SetSizer(grid_sizer_1)
sizer_1.Add(self.panel, 1, wx.EXPAND, 0)
self.SetAutoLayout(True)
self.SetSizer(sizer_1)
sizer_1.Fit(self)
sizer_1.SetSizeHints(self)
self.Layout()
# end wxGlade
# end of class MyFrame1
class MyApp(wx.App):
def OnInit(self):
wx.InitAllImageHandlers()
frame = TestFrame(None, -1, "")
self.SetTopWindow(frame)
frame.Show()
return 1
# end of class MyApp
if __name__ == "__main__":
app = MyApp(0)
app.MainLoop()
--
http://mail.python.org/mailman/listinfo/python-list