mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-22 20:36:06 +08:00
papgets growing
This commit is contained in:
@@ -476,14 +476,36 @@ let pack_papget =
|
||||
let ct = new Papget.canvas_text geomap#still x y msg_listener field_name in
|
||||
begin
|
||||
try
|
||||
let format = ExtXml.attrib papget "format" in
|
||||
ct#set_renderer (fun x -> sprintf (Obj.magic format) (float_of_string x))
|
||||
ct#set_format (ExtXml.attrib papget "format")
|
||||
with
|
||||
_ -> ()
|
||||
end
|
||||
| _ -> failwith (sprintf "pack_papget: %s" field)
|
||||
|
||||
|
||||
(* Drag and drop handler *)
|
||||
let dnd_targets = [ { Gtk.target = "STRING"; flags = []; info = 0} ]
|
||||
let parse_dnd =
|
||||
let sep = Str.regexp ":" in
|
||||
fun s ->
|
||||
match Str.split sep s with
|
||||
[s; c; m; f] -> (s, c, m, f)
|
||||
| _ -> failwith (Printf.sprintf "parse_dnd: %s" s)
|
||||
let listen_dropped_papgets = fun (geomap:G.widget) ->
|
||||
let data_received = fun context ~x ~y data ~info ~time ->
|
||||
try
|
||||
let (sender, class_name, msg_name, field_name) = parse_dnd data#data in
|
||||
let sender = if sender = "*" then None else Some sender in
|
||||
let msg_listener = new Papget.message ~class_name ?sender msg_name in
|
||||
let _ct = new Papget.canvas_text geomap#still (float x) (float y) msg_listener field_name in
|
||||
()
|
||||
with
|
||||
exc -> prerr_endline (Printexc.to_string exc) in
|
||||
|
||||
geomap#canvas#drag#dest_set dnd_targets ~actions:[`COPY];
|
||||
ignore (geomap#canvas#drag#connect#data_received ~callback:data_received)
|
||||
|
||||
|
||||
|
||||
(************************** MAIN ********************************************)
|
||||
let () =
|
||||
@@ -566,6 +588,7 @@ let () =
|
||||
(** packing mapgets *)
|
||||
let papgets = find_widget_children "map2d" the_layout in
|
||||
List.iter (pack_papget geomap) papgets;
|
||||
listen_dropped_papgets geomap;
|
||||
|
||||
if !mplayer <> "" then
|
||||
plugin_window := sprintf "mplayer -nomouseinput %s -wid " !mplayer;
|
||||
|
||||
@@ -32,7 +32,7 @@ SRC = debug.ml base64.ml serial.ml ocaml_tools.ml extXml.ml env.ml xml2h.ml latl
|
||||
CMO = $(SRC:.ml=.cmo)
|
||||
CMX = $(SRC:.ml=.cmx)
|
||||
|
||||
XSRC = platform.ml wind_sock.ml papget.ml mapCanvas.ml mapWaypoints.ml mapTrack.ml mapGoogle.ml mapIGN.ml ml_gtk_drag.o xmlEdit.ml mapFP.ml
|
||||
XSRC = platform.ml wind_sock.ml gtk_papget_text_editor.ml papget.ml mapCanvas.ml mapWaypoints.ml mapTrack.ml mapGoogle.ml mapIGN.ml ml_gtk_drag.o xmlEdit.ml mapFP.ml
|
||||
XCMO = $(XSRC:.ml=.cmo)
|
||||
XCMX = $(XSRC:.ml=.cmx)
|
||||
|
||||
@@ -93,6 +93,9 @@ ml_gtkgl_hack.o : ml_gtkgl_hack.c
|
||||
@echo OC $<
|
||||
$(Q)$(OCAMLC) $(XINCLUDES) $<
|
||||
|
||||
gtk_papget_text_editor.ml : widgets.glade
|
||||
lablgladecc2 -root papget_text_editor -hide-default $< | grep -B 1000000 " end" > $@
|
||||
|
||||
clean :
|
||||
rm -f *~ *.cm* *.out *.opt .depend *.a *.o *.so
|
||||
|
||||
|
||||
+85
-17
@@ -1,35 +1,103 @@
|
||||
open Printf
|
||||
|
||||
class message = fun ?(class_name="telemetry") msg_name ->
|
||||
let (//) = Filename.concat
|
||||
|
||||
class message = fun ?sender ?(class_name="telemetry") msg_name ->
|
||||
object
|
||||
val mutable callbacks = []
|
||||
method connect = fun f cb -> callbacks <- (f, cb) :: callbacks
|
||||
initializer
|
||||
let module P = Pprz.Messages (struct let name = class_name end) in
|
||||
ignore (P.message_bind msg_name
|
||||
(fun _sender values ->
|
||||
List.iter
|
||||
(fun (field_name, cb) ->
|
||||
let field = Pprz.string_assoc field_name values in
|
||||
cb field)
|
||||
callbacks))
|
||||
let cb = fun _sender values ->
|
||||
List.iter
|
||||
(fun (field_name, cb) ->
|
||||
let field = Pprz.string_assoc field_name values in
|
||||
cb field)
|
||||
callbacks in
|
||||
ignore (P.message_bind ?sender msg_name cb)
|
||||
end
|
||||
|
||||
class field = fun msg_obj field_name ->
|
||||
object (self)
|
||||
val mutable last_val = ""
|
||||
method store = fun value -> last_val <- value
|
||||
method update = fun value -> last_val <- value
|
||||
initializer
|
||||
msg_obj#connect field_name self#store
|
||||
msg_obj#connect field_name self#update
|
||||
end
|
||||
|
||||
class canvas_item = fun canvas_group x1 y1 ->
|
||||
let x2 = x1 +. 100. and y2 = y1 +. 25. in
|
||||
let box = GnoCanvas.rect ~props:[`X1 x1; `X2 x2; `Y1 y1; `Y2 y2; (* `NO_OUTLINE_COLOR*) `OUTLINE_COLOR "green"] canvas_group in
|
||||
object (self)
|
||||
val box = box
|
||||
method set_size = fun width height ->
|
||||
box#set [`X2 (x1+.width); `Y2 (y1+.height)]
|
||||
end
|
||||
|
||||
class canvas_text = fun ?(text="") canvas_group x y msg_obj field_name ->
|
||||
let item = GnoCanvas.text ~x ~y ~text canvas_group in
|
||||
object
|
||||
let text = GnoCanvas.text ~x ~y ~text canvas_group in
|
||||
object (self)
|
||||
inherit field msg_obj field_name as super
|
||||
val mutable renderer = fun x -> x
|
||||
method set_renderer = fun f -> renderer <- f
|
||||
method store = fun value ->
|
||||
super#store value;
|
||||
item#set [`SIZE_POINTS 25.; `TEXT (renderer value); `FILL_COLOR "green"; `ANCHOR `NW]
|
||||
val mutable format = "%.2f"
|
||||
val mutable motion = false
|
||||
val mutable size = 15.
|
||||
initializer
|
||||
ignore (text#connect#event self#event)
|
||||
method event = fun (ev : GnoCanvas.item_event) ->
|
||||
match ev with
|
||||
(*** `ENTER_NOTIFY _ -> prerr_endline "enter"; box#set [`OUTLINE_COLOR "green"]; true
|
||||
| `LEAVE_NOTIFY _ -> prerr_endline "leave"; box#set [`NO_OUTLINE_COLOR]; true
|
||||
***)
|
||||
| `BUTTON_PRESS ev ->
|
||||
begin
|
||||
match GdkEvent.Button.button ev with
|
||||
| 1 ->
|
||||
motion <- false;
|
||||
let curs = Gdk.Cursor.create `FLEUR in
|
||||
text#grab [`POINTER_MOTION; `BUTTON_RELEASE] curs
|
||||
(GdkEvent.Button.time ev)
|
||||
| _ -> ()
|
||||
end;
|
||||
true
|
||||
| `MOTION_NOTIFY ev ->
|
||||
let state = GdkEvent.Motion.state ev in
|
||||
if Gdk.Convert.test_modifier `BUTTON1 state then begin
|
||||
motion <- true;
|
||||
let x = GdkEvent.Motion.x ev
|
||||
and y = GdkEvent.Motion.y ev in
|
||||
let (xw, yw) = canvas_group#w2i x y in
|
||||
text#set [`X xw; `Y yw]
|
||||
end;
|
||||
true
|
||||
| `BUTTON_RELEASE ev ->
|
||||
if GdkEvent.Button.button ev = 1 then begin
|
||||
text#ungrab (GdkEvent.Button.time ev);
|
||||
if not motion then begin
|
||||
let file = Env.paparazzi_src // "sw" // "lib" // "ocaml" // "widgets.glade" in
|
||||
let dialog = new Gtk_papget_text_editor.papget_text_editor ~file () in
|
||||
(* Initialize the entries *)
|
||||
dialog#entry_format#set_text format;
|
||||
dialog#spinbutton_size#set_value size;
|
||||
|
||||
(* Connect the entries *)
|
||||
let callback = fun () ->
|
||||
format <- dialog#entry_format#text in
|
||||
ignore (dialog#entry_format#connect#activate ~callback);
|
||||
let callback = fun () ->
|
||||
size <- dialog#spinbutton_size#value in
|
||||
ignore (dialog#spinbutton_size#connect#value_changed ~callback);
|
||||
|
||||
(* Connect the buttons *)
|
||||
ignore (dialog#button_ok#connect#clicked (fun () -> dialog#papget_text_editor#destroy ()))
|
||||
end;
|
||||
motion <- false
|
||||
end;
|
||||
true
|
||||
| _ -> false
|
||||
|
||||
method set_format = fun f -> format <- f
|
||||
method update = fun value ->
|
||||
super#update value;
|
||||
let renderer = fun x -> sprintf (Obj.magic format) (float_of_string x) in
|
||||
text#set [`SIZE_POINTS size; `TEXT (renderer value); `FILL_COLOR "green"; `ANCHOR `NW]
|
||||
end
|
||||
|
||||
@@ -0,0 +1,190 @@
|
||||
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
|
||||
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
|
||||
|
||||
<glade-interface>
|
||||
|
||||
<widget class="GtkWindow" id="papget_text_editor">
|
||||
<property name="visible">True</property>
|
||||
<property name="title" translatable="yes">Text Papget Properties</property>
|
||||
<property name="type">GTK_WINDOW_TOPLEVEL</property>
|
||||
<property name="window_position">GTK_WIN_POS_MOUSE</property>
|
||||
<property name="modal">False</property>
|
||||
<property name="resizable">True</property>
|
||||
<property name="destroy_with_parent">False</property>
|
||||
<property name="decorated">True</property>
|
||||
<property name="skip_taskbar_hint">False</property>
|
||||
<property name="skip_pager_hint">False</property>
|
||||
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
|
||||
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
|
||||
<property name="focus_on_map">True</property>
|
||||
<property name="urgency_hint">False</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkVBox" id="vbox5">
|
||||
<property name="visible">True</property>
|
||||
<property name="homogeneous">False</property>
|
||||
<property name="spacing">0</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkTable" id="table5">
|
||||
<property name="visible">True</property>
|
||||
<property name="n_rows">2</property>
|
||||
<property name="n_columns">2</property>
|
||||
<property name="homogeneous">False</property>
|
||||
<property name="row_spacing">0</property>
|
||||
<property name="column_spacing">0</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label37">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">Format</property>
|
||||
<property name="use_underline">False</property>
|
||||
<property name="use_markup">False</property>
|
||||
<property name="justify">GTK_JUSTIFY_LEFT</property>
|
||||
<property name="wrap">False</property>
|
||||
<property name="selectable">False</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="yalign">0.5</property>
|
||||
<property name="xpad">0</property>
|
||||
<property name="ypad">0</property>
|
||||
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
|
||||
<property name="width_chars">-1</property>
|
||||
<property name="single_line_mode">False</property>
|
||||
<property name="angle">0</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="right_attach">1</property>
|
||||
<property name="top_attach">0</property>
|
||||
<property name="bottom_attach">1</property>
|
||||
<property name="x_options">fill</property>
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label38">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">Size</property>
|
||||
<property name="use_underline">False</property>
|
||||
<property name="use_markup">False</property>
|
||||
<property name="justify">GTK_JUSTIFY_RIGHT</property>
|
||||
<property name="wrap">False</property>
|
||||
<property name="selectable">False</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="yalign">0.5</property>
|
||||
<property name="xpad">0</property>
|
||||
<property name="ypad">0</property>
|
||||
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
|
||||
<property name="width_chars">-1</property>
|
||||
<property name="single_line_mode">False</property>
|
||||
<property name="angle">0</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="right_attach">1</property>
|
||||
<property name="top_attach">1</property>
|
||||
<property name="bottom_attach">2</property>
|
||||
<property name="x_options">fill</property>
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkEntry" id="entry_format">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="editable">True</property>
|
||||
<property name="visibility">True</property>
|
||||
<property name="max_length">0</property>
|
||||
<property name="text" translatable="yes"></property>
|
||||
<property name="has_frame">True</property>
|
||||
<property name="invisible_char">●</property>
|
||||
<property name="activates_default">False</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="top_attach">0</property>
|
||||
<property name="bottom_attach">1</property>
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkSpinButton" id="spinbutton_size">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="climb_rate">1</property>
|
||||
<property name="digits">0</property>
|
||||
<property name="numeric">False</property>
|
||||
<property name="update_policy">GTK_UPDATE_ALWAYS</property>
|
||||
<property name="snap_to_ticks">False</property>
|
||||
<property name="wrap">False</property>
|
||||
<property name="adjustment">1 0 100 1 10 10</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="top_attach">1</property>
|
||||
<property name="bottom_attach">2</property>
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkHBox" id="hbox8">
|
||||
<property name="visible">True</property>
|
||||
<property name="homogeneous">True</property>
|
||||
<property name="spacing">0</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkButton" id="button_delete">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="label">gtk-delete</property>
|
||||
<property name="use_stock">True</property>
|
||||
<property name="relief">GTK_RELIEF_NORMAL</property>
|
||||
<property name="focus_on_click">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkButton" id="button_ok">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="label">gtk-ok</property>
|
||||
<property name="use_stock">True</property>
|
||||
<property name="relief">GTK_RELIEF_NORMAL</property>
|
||||
<property name="focus_on_click">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
|
||||
</glade-interface>
|
||||
Reference in New Issue
Block a user