require 'gtktrayicon' Gtk.init def myeval(str) #puts str #puts puts str system(str) end class XawTV attr_reader :volume, :color, :brightness, :hue, :contrast, :station, :is_muted, :input def initialize() set_station "Pro 7" mute false set_input ("Television") set_volume 90 set_color 50 set_brightness 50 set_hue 50 set_contrast 50 end def set_input(input) if (@input != input) @input = input myeval("xawtv-remote setinput '%s'" % [@input]) end end def mute(val) @is_muted = val if is_muted then myeval("xawtv-remote volume mute on") else myeval("xawtv-remote volume mute off") end end def screenshot(format, filename) myeval("xawtv-remote snap %s full '%s'" % [format, filename]) end def prev_station() set_input("Television") myeval("xawtv-remote setstation prev") end def next_station() set_input("Television") myeval("xawtv-remote setstation next") end def set_station(arg) set_input("Television") @station = arg myeval("xawtv-remote setstation '%s'" % [@station]) end def set_volume(volume) @volume = volume myeval("xawtv-remote volume %d%%" % [@volume]) end def set_hue(hue) @hue = hue myeval("xawtv-remote hue %d%%" % [@hue]) end def set_brightness(brightness) @brightness = brightness myeval("xawtv-remote bright %d%%" % [@brightness]) end def set_contrast(contrast) @contrast = contrast myeval("xawtv-remote contrast %d%%" % [@contrast]) end def set_color(color) @color = color myeval("xawtv-remote color %d%%" % [@color]) end end class GUI def initialize() @window = Gtk::Window.new() @window.set_title("Xawtv Remote Control") @vbox = Gtk::VBox.new(false, 10) @vbox.border_width = 5 @hbox = Gtk::HBox.new() @hbox.add(create_buttons()) @hbox.add(create_slider("Vol", $xawtv.method(:set_volume), $xawtv.method(:volume))) @hbox.add(create_slider("Color", $xawtv.method(:set_color), $xawtv.method(:color))) @hbox.add(create_slider("Hue", $xawtv.method(:set_hue), $xawtv.method(:hue))) @hbox.add(create_slider("Bright", $xawtv.method(:set_brightness), $xawtv.method(:brightness))) @hbox.add(create_slider("Contr", $xawtv.method(:set_contrast), $xawtv.method(:contrast))) @vbox.pack_start(@hbox, true, true, 0) @vbox.add(create_channel_buttons()) @window.add(@vbox) @window.set_default_size(400, 400) @window.show_all @window.signal_connect("destroy") { Gtk.main_quit } end def create_channel_buttons() channels = ["ARD", "ZDF", "WDR", "NDR", "BR-3", "HR", "KiKa", "3sat", "Arte", "n-tv", "XXP", "CNN", "BBC", "EuroNews", "Phoenix", "NRW", "RTL", "RTL 2", "PRO 7", "Super RTL", "SAT 1", "Kabel 1", "VOX", "DSF", "Eurosport", "NBC/Giga", "MTv", "VIVA", "VIVA 2", "TV5", "TRT-1", "QVC", "HSE"] table = Gtk::Table.new(6, 6, 'homogeneous' => false) x = 0 y = 0 channels.each { |station| button = Gtk::Button.new(station) button.signal_connect("clicked") { $xawtv.set_station(station) } table.attach(button, x, x+1, y, y+1) x += 1 if (x >= 6) y += 1 x = 0 end } button = Gtk::Button.new("Composite") table.attach(button, x, x+1, y, y+1) button.signal_connect("clicked") { $xawtv.set_input("Composite1") } return table end def create_buttons() vbox = Gtk::VBox.new() cmd = Gtk::Entry.new cmd.set_width_request(128) cmd.signal_connect("activate") { |entry| puts("CMD: %s\n" % [entry.text]) myeval("xawtv-remote %s" % [entry.text]) } vbox.add(cmd) nextb = Gtk::Button.new("Next") nextb.signal_connect("clicked") { $xawtv.next_station() } vbox.add(nextb) prevb = Gtk::Button.new("Prev") prevb.signal_connect("clicked") { $xawtv.prev_station() } vbox.add(prevb) vtext = Gtk::Button.new("VText") vtext.signal_connect("clicked") { tmp = ENV['DISPLAY'] ENV['DISPLAY'] = $native_display myeval("alevt -vbi /dev/vbi0") ENV['DISPLAY'] = tmp } vbox.add(vtext) mute = Gtk::Button.new("Mute") mute.signal_connect("clicked") { if $xawtv.is_muted then $xawtv.mute(false) else $xawtv.mute(true) end } vbox.add(mute) snap = Gtk::Button.new("Screenshot") snap.signal_connect("clicked") { time = Time.now() filename = ("/tmp/%s-%d-%02d-%02d-%02d:%02d:%02d.jpg" \ % [$xawtv.station, time.year, time.month, time.day, time.hour, time.min, time.sec]) $xawtv.screenshot("jpeg", filename) puts("Wrote screenshot to: '%s'" % [filename]) } vbox.add(snap) return vbox end def create_slider(label, setter, getter) vbox = Gtk::VBox.new() label = Gtk::Label.new(label) scale = Gtk::VScale.new(0, 100, 1) scale.adjustment.value = 100 - getter.call() vbox.pack_start(label, false, true, 5) vbox.add(scale) scale.set_draw_value(false) scale.signal_connect("value-changed") { |scale| setter.call(100 - scale.adjustment.value) } return vbox end end $native_display = ENV['DISPLAY'] ENV['DISPLAY'] = ":0" $xawtv = XawTV.new() gui = GUI.new() Gtk.main # EOF #