[wxpython-users] where we put the .png files?
Abdessamad EL GON-NOUNI
abdessamadg at gmail.com
Thu May 1 14:47:03 PDT 2008
2008/5/1 Mike Driscoll <mdriscoll at co.marshall.ia.us>:
> Abdessamad EL GON-NOUNI wrote:
>
> > It dosn't work, he gives me the msg "Can'l load image from file
> > 'Exit.png':files does not exist"
> >
> >
> Make sure the path to your png is correct. Also, check out wx.ArtProvider
> for standard icons. I use img2py if I need custom icons because it's easi=
er
> to embed them in my application.
where do I can check this path?
>
>
> I have another problem: when I want to bind an element from the menubar
> > to an event, the program doesn't recognize the method, I have this error
> > msg: 'MainWindow' object has no attribute 'OnExit'
> >
>
> Are you talking about a menu event or a toolbar event?
Both menu and toolbar
> Here's a generic way to create code for a toolbar (I created a ):
>
> <code>
>
> def createToolbar(self):
> toolbar =3D self.CreateToolBar(wx.TB_3DBUTTONS|wx.TB_TEXT)
> self.toolbar.SetToolBitmapSize((16,16))
> print_ico =3D wx.ArtProvider.GetBitmap(wx.ART_PRINT, wx.ART_TOOLBAR,
> (16,16))
> printTool =3D self.toolbar.AddSimpleTool(wx.ID_ANY, print_ico, 'Print',
> 'Sends Timesheet to Default Printer')
> self.Bind(wx.EVT_MENU, self.OnPrint, sendTool) toolbar.Realize()
>
> </code>
>
> And here's how I do menubar code for the same function as above:
>
> <code>
>
> menubar =3D wx.MenuBar()
> fileMenu =3D wx.Menu()
> printDefault_menu_item =3D fileMenu.Append(wx.ID_ANY, '&Print\tCtrl+P',
> 'Prints to Default Printer')
> self.Bind(wx.EVT_MENU, self.onPrintDefault, printDefault_menu_item)
> menubar.Append(fileMenu, '&File')
> self.SetMenuBar(menubar)
>
> </code>
>
this is my code:
<code>
import wx
ID_OPEN=3D001
ID_ABOUT=3D101
ID_EXIT=3D110
class MainWindow(wx.Frame):
def __init__(self, title):
wx.Frame.__init__(self, None, -1, title)
#self.CreateStatusBar() # A Statusbar in the bottom of the window
# Setting up the menu.
menubar =3D wx.MenuBar(wx.MB_DOCKABLE)
file =3D wx.Menu()
edit =3D wx.Menu()
help =3D wx.Menu()
file.Append(-1,'&New')
file.Append(-1, "&Open")
file.Append(-1, "&Save")
file.AppendSeparator()
file.Append(ID_EXIT,"E&xit"," Terminate the program")
edit.Append(-1, '&Preferences')
edit.Append(-1, 'Sea&rch')
menubar.Append(file, '&File')
menubar.Append(edit, '&Edit')
menubar.Append(help, '&Help')
self.SetMenuBar(menubar)
#Tool Bar
toolbar =3D wx.ToolBar(self,-1,style =3D wx.TB_HORIZONTAL |
wx.NO_BORDER)
toolbar.AddSimpleTool(wx.ID_OPEN,wx.Bitmap("Open.png",
wx.BITMAP_TYPE_PNG),shortHelpString =3D "Ouvrir",longHelpString =3D "Ouvrir=
une
confiiguration")
toolbar.AddSimpleTool (wx.ID_CLOSE,wx.Bitmap("Exit.png",
wx.BITMAP_TYPE_PNG),shortHelpString =3D "Fermer",longHelpString =3D "Fermer=
le
fichier ouvert")
toolbar.AddSeparator()
toolbar.Realize()
self.SetToolBar(toolbar)
wx.EVT_MENU(self, ID_ABOUT, self.OnAbout) # attach the menu-event
ID_ABOUT to the
# method
self.OnAbout
wx.EVT_MENU(self, ID_EXIT, self.OnExit) # attach the menu-event
ID_EXIT to the
# method
self.OnExit
def OnAbout(self,e):
d=3D wx.MessageDialog(self, " Simulateur de reseaux de machines=
\n
Auteurs: Abdessamad EL GON NOUNI, Mathieu CHOLLET, Pierre-Yves CLADIERRE","A
propos", wx.OK)
# Create a message dialog box
d.ShowModal() # Shows it
d.Destroy() # finally destroy it when finished.
def OnExit(self,e):
self.Destroy() # Close the frame.
def OnOpen(self,e):
#Open a file
self.dirname =3D ''
dlg =3D wx.FileDialog(self, "Choose a file", self.dirname, "",
"*.*", wx.OPEN)
if dlg.ShowModal() =3D=3D wx.ID_OK:
self.filename=3Ddlg.GetFilename()
self.dirname=3Ddlg.GetDirectory()
f=3Dopen(os.path.join(self.dirname,self.filename),'r')
self.control.SetValue(f.read())
f.close()
dlg.Destroy()
"""
self.Show(True)
class MonApp(wx.App):
def OnInit(self):
self.MainWindow =3D MainWindow(title=3D'Image Viewer')
self.MainWindow.Show()
self.SetTopWindow(self.MainWindow)
return True
app =3D MonApp()
app.MainLoop()
</code>
Hope that helps,
>
> Mike
>
> _______________________________________________
> wxpython-users mailing list
> wxpython-users at lists.wxwidgets.org
> http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/200805=
01/92b67f74/attachment-0001.htm
More information about the wxpython-users
mailing list