Im sorry for what I know is a really basic question, but Ive spent an hour
searching and trying different things and cant figure it out, so im turning
here for help.
Hopefully this code example isnt too basic, im trying to keep it concise. I
know how to draw on the screen, and can do it as long as my functions are
inside the class, how do I do it from a function outside the class? Id
rather have the function im passing the variable to handle the drawing
instead of returning data back to the original function and then doing the
drawing from there.
import wx
class Example(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, 'example', size = (600, 400))
panel = wx.Panel(self)
button = wx.Button(panel, label='DoStuff', pos=(300,300),
size=(60,40))
self.Bind(wx.EVT_BUTTON, self.DoStuff, button)
def DoStuff(self, event):
var1 = 123
morestuff(var1)
def morestuff(num):
do some math
blah blah blah
draw on screen
Again, Im sorry for such a basic level question that Im sure I should be
able to figure out on my own, but I seem to be stuck. Thanks ---Justin
···
--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/nOOb-question-drawing-to-panel-from-a-function-outside-the-class-tp5716805.html
Sent from the wxPython-users mailing list archive at Nabble.com.
Justin Merrell wrote:
Hopefully this code example isnt too basic, im trying to keep it concise. I
know how to draw on the screen, and can do it as long as my functions are
inside the class, how do I do it from a function outside the class? Id
rather have the function im passing the variable to handle the drawing
instead of returning data back to the original function and then doing the
drawing from there.
What kind of drawing are you trying to do? Most drawing just requires a
DC. As long as you pass a DC to your "morestuff" function, it can call
whatever methods of that object that it needs to.
Please remember that all drawing has to be done in the main thread. If
you're using threading, then it's often easier to send a message to the
window that triggers the drawing.
···
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
why? it's hard to tell what you have in mind, but in general, you
probably want to wrap up all the drawing code in one place -- i.e. a
class.
but if there really is good reason to put it elsewhere, generally one
creates the appropriate DC in a wx.Windows class, then passes that DC
on to drawing functions.
-Chris
···
On Mon, Apr 1, 2013 at 10:11 AM, Justin Merrell <justin@toxicshock.biz> wrote:
Im sorry for what I know is a really basic question, but Ive spent an hour
searching and trying different things and cant figure it out, so im turning
here for help.
Hopefully this code example isnt too basic, im trying to keep it concise. I
know how to draw on the screen, and can do it as long as my functions are
inside the class, how do I do it from a function outside the class? Id
rather have the function im passing the variable to handle the drawing
instead of returning data back to the original function and then doing the
drawing from there.
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov
El 01/04/2013 19:11, Justin Merrell escribi�:
Im sorry for what I know is a really basic question, but Ive spent an hour
searching and trying different things and cant figure it out, so im turning
here for help.
Hopefully this code example isnt too basic, im trying to keep it concise. I
know how to draw on the screen, and can do it as long as my functions are
inside the class, how do I do it from a function outside the class? Id
rather have the function im passing the variable to handle the drawing
instead of returning data back to the original function and then doing the
drawing from there.
import wx
class Example(wx.Frame):
......
def DoStuff(self, event):
var1 = 123
# morestuff(var1)
morestuff(var1, self)
def morestuff(var1, FrameInstance)
# Here use FrameInstante as self inside class frame
...
···
--
Oswaldo
morestuff(var1, self)
def morestuff(var1, FrameInstance)
# Here use FrameInstante as self inside class frame
that could work, but you really don't want to do that!
if more stuff needs to know the fill Frame API, then it might as well
be a method of Frame.
-Chris
···
On Mon, Apr 1, 2013 at 1:26 PM, Oswaldo <listas@soft-com.es> wrote:
...
--
Oswaldo
--
You received this message because you are subscribed to the Google Groups
"wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov
Thank you so much for the help everyone, that answered my question
perfectly!!!
--Justin
···
--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/nOOb-question-drawing-to-panel-from-a-function-outside-the-class-tp5716805p5716814.html
Sent from the wxPython-users mailing list archive at Nabble.com.