Class: Iconify::CommandStatusIcon

Inherits:
Gtk::StatusIcon
  • Object
show all
Includes:
Gtk
Defined in:
lib/iconify.rb

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ CommandStatusIcon

Returns a new instance of CommandStatusIcon.



79
80
81
82
83
# File 'lib/iconify.rb', line 79

def initialize(name)
  super()

  @name = name
end

Instance Method Details

#redrawObject



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/iconify.rb', line 99

def redraw
  pixmap = Gdk::Pixmap.new(nil, 64, 64, 24)

  cr = pixmap.create_cairo_context

  cr.set_source_rgba(*@background_color, 1.0)
  cr.set_operator(Cairo::OPERATOR_SOURCE)
  cr.paint

  cr.set_font_size(24)
  cr.move_to(3, 64 / 2 + cr.font_extents.ascent / 2)
  cr.set_source_rgba(*@foreground_color, 1)
  cr.show_text(@name)

  cr.destroy

  buf = Gdk::Pixbuf.from_drawable(nil, pixmap, 0, 0, 64, 64)
  self.pixbuf = buf
end

#set_state(state) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/iconify.rb', line 85

def set_state(state)
  case state
  when :running
    @background_color = [0.67, 1.0, 0.0]
    @foreground_color = [0.1, 0.1, 0.1]
  when :stopped
    @background_color = [192/255.0, 0.0, 0.0]
    @foreground_color = [0.9, 0.9, 0.9]
  else
    raise "unknown sate #{state}"
  end
  redraw
end