lib/rabbit/progress.rb in rabbit-2.2.1 vs lib/rabbit/progress.rb in rabbit-3.0.0

- old
+ new

@@ -2,10 +2,12 @@ module Rabbit class Progress attr_reader :window, :foreground, :background def initialize + @width = 100 + @height = 20 @foreground = nil @background = nil end def foreground=(color) @@ -25,12 +27,12 @@ return if max.zero? @window = Gtk::Window.new(:popup) @window.transient_for = parent @window.app_paintable = true + @window.set_default_size(@width, @height) @bar = Gtk::ProgressBar.new - @bar.show_text = true @window.add(@bar) @window.show_all @bar.fraction = @current = 0 @max = max.to_f @@ -50,39 +52,48 @@ @current = @max @bar.fraction = @current / @max end def hide + @max = nil @window.destroy @bar = nil @window = nil end private 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 + css = <<-CSS +progress { + padding: 0px; + padding-top: #{@height}px; + padding-bottom: #{@height}px; +} + +trough { + border-width: 0px; +} + CSS + if @foreground + css << <<-CSS +progress { + background-color: #{@foreground.to_css_rgba}; + border-color: #{@foreground.to_css_rgba}; +} + CSS end + if @background + css << <<-CSS +progressbar, +trough { + background-color: #{@background.to_css_rgba}; +} + CSS + end + provider = Gtk::CssProvider.new + provider.load(:data => css) + @bar.style_context.add_provider(provider, + Gtk::StyleProvider::PRIORITY_USER) end end end