OTWO-1213 Works around lost encoding in Ruby/C binding layer
[ohcount] / test / expected_dir / boo1.boo
1 boo     code    import System
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"
6 boo     blank   
7 boo     code    class StuffBrowser():
8 boo     code      public static final phile = """stuffbrowser.glade"""
9 boo     blank   
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" )
12 boo     blank   
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)
18 boo     blank   
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()
22 boo     blank   
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()
26 boo     blank   
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()
30 boo     blank   
31 boo     code      def OnAboutDelete(sender as object, e as DeleteEventArgs):
32 boo     code        e.RetVal = true
33 boo     code        aboutDialog.Hide()
34 boo     blank   
35 boo     code      def OnAboutResponse(sender as object, e as ResponseArgs):
36 boo     code        if e.ResponseId == ResponseType.Close:
37 boo     code          aboutDialog.Hide()
38 boo     blank   
39 boo     code      def OnOpenDirectory(sender as object, e as EventArgs):
40 boo     comment     #changed
41 boo     code        directorySelector.FileList.Sensitive = false
42 boo     code        directorySelector.Show()
43 boo     blank   
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.
47 boo     blank   
48 boo     code      def OnDirectoryResponse(sender as object, args as ResponseArgs):
49 boo     code        directorySelector.Hide()
50 boo     comment     #changed
51 boo     code        if args.ResponseId == ResponseType.Ok and directorySelector.Filename.Length != 0:
52 boo     code          LoadDirectory(directorySelector.Filename)
53 boo     blank   
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)
61 boo     blank   
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
65 boo     blank   
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))
69 boo     blank   
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!
78 boo     comment         #changed
79 boo     comment         // If we couldn't read a file pass over it.
80 boo     code            try:
81 boo     code              using image = Gdk.Pixbuf(file):
82 boo     code                store.AppendValues( (image.ScaleSimple(128, 128, InterpType.Bilinear), file ) )
83 boo     code            except e:
84 boo     code              print " Couldn't read file ${file} "
85 boo     blank   
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.
89 boo     blank   
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)
94 boo     blank   
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)
100 boo     blank   
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
108 boo     blank   
109 boo     comment //Run the application.
110 boo     code    Application.Init()
111 boo     code    StuffBrowser()
112 boo     code    Application.Run()