473,320 Members | 1,957 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

same menu point is activated

Hi all

Im trying to learn wxpython by some samples and Ive come across this.
After change EVT_MENU lines from
EVT_MENU(self, ID_OPEN, self.OnOpen) to
self.Bind(wx.EVT_MENU, self.OnOpen)

It can run, but the menu points all trigger the openfile dialog.
Seems like the last bind rules them all.
What am i doing wrong?

All the best

OllieZ

Code below

import wx
import os
ID_ABOUT=101
ID_OPEN=102
ID_BUTTON1=110
ID_EXIT=200

class MainWindow(wx.Frame):
def __init__(self,parent,id,title):
self.dirname=''
wx.Frame.__init__(self,parent,wx.ID_ANY, title,
style=wx.DEFAULT_FRAME_STYLE|
wx.NO_FULL_REPAINT_ON_RESIZE)
self.control = wx.TextCtrl(self, 1, style=wx.TE_MULTILINE)
self.CreateStatusBar() # A Statusbar in the bottom of the
window
# Setting up the menu.
filemenu= wx.Menu()
filemenu.Append(ID_OPEN, "&Open"," Open a file to edit")
filemenu.AppendSeparator()
filemenu.Append(ID_ABOUT, "&About"," Information about this
program")
filemenu.AppendSeparator()
filemenu.Append(ID_EXIT,"&Exit"," Terminate the program")
# Creating the menubar.
menuBar = wx.MenuBar()
menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the
MenuBar
self.SetMenuBar(menuBar) # Adding the MenuBar to the Frame
content.
self.Bind(wx.EVT_MENU, self.OnAbout)
self.Bind(wx.EVT_MENU, self.OnExit)
self.Bind(wx.EVT_MENU, self.OnOpen)
# EVT_MENU(self, ID_OPEN, self.OnOpen)
self.sizer2 = wx.BoxSizer(wx.HORIZONTAL)
self.buttons=[]
for i in range(0,6):
self.buttons.append(wx.Button(self, ID_BUTTON1+i, "Button
&"+`i`))
self.sizer2.Add(self.buttons[i],1,wx.EXPAND)

# Use some sizers to see layout options
self.sizer=wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.control,1,wx.EXPAND)
self.sizer.Add(self.sizer2,0,wx.EXPAND)

#Layout sizers
self.SetSizer(self.sizer)
self.SetAutoLayout(1)
self.sizer.Fit(self)

self.Show(1)

def OnAbout(self,e):
d = wx.MessageDialog( self, " A sample editor \n"
" in wxPython","About Sample Editor",
wx.OK)
# Create a message dialog box
d.ShowModal() # Shows it
d.Destroy() # finally destroy it when finished.

def OnExit(self,e):
self.Close(True) # Close the frame.

def OnOpen(self,e):
""" Open a file"""
dlg = wx.FileDialog(self, "Choose a file", self.dirname, "",
"*.*", wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
self.filename=dlg.GetFilename()
self.dirname=dlg.GetDirectory()
f=open(os.path.join(self.dirname, self.filename),'r')
self.control.SetValue(f.read())
f.close()
dlg.Destroy()
app = wx.PySimpleApp()
frame = MainWindow(None, -1, "Sample editor")
app.MainLoop()

Aug 25 '05 #1
2 1176
OllieZ wrote:
Hi all

Im trying to learn wxpython by some samples and Ive come across this.
After change EVT_MENU lines from
EVT_MENU(self, ID_OPEN, self.OnOpen) to
self.Bind(wx.EVT_MENU, self.OnOpen)


It should be:

self.Bind(wx.EVT_MENU, self.OnOpen, id=ID_OPEN)
^^^^^^^^^^

etc.
-greg
Aug 25 '05 #2
Thx a lot, i'll try that asap :)

OllieZ

Aug 26 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ansgar Hein | last post by:
I have been playing around with several different versions for a horizontal menu, but I haven't been able to build a horizontal navigation based on the vertical one featured on www.alistapart.com...
0
by: geebloo | last post by:
Hello World, I need to modify with Access97 a freeware called TCM (available on http://www.matpie.drw.net/PBSystems/products/tcm/TCM.html . Easy to install. Use Admin/Admin to loggin). I know...
2
by: Robert W. | last post by:
I want to introduce a special "Admin" menu item into my WinForms app. It'll normally be hidden but activated by a special key-sequence. To make it more visible to a user (ex. while talking with a...
2
by: Mac via DotNetMonster.com | last post by:
Hi all, I have a menu that is populated from the results of an SQL query. For example lets say the menu contains a list of clients IDs. I would like to click on a particular item and open up a...
6
by: Joseph Geretz | last post by:
Writing an Outlook AddIn with C#. For the user interface within Outlook I'm adding matching pairs of Toolbar buttons and Menu items. All of the buttons and menu items are wired up to send events to...
2
by: warrenf | last post by:
Greetings, I have been muddling my way through developing a DHTML menu. I finally have something workable. My problem now is that I have implemented my menus in a DIV that overlaps my 'master'...
0
by: Jim Devenish | last post by:
I have successfully added shortcut menus to Forms but I am now having difficulty when I attach a shortcut menu to a text control. I have a shortcut menu entitled 'CalendarEntries' with one command...
5
omerbutt
by: omerbutt | last post by:
hi all, i have a menu based on <ul> and <li> it is working fine on mozilla all versions IE 6 and 7 all versions and google chrome ver 2.0.172.31 , the only problem is occuring is with the IE8 here...
1
omerbutt
by: omerbutt | last post by:
hi every one i have a menu li and ul based the problem is when any specific category in the li is hovered the li or the sub-cat items appear but as i move my mouse over the sub-cat or level two li it...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.