Wine rack designer
I had the need to allow the user to design their wine racks. There are "standard" wine racks were one stores a bottle in each bin, this I implemented with a wx.Grid, however there are many other wine rack shapes which can not be represented by a grid (or at least not that easily).
I looked at wx.FloatCanvas and wx.lib.ogl to create a designer, I created prototypes using both of them (with lots of help from Chris and others) for the designer (which I will exand on below) and a viewer.
Requirements
- As I use the amara xml tool kit for other uses, I used it for the rack designer too. You can get it from here:
http://uche.ogbuji.net/tech/4suite/amara/
- The wx.FloatCanvas version also requires numpy or numeric
OGL Implementation comments
The code below allows you to add predefined shapes (currently rectangles and different size triangles), these shapes allow you to create a wine rack which is made of large bins. Each bin can hold many bottles, typically 6 bottles and more, my own rack has bins which can hold 6, 12, 18 or 32 bottles and they are stored back to back.
I was not interested in showing each of the bottles (for this type of rack) but just each bin, that is what defined the shapes. They allow to create square/rectangle bins, half squares and diamond shaped bins (i.e. a square bin divided into four triangles).
The rack design is saved as XML into a blob field in the database and can be retrieved from there to change it or just to view it. The sample code below has all the database related code commented out and the save button is actually just "printing" the xml.
In the application I also have a rack viewer, which just shows the rack design and indicates what type of wine is in which bin (using different colors for the bins) and gives some details about the wine in a bin when one clicks on a shape.
Here is an image on how this might look:
FloatCanvas Implementation comments
The code allows you to add predefined shapes (currently rectangles and different size triangles), these shapes allow you to create a wine rack which is made of large bins. Each bin can hold many bottles, typically 6 bottles and more, my own rack has bins which can hold 6, 12, 18 or 32 bottles and they are stored back to back.
I was not interested in showing each of the bottles (for this type of rack) but just each bin, that is what defined the shapes. They allow to create square/rectangle bins, half squares and diamond shaped bins (i.e. a square bin divided into four triangles).
The rack design is saved as XML into a blob field in the database and can be retrieved from there to change it or just to view it. The sample code has some "inline" code to import from XML and allows to save (in the sample to stdout) to XML.
The code
As it is a bit long for a wiki I have attached (winerackdesigner.zip) and it contains:
rackdesigner.py - the OGL version
rackdesignerFC.py - the FloatCanvas version
myimages.py - images used for the toolbar
Notes
It would be nice if aligning of rectangles and triangles would work better, they are a few pixels ouf of line. Tried SetGridSpacing to help in this but if anything it makes it only worse. - Maybe something to do with how I create the triangles?
- Would be nice to be able to select all existing shapes and move them all in one go, instead of moving a shape at the time.
Comments
Feel free to make changes and/or suggestions to this on this page, or you can send them to me at werner.bruhin at free.fr.