class Rabbit::Progress

Attributes

background[R]
foreground[R]
window[R]

Public Class Methods

new() click to toggle source
# File lib/rabbit/progress.rb, line 6
def initialize
  @foreground = nil
  @background = nil
end

Public Instance Methods

background=(color) click to toggle source
# File lib/rabbit/progress.rb, line 15
def background=(color)
  @background = color
end
clear_color() click to toggle source
# File lib/rabbit/progress.rb, line 19
def clear_color
  @foreground = nil
  @background = nil
end
end_progress() click to toggle source
# File lib/rabbit/progress.rb, line 47
def end_progress
  return if @max.nil?

  @current = @max
  @bar.fraction = @current / @max
end
foreground=(color) click to toggle source
# File lib/rabbit/progress.rb, line 11
def foreground=(color)
  @foreground = color
end
hide() click to toggle source
# File lib/rabbit/progress.rb, line 54
def hide
  @window.destroy
  @bar = nil
  @window = nil
end
start_progress(max, parent) click to toggle source
# File lib/rabbit/progress.rb, line 24
def start_progress(max, parent)
  return if max.zero?

  @window = Gtk::Window.new(:popup)
  @window.transient_for = parent
  @window.app_paintable = true
  @bar = Gtk::ProgressBar.new
  @bar.show_text = true
  @window.add(@bar)
  @window.show_all
  @bar.fraction = @current = 0
  @max = max.to_f

  setup_progress_color
end
update_progress(i) click to toggle source
# File lib/rabbit/progress.rb, line 40
def update_progress(i)
  return if @max.nil?

  @current = i
  @bar.fraction = @current / @max
end

Private Instance Methods

setup_progress_color() click to toggle source
# File lib/rabbit/progress.rb, line 61
def setup_progress_color
  if Gtk.const_defined?(:CssProvider)
    css = "progressbar {\n"
    if @foreground
      css << "  color: #{@foreground.to_css_rgba};\n"
    end
    if @background
      css << "  background-color: #{@background.to_css_rgba};\n"
    end
    css << "}\n"
    provider = Gtk::CssProvider.default
    provider.load(:data => css)
  else
    style = @bar.style.copy
    if @foreground
      rgb = @foreground.to_gdk_rgb
      style.set_bg(Gtk::STATE_PRELIGHT, *rgb)
    end
    if @background
      rgb = @background.to_gdk_rgb
      style.set_bg(Gtk::STATE_NORMAL, *rgb)
    end
    @bar.style = style
  end
end