text stringlengths 0 601k |
|---|
module Make ( Node_id : S . NODE_ID ) ( Node : S . NODE with type nid := Node_id . t ) : S . VIEW with type nid := Node_id . t and type node := Node . t = struct let min x y = if x < y then x else y let max x y = if x < y then y else x module I = struct type t = int let compare ( a : int ) b = compare a b end module In... |
let list_modules ~ path = List . fold_left path ~ init [ ] : ~ f : begin fun modules dir -> let l = List . filter ( Useunix . get_files_in_directory dir ) ~ f ( : fun x -> Filename . check_suffix x " . cmi " ) in let l = List . map l ~ f : begin fun x -> String . capitalize ( Filename . chop_suffix x " . cmi " ) end in... |
let reset_modules box = Listbox . delete box ~ first ( ` : Num 0 ) ~ last ` : End ; module_list := Sort . list ( Jg_completion . lt_string ~ nocase : true ) ( list_modules ~ path :! Config . load_path ) ; Listbox . insert box ~ index ` : End ~ texts :! module_list ; Jg_box . recenter box ~ index ( ` : Num 0 ) |
let view_symbol ~ kind ~ env ? path id = let name = match id with Lident x -> x | Ldot ( _ , x ) -> x | _ -> match kind with Pvalue | Ptype | Plabel -> " z " | _ -> " Z " in match kind with Pvalue -> let path , vd = lookup_value id env in view_signature_item ~ path ~ env [ Tsig_value ( Ident . create name , vd ) ] | Pt... |
let choose_symbol ~ title ~ env ? signature ? path l = if match path with None -> false | Some path -> is_shown_module path then ( ) else let tl = Jg_toplevel . titled title in Jg_bind . escape_destroy tl ; top_widgets := coe tl :: ! top_widgets ; let buttons = Frame . create tl in let all = Button . create buttons ~ t... |
let choose_symbol_ref = ref choose_symbol |
let guess_search_mode s : [ ` Type | ` Long | ` Pattern ] = let is_type = ref false and is_long = ref false in for i = 0 to String . length s - 2 do if s . [ i ] = ' ' - && s . [ i + 1 ] = ' ' > then is_type := true ; if s . [ i ] = ' . ' then is_long := true done ; if ! is_type then ` Type else if ! is_long then ` Lon... |
let search_string ( ? mode " = symbol " ) ew = let text = Entry . get ew in try if text = " " then ( ) else let l = match mode with " Name " -> begin match guess_search_mode text with ` Long -> search_string_symbol text | ` Pattern -> search_pattern_symbol text | ` Type -> search_string_type text ~ mode ` : Included en... |
let search_which = ref " Name " |
let search_symbol ( ) = if ! module_list = [ ] then module_list := List . sort ~ cmp : compare ( list_modules ~ path :! Config . load_path ) ; let tl = Jg_toplevel . titled " Search symbol " in Jg_bind . escape_destroy tl ; let ew = Entry . create tl ~ width : 30 in let choice = Frame . create tl and which = Textvariab... |
let ident_of_decl ~ modlid = function Tsig_value ( id , _ ) -> Lident ( Ident . name id ) , Pvalue | Tsig_type ( id , _ , _ ) -> Lident ( Ident . name id ) , Ptype | Tsig_exception ( id , _ ) -> Ldot ( modlid , Ident . name id ) , Pconstructor | Tsig_module ( id , _ , _ ) -> Lident ( Ident . name id ) , Pmodule | Tsig_... |
let view_defined ~ env ( ? show_all = false ) modlid = try match lookup_module modlid env with path , Tmty_signature sign -> let rec iter_sign sign idents = match sign with [ ] -> List . rev idents | decl :: rem -> let rem = match decl , rem with Tsig_class _ , cty :: ty1 :: ty2 :: rem -> rem | Tsig_cltype _ , ty1 :: t... |
let close_all_views ( ) = List . iter ! top_widgets ~ f ( : fun tl -> try destroy tl with Protocol . TkError _ -> ( ) ) ; top_widgets := [ ] |
let shell_counter = ref 1 |
let default_shell = ref " ocaml " |
let start_shell master = let tl = Jg_toplevel . titled " Start New Shell " in Wm . transient_set tl ~ master ; let input = Frame . create tl and buttons = Frame . create tl in let ok = Button . create buttons ~ text " : Ok " and cancel = Jg_button . create_destroyer tl ~ parent : buttons ~ text " : Cancel " and labels ... |
let show_help ( ) = let tl = Jg_toplevel . titled " OCamlBrowser Help " in Jg_bind . escape_destroy tl ; let fw , tw , sb = Jg_text . create_with_scrollbar tl in let ok = Jg_button . create_destroyer ~ parent : tl ~ text " : Ok " tl in Text . insert tw ~ index : tend ~ text : Help . text ; Text . configure tw ~ state `... |
let f ( ? dir = Unix . getcwd ( ) ) ? on ( ) = let ( top , tl ) = match on with None -> let tl = Jg_toplevel . titled " Module viewer " in ignore ( Jg_bind . escape_destroy tl ) ; ( tl , coe tl ) | Some top -> Wm . title_set top " OCamlBrowser " ; Wm . iconname_set top " OCamlBrowser " ; let tl = Frame . create top in ... |
let st_viewer ? dir ? on ( ) = let viewer = new st_viewer ? dir ? on ( ) in choose_symbol_ref := viewer # choose_symbol |
let pi = 4 . . * atan 1 . |
module F ( M : sig type font type color type text val white : color type ctx val save : ctx -> unit val restore : ctx -> unit val scale : ctx -> sx : float -> sy : float -> unit val translate : ctx -> tx : float -> ty : float -> unit val begin_path : ctx -> unit val close_path : ctx -> unit val move_to : ctx -> x : flo... |
type rect = { x : int ; y : int ; width : int ; height : int } |
let create_canvas w h = let c = Html . createCanvas Html . document in c . ## width := w ; c . ## height := h ; c |
module Common = Viewer_common . F ( struct type font = Js . js_string Js . t type color = Js . js_string Js . t type text = Js . js_string Js . t let white = Js . string " white " type ctx = Html . canvasRenderingContext2D Js . t let save ctx = ctx ## save let restore ctx = ctx ## restore let scale ctx ~ sx ~ sy = ctx ... |
let redraw st s h v ( canvas : Html . canvasElement Js . t ) = let width = canvas . ## width in let height = canvas . ## height in redraw st s h v canvas { x = 0 ; y = 0 ; width ; height } 0 0 width height |
let json : < parse : Js . js_string Js . t -> ' a > Js . t = Js . Unsafe . pure_js_expr " JSON " |
let ( >>= ) = Lwt . bind |
let http_get url = XmlHttpRequest . get url >>= fun { XmlHttpRequest . code = cod ; content = msg ; _ } -> if cod = 0 || cod = 200 then Lwt . return msg else fst ( Lwt . wait ( ) ) |
let getfile f = try Lwt . return ( Sys_js . read_file ~ name : f ) with Not_found -> http_get f ( ? value = 0 . ) ( ? lower = 0 . ) ( ? upper = 100 . ) ( ? step_incr = 1 . ) ( ? page_incr = 10 . ) ( ? page_size = 10 . ) ( ) = object val mutable _value = value method value = _value val mutable _lower = lower method lowe... |
let handle_drag element f = let mx = ref 0 in let my = ref 0 in element . ## onmousedown := Html . handler ( fun ev -> mx := ev . ## clientX ; my := ev . ## clientY ; element . ## style . ## cursor := Js . string " move " ; let c1 = Html . addEventListener Html . document Html . Event . mousemove ( Html . handler ( fun... |
let start ( ) = let doc = Html . document in let page = doc . ## documentElement in page . ## style . ## overflow := Js . string " hidden " ; doc . ## body . ## style . ## overflow := Js . string " hidden " ; doc . ## body . ## style . ## margin := Js . string " 0px " ; let started = ref false in let p = Html . createP... |
let _ = Html . window . ## onload := Html . handler ( fun _ -> ignore ( start ( ) ) ; Js . _false ) |
type t_point = float * float |
type t_coord = t_point * t_point |
type t_shape = Srect | Sellipse |
type t_gtk_obj = GnomeCanvas . re_p GnoCanvas . item |
module Node = struct type t = string * ( t_shape * t_coord * t_gtk_obj ) option let id n = fst n let coord n = match snd n with None -> None | Some ( _ , c , _ ) -> Some c let item n = match snd n with None -> None | Some ( _ , _ , r ) -> Some r end |
type t_graph = B . G . t * GnoCanvas . pixbuf |
let get_graph g = fst g |
let get_pixbuf g = snd g |
let get_node_info n = B . G . V . label n |
let get_coord n = Node . coord ( get_node_info n ) |
let get_id n = Node . id ( get_node_info n ) |
let get_obj n = Node . item ( get_node_info n ) |
let get_info attr_list_list = let get ( shp , p , w , h ) ( attr , val_opt ) = match attr , val_opt with | ( Dot_ast . Ident " shape " ) , Some ( Dot_ast . String s ) -> ( Some s ) , p , w , h | ( Dot_ast . Ident " pos " ) , Some ( Dot_ast . String s ) -> shp , ( Some s ) , w , h | ( Dot_ast . Ident " width " ) , Some ... |
let compute_coord pos w h = let dot_ppi = 72 . in let dot_png_ppi = 96 . in try let w = float_of_string w in let h = float_of_string h in let x , y = Scanf . sscanf pos " % d , % d " ( fun x y -> ( x , y ) ) in let pad = 4 in let x = float_of_int ( x + pad ) in let y = float_of_int ( y + pad ) in let dx = w . * dot_ppi... |
module DotParser ( C : sig val mk_node : t_shape -> t_coord -> t_gtk_obj end ) = Dot . Parse ( B ) ( struct let node ( id , _ ) attr_list = let name = match id with | Dot_ast . Ident s | Dot_ast . Number s | Dot_ast . String s | Dot_ast . Html s -> s in let info = match get_info attr_list with | shp , Some pos , Some w... |
let png_graph_image dot_cmd dot_file png_file = let cmd = Printf . sprintf " % s - T png % s > % s " dot_cmd dot_file png_file in match Sys . command cmd with | 0 -> png_file | _ -> raise ( DotError cmd ) |
let build_graph dot_cmd dot_file annot_dot_file mk_node_item = let cmd = Printf . sprintf " % s - y % s > % s " dot_cmd dot_file annot_dot_file in match Sys . command cmd with | 0 -> let module Parser = DotParser ( struct let mk_node = mk_node_item end ) in let graph = Parser . parse annot_dot_file in graph | _ -> rais... |
let get_neighbours graph n = let graph = get_graph graph in let preds = B . G . pred graph n in let succs = B . G . succ graph n in ( preds , succs ) |
module type SigCb = sig type t_env val button_one_press_on_graph : t_env -> unit val button_two_press_on_graph : t_env -> unit val button_three_press_on_graph : t_env -> unit val button_one_press_on_node : t_env -> t_node -> unit val button_two_press_on_node : t_env -> t_node -> unit val button_three_press_on_node : t_... |
module EmptyCb = struct type t_env = unit let button_one_press_on_graph _env = ( ) let button_two_press_on_graph _env = ( ) let button_three_press_on_graph _env = ( ) let button_one_press_on_node _env _n = ( ) let button_two_press_on_node _env _n = ( ) let button_three_press_on_node _env _n = ( ) let enter_node _env _n... |
module M ( Cb : SigCb ) = struct let mk_node_item canvas shp ( ( x1 , y1 ) , ( x2 , y2 ) ) = let no_color = [ ` FILL_COLOR " black " ; ` FILL_STIPPLE ( Gdk . Bitmap . create_from_data ~ width : 1 ~ height : 1 " \ 000 " ) ] in let props = [ ` X1 x1 ; ` Y1 y1 ; ` X2 x2 ; ` Y2 y2 ] @ no_color in let n_obj = match shp with... |
module CircLists = struct type t_elem = ViewGraph_core . t_node type t_lists = t_elem list * t_elem list * t_elem list type t = bool * t_lists let mk ( l1 , l2 ) = match l1 , l2 with | [ ] , [ ] -> true , ( [ ] , [ ] , [ ] ) | [ ] , l2 -> false , ( l2 , [ ] , [ ] ) | l1 , l2 -> true , ( l1 , l2 , [ ] ) let current_node... |
type t_options = { sel_1_color : string ; sel_2_color : string ; center_node_when_selected : bool ; } |
let default_options = { sel_1_color = " red " ; sel_2_color = " green " ; center_node_when_selected = true ; } |
type t_widgets = { canvas : GnoCanvas . canvas ; sel_1_txt : GMisc . label ; sel_edge_txt : GMisc . label ; sel_2_txt : GMisc . label ; } |
type t_state = { w : t_widgets ; opt : t_options ; mutable graph : ViewGraph_core . t_graph option ; mutable ppu : float ; mutable selected : ViewGraph_core . t_node option ; mutable neighbours : CircLists . t option ; mutable gui_sel : ( ViewGraph_core . t_gtk_obj option ) array ; } |
let change_zoom state delta = state . ppu <- state . ppu . + delta ; state . w . canvas # set_pixels_per_unit state . ppu |
let center_selected_node state = match state . selected with | None -> ( ) | Some n -> match ViewGraph_core . get_coord n with | None -> ( ) | Some ( ( x1 , y1 ) , ( x2 , y2 ) ) -> let canvas = state . w . canvas in let x = x1 . + ( x2 . - x1 ) . / 2 . in let y = y1 . + ( y2 . - y1 ) . / 2 . in let w = canvas # hadjust... |
let key_press state ev = let canvas = state . w . canvas in let ( x , y ) = canvas # get_scroll_offsets in match GdkEvent . Key . keyval ev with | k when k = GdkKeysyms . _Up -> canvas # scroll_to ~ x ~ y ( : y - 20 ) ; true | k when k = GdkKeysyms . _Down -> canvas # scroll_to ~ x ~ y ( : y + 20 ) ; true | k when k = ... |
let init options ( canvas : GnoCanvas . canvas ) pack_txt = let _ = GMisc . label ~ text " : Selected : " ~ packing : pack_txt ( ) in let sel_1_txt = GMisc . label ~ packing : pack_txt ( ) in let sel_edge_txt = GMisc . label ~ packing : pack_txt ( ) in let sel_2_txt = GMisc . label ~ packing : pack_txt ( ) in let w = {... |
let sel_1_bitmap ( ) = Gdk . Bitmap . create_from_data ~ width : 2 ~ height : 2 " \ 002 \ 001 " |
let sel_2_bitmap ( ) = Gdk . Bitmap . create_from_data ~ width : 2 ~ height : 2 " \ 002 \ 001 " |
let no_bitmap ( ) = Gdk . Bitmap . create_from_data ~ width : 1 ~ height : 1 " \ 000 " |
let move_selection state n_opt1 n_opt2 = let set_props o col bitmap = match o with None -> ( ) | Some o -> o # set [ ` FILL_COLOR col ; ` FILL_STIPPLE bitmap ] in let n_obj n_opt = match n_opt with | None -> None | Some n -> ViewGraph_core . get_obj n in let obj1 = n_obj n_opt1 in let obj2 = n_obj n_opt2 in let reset_o... |
let show_selection state = let n_opt , txt1 , txt2 , txt3 = match state . selected with | None -> None , " ( none ) " , " " , " " | Some n -> let txt1 = ViewGraph_core . get_id n in let n_opt , txt2 , txt3 = match state . neighbours with | None -> None , " " , " " | Some info -> match CircLists . current_node info with... |
let select_node state n_opt = state . selected <- n_opt ; state . neighbours <- None ; show_selection state |
let select_neighbour state = match state . graph with None -> ( ) | Some graph -> match state . selected with None -> ( ) | Some n -> let new_info = match state . neighbours with | None -> let neighbours = ViewGraph_core . get_neighbours graph n in CircLists . mk neighbours | Some info -> CircLists . go_next info in st... |
let goto_neighbour state = match state . graph with None -> ( ) | Some graph -> match state . neighbours with | None -> ( ) | Some info -> match CircLists . current_node info with | None -> ( ) | Some ( _ , n ) -> match state . selected with | None -> assert false | Some old_n -> state . selected <- Some n ; let neighb... |
let clear_state state = state . graph <- None ; state . ppu <- 1 . ; state . selected <- None ; state . neighbours <- None ; state . gui_sel <- [ | None ; None ] ; | show_selection state |
module SelectCb ( UserCb : ViewGraph_core . SigCb ) = struct type t_env = UserCb . t_env * t_state let button_one_press_on_graph ( u_env , state ) = select_node state None ; UserCb . button_one_press_on_graph ( u_env ) let button_two_press_on_graph ( u_env , state ) = select_neighbour state ; UserCb . button_two_press_... |
module VG ( UserCb : ViewGraph_core . SigCb ) = struct module Cb = SelectCb ( UserCb ) module V = ViewGraph_core . M ( Cb ) let open_dot_file u_env state ( ? dot_cmd " = dot " ) file = let canvas = state . w . canvas in ( match state . graph with None -> ( ) | Some g -> V . clear canvas g ) ; let _ = clear_state state ... |
let show_help ( ) = GToolbox . message_box ~ title " : Help " " Selection :\ n - use the mouse button - 1 to select a node : \ it should turn red and ( optionally ) be centered . - when a node is selected , button - 2 selects one of its neighbour : \ it should turn green . - using button - 2 again selects the next neig... |
module CbTest = struct type t_env = unit let button_one_press_on_graph _env = Format . printf " [ CbTest ] button_one_press_on_graph . " @ let button_two_press_on_graph _env = Format . printf " [ CbTest ] button_two_press_on_graph . " @ let button_three_press_on_graph _env = Format . printf " [ CbTest ] button_three_pr... |
module V = ViewGraph_select . VG ( CbTest ) |
let open_file select_init_env file = try let env = ( ) in let _graph = V . open_dot_file env select_init_env file in ( ) with ViewGraph . DotError cmd -> GToolbox . message_box " Error " ( Printf . sprintf " % s failed \ nDidn ' t succed to build graph for % s \ nSorry " ! cmd file ) |
let open_cb select_init_env ( ) = match GToolbox . select_file ~ title " : Select a dot file " ( ) with | None -> ( ) | Some filename -> open_file select_init_env filename |
let help_act_cb _ac = ViewGraph_select . show_help ( ) |
let error_act_cb ac = GToolbox . message_box " Error " ( Printf . sprintf " Action ' % s ' activated : no callback ?\ n " ac # name ) |
let quit_cb ( ) = GMain . Main . quit ( ) |
let quit_act_cb _a = quit_cb ( ) |
let menu_desc = " < ui >\ < menubar name ' = MenuBar ' >\ < menu action ' = FileMenu ' >\ < menuitem action ' = Open ' />\ < separator />\ < menuitem action ' = Quit ' />\ </ menu >\ < menu action ' = HelpMenu ' >\ < menuitem action ' = Help ' />\ </ menu >\ </ menubar >\ </ ui " > |
let create_menu ( ) = let ui_m = GAction . ui_manager ( ) in let actions = GAction . action_group ~ name " : Actions " ( ) in GAction . add_actions actions [ GAction . add_action " FileMenu " ~ label " : File " ; GAction . add_action " Open " ~ label " : Open " ~ accel " : o " ; GAction . add_action " Quit " ~ label " ... |
let create_gui ( ) = let window = GWindow . window ~ title " : ViewGraph " ~ allow_shrink : true ~ allow_grow : true ( ) in let vbox = GPack . vbox ~ border_width : 4 ~ spacing : 4 ~ packing : window # add ( ) in let ui_m = create_menu ( ) in window # add_accel_group ui_m # get_accel_group ; vbox # pack ~ expand : fals... |
let main ( ) = let _ = GMain . Main . init ( ) in let canvas , select_init_env = create_gui ( ) in if Array . length Sys . argv = 2 then open_file select_init_env Sys . argv . ( 1 ) ; GMain . Main . main ( ) |
let _ = Printexc . print main ( ) |
let create_scrolled_canvas packing = let frame = GBin . frame ~ shadow_type ` : IN ( ) in let canvas = let aa = false in GnoCanvas . canvas ~ aa ~ width : 600 ~ height : 400 ~ packing : frame # add ( ) in let _ = canvas # set_center_scroll_region true in let table = GPack . table ~ packing ~ rows : 2 ~ columns : 2 ~ ro... |
let create_graph_win title = let window = GWindow . window ~ title ~ allow_shrink : true ~ allow_grow : true ( ) in let vbox = GPack . vbox ~ border_width : 4 ~ spacing : 4 ~ packing : window # add ( ) in let help_but = GButton . button ~ label " : Help " ~ packing ( : vbox # pack ~ expand : false ~ fill : true ) ( ) i... |
let left_click = ref GLUT_UP ; ; |
let right_click = ref GLUT_UP ; ; |
let xold = ref 0 ; ; |
let yold = ref 0 ; ; |
let width = ref 0 ; ; |
let height = ref 0 ; ; |
let rotate_x = ref 30 . 0 ; ; |
let rotate_y = ref 15 . 0 ; ; |
let alpha = ref 0 . 0 ; ; |
let beta = ref 0 . 0 ; ; |
let teapot ( ) = glBegin ( GL_LINES ) ; glColor3 ( 1 . 0 ) ( 0 . 0 ) ( 0 . 0 ) ; glVertex3 ( - 1 . 0 ) ( - 1 . 0 ) ( - 1 . 0 ) ; glVertex3 ( 1 . 0 ) ( - 1 . 0 ) ( - 1 . 0 ) ; glColor3 ( 0 . 0 ) ( 1 . 0 ) ( 0 . 0 ) ; glVertex3 ( - 1 . 0 ) ( - 1 . 0 ) ( - 1 . 0 ) ; glVertex3 ( - 1 . 0 ) ( 1 . 0 ) ( - 1 . 0 ) ; glColor3 (... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.