Class: Gtk::ProgressBarWindow
- Defined in:
- lib/gtk_paradise/examples/gtk3/065_progress_bar_example.rb
Constant Summary collapse
- TITLE =
#
TITLE
#
'ProgressBar Example'
- CSS_TO_USE =
#
CSS_TO_USE
Define all CSS rules here.
#
' @define-color progress_bg_color #37C8AB; progressbar { color: rgba(204, 215, 212, 0.7); font-feature-settings: "tnum"; } #progressbar1 { background-color: snow; color: green; border-color: tomato; border-width: 35px; background-image: linear-gradient( to bottom, shade (@progress_bg_color, 1.3), shade (@progress_bg_color, 1.08) ); border: 5px solid shade (@progress_bg_color, 0.9); } #progressbar1.horizontal > trough { min-width: 550px; } progressbar > trough { border: none; border-radius: 80px; background-color: #101415; } '
Instance Method Summary collapse
-
#create_and_add_another_progressbar ⇒ Object
# === create_and_add_another_progressbar.
-
#initialize ⇒ ProgressBarWindow
constructor
# === initialize ========================================================================= #.
-
#on_activity_mode_toggled(button) ⇒ Object
# === on_activity_mode_toggled ========================================================================= #.
-
#on_right_to_left_toggled(button) ⇒ Object
# === on_right_to_left_toggled ========================================================================= #.
-
#on_show_text_toggled(button) ⇒ Object
# === on_show_text_toggled ========================================================================= #.
-
#on_timeout ⇒ Object
# === on_timeout ========================================================================= #.
-
#run ⇒ Object
# === run ========================================================================= #.
Methods inherited from Box
#add_space, #left_aligned_text, #text
Constructor Details
#initialize ⇒ ProgressBarWindow
#
initialize
#
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/gtk_paradise/examples/gtk3/065_progress_bar_example.rb', line 63 def initialize super(:vertical) set_title(TITLE) if respond_to?(:set_title) set_size_request(800, 350) # ======================================================================= # # Put it all onto the vertical box next. # ======================================================================= # @vbox = ::Gtk::Box.new(:vertical, 6) add(@vbox) # in a class, using variables with @ character, is instance variable # that means access it from everywhere in this class without @progressbar = ::Gtk::ProgressBar.new @vbox.pack_start(@progressbar, expand: true, fill: false, padding: 0) = ::Gtk::CheckButton.new('Show text') .signal_connect(:toggled) {|| on_show_text_toggled() } @vbox.pack_start(, expand: true, fill: true, padding: 0) # The activity mode goes from left to right to left. = ::Gtk::CheckButton.new('Activity mode') .signal_connect(:toggled) {|| on_activity_mode_toggled() } @vbox.pack_start(, expand: true, fill: true, padding: 0) = ::Gtk::CheckButton.new('Right to Left') .signal_connect(:toggled) {|| on_right_to_left_toggled() } @vbox.pack_start(, expand: true, fill: true, padding: 0) # ======================================================================= # # Set the timeout next. # ======================================================================= # @timeout_id = GLib::Timeout.add(50) { on_timeout } @activity_mode = false signal_connect(:destroy) { ::Gtk.main_quit } run end |
Instance Method Details
#create_and_add_another_progressbar ⇒ Object
#
create_and_add_another_progressbar
This second progress-bar is used as an indicator widget, so it won’t change.
#
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/gtk_paradise/examples/gtk3/065_progress_bar_example.rb', line 163 def provider = ::Gtk::CssProvider.new provider.load(data: CSS_TO_USE) ::Gtk::StyleContext.add_provider_for_screen( Gdk::Screen.default, provider, Gtk::StyleProvider::PRIORITY_APPLICATION ) = ::Gtk::ProgressBar.new .set_fraction(0.5) # 50%. .set_show_text(true) .style_context.add_class('GtkProgress') .set_text('Hello world!') .set_name('progressbar1') @vbox.pack_start(, expand: true, fill: true, padding: 0) end |
#on_activity_mode_toggled(button) ⇒ Object
#
on_activity_mode_toggled
#
119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/gtk_paradise/examples/gtk3/065_progress_bar_example.rb', line 119 def on_activity_mode_toggled() @activity_mode = .active? if @activity_mode # ===================================================================== # # This here is the pulsing-bar going left to right. # Via set_pulse_step() we can set the pulse-step size. # ===================================================================== # @progressbar.set_pulse_step(0.001) @progressbar.pulse else @progressbar.set_fraction(0.0) end end |
#on_right_to_left_toggled(button) ⇒ Object
#
on_right_to_left_toggled
#
136 137 138 139 |
# File 'lib/gtk_paradise/examples/gtk3/065_progress_bar_example.rb', line 136 def on_right_to_left_toggled() value = .active? @progressbar.set_inverted(value) if @progressbar.respond_to? :set_inverted end |
#on_show_text_toggled(button) ⇒ Object
#
on_show_text_toggled
#
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/gtk_paradise/examples/gtk3/065_progress_bar_example.rb', line 105 def on_show_text_toggled() show_text = .active? if show_text text = 'some text' else text = nil end @progressbar.set_text(text) @progressbar.set_show_text(show_text) end |
#on_timeout ⇒ Object
#
on_timeout
#
144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/gtk_paradise/examples/gtk3/065_progress_bar_example.rb', line 144 def on_timeout if @activity_mode @progressbar.pulse else new_value = @progressbar.fraction + 0.01 if new_value > 1 new_value = 0 end @progressbar.set_fraction(new_value) end return true end |