Can I allow the user to browse images

If you are doing graphics manipulation in your program, it's often useful to provide the user with thumbnails of the images while they're browsing the file tree. A wxPython dialog for this purpose is called wx.lib.imagebrowser.Image-Dialog. Figure 9.10 displays a sample.

Listing 9.10 displays the simple code for this image browser dialog.

Listing 9.10 Creating an image browser dialog import wx import wx.lib.imagebrowser as imagebrowser if _name_ == "_main_":

app = wx.PySimpleApp()

dialog = imagebrowser.ImageDialog(None) if dialog.ShowModal() == wx.ID_OK:

print "You Selected File: " + dialog.GetFile() dialog.Destroy()

Example For Splitter Window Wxpython
Figure 9.10 A typical image dialog browser

The wx.lib.imagebrowser.ImageDialog class is straightforward, and has relatively few options for the programmer to set. To change the dialog's behavior, review the Python source for changing the types of files displayed. The constructor takes just two arguments.

ImageDialog(parent, set_dir=None)

The set_dir argument is the directory in which the dialog when displayed. If it is not set, the application's current working directory is used. After the dialog is closed, GetFile() returns the complete path string of the selected file, and Get-Directory() returns just the directory portion.

Was this article helpful?

0 0

Post a comment