[Python.NET] Problem with toolbar
Brian Lloyd
brian at zope.com
Thu Jan 8 19:32:21 EST 2004
Glad you're enjoying it :)
What you're seeing is almost always due to an exception being raised in the
Python callback (which has nowhere good to go in a windows app - need to
think about what to do there).
The first thing to try is replacing the body of your callback with just
'pass' or 'return'. Now, if you can click the thing that calls it w/o
getting
an error, you've verified that theres some prob with the Python code.
If so, 'the debugger is your friend', as Jim always tells me :) Put a
import pdb
pdb.set_trace()
...at the top of the callback method code and go from there.
Given the one-liner in your example, the only thing I can think of is
if MessageBox hasn't been defined as a name (maybe you need to
use the fully-qualified name or import that name explicitly?)
Hope this helps,
Brian Lloyd brian at zope.com
V.P. Engineering 540.361.1716
Zope Corporation http://www.zope.com
-----Original Message-----
From: pythondotnet-bounces at python.org
[mailto:pythondotnet-bounces at python.org]On Behalf Of Thane
Sent: Thursday, January 08, 2004 6:21 PM
To: pythondotnet at python.org
Subject: [Python.NET] Problem with toolbar
I think there's a bug in the toolbar event handler. Here's the relevant
code:
#-------------------------------------------------------
class KtIde(WinForms.Form):
"""A simple Integrated Development Environment for Python.NET
from Kokopelli Technology."""
def __init__(self):
# a bunch of stuff...
# Add a toolbar
self.toolBar1 = WinForms.ToolBar()
self.imageList1 = WinForms.ImageList(self.components)
self.toolBarButton1 = WinForms.ToolBarButton()
self.toolBar1.Buttons.Add(self.toolBarButton1)
self.toolBar1.ImageList = self.imageList1
self.toolBar1.Location = Point(0, 30)
self.toolBar1.Name = "toolBar1"
self.toolBar1.ShowToolTips = True
self.toolBar1.Size = Size(632, 28)
self.toolBar1.TabIndex = 0
#
# Image list
#
self.imageList1.ImageSize = Size(16, 16)
self.imageList1.TransparentColor = Color.Transparent
fname = "ARW01RT.ICO"
self.imageList1.Images.Add(Image.FromFile(fname))
# toolBarButtons
self.toolBarButton1.ImageIndex = 0
###################### PROBLEM ########################
self.toolBar1.ButtonClick += self.toolBar1_ButtonClick
# Or is it...?
#self.toolBar1.ButtonClick +=
WinForms.ToolBarButtonClickEventHandler(self.toolBar1_ButtonClick)
##########################################################
# more stuff....
def toolBar1_ButtonClick(self, sender, args):
'''The toolbar event handler'''
MessageBox.Show(args.ToString())
#~ if args.Button == self.toolBarButton1:
#~ MessageBox.Show("Hey, it works!")
#-------------------------------------------------------
This bombs every time I press the toolbar button -- unhandled exception.
Message is:
************** Exception Text **************
Python.Runtime.PythonException: Exception of type
Python.Runtime.PythonException was thrown.
at Python.Runtime.Dispatcher.Dispatch(ArrayList args)
at
__System_Windows_Forms_ToolBarButtonClickEventHandlerDispatcher.Invoke(Objec
t , ToolBarButtonClickEventArgs )
at
System.Windows.Forms.ToolBar.OnButtonClick(ToolBarButtonClickEventArgs e)
at System.Windows.Forms.ToolBar.WmReflectCommand(Message& m)
at System.Windows.Forms.ToolBar.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)
Any clues?
Also, this is the most fun I've had programming in a LONG time. MFC is
out the window. Brian -- my hat is off to you. Many thanks for your
efforts.
Cheers,
--Thane
Thane Plummer
CEO Magna Capital
"La perfection est atteinte non quand il ne reste rien à ajouter, mais
quand il ne reste rien à enlever"
Antoine de St. Exupery from The Little Prince (perfection is reached not
when there's nothing left to add, but when there's nothing left to remove)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/pythondotnet/attachments/20040108/5f6916b2/attachment-0001.html
More information about the PythonDotNet
mailing list