Thread: [Boa Constr] newbie question -- using Boa for creating a drawing canvas
Status: Beta
Brought to you by:
riaan
From: John B. <joh...@om...> - 2002-07-03 22:06:48
|
Hello: I am new and hoping to complete an easy (?) project. In a nutshell, I need to place a gif pic (a pic of a graph) on a frame, then draw litle boxes around points on the graph and collect the coordinates for the box centers. Sounds simple enough....but I downloaded Boa and see that it has no canvas tab on the Editor window. How does one go about placing a drawing canvas on a frame using Boa? Any help is appreciated. John John Boik Oregon Medical Press www.ompress.com joh...@om... |
From: John B. <jbe...@ya...> - 2002-07-04 02:30:29
|
Hi John, --- John Boik <joh...@om...> wrote: > Hello: > I am new and hoping to complete an easy (?) project. > In a nutshell, I need > to place a gif pic (a pic of a graph) on a frame, > then draw litle boxes > around points on the graph and collect the > coordinates for the box centers. > Sounds simple enough....but I downloaded Boa and see > that it has no canvas > tab on the Editor window. How does one go about > placing a drawing canvas on > a frame using Boa? I presume that what you mean is that you can't find any form of "Canvas" type control on the Palette. This is not surprising since wxPython has no control of this type. You need to associate a Device Context with the frame and draw to that. There should be an example in the wxPython demo. From a Boa integration point of view your options are either to add the extra code in the __init__ block by hand (along with required event handlers in the module block) or to build a canvas class as a derived class of one of the container classes, maintaining the same initialisation signature as the container class and then use it as a Custom Class (see Boa documentation). John Bell > > Any help is appreciated. John > > John Boik > Oregon Medical Press > www.ompress.com > joh...@om... > > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > No, I will not fix your computer. > http://thinkgeek.com/sf > _______________________________________________ > Boa-constructor-users mailing list > Boa...@li... > https://lists.sourceforge.net/lists/listinfo/boa-constructor-users __________________________________________________ Do You Yahoo!? Sign up for SBC Yahoo! Dial - First Month Free http://sbc.yahoo.com |
From: John B. <joh...@om...> - 2002-07-04 04:54:20
|
Thanks for the help John. But I see (at least) one more problem. Does anyone have a suggestion? I can build a canvas class as a derived class of one of the container classes, maintaining the same initialisation signature as the container class and then using it as a Custom Class, as suggested, but it produces errors because the wxShapeCanvas widget that I need to use does not take "name=..." in its constructor. Because all the other containers do, they would all produce an error. Short of hand typing the whole thing in for the widget, does anyone have a suggestion as to how to get around the "name=..." problem in defining the new constructor? John |
From: Riaan B. <riaan@e.co.za> - 2002-07-04 11:45:16
|
Hi John, John Boik wrote: > > Thanks for the help John. But I see (at least) one more problem. Does > anyone have a suggestion? I can build a canvas class as a derived class of > one of the container classes, maintaining the same initialisation signature > as the container class and then using it as a Custom Class, as suggested, > but it produces errors because the wxShapeCanvas widget that I need to use > does not take "name=..." in its constructor. Because all the other > containers do, they would all produce an error. Short of hand typing the > whole thing in for the widget, does anyone have a suggestion as to how to > get around the "name=..." problem in defining the new constructor? John Bell gave the correct advice, but wxShapeCanvas is unfortunately an exception to convention of supporting a 'name' keyword argument. Just for consistency I wish this could be added to wxWindows, Robin? Personally I think you should do the creation of the wxShapeCanvas manually after the generated code is called in __init__. This is what I always do with the dynamic or non supported elements of any wxFrame. If you do have compelling reasons to want the object (or it's nearest equivalent which is wxScrolledWindow) in the design time environment you may define a small adapter class which just wraps the constructor signature (untested). class wxBoaShapeCanvas(wxShapeCanvas): def __init__(self, parent=None, id=-1, pos=wxDefaultPos, size=wxDefaultSize, style=wxBORDER, name='shapecanvas'): wxShapeCanvas.__init__(parent, id, pos, size, style) self.SetName(name) with _custom_classes = {'wxScrolledWindow': ['wxBoaShapeCanvas']} > John HTH, Riaan. |
From: John B. <joh...@om...> - 2002-07-05 02:21:12
|
Thanks Riaan. I had to modify your suggestion a bit to get it working. Here is what I used: class wxBoaShapeCanvas(wxShapeCanvas): def __init__(self, parent=NULL, id=-1, pos=wxPoint(224, 16), size=wxSize(200, 304), style=wxBORDER, name='shapecanvas'): wxShapeCanvas.__init__(self, parent, id, pos, size, style) self.SetName(name) That seems to work OK. I have another question though. I would like to place a bitmap (or gif if I could) on the canvas and then be able to rotate it when I want. I could use the static bitmap control in Boa, but that references a filename for the bitmap. So if I want to rotate it (using image.Rotate() from PIL), I would have to open the file, rotate it, save it to a temp file, and then open it again with the bitmap control. Is there a more efficient way to do this? Unfortunately, wxShapeCanvas does not have methods to paste a bitmap to the canvas. I am very new (to OOP, Python, Boa), so maybe I am missing something here that would make the job easy. Any suggestions are appreciated. John John Boik Oregon Medical Press www.ompress.com joh...@om... |
From: John B. <joh...@om...> - 2002-07-05 05:09:47
|
I figured out an answer to my question on rotating bitmaps...never mind. And I was wrong about wxOGL not having a method to paste bitmaps. Cheers. John John Boik Oregon Medical Press www.ompress.com joh...@om... -----Original Message----- From: John Boik [mailto:joh...@om...] Sent: Thursday, July 04, 2002 9:21 PM To: Riaan Booysen Cc: Boa, Subject: RE: [Boa Constr] newbie question -- using Boa for creating a drawing canvas Thanks Riaan. I had to modify your suggestion a bit to get it working. Here is what I used: class wxBoaShapeCanvas(wxShapeCanvas): def __init__(self, parent=NULL, id=-1, pos=wxPoint(224, 16), size=wxSize(200, 304), style=wxBORDER, name='shapecanvas'): wxShapeCanvas.__init__(self, parent, id, pos, size, style) self.SetName(name) That seems to work OK. I have another question though. I would like to place a bitmap (or gif if I could) on the canvas and then be able to rotate it when I want. I could use the static bitmap control in Boa, but that references a filename for the bitmap. So if I want to rotate it (using image.Rotate() from PIL), I would have to open the file, rotate it, save it to a temp file, and then open it again with the bitmap control. Is there a more efficient way to do this? Unfortunately, wxShapeCanvas does not have methods to paste a bitmap to the canvas. I am very new (to OOP, Python, Boa), so maybe I am missing something here that would make the job easy. Any suggestions are appreciated. John John Boik Oregon Medical Press www.ompress.com joh...@om... |
From: John B. <joh...@om...> - 2002-07-05 18:41:29
|
Hello Riaan, John, and all. The wraparound for the wxShapeCanvas widget still seems to have one problem in it. I created the custom canvas, as we discussed, but it does not seem to handle mouse events. Using wxBell() as a test, I can get a mousedown event to ring the bell on a regular wxPanel, but on the new canvas it causes python to crash. No message is given, just a python crash. The applicable code is: class wxBoaShapeCanvas(wxShapeCanvas): def __init__(self, parent=NULL, id=-1, pos=wxPoint(224, 16), size=wxSize(200, 304), style=wxBORDER, name='shapecanvas'): wxShapeCanvas.__init__(self, parent, id, pos, size, style) self.SetName(name) ------------------------------- class wxFrame1(wxFrame): _custom_classes = {'wxScrolledWindow': ['wxBoaShapeCanvas']} def _init_ctrls(self, prnt): wxFrame.__init__(self, id = wxID_WXFRAME1, name = '', parent = prnt, pos = wxPoint(353, 110), size = wxSize(484, 424), style = wxDEFAULT_FRAME_STYLE, title = 'wxFrame1') self._init_utils() self.SetClientSize(wxSize(476, 397)) self.panel1 = wxPanel(id = wxID_WXFRAME1PANEL1, name = 'panel1', parent = self, pos = wxPoint(8, 0), size = wxSize(176, 384), style = wxTAB_TRAVERSAL) self.panel1.SetForegroundColour(wxColour(255, 128, 255)) self.panel1.SetBackgroundColour(wxColour(0, 255, 0)) EVT_LEFT_DOWN(self.panel1, self.OnPanel1LeftDown) self.scrolledWindow1 = wxBoaShapeCanvas(id = wxID_WXFRAME1SCROLLEDWINDOW1, name = 'scrolledWindow1', parent = self, pos = wxPoint(216, 16), size = wxSize(232, 368), style = wxTAB_TRAVERSAL) self.scrolledWindow1.SetForegroundColour(wxColour(128, 0, 255)) self.scrolledWindow1.SetBackgroundColour(wxColour(0, 0, 255)) EVT_LEFT_DOWN(self.scrolledWindow1, self.OnScrolledwindow1LeftDown) ----------------------------------- def OnScrolledwindow1LeftDown(self, event): wxBell() ------------------------------ Actually, the bell goes off and then Python crashes. Again, I am using Win XP. Any ideas as to why this might be occuring? I am stumped. I can, however, place a static bitmap on the canvas. That seems to work just fine. John John Boik Oregon Medical Press www.ompress.com joh...@om... |
From: Riaan B. <riaan@e.co.za> - 2002-07-05 20:57:02
|
Hi John, John Boik wrote: > > Hello Riaan, John, and all. The wraparound for the wxShapeCanvas widget > still seems to have one problem in it. I created the custom canvas, as we > discussed, but it does not seem to handle mouse events. Using wxBell() as a > test, I can get a mousedown event to ring the bell on a regular wxPanel, but > on the new canvas it causes python to crash. No message is given, just a > python crash. The applicable code is: <snipped> The problem is that you are using a wxShapeCanvas that has not been initialised properly. When it's initialised properly, it behaves and does not crash. Add the following code to your __init__ method beneath _init_ctrls: self.diagram = wxDiagram() self.diagram.SetCanvas(self.scrolledWindow1) self.scrolledWindow1.SetDiagram(self.diagram) I see you almost got this in the next mail you sent, close ;) Cheers, Riaan. |
From: Robin D. <ro...@al...> - 2002-07-06 18:35:44
|
> John Bell gave the correct advice, but wxShapeCanvas is unfortunately > an exception to convention of supporting a 'name' keyword argument. > > Just for consistency I wish this could be added to wxWindows, Robin? Done. -- Robin Dunn Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython! |
From: John B. <jbe...@ya...> - 2002-07-07 07:05:38
|
Hi John, I just thought that I'd jump in and offer a bit of meta-advice here. I know that jumping into an area like GUI programming can be a bit daunting if your primary area isn't computer science, and perhaps even more so when you're using Open Source code since this necessarily immerses you in the playpen of us CS types :-) I apologise if any of this advice is redundant to you, but I have no way of knowing exactly what you have and haven't worked out to date. Firstly, let's look at the subject of what list to post any specific question to. The important thing here is to understand that the code generated by Boa runs stand-alone. That is, Boa is not used only in the design process. It is not invoked at run time. Therefore any problem encountered at run time is almost certainly a non-Boa problem and should be directed to the wxPython list. Similarly, any question of the type "How do I get widget XXX to do YYY?" is best directed to the wxPython list. You can be assured that all the "top" wxPython people know Boa and will have no problems understanding your code. A lot more people read the wxPython list including many non-CS types (even some medical researchers :-) ) You should direct questions/grizzles re. code generation and generated code to the Boa list. On the subject of what platform to use, you're really best off with the CVS version of boa, wxPython/Windows 2.3.2.1. Have you got CVS under control yet? I'd advise against working on CVS versions of wxPython/Windows as these are HIGHLY volatile and often introduce new method signatures that Boa won't understand. John --- Robin Dunn <ro...@al...> wrote: > > John Bell gave the correct advice, but > wxShapeCanvas is unfortunately > > an exception to convention of supporting a 'name' > keyword argument. > > > > Just for consistency I wish this could be added to > wxWindows, Robin? > > Done. > > -- > Robin Dunn > Software Craftsman > http://wxPython.org Java give you jitters? Relax > with wxPython! > > > > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Got root? We do. > http://thinkgeek.com/sf > _______________________________________________ > Boa-constructor-users mailing list > Boa...@li... > https://lists.sourceforge.net/lists/listinfo/boa-constructor-users __________________________________________________ Do You Yahoo!? Sign up for SBC Yahoo! Dial - First Month Free http://sbc.yahoo.com |