File: glade_demo.ml

package info (click to toggle)
lablgtk3 3.1.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,796 kB
  • sloc: ml: 40,890; ansic: 22,312; makefile: 133; sh: 17
file content (69 lines) | stat: -rw-r--r-- 2,099 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
(**************************************************************************)
(*    Lablgtk - Examples                                                  *)
(*                                                                        *)
(*    This code is in the public domain.                                  *)
(*    You may freely copy parts of it in your application.                *)
(*                                                                        *)
(**************************************************************************)

(* $Id$ *)

(* An experiment on using libglade in lablgtk *)

(* lablgladecc3 project1.ui > project1.ml *)
(* #use "project1.ml";; *)

open Project1

let load_file f =
  let ic = open_in f in
  let n = in_channel_length ic in
  let s = Bytes.create n in
  really_input ic s 0 n;
  close_in ic;
  Bytes.to_string s

class editor () =
  object (self)
    inherit window1 ()

    method open_file () =
     let fileSel = GWindow.file_chooser_dialog
       ~action:`OPEN
       ~title:"Open file"
       ~modal:true
       ~type_hint:`DIALOG
       ~position:`CENTER
       () in
     fileSel#add_select_button_stock `OPEN `OK;
     fileSel#add_button_stock `CANCEL `CANCEL;
     (match fileSel#run () with
      | `OK ->
          (match fileSel#filename with
              Some fn -> self#textview1#buffer#set_text (load_file fn)
            | None -> ())
      | `CANCEL -> ()
      | `DELETE_EVENT -> ()) ;
     fileSel#destroy ()

    initializer
      self#textview1#buffer#set_text "A text editor skeleton. Only File/Open and Help/About are implemented." ;
      self#open1#connect#activate ~callback:self#open_file;
      self#about1#connect#activate ~callback:(fun () ->
       let d =
        GWindow.about_dialog
         ~name:"Editor skeleton"
         ~authors:["Anonymous coward"]
         () in
       d#set_logo (GMisc.image ~file:"logo.jpg" ())#pixbuf ;
       d#show ());
      ()
  end

let main () =
  let editor = new editor () in
  (* show bindings *)
  editor#window1#connect#destroy ~callback:GMain.quit;
  GMain.main ()

let _ = main ()