Bind() for menu events

Hi,

  Trying to get the new Bind() working in 2.5.1.5, GTK2 without success. Here's the code sample I'm using:

import wx
class FileMenu(wx.Menu):
  def __init__(self, frame):
    wx.Menu.__init__(self)
    exitID = wx.NewId()
    exitItem = wx.MenuItem(self, exitID, "E&xit", "Outta Here")
    self.AppendItem(exitItem)
    wx.App_SetMacExitMenuItemId(exitID) self.Bind(wx.EVT_MENU, frame.onFileExit, exitItem, exitID)

  The menu shows up as expected on the frame, but selecting the exit item has no effect. If I use the old-style binding instead:

    wx.EVT_MENU(frame, exitID, frame.onFileExit)

everything works fine. What am I doing wrong?

      ___/
     /
    __/
   /
  ____/
  Ed Leafe
  http://leafe.com/
  http://opentech.leafe.com

Ed Leafe wrote:

Hi,

    Trying to get the new Bind() working in 2.5.1.5, GTK2 without success. Here's the code sample I'm using:

import wx
class FileMenu(wx.Menu):
    def __init__(self, frame):
        wx.Menu.__init__(self)
        exitID = wx.NewId()
        exitItem = wx.MenuItem(self, exitID, "E&xit", "Outta Here")
        self.AppendItem(exitItem)
        wx.App_SetMacExitMenuItemId(exitID) self.Bind(wx.EVT_MENU, frame.onFileExit, exitItem, exitID)

You can do either

     self.Bind(wx.EVT_MENU, frame.onFileExit, exitItem)

or

     self.Bind(wx.EVT_MENU, frame.onFileExit, id=exitID)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

OK, I've tried both, and neither has any effect. Is this working for anyone? Am I doing something stupid here? I've verified that the 'frame' reference is indeed a reference to the frame that contains the event handler, so what else could be the problem here?

      ___/
     /
    __/
   /
  ____/
  Ed Leafe
  http://leafe.com/
  http://opentech.leafe.com

···

On Apr 6, 2004, at 10:17 PM, Robin Dunn wrote:

    Trying to get the new Bind() working in 2.5.1.5, GTK2 without success. Here's the code sample I'm using:
import wx
class FileMenu(wx.Menu):
    def __init__(self, frame):
        wx.Menu.__init__(self)
        exitID = wx.NewId()
        exitItem = wx.MenuItem(self, exitID, "E&xit", "Outta Here")
        self.AppendItem(exitItem)
        wx.App_SetMacExitMenuItemId(exitID) self.Bind(wx.EVT_MENU, frame.onFileExit, exitItem, exitID)

You can do either

    self.Bind(wx.EVT_MENU, frame.onFileExit, exitItem)

or

    self.Bind(wx.EVT_MENU, frame.onFileExit, id=exitID)

Ed Leafe wrote:

You can do either

    self.Bind(wx.EVT_MENU, frame.onFileExit, exitItem)

or

    self.Bind(wx.EVT_MENU, frame.onFileExit, id=exitID)

    OK, I've tried both, and neither has any effect. Is this working for anyone? Am I doing something stupid here? I've verified that the 'frame' reference is indeed a reference to the frame that contains the event handler, so what else could be the problem here?

Appologies if I'm off base here, but you may have missed Robin's point. Your original example used the format:

    self.Bind(wx.EVT_MENU, frame.onFileExit, exitID)

Whereas Robin's example:

    self.Bind(wx.EVT_MENU, frame.onFileExit, id=exitID)

The difference is that when using an ID, you *must* specifiy the 'id' keyword. Otherwise Bind() assumes that the next arg is an object. (Actually, I'm amazed it didn't throw an exception since an ID doesn't have a 'GetId() method).

Or am I just totally off base here? :slight_smile:

···

On Apr 6, 2004, at 10:17 PM, Robin Dunn wrote:

I guess I wasn't clear. I tried both formats: passing the MenuItem directly, and passing its ID, using the "id=" keyword. Neither worked.

      ___/
     /
    __/
   /
  ____/
  Ed Leafe
  http://leafe.com/
  http://opentech.leafe.com

···

On Apr 7, 2004, at 8:21 AM, Jeff Grimmett wrote:

Appologies if I'm off base here, but you may have missed Robin's point. Your original example used the format:

   self.Bind(wx.EVT_MENU, frame.onFileExit, exitID)

Whereas Robin's example:

   self.Bind(wx.EVT_MENU, frame.onFileExit, id=exitID)

The difference is that when using an ID, you *must* specifiy the 'id' keyword. Otherwise Bind() assumes that the next arg is an object. (Actually, I'm amazed it didn't throw an exception since an ID doesn't have a 'GetId() method).

Or am I just totally off base here? :slight_smile:

Can anyone tell me what is the equivalent of SystemParametersInfo used in
wxPython.

Thanks
Gop

try sys.argv (see sys module documentation from python documentation) maybe is what you're loooking for. Alternatively you could tell us what do you need SystemParametersInfo for.

···

On Wed, 7 Apr 2004 20:05:29 +0530, GopinathR <gop@srasys.co.in> wrote:

Can anyone tell me what is the equivalent of SystemParametersInfo used in
wxPython.

Thanks
Gop

--
Peter Damoc
Hacker Wannabe
http://www.sigmacore.net/about.html

Robin Dunn writes:

> Trying to get the new Bind() working in 2.5.1.5, GTK2
> without success. Here's the code sample I'm using:

You can do either
     self.Bind(wx.EVT_MENU, frame.onFileExit, exitItem)
or
     self.Bind(wx.EVT_MENU, frame.onFileExit, id=exitID)

Actually, it needs to be:
      frame.Bind(wx.EVT_MENU, frame.onFileExit, exitItem)
or
      frame.Bind(wx.EVT_MENU, frame.onFileExit, id=exitID)

···

--
Paul

Someone just pointed out to me off-list that if I change the line:

    self.Bind(wx.EVT_MENU, frame.onFileExit, exitItem)
to:
    frame.Bind(wx.EVT_MENU, frame.onFileExit, exitItem)

it will work, and I've verified that it does. Is this correct behavior? I haven't had a need to use any other object reference other than 'self' to get Bind to work anywhere else.

      ___/
     /
    __/
   /
  ____/
  Ed Leafe
  http://leafe.com/
  http://opentech.leafe.com

···

On Apr 6, 2004, at 10:17 PM, Robin Dunn wrote:

    Trying to get the new Bind() working in 2.5.1.5, GTK2 without success. Here's the code sample I'm using:
import wx
class FileMenu(wx.Menu):
    def __init__(self, frame):
        wx.Menu.__init__(self)
        exitID = wx.NewId()
        exitItem = wx.MenuItem(self, exitID, "E&xit", "Outta Here")
        self.AppendItem(exitItem)
        wx.App_SetMacExitMenuItemId(exitID) self.Bind(wx.EVT_MENU, frame.onFileExit, exitItem, exitID)

You can do either

    self.Bind(wx.EVT_MENU, frame.onFileExit, exitItem)

or

    self.Bind(wx.EVT_MENU, frame.onFileExit, id=exitID)

Thanks for your reply. Im looking for help regarding Mouse. I want to set
the speed of the mouse using the code

SystemParametersInfo(win32con.SPI_GETMOUSESPEED, 0, oldSpeed, 0)

using the win32api, I couldnot able to find 'SystemParametersInfo'.

(The sys module didnot help me. I tried it just now.)

awaiting for your reply.

Bye
Gop.

···

----- Original Message -----
From: "Peter Damoc" <pdamoc@gmx.net>
To: <wxPython-users@lists.wxwidgets.org>
Sent: Wednesday, April 07, 2004 9:01 PM
Subject: Re: [wxPython-users] equivalent of SystemParametersInfo

On Wed, 7 Apr 2004 20:05:29 +0530, GopinathR <gop@srasys.co.in> wrote:

> Can anyone tell me what is the equivalent of SystemParametersInfo used

in

> wxPython.
>
> Thanks
> Gop

try sys.argv (see sys module documentation from python documentation)
maybe is what you're loooking for. Alternatively you could tell us what do
you need SystemParametersInfo for.

--
Peter Damoc
Hacker Wannabe
sigmacore.net

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

"GopinathR" <gop@srasys.co.in> writes:

Thanks for your reply. Im looking for help regarding Mouse. I want to set
the speed of the mouse using the code

SystemParametersInfo(win32con.SPI_GETMOUSESPEED, 0, oldSpeed, 0)

using the win32api, I couldnot able to find 'SystemParametersInfo'.

(The sys module didnot help me. I tried it just now.)

To call functions not wrapped by the win32 extensions, the easiest is to
use ctypes:

"""
import win32con
from ctypes import windll, byref, c_int

speed = c_int()
windll.user32.SystemParametersInfoA(win32con.SPI_GETMOUSESPEED, 0,
                                    byref(speed), 0)
print speed
print speed.value
"""

Thomas

Hi, Thanks.

like

windll.user32.SystemParametersInfoA(win32con.SPI_GETMOUSESPEED, 0,
byref(speed), 0)

I tried for SPI_SETMOUSESPEED, it seems to me like the mouse speed does not
change.

what can I do for that to achieve.

awaiting for your reply,
-Gop

···

----- Original Message -----
From: "Thomas Heller" <theller@python.net>
To: <wxpython-users@lists.wxwindows.org>
Sent: Thursday, April 08, 2004 12:46 AM
Subject: [wxPython-users] Re: equivalent of SystemParametersInfo

"GopinathR" <gop@srasys.co.in> writes:

> Thanks for your reply. Im looking for help regarding Mouse. I want to

set

> the speed of the mouse using the code
>
> SystemParametersInfo(win32con.SPI_GETMOUSESPEED, 0, oldSpeed, 0)
>
> using the win32api, I couldnot able to find 'SystemParametersInfo'.
>
> (The sys module didnot help me. I tried it just now.)

To call functions not wrapped by the win32 extensions, the easiest is to
use ctypes:

"""
import win32con
from ctypes import windll, byref, c_int

speed = c_int()
windll.user32.SystemParametersInfoA(win32con.SPI_GETMOUSESPEED, 0,
                                    byref(speed), 0)
print speed
print speed.value
"""

Thomas

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Hi, I got it solved, by setting the pvparam. Thanks for all your help.

changing the value of speed, which is a Integer.

windll.user32.SystemParametersInfoA(win32con.SPI_GETMOUSESPEED, 0, speed, 0)

Bye
Gop.

···

----- Original Message -----
From: "GopinathR" <gop@srasys.co.in>
To: <wxPython-users@lists.wxwidgets.org>
Sent: Thursday, April 08, 2004 1:19 AM
Subject: Re: [wxPython-users] Re: equivalent of SystemParametersInfo

Hi, Thanks.

like

windll.user32.SystemParametersInfoA(win32con.SPI_GETMOUSESPEED, 0,
byref(speed), 0)

I tried for SPI_SETMOUSESPEED, it seems to me like the mouse speed does

not

change.

what can I do for that to achieve.

awaiting for your reply,
-Gop

----- Original Message -----
From: "Thomas Heller" <theller@python.net>
To: <wxpython-users@lists.wxwindows.org>
Sent: Thursday, April 08, 2004 12:46 AM
Subject: [wxPython-users] Re: equivalent of SystemParametersInfo

> "GopinathR" <gop@srasys.co.in> writes:
>
> > Thanks for your reply. Im looking for help regarding Mouse. I want to
set
> > the speed of the mouse using the code
> >
> > SystemParametersInfo(win32con.SPI_GETMOUSESPEED, 0, oldSpeed, 0)
> >
> > using the win32api, I couldnot able to find 'SystemParametersInfo'.
> >
> > (The sys module didnot help me. I tried it just now.)
>
> To call functions not wrapped by the win32 extensions, the easiest is to
> use ctypes:
>
> """
> import win32con
> from ctypes import windll, byref, c_int
>
> speed = c_int()
> windll.user32.SystemParametersInfoA(win32con.SPI_GETMOUSESPEED, 0,
> byref(speed), 0)
> print speed
> print speed.value
> """
>
> Thomas
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

"GopinathR" <gop@srasys.co.in> writes:

Hi, Thanks.

like

windll.user32.SystemParametersInfoA(win32con.SPI_GETMOUSESPEED, 0,
byref(speed), 0)

I tried for SPI_SETMOUSESPEED, it seems to me like the mouse speed does not
change.

what can I do for that to achieve.

It does work for me, on Win XP Pro SP1.

Note that you must pass the speed directly, not 'byref':

windll.user32.SystemParametersInfoA(SPI_SETMOUSESPEED, 0, 1, 0)
  or
windll.user32.SystemParametersInfoA(SPI_SETMOUSESPEED, 0, 20, 0)

Also note that the function returns 0 when it fails!
You have to read the MSDN docs carefully, it's the same as programming
in C.

Thomas

Ed Leafe wrote:

    Someone just pointed out to me off-list that if I change the line:

        self.Bind(wx.EVT_MENU, frame.onFileExit, exitItem)
to:
        frame.Bind(wx.EVT_MENU, frame.onFileExit, exitItem)

it will work, and I've verified that it does. Is this correct behavior? I haven't had a need to use any other object reference other than 'self' to get Bind to work anywhere else.

I believe that's the magic formula. The menu (and I think toolbar) events 'belong' to the frame; I think I encountered this during early 2.5 development and Robin explained it. Sorry about forgetting that, but glad you got it working :slight_smile:

... WARNING: This computer attracts every other piece of matter in
     the universe, including the products of other computer
     companies with a force proportional to the product of the
     masses and inversely proportional to the square of the
     distance between them.

GopinathR wrote:

Thanks for your reply. Im looking for help regarding Mouse. I want to set
the speed of the mouse using the code

SystemParametersInfo(win32con.SPI_GETMOUSESPEED, 0, oldSpeed, 0)

using the win32api, I couldnot able to find 'SystemParametersInfo'.

(The sys module didnot help me. I tried it just now.)

awaiting for your reply.

wxWidgets doesn't expose that functionality as far as I know. Some
read-only system parameters are available via wxSystemSettings.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Hi All,
Here is a piece of code for drawing a line using DC. When I create the Pen,
and use the dc.SelectObject, the following error occours.

if win32con.WM_ERASEBKGND:
            dc = win32ui.CreateDCFromHandle(self.windowHWnd)
            win32gui.GetClientRect(self.windowHWnd)

            hBrush = win32ui.CreateBrush(win32con.PS_SOLID,
win32con.BLACK_BRUSH, 0)

            dc.FillRect(selectedProxy.location, hBrush)

            hPen = win32ui.CreatePen(win32con.PS_SOLID, 5,
win32con.BLACK_PEN)
            print hPen, "hPen"

            hOldPen = dc.SelectObject(hPen)

The Error Message is:

hOldPen = dc.SelectObject(hPen)
win32ui: Select pen object failed

Thanks for your Help.
Gop.

GopinathR wrote:

Hi All,
Here is a piece of code for drawing a line using DC. When I create the Pen,
and use the dc.SelectObject, the following error occours.

if win32con.WM_ERASEBKGND:
            dc = win32ui.CreateDCFromHandle(self.windowHWnd)
            win32gui.GetClientRect(self.windowHWnd)

This looks like you're trying to use a native Win32 DC, rather than a wxPython DC. If that's what you intend, this isn't the right list for that kind of question.

In fact, I don't see any wxPython code here. If you do want to use wxPython, check out the Wiki the demo, and then come here with a question if there is something you can't figure out.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (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

Hi All,
To draw a rectangle around a window, that changes everytime w.r t the
location of the window (works exactly like Accessible Explorer), I use
CreateWindowEx. The Window pops up exactly at the same location, but I could
not draw a frame around the window, moreover the window pops up with a title
bar every time. Anybody having worked in DC can help me out.

Thanks in Advance
GopinathR.

GopinathR wrote:

Hi All,
To draw a rectangle around a window, that changes everytime w.r t the
location of the window (works exactly like Accessible Explorer), I use
CreateWindowEx. The Window pops up exactly at the same location, but I could
not draw a frame around the window, moreover the window pops up with a title
bar every time. Anybody having worked in DC can help me out.

What exactly are you trying to do, and why do you need CreateWindowEx to do it?

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!