El 28/02/2011 01:05 p.m., Robin Dunn escribi�:
Hello list!..
Am designing a piping software, right now it works on 2D. I implemented
a very simple canvas with wx.paintDC() it basically goes like this:
def OnDrawing(self, evt):
dc = wx.PaintDC(self.leftWindow)
self.leftWindow.PrepareDC(dc)
dc.Clear()
for image in self.images[1:]:
x = image[1][0]
y = image[1][1]
img = wx.Image(image[0], wx.BITMAP_TYPE_ANY)
bmp = wx.BitmapFromImage(img)
dc.DrawBitmap(bmp, x, y, True)
What is image[0]? If it's the filename of the tile to be painted then you'll save a lot of time and resources by preloading those bitmaps and reusing them. Also, you don't need to load into a wx.Image if all you're going to do with it is convert it to a bitmap. wx.Bitmap can load the file itself.
yes its the files. I have this:
def workingImages(self):
return {self.rightButtonsData()[0][1] : ("img/pipesmallH.png", (100, 10)),
self.rightButtonsData()[1][1] : ("img/pipesmallV.png", (10, 100)),
self.rightButtonsData()[2][1] : ("img/bendsmallSE.png", (17, 17)),
self.rightButtonsData()[3][1] : ("img/bendsmallNO.png", (17, 17)),
self.rightButtonsData()[4][1] : ("img/bendsmallSO.png", (17, 17)),
self.rightButtonsData()[5][1] : ("img/bendsmallNE.png", (17, 17)),
self.rightButtonsData()[6][1] : ("img/valvesmallH.png", (14, 12)),
self.rightButtonsData()[7][1] : ("img/valvesmallV.png", (14, 12)),
self.rightButtonsData()[8][1] : ("img/contrsmallH.png", (15, 10)),
self.rightButtonsData()[9][1] : ("img/contrsmallV.png", (10, 15)),
self.rightButtonsData()[10][1] : ("img/180bendsmallE.png", (15, 23)),
self.rightButtonsData()[11][1] : ("img/180bendsmallN.png", (23, 15)),
self.rightButtonsData()[12][1] : ("img/180bendsmallO.png", (15, 23)),
self.rightButtonsData()[13][1] : ("img/180bendsmallS.png", (23, 15))
}
and I have a function that respond with every buttons click, that depending on the button, it appends entries on a self.image list that is used in the OnDrawing.
Honestly although the program works fine, being my first project in python and wxpython (and programming in general) I expect a lot of "things can be done better" and a bad coding style, am working on improving all that, so thank you for the tips!!..
Finally, I expect that you're seeing a lot of flicker on Windows as the paint event method is working. You should learn about doing double-buffered drawing to see what alternate approaches you could take to minimize the flicker. There are some examples in the wiki.
I haven't notice any (maybe I just haven't gave any attention to that) but thanks for the recommendation..
The result is this [1]. The buttons on the right are used to add
sections (pipes, valves, etc) to the canvas. when you click on a button
the program calculate the position and draw it, so the canvas its non
interactive, you cant clic on the segments of pipe or valves, cant
resize it, etc.
This its very easy and simple, but as a new programmer it cost me some
time (and am fairly proud of it). now I want to improve that, what I
want to do now is to create a 3D-like interactive canvas, where the user
could create "by mouse" the pipe diagram, click on them to change
properties etc.
what am aiming for its something like these [2] [3]. with a isometric
background like this [4]
I guess thats not going to be easy (but neither was for me at the
beginning what I did), but am decided to keep trying and studying to
make it. What I want from you guys is directions..
Now I dont know where to start, am wondering "is this possible on wx?",
"should I use openGL?". I need you to point to the right direction.
is this possible to implement with only wx? or I need pyopengl (witch I
dont know anything about), or something like that?
It can all be done in plain wx, but I expect that something done with OpenGL would look lots better, and if you want to do things like rotate the drawing in 3D space then something like OpenGL is probably the only approach you should take. I don't know a whole lot about it myself however so I can't give you any idea about relative complexities.
I only need things like zoom-in and zoom-out, and that the objects being draw to respond to mouse click..
as the images show, I wont be creating a 3D structure, I just need a 3D-like background, more precisely an isometric one, to draw piping representation, this image [0] show exactly what I want to do (without the yellow, blue and green part I just want the program to be able to make the piping diagram)
Now that you said that it can be done with wx, can you gave me some pointers on how to implement it?. last time I tried I didn't find a way to make the objects being draw to respond to mouse click.
Do you think that pygame could do the trick too? as long as it can be used with wx I could try anything..
[0] http://img13.imageshack.us/i/pipemht.jpg/sr=1
···
On 2/27/11 12:43 PM, PythonJourney wrote: