2 boo code import System.IO
3 boo code import Gtk from "gtk-sharp"
4 boo code import Gdk from "gdk-sharp"
5 boo code import Glade from "glade-sharp"
7 boo code class StuffBrowser():
8 boo code public static final phile = """stuffbrowser.glade"""
10 boo comment //Unfortunately, Gtk does not provide a builtin "IsSupported" function for images.
11 boo code public static final supportedExtensions = ( ".png", ".jpeg", ".jpg", ".gif", ".tga", ".bmp", ".ico", ".tiff" )
13 boo code def constructor():
14 boo comment //Connect event handlers and mainStuff, aboutDialog, etc, to their respective methods/handlers.
15 boo code for widget in ("mainStuff", "aboutDialog", "directorySelector"):
16 boo code gxml = Glade.XML(phile, widget, null)
17 boo code gxml.Autoconnect(self)
19 boo code def OnStuffClose(sender as object, e as DeleteEventArgs):
20 boo comment """The user is leaving the application via the Big Red 'X'"""
21 boo code Application.Quit()
23 boo code def OnStuffQuit(sender as object, e as EventArgs):
24 boo comment """The user is leaving the application via File-->Quit"""
25 boo code Application.Quit()
27 boo code def OnAboutActivate(sender as object, e as EventArgs):
28 boo comment """The user is trying to view the about dialog"""
29 boo code aboutDialog.Show()
31 boo code def OnAboutDelete(sender as object, e as DeleteEventArgs):
32 boo code e.RetVal = true
33 boo code aboutDialog.Hide()
35 boo code def OnAboutResponse(sender as object, e as ResponseArgs):
36 boo code if e.ResponseId == ResponseType.Close:
37 boo code aboutDialog.Hide()
39 boo code def OnOpenDirectory(sender as object, e as EventArgs):
41 boo code directorySelector.FileList.Sensitive = false
42 boo code directorySelector.Show()
44 boo code def OnDirectoryDelete(sender as object, e as DeleteEventArgs):
45 boo code e.RetVal = true
46 boo code directorySelector.Hide() //Don't worry, the "Destroy" event will kill it.
48 boo code def OnDirectoryResponse(sender as object, args as ResponseArgs):
49 boo code directorySelector.Hide()
51 boo code if args.ResponseId == ResponseType.Ok and directorySelector.Filename.Length != 0:
52 boo code LoadDirectory(directorySelector.Filename)
54 boo code private def LoadDirectory(path as string):
55 boo comment //Create a new store that has two columns; the first is a Pixbuf (image) the second, a string.
56 boo code store = ListStore( (Gdk.Pixbuf, string) )
57 boo code stuffThumbs.Model = store
58 boo code cell = CellRendererPixbuf()
59 boo code column = TreeViewColumn()
60 boo code column.PackStart(cell, false)
62 boo comment //Bind the element in column 0 of the store to the pixbuf property in this column's CellRendererPixbuf!
63 boo code column.AddAttribute(cell, "pixbuf", 0)
64 boo code column.Title = path
66 boo comment //Detach the old column.
67 boo code if stuffThumbs.GetColumn(0) is not null:
68 boo code stuffThumbs.RemoveColumn(stuffThumbs.GetColumn(0))
70 boo comment //Finally, attach the new column so it will be updated in real time.
71 boo code stuffThumbs.AppendColumn(column)
72 boo code files = Directory.GetFiles(path)
73 boo code validFiles = e for e as string in files if System.IO.FileInfo(e).Extension in StuffBrowser.supportedExtensions
74 boo code parse = do():
75 boo code for i as int, file as string in enumerate(validFiles):
76 boo comment //The using construct ensures that the program's memory size does not inflate wildly out of control.
77 boo comment //Having these "image" floating around afterwards ensures lots of memory consuming havoc until garbaged collected!
79 boo comment // If we couldn't read a file pass over it.
81 boo code using image = Gdk.Pixbuf(file):
82 boo code store.AppendValues( (image.ScaleSimple(128, 128, InterpType.Bilinear), file ) )
84 boo code print " Couldn't read file ${file} "
86 boo code print "Indexing start: ${DateTime.Now}"
87 boo comment //Update the treeview in real time by starting an asynchronous operation.
88 boo code parse.BeginInvoke( { print "Indexing complete: ${DateTime.Now}" } ) //Spin off a new thread; fill the progress bar.
90 boo code def OnPictureActivated(sender as object, args as RowActivatedArgs):
91 boo comment //Grabs the TreeIter object that represents the currently selected node -- icky stuff with "ref" keyword. ;(
92 boo code x as TreeIter
93 boo code stuffThumbs.Model.GetIter(x, args.Path)
95 boo comment //In the second column we've stored the filename that represents the thumbnail image in the treeview.
96 boo comment //Grab this filename and then use it to inform the user what file he's viewing, as well as loading it.
97 boo code image = stuffThumbs.Model.GetValue(x, 1) as string
98 boo code stuffImage.Pixbuf = Gdk.Pixbuf(image)
99 boo code imageName.Text = Path.GetFileName(image)
101 boo comment //All of the widgets we want Autoconnect to hook up to Glade-created widgets in stuffBrowser.glade
102 boo code [Glade.Widget] aboutDialog as Gtk.Dialog
103 boo code [Glade.Widget] mainStuff as Gtk.Window
104 boo code [Glade.Widget] directorySelector as Gtk.FileSelection
105 boo code [Glade.Widget] stuffImage as Gtk.Image
106 boo code [Glade.Widget] stuffThumbs as Gtk.TreeView
107 boo code [Glade.Widget] imageName as Gtk.Label
109 boo comment //Run the application.
110 boo code Application.Init()
111 boo code StuffBrowser()
112 boo code Application.Run()