Class: Gtk::ProgressBarWindow

Inherits:
Box
  • Object
show all
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

Methods inherited from Box

#add_space, #left_aligned_text, #text

Constructor Details

#initializeProgressBarWindow

#

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)

  button = ::Gtk::CheckButton.new('Show text')
  button.signal_connect(:toggled) {|button| on_show_text_toggled(button) }
  @vbox.pack_start(button, expand: true, fill: true, padding: 0)

  # The activity mode goes from left to right to left.
  button = ::Gtk::CheckButton.new('Activity mode')
  button.signal_connect(:toggled) {|button| on_activity_mode_toggled(button) }
  @vbox.pack_start(button, expand: true, fill: true, padding: 0)

  button = ::Gtk::CheckButton.new('Right to Left')
  button.signal_connect(:toggled) {|button| on_right_to_left_toggled(button) }
  @vbox.pack_start(button, expand: true, fill: true, padding: 0)

  # ======================================================================= #
  # Set the timeout next.
  # ======================================================================= #
  @timeout_id = GLib::Timeout.add(50) { on_timeout }
  @activity_mode = false
  create_and_add_another_progressbar
  signal_connect(:destroy) { ::Gtk.main_quit }
  run
end

Instance Method Details

#create_and_add_another_progressbarObject

#

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 create_and_add_another_progressbar
  provider = ::Gtk::CssProvider.new
  provider.load(data: CSS_TO_USE)
  ::Gtk::StyleContext.add_provider_for_screen(
    Gdk::Screen.default,
    provider,
    Gtk::StyleProvider::PRIORITY_APPLICATION
  )

  progress_bar = ::Gtk::ProgressBar.new
  progress_bar.set_fraction(0.5) # 50%.
  progress_bar.set_show_text(true)
  progress_bar.style_context.add_class('GtkProgress')
  progress_bar.set_text('Hello world!')
  progress_bar.set_name('progressbar1')
  @vbox.pack_start(progress_bar, 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(button)
  @activity_mode = button.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(button)
  value = button.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(button)
  show_text = button.active?
  if show_text
    text = 'some text'
  else
    text = nil
  end
  @progressbar.set_text(text)
  @progressbar.set_show_text(show_text)
end

#on_timeoutObject

#

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

#runObject

#

run

#


184
185
186
187
# File 'lib/gtk_paradise/examples/gtk3/065_progress_bar_example.rb', line 184

def run
  set_border_width(15)
  show_all
end