Class: GtkNotify
- Inherits:
-
Object
- Object
- GtkNotify
- Defined in:
- lib/gtk2notify.rb
Overview
note: If calling this from within an EventMachine defer statement it
may be necessary to call it through a system call e.g.
`ruby -r gtk2notify -e "GtkNotify.show body: 'Testing this works'"`
Class Method Summary collapse
Class Method Details
.show(body: 'message body goes here', summary: '', timeout: 3.5, offset: {}) ⇒ Object
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 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/gtk2notify.rb', line 14 def self.show(body: 'message body goes here', summary: '', timeout: 3.5, offset: {}) offset = {x: 100, y: 10}.merge offset window = Gtk::Window.new area = Gtk::DrawingArea.new svg ="<svg width=\"350\" height=\"80\">\n <text x=\"20\" y=\"10\" fill=\"green\" style=\"font-size: 14\">\n \#{body.gsub(/<\\/?\\w+[^>]*>/,'')}\n </text>\n</svg>\n" doc = Svgle.new(svg, callback: self) a = Gtk2SVG::Render.new(doc).to_a area.signal_connect("expose_event") do drawing = Gtk2SVG::DrawingInstructions.new area drawing.render a end svg_width, svg_height = i(width height).map{|x| doc.root.attributes[x].to_i } if svg_width and svg_height then window.set_default_size(svg_width, svg_height) end window.add(area).show_all window.decorated = false window.border_width = 10 window.gravity = Gdk::Window::GRAVITY_NORTH_EAST width, height = window.size x,y = offset[:x], offset[:y] window.move(Gdk.screen_width - (width + x), y) window.show_all Thread.new {sleep timeout; window.hide_all; Gtk.main_quit} Gtk.main end |