/GTK3 - ProgressBar
gem install gtk3
# frozen_string_literal: true
require 'gtk3'
class ProgressBarWindow < Gtk::Window
attr_accessor :progressbar, :activity_mode
def initialize
super
self.title = 'ProgressBar Demo'
self.border_width = 10
vbox = Gtk::Box.new(:vertical, 6)
add vbox
@progressbar = Gtk::ProgressBar.new
vbox.pack_start progressbar
button = Gtk::CheckButton.new('Show text')
button.signal_connect('toggled') { |b| on_show_text_toggled b }
vbox.pack_start button
button = Gtk::CheckButton.new('Activity mode')
button.signal_connect('toggled') { |b| on_activity_mode_toggled b }
vbox.pack_start button
button = Gtk::CheckButton.new('Right to Left')
button.signal_connect('toggled') { |b| on_right_to_left_toggled b }
vbox.pack_start button
timeout_id = GLib::Timeout.add(50) { on_timeout }
end
def on_show_text_toggled(button)
show_text = button.active?
text = show_text ? 'some text' : ''
progressbar.text = text
progressbar.show_text = show_text
end
def on_activity_mode_toggled(button)
@activity_mode = button.active?
if activity_mode
progressbar.pulse
else
progressbar.set_fraction 0
end
end
def on_right_to_left_toggled(button)
value = button.active?
progressbar.set_inverted value
end
def on_timeout
if activity_mode
progressbar.pulse
else
new_value = progressbar.fraction + 0.01
new_value = 0 if new_value > 1
progressbar.fraction = new_value
end
end
end
win = ProgressBarWindow.new
win.signal_connect('destroy') { Gtk.main_quit }
win.show_all
Gtk.main
Author And Source
この問題について(/GTK3 - ProgressBar), 我々は、より多くの情報をここで見つけました https://qiita.com/kojix2/items/9de19677bc4db6445931著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .