Ultimately I will need a rack designer and a rack viewer, the attached
is a very simple/rudimentary designer.
I used aui to manage a 'rack element' toolbar and the canvas. The user
would then be allowed to "compose" his rack configuration by clicking on
the appropriate rack elements.
The left toolbar button creates what I call a "single stacked rack"
(blue circles), in the real world these come in any kind of dimension
but I just have it hard coded with 20 rows and 10 columns, the right one
does a "double stacked rack" (blue circles are the "front" bottles, red
circles are the "back" bottles.
For some reason I have to detach the toolbar for the two buttons to
become active (they will have some kind of an image to indicate the type
of rack element they will add) - will have to figure out what is the
cause of this problem.
My questions:
- what would I need to do to be able to move individual elements, i.e.
move the double stacked rack independently from the single stacked one?
Does this have to do with the group hierarchy?
- is there something obvious which could be done to speed the creation
of a rack up a bit?
- in the real world I would like to "append" an element to whatever
exists, so instead of hard coding "202" on line 137 I would like to get
the "right" edge position of the right most element - actually it could
be the right edge of the canvas - what is the right method to call to
get this information?
- each bottle (red/blue circle) needs have some additional information
attached - in my old version I have a "ShapeMixin" would this be the
right approach too?
Sorry if some of this is a bit basic - I am still fighting to get to
grips with all of this.
Werner
#Boa:Frame:Frame1
import wx
import wx.lib.agw.aui as aui
# import the floatcanvas2 module
import wx.lib.floatcanvas2.floatcanvas as fc
import gettext
def create(parent):
return Frame1(parent)
[wxID_FRAME1, wxID_FRAME1PANEL1,
] = [wx.NewId() for _init_ctrls in range(2)]
class Frame1(wx.Frame):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
pos=wx.Point(629, 274), size=wx.Size(689, 470),
style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
self.SetClientSize(wx.Size(673, 432))
self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self,
pos=wx.Point(0, 0), size=wx.Size(673, 432),
style=wx.TAB_TRAVERSAL)
def __init__(self, parent):
self._init_ctrls(parent)
# setup aui
self._mgr = aui.AuiManager()
self._mgr.SetManagedWindow(self.panel1)
self.canvas = fc.NavCanvas( self.panel1, backgroundColor = 'white' )
self._mgr.AddPane(self.canvas.mainPanel, aui.AuiPaneInfo().
Name("Canvas").Caption('Canvas').
CenterPane().MinimizeButton(False).MaximizeButton(True))
# create toolbar
self.myTB = wx.ToolBar(self, -1, wx.DefaultPosition, wx.DefaultSize,
wx.TB_FLAT | wx.TB_NODIVIDER)
self.myTB.SetToolBitmapSize(wx.Size(32,32))
self.CreateMyToolBar()
self._mgr.AddPane(self.myTB, aui.AuiPaneInfo().
Name("Toolbar").Caption('Toolbar').
ToolbarPane().Top().
LeftDockable(False).RightDockable(False))
self._mgr.Update()
## self.addRackUnit(self.canvas)
## self.addRackUnit2(self.canvas)
self.canvas.zoomToExtents()
def CreateMyToolBar(self):
toolSize = (32, 32)
self.myTB.SetToolBitmapSize(toolSize)
self.myTB.SetBackgroundColour(self.GetBackgroundColour())
bmp = wx.EmptyBitmap(32, 32)
bmpDA = wx.EmptyBitmap(32, 32)
self.wxId_myTBSingleStack =wx.NewId()
## img = myimages.getbottlePurImage()
## imgGO = myimages.getbottlePurImage()
## imgutil.grayOut(imgGO)
## bmp = wx.BitmapFromImage(img)
## bmpDA = wx.BitmapFromImage(imgGO)
self.myTB.AddLabelTool(label = u'Add a single stack rack',
bitmap = bmp,
bmpDisabled = bmpDA,
id = self.wxId_myTBSingleStack,
longHelp = u'',
shortHelp = u'')
self.Bind(wx.EVT_TOOL, self.addRackUnit, id=self.wxId_myTBSingleStack)
self.wxId_myTBDoubleStack =wx.NewId()
self.myTB.AddLabelTool(label = u'Add a double stack rack',
bitmap = bmp,
bmpDisabled = bmpDA,
id = self.wxId_myTBDoubleStack,
longHelp = u'',
shortHelp = u'')
self.Bind(wx.EVT_TOOL, self.addRackUnit2, id=self.wxId_myTBDoubleStack)
self.myTB.Realize()
self.myTB.EnableTool(self.wxId_myTBSingleStack, True)
self.myTB.EnableTool(self.wxId_myTBDoubleStack, True)
self.myTB.Refresh()
def addRackUnit(self, evt):
"""a single stacked bottle rack"""
wx.BeginBusyCursor()
rackUnit = self.canvas.create( 'Group', name = 'Rack Unit' )
rackFrame = self.canvas.createRectangle( (200, 400), pos = (0, 0), look = ('black', 'white'), where = 'back', parent = rackUnit )
bLook = fc.OutlineLook( line_colour = 'blue', width = 1)
nRows = 20
startRowPos = -210
nCols = 10
startColPos = -110
for rowPos in range(nRows):
startRowPos += 20
actColPos = startColPos
for colPos in range(nCols):
actColPos += 20
botName = 'Bottle %i' % colPos
self.canvas.create( 'Circle', 10, name = botName, pos = (actColPos, startRowPos), look = bLook, parent = rackFrame)
self.canvas.zoomToExtents()
wx.EndBusyCursor()
def addRackUnit2(self, evt):
"""a double stacked bottle rack"""
wx.BeginBusyCursor()
rackUnit = self.canvas.create( 'Group', name = 'Rack Unit' )
rackFrame = self.canvas.createRectangle( (200, 400), pos = (202, 0), look = ('black', 'white'), where = 'back', parent = rackUnit )
# front stack
bLook = fc.OutlineLook( line_colour = 'blue', width = 1)
nRows = 20
startRowPos = -210
nCols = 10
startColPos = -110
for rowPos in range(nRows):
startRowPos += 20
actColPos = startColPos
for colPos in range(nCols):
actColPos += 20
botName = 'Bottle %i' % colPos
self.canvas.create( 'Circle', 10, name = botName, pos = (actColPos, startRowPos), look = bLook, parent = rackFrame)
# back stack
bLook = fc.OutlineLook( line_colour = 'red', width = 1)
nRows += -1
startRowPos = -200
nCols += -1
startColPos = -100
for rowPos in range(nRows):
startRowPos += 20
actColPos = startColPos
for colPos in range(nCols):
actColPos += 20
botName = 'Bottle %i' % colPos
self.canvas.create( 'Circle', 5, name = botName, pos = (actColPos, startRowPos), look = bLook, parent = rackFrame)
self.canvas.zoomToExtents()
wx.EndBusyCursor()
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = create(None)
frame.Show()
app.MainLoop()
_______________________________________________
FloatCanvas mailing list
[email protected]
http://paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas