forked from garrigue/lablgtk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pixview.ml
40 lines (31 loc) · 1.38 KB
/
pixview.ml
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
(**************************************************************************)
(* Lablgtk - Examples *)
(* *)
(* This code is in the public domain. *)
(* You may freely copy parts of it in your application. *)
(* *)
(**************************************************************************)
(* $Id$ *)
(* An image viewer, supporting all formats allowed by GdkPixbuf *)
let pb =
if Array.length Sys.argv < 2 then begin
Printf.eprintf "usage : %s <file>\n" Sys.argv.(0);
exit 2;
end;
try GdkPixbuf.from_file Sys.argv.(1)
with GdkPixbuf.GdkPixbufError(_,msg) as exn ->
let d = GWindow.message_dialog ~message:msg ~message_type:`ERROR
~buttons:GWindow.Buttons.close ~show:true () in
d#run ();
raise exn
let pm, _ = GdkPixbuf.create_pixmap pb
let width = GdkPixbuf.get_width pb
let height = GdkPixbuf.get_height pb
let w = GWindow.window ~width ~height ~title:Sys.argv.(1) ()
let da = GMisc.drawing_area ~packing:w#add ()
let dw = da#misc#realize (); new GDraw.drawable da#misc#window
let () =
da#event#connect#expose (fun _ -> dw#put_pixmap ~x:0 ~y:0 pm; true);
w#connect#destroy GMain.quit;
w#show ();
GMain.main ()