To: lablgtk at kaba.or.jp Subject: filling data in glade-2 generated code From: Friedrich Dominicus Organization: Q Software Solutions GmbH Date: Wed, 26 May 2004 08:39:39 +0200 Message-ID: <871xl74rpw.fsf at fbigm.here> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Nice to reach this mailing list finally. I'm writing an article about Ocaml and wanted to implement a small program I privious had implemented with squeak. It should do the following. Show an Dialog in which one can choose from which currency one wanted to converse to another. The dialog contains to listview one edit field one output field and two buttons. It than builds a query which will be send to a site where information about exchange rates are kept. The answer will be scanned and the output will be written. Very simple indeed, however I ran into some trouble. I first have written the gui-layout by hand which kind of works but which I simply to not like all too much. Then I found that glade should be usable with lablgtk2. I studied the examples, and wanted to write my stuff like that. this is the generated code for the dialog: (* Automatically generated from exchange_rate.glade by lablgladecc *) class window1 ?(file="exchange_rate.glade") ?domain ?autoconnect(*=true*) () = let xmldata = Glade.create ~file ~root:"window1" ?domain () in object (self) inherit Glade.xml ?autoconnect xmldata val toplevel = try new GWindow.window (GtkWindow.Window.cast (Glade.get_widget xmldata ~name:"window1")) with | Gpointer.Null -> failwith "GtkWindow:toplevel is not accessible." method toplevel = toplevel val window1 = try new GWindow.window (GtkWindow.Window.cast (Glade.get_widget xmldata ~name:"window1")) with | Gpointer.Null -> failwith "GtkWindow:window1 is not accessible." method window1 = window1 val table1 = try new GPack.table (GtkPack.Table.cast (Glade.get_widget xmldata ~name:"table1")) with | Gpointer.Null -> failwith "GtkTable:table1 is not accessible." method table1 = table1 val scrolledwindow2 = try new GBin.scrolled_window (GtkBin.ScrolledWindow.cast (Glade.get_widget xmldata ~name:"scrolledwindow2")) with | Gpointer.Null -> failwith "GtkScrolledWindow:scrolledwindow2 is not accessible." method scrolledwindow2 = scrolledwindow2 val to_cur = try new GTree.view (GtkTree.TreeView.cast (Glade.get_widget xmldata ~name:"to_cur")) with | Gpointer.Null -> failwith "GtkTreeView:to_cur is not accessible." method to_cur = to_cur val button_fetch_exchange_rate = try new GButton.button (GtkButton.Button.cast (Glade.get_widget xmldata ~name:"button_fetch_exchange_rate")) with | Gpointer.Null -> failwith "GtkButton:button_fetch_exchange_rate is not accessible." method button_fetch_exchange_rate = button_fetch_exchange_rate val button_cancel = try new GButton.button (GtkButton.Button.cast (Glade.get_widget xmldata ~name:"button_cancel")) with | Gpointer.Null -> failwith "GtkButton:button_cancel is not accessible." method button_cancel = button_cancel val scrolledwindow1 = try new GBin.scrolled_window (GtkBin.ScrolledWindow.cast (Glade.get_widget xmldata ~name:"scrolledwindow1")) with | Gpointer.Null -> failwith "GtkScrolledWindow:scrolledwindow1 is not accessible." method scrolledwindow1 = scrolledwindow1 val from_cur = try new GTree.view (GtkTree.TreeView.cast (Glade.get_widget xmldata ~name:"from_cur")) with | Gpointer.Null -> failwith "GtkTreeView:from_cur is not accessible." method from_cur = from_cur val label2 = try new GMisc.label (GtkMisc.Label.cast (Glade.get_widget xmldata ~name:"label2")) with | Gpointer.Null -> failwith "GtkLabel:label2 is not accessible." method label2 = label2 val ef_amount = try new GEdit.entry (GtkEdit.Entry.cast (Glade.get_widget xmldata ~name:"ef_amount")) with | Gpointer.Null -> failwith "GtkEntry:ef_amount is not accessible." method ef_amount = ef_amount val out_exchange_rate = try new GMisc.label (GtkMisc.Label.cast (Glade.get_widget xmldata ~name:"out_exchange_rate")) with | Gpointer.Null -> failwith "GtkLabel:out_exchange_rate is not accessible." method out_exchange_rate = out_exchange_rate method reparent parent = table1#misc#reparent parent; toplevel#destroy () method check_widgets () = ignore self#toplevel; ignore self#window1; ignore self#table1; ignore self#scrolledwindow2; ignore self#to_cur; ignore self#button_fetch_exchange_rate; ignore self#button_cancel; ignore self#scrolledwindow1; ignore self#from_cur; ignore self#label2; ignore self#ef_amount; ignore self#out_exchange_rate; end let check_all ?(show=false) () = GMain.Main.init (); let window1 = new window1 () in if show then window1#toplevel#show (); window1#check_widgets (); if show then GMain.Main.main () ;; Very nice indeed ;-) Now my question how am I able to fill the view with data? here are some of those: let currencies = ["Afghanistan Afghani . AFA"; "Albanian Lek . ALL"; "Algerian Dinar . DZD"; "Andorran Franc . ADF" ];; This data should be put into the listbox. I assume that i have to use store_of_list from proper. But I did not get the right types for it. So could anyone give me a hand please. Regards Friedrich