Thread: How to design aa progress bar button with gtk3 c code?

  1. #1
    Registered User
    Join Date
    Feb 2017
    Posts
    4

    How to design aa progress bar button with gtk3 c code?

    I'm new in gtk. I have a noisy image and to reduce it, I use a function from opencv. It has a run time, for example 5 seconds. I want to show progressing the run time by using progress bar. This is my code:

    Code:
    #include <opencv2/opencv.hpp>
    #include <gtk/gtk.h>
    #include <time.h>
    
    using namespace cv;
    using namespace std;
    
    gboolean Func (gpointer data) {
    gdouble value;
    GString *text;
    
    //part of code that generate run time
    clock_t start, end;
    start = clock();
    
    Mat image, src1, DENO;
    image = imread("C:/Users/Alireza/Desktop/1.png");
    cvtColor(image, src1, CV_RGB2GRAY);
    fastNlMeansDenoising(src1, DENO, 19, 29, 38);
    imwrite("DENO.png", DENO);
    
    end = clock();
    int runtime = ((int)(end - start)) / CLOCKS_PER_SEC;
    cout << "Time1 = " << runtime << "s" << endl;
    
    
    //part of code that I want to show run time progress by progress bar
    value = gtk_progress_bar_get_fraction(GTK_PROGRESS_BAR(data));
    
    value += 0.01;
    if (value > 1.0) {
        value = 0.0;
    }
    
    text = g_string_new(gtk_progress_bar_get_text(GTK_PROGRESS_BAR(data)));
    g_string_sprintf(text, "%d%%", (int)(value * 100));
    gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(data), value);
    gtk_progress_bar_set_show_text(GTK_PROGRESS_BAR(data), TRUE);
    gtk_progress_bar_set_text(GTK_PROGRESS_BAR(data), text->str);
    
    while (gtk_events_pending())
        gtk_main_iteration();
    
    return TRUE;
    }
    
    int main(int argc, char *argv[])
    {
    GtkWidget *window;
    GtkWidget *progressBar;
    gint timer;
    
    gtk_init(&argc, &argv);
    
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "GtkProgressBar");
    gtk_window_set_default_size(GTK_WINDOW(window), 300, 30);
    
    progressBar = gtk_progress_bar_new();
    timer = g_timeout_add(100, Func, progressBar);
    
    gtk_container_add(GTK_CONTAINER(window), progressBar);
    
    gtk_widget_show_all(window);
    
    gtk_main();
    
    return 0;
    
    }

    and this is my image:

    How to design aa progress bar button  with gtk3 c code?-1-png



    But I can't combine these codes together to show progress run time of my project. I'm new in gtk3. Does any one have any thoughts or suggestions on this?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    I closed your C forum copies because you seem to be writing in C++, but are unable to tell the difference.
    How To Ask Questions The Smart Way

    If you haven't asked over here yet, then I suggest you do.
    Questions - OpenCV Q&A Forum

    Your basic problem is to figure out how to measure 'progress' when calling the OpenCV API.
    Maybe it does, maybe it doesn't - but the place to ask would be the forum which specialises in the API in question.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to design a magnifier glass button with gtk3 c code?
    By Alireza Alipour in forum C++ Programming
    Replies: 0
    Last Post: 02-09-2017, 09:20 AM
  2. Which toolkit should I use: gtk2+ or gtk3+?
    By hikerFreak in forum General Discussions
    Replies: 2
    Last Post: 12-10-2016, 02:59 AM
  3. I need help with GTK3 treeviews, and paneviews
    By KoRn KloWn in forum C Programming
    Replies: 6
    Last Post: 01-18-2013, 01:31 PM
  4. Problem with progress code
    By JFonseka in forum C Programming
    Replies: 13
    Last Post: 04-25-2008, 05:03 PM
  5. Button Design
    By vopo in forum Windows Programming
    Replies: 3
    Last Post: 11-14-2007, 04:01 PM

Tags for this Thread