Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Progress bar example when button is pressed #209

Open
jpercyasnet opened this issue Dec 15, 2018 · 4 comments
Open

Progress bar example when button is pressed #209

jpercyasnet opened this issue Dec 15, 2018 · 4 comments

Comments

@jpercyasnet
Copy link

when I try to do progress bar update when a button is clicked, nothing is updated until the button click code is completed. Does any one have an example for using the Progress Bar?

@EPashkin
Copy link
Member

@jpercyasnet You not tried do something like https://stackoverflow.com/a/8383141/2604116 ?

@jpercyasnet
Copy link
Author

This is the rust code when button is clicked. addition code is added later to update the progress bar but even the first set does not update.

//----------------- list button start -----------------------------------

let directory_combobox_weak2 = directory_combobox.downgrade();
let messageval_label_weak2 = messageval_label.downgrade();
let from_entry_weak2 = from_entry.downgrade();
let to_entry_weak2 = to_entry.downgrade();
let iconsize_entry_weak2 = iconsize_entry.downgrade();
let icon_view_weak2 = icon_view.downgrade();
let progress_progressbar_weak2 = progress_progressbar.downgrade();



listgroup_button.connect_clicked(clone!(directory_combobox_weak2, messageval_label_weak2, from_entry_weak2, to_entry_weak2, iconsize_entry_weak2, progress_progressbar_weak2 => move|_| {
    let directory_combobox = upgrade_weak!(directory_combobox_weak2);
    let messageval_label = upgrade_weak!(messageval_label_weak2);
    let from_entry = upgrade_weak!(from_entry_weak2);
    let to_entry = upgrade_weak!(to_entry_weak2);
    let iconsize_entry = upgrade_weak!(iconsize_entry_weak2);
    let icon_view = upgrade_weak!(icon_view_weak2);
    let progress_progressbar = upgrade_weak!(progress_progressbar_weak2);
    progress_progressbar.set_fraction(0.5);

.
.
.
}

@jpercyasnet
Copy link
Author

from your suggested discussion, to execute progressbar.set_fraction one has to use this code:
progress_progressbar.set_fraction(somef64variable);
while gtk::events_pending() {
gtk::main_iteration_do(true);
}
I really appreciate your assistance.

@mmstick
Copy link
Contributor

mmstick commented Jan 9, 2019

GTK signals are always blocking operations. This means that if you need to do a long-running task, it should be spawned in the background. How you keep up with progress is up to you -- atomics are often a good idea alongside a gtk::idle_add() to check up with the progress over time.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants