class XYP::GUI
Public Class Methods
new()
click to toggle source
# File lib/xyp/gui.rb, line 18 def initialize glade_file = File.expand_path(__dir__)+"/gui_v0.glade" builder=Gtk::Builder.new builder.add_from_file(glade_file) builder.connect_signals{|handler| method(handler)} @main_window = builder['window1'] @main_window.signal_connect("destroy"){Gtk.main_quit} @drawing =builder['drawingarea1'] @drawing.add_events [:leave_notify_mask, :button_press_mask, :pointer_motion_mask, :pointer_motion_hint_mask] create_callbacks dummy_test end
Public Instance Methods
create_callbacks()
click to toggle source
# File lib/xyp/gui.rb, line 36 def create_callbacks @drawing.signal_connect("draw"){redraw} @drawing.signal_connect("button-press-event") do |widget, event| @start_drag=Point.new(event.x,event.y) end @drawing.signal_connect("motion-notify-event") do |widget, event| do_it=false if @start_drag modify_center event @start_drag=@end_drag redraw end end @drawing.signal_connect("button-release-event") do |widget, event| modify_center event @start_drag=nil redraw end end
dummy_test()
click to toggle source
handle_window_redimensioning()
click to toggle source
load_data(filename)
click to toggle source
# File lib/xyp/gui.rb, line 104 def load_data filename @dataset=IO.readlines(filename).inject({}) do |hash,line| x,y=*line.split.map(&:to_f) hash[x]=y hash end @plot=Plot.new(filename) @plot.set_background_rgba GREY @plot.set_data_set @dataset on_button_zoom_fit_clicked end
modify_center(event)
click to toggle source
# File lib/xyp/gui.rb, line 59 def modify_center event @end_drag=Point.new(event.x,event.y) delta_x=((@end_drag.x-@start_drag.x)/@plot.ratio.x) delta_y=((@end_drag.y-@start_drag.y)/@plot.ratio.y) delta=Point.new(delta_x,-delta_y) @view.center=@view.center-delta end
quit()
click to toggle source
signal handler for main window destory event
# File lib/xyp/gui.rb, line 76 def quit Gtk.main_quit end
redraw()
click to toggle source
# File lib/xyp/gui.rb, line 164 def redraw handle_window_redimensioning cr = @drawing.window.create_cairo_context @plot.plot(cr) end
run(options)
click to toggle source
# File lib/xyp/gui.rb, line 67 def run options @main_window.show if filename=options[:data_file] load_data(filename) end Gtk.main end