13.07.2015 Views

The wxPython tutorial

The wxPython tutorial

The wxPython tutorial

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Drag and drop in <strong>wxPython</strong>http://www.zetcode.com/wxpython/draganddrop/example, deleting a file by dragging it and droping it to the trash basket is veryintuitive and easy to understand, but actually most people just press the deletekey. (shift + delete) It is more effective. In our next example we explore agraphical operation, that is very handy. In most GUI text editors, you can open afile by simply dragging it from the file manager and dropping it on the editor.#!/usr/bin/python# filedrop.pyimport wxclass FileDrop(wx.FileDropTarget):def __init__(self, window):wx.FileDropTarget.__init__(self)self.window = windowdef OnDropFiles(self, x, y, filenames):for name in filenames:try:file = open(name, 'r')text = file.read()self.window.WriteText(text)file.close()except IOError, error:dlg = wx.MessageDialog(None, 'Error opening file\n' + str(error))dlg.ShowModal()except UnicodeDecodeError, error:dlg = wx.MessageDialog(None, 'Cannot open non ascii files\n' + str(error))dlg.ShowModal()class DropFile(wx.Frame):def __init__(self, parent, id, title):wx.Frame.__init__(self, parent, id, title, size = (450, 400))self.text = wx.TextCtrl(self, -1, style = wx.TE_MULTILINE)dt = FileDrop(self.text)self.text.SetDropTarget(dt)self.Centre()self.Show(True)app = wx.App()DropFile(None, -1, 'filedrop.py')app.MainLoop()eXtreme ProgrammingAssistance Technique Java/J2ee, .Net/C#,Python, RubyPython Database InterfaceEasily connect Python to all your databases.mxodbc.egenix.comHome ‡ Contents ‡ Top of PageZetCode last modified June 28, 2007© 2007 Jan Bodnar3 de 3 27/04/2008 1:05

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!