Binding in multiple frame app

Hi,
I have an application with two frames, a parent and a child.
Resource for these frame are taxen from a xrc file.
The main frame has a button to show the child "VampireFrame".
VampireFrame has a button to became semi-transparent.
The problem is that when I start the application, the alphaCycle
method is fired even if I didn't press any button...
What is wrong with this code?

[code]
import wx
from wx import xrc
import random

class MainFrame(wx.Frame):
    def __init__(self,parent,resource):
        self.PostCreate(resource.LoadFrame(parent,"gigiwxcapture"))
        self.panel = xrc.XRCCTRL(self, "config")
        self.Bind(wx.EVT_BUTTON, self.OnVampireFrame,
id=xrc.XRCID("selectcapturewindow"))

        self.VampireFrame=VampireFrame(self,resource)

    def OnVampireFrame(self,evt):
        self.VampireFrame.Show()

class VampireFrame(wx.Frame):
    def __init__(self,parent,resource):
        self.PostCreate(resource.LoadFrame(parent,"vampireFrame"))
        self.Centre()
        self.SetBackgroundColour(wx.BLUE)
        self.Bind(wx.EVT_MOTION, self.ilmousesimuove)
        self.windowplaced = xrc.XRCCTRL(self,"windowplaced")
        self.windowplaced.Bind(wx.EVT_BUTTON, self.alphaCycle(self,
100))

    def ilmousesimuove(self,event):
        print "moving"

    def alphaCycle(self,dest,amount):
        dest.SetTransparent(amount)
        print "tras"

class MyApp(wx.App):
    def OnInit(self):
      resource=xrc.XmlResource("gigiwxGUI.xrc")
      self.MainFrame=MainFrame(None,resource)
      self.MainFrame.Show()
      return True

def main():
    app = MyApp(0)
    app.MainLoop()
if __name__ == '__main__':
    main()

[/code]

Another minor issue: the Centre method puts the child frame in the
centre of the parent frame, I'd like to put it in the centre if the
screen instead: how can I obtain this?

By doing this self.alphaCycle(self,100) you are actually calling the function thats why it gets invokes on startup. To bind events to a function you need to pass its reference like below.

self.windowplaced.Bind(wx.EVT_BUTTON, self.alphaCycle)

Like you did for self.onVampireFrame

···

On Thu, Dec 16, 2010 at 6:19 PM, andreaconsole andreaconsole@gmail.com wrote:

Hi,

I have an application with two frames, a parent and a child.

Resource for these frame are taxen from a xrc file.

The main frame has a button to show the child “VampireFrame”.

VampireFrame has a button to became semi-transparent.

The problem is that when I start the application, the alphaCycle

method is fired even if I didn’t press any button…

What is wrong with this code?

[code]

import wx

from wx import xrc

import random

class MainFrame(wx.Frame):

def __init__(self,parent,resource):

    self.PostCreate(resource.LoadFrame(parent,"gigiwxcapture"))

    self.panel = xrc.XRCCTRL(self, "config")

    self.Bind(wx.EVT_BUTTON, self.OnVampireFrame,

id=xrc.XRCID(“selectcapturewindow”))

    self.VampireFrame=VampireFrame(self,resource)



def OnVampireFrame(self,evt):

    self.VampireFrame.Show()

class VampireFrame(wx.Frame):

def __init__(self,parent,resource):

    self.PostCreate(resource.LoadFrame(parent,"vampireFrame"))

    self.Centre()

    self.SetBackgroundColour(wx.BLUE)

    self.Bind(wx.EVT_MOTION, self.ilmousesimuove)

    self.windowplaced = xrc.XRCCTRL(self,"windowplaced")

    self.windowplaced.Bind(wx.EVT_BUTTON, self.alphaCycle(self,

100))


Thanks & Regards,
Godson Gera
FreeSWITCH constultant India

Thanks a lot!
I wanted to pass amount parameter, but I see that I can pass it
trought an object property (self.alphaAmount).
About the "Centre()" issue, I found that the method CentreOnScreen is
what I was looking for.

···

On 16 Dic, 14:34, Godson Gera <godso...@gmail.com> wrote:

On Thu, Dec 16, 2010 at 6:19 PM, andreaconsole <andreacons...@gmail.com>wrote:

> Hi,
> I have an application with two frames, a parent and a child.
> Resource for these frame are taxen from a xrc file.
> The main frame has a button to show the child "VampireFrame".
> VampireFrame has a button to became semi-transparent.
> The problem is that when I start the application, the alphaCycle
> method is fired even if I didn't press any button...
> What is wrong with this code?

> [code]
> import wx
> from wx import xrc
> import random

> class MainFrame(wx.Frame):
> def __init__(self,parent,resource):
> self.PostCreate(resource.LoadFrame(parent,"gigiwxcapture"))
> self.panel = xrc.XRCCTRL(self, "config")
> self.Bind(wx.EVT_BUTTON, self.OnVampireFrame,
> id=xrc.XRCID("selectcapturewindow"))

> self.VampireFrame=VampireFrame(self,resource)

> def OnVampireFrame(self,evt):
> self.VampireFrame.Show()

> class VampireFrame(wx.Frame):
> def __init__(self,parent,resource):
> self.PostCreate(resource.LoadFrame(parent,"vampireFrame"))
> self.Centre()
> self.SetBackgroundColour(wx.BLUE)
> self.Bind(wx.EVT_MOTION, self.ilmousesimuove)
> self.windowplaced = xrc.XRCCTRL(self,"windowplaced")
> self.windowplaced.Bind(wx.EVT_BUTTON, self.alphaCycle(self,
> 100))

By doing this self.alphaCycle(self,100) you are actually calling the
function thats why it gets invokes on startup. To bind events to a function
you need to pass its reference like below.

self.windowplaced.Bind(wx.EVT_BUTTON, self.alphaCycle)

Like you did for self.onVampireFrame

--
Thanks & Regards,
Godson Gera
FreeSWITCH constultant
India<http://blog.godson.in/2010/12/use-of-returnringready-originate.html&gt;

If you want to pass arguments in the callback, then check this out:

http://wiki.wxpython.org/Passing%20Arguments%20to%20Callbacks

This should also be of interest to you:

http://wiki.wxpython.org/self.Bind%20vs.%20self.button.Bind

···

On Dec 16, 7:57 am, andreaconsole <andreacons...@gmail.com> wrote:

Thanks a lot!
I wanted to pass amount parameter, but I see that I can pass it
trought an object property (self.alphaAmount).
About the "Centre()" issue, I found that the method CentreOnScreen is
what I was looking for.

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org