File: cputs.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 (46 lines) | stat: -rw-r--r-- 1,642 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
(**************************************************************************)
(*    Lablgtk - Examples                                                  *)
(*                                                                        *)
(*    This code is in the public domain.                                  *)
(*    You may freely copy parts of it in your application.                *)
(*                                                                        *)
(**************************************************************************)

open Printf

let print_msg msg = printf "%s" msg; flush stdout
let flush_stdout () = flush stdout

open Unix

let clear_func name () =
  printf "(%s) Cleared\n" name;
  flush_stdout ()

let get_func name (context: GObj.selection_context) ~info ~time =
  printf "(%s) selection_handle: target[%s]\n" name context#target;
  flush_stdout ();
  let tm = Unix.localtime (Unix.gettimeofday ()) in
  let data = Printf.sprintf "(%s) %d/%d/%d %d::%d::%d"
    name
    (tm.tm_year + 1900) (tm.tm_mon + 1) tm.tm_mday
    tm.tm_hour tm.tm_min tm.tm_sec in
  context#return data

let clicked name () =
  clipboard#set_contents ~targets:["STRING"] ~get:(get_func name)
	~clear:(clear_func name)

let main () =
  let name = if Array.length Sys.argv > 1 then Sys.argv.(1) else "" in
  let window = GWindow.window ~title:"Clipboard Puts" ~border_width:10 () in
  window#connect#destroy ~callback:GMain.quit;

  let button =
    GButton.toggle_button ~label:"Claim Selection" ~packing:window#add () in
  button#connect#clicked ~callback:(clicked name);

  window#show ();
  GMain.main ()

let _ = Printexc.print main ()