progress bar on panel

Matthew Brush mbrush at codebrainz.ca
Sun Dec 10 08:06:06 CET 2017


On 2017-12-09 08:34 AM, Dani wrote:
> Hello:
> 
> I guess I'm asking wrong when nobody has answered anything ...
> Apologies for not knowing how to ask.

Best would be to try and reproduce in a simple standalone C file without 
panel stuff. If you don't work it out while simplifying your layout, it 
will at least make it easier for people to try and compile without 
having to mess with their panel/plugins.

Regards,
Matthew Brush

> I have more than 90 compilations to try to know how this is done and I 
> am not able to know how to do it. That's why I'm asking to see if anyone 
> can give me a clue.
> 
> I want to put a progress bar centered or with a border of about 5 px on 
> each side but for more than try it I do not know what parameters I 
> should set to get it
> I am not able to control the width of the plugin or center the progress 
> bar ...
> 
> This is the plugin code that sets the progress bar (only horizontal part)
> 
> Esta es una captura de como se ve actualmente
> 
> https://image.ibb.co/kNNaLG/xfce4_timer_plugin_02.png
> 
> 
>      pd->box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
>      gtk_widget_set_name (GTK_WIDGET (pd->box ), "xfce4-timer-plugin-v");
>      gtk_container_set_border_width (GTK_CONTAINER(pd->box), 0);
> 
>      gtk_container_add(GTK_CONTAINER(plugin),pd->box);
>      gtk_orientable_set_orientation(GTK_ORIENTABLE(pd->pbar),
>                                     GTK_ORIENTATION_VERTICAL);
>      gtk_widget_set_size_request(GTK_WIDGET(pd->pbar),0,0);
>      gtk_widget_set_size_request(GTK_WIDGET (plugin),0,0);
> 
> 
> 
> //        /* Sane default Gtk style */
>          css_provider = gtk_css_provider_new ();
>          gtk_css_provider_load_from_data (css_provider,
>                                           "#xfce4-timer-plugin-v {"
>                                           "background-color: red;"
>                                           "}",
>                                           -1, NULL);
>          gtk_style_context_add_provider (GTK_STYLE_CONTEXT 
> (gtk_widget_get_style_context (GTK_WIDGET (pd->box ))),
>                                          GTK_STYLE_PROVIDER 
> (css_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
> 
>      gtk_box_pack_start(GTK_BOX(pd->box),pd->pbar,TRUE,TRUE,0);
> 
>    size = xfce_panel_plugin_get_size (plugin);
>    gtk_widget_set_size_request (GTK_WIDGET (plugin), 1, size);
> 
>    gtk_widget_show_all(GTK_WIDGET(plugin));
> 
> 
> Dani
> 
> On 06/12/17 10:47, Dani wrote:
>> Hello:
>>
>> (I ama novice with gtk)
>>
>> I wanted to put a progress bar on xfce4-panel.
>> I do not know why the behavior is different if it goes horizontally or 
>> vertically.
>> I am not able to focus on the widget.
>> They put different background colors so that the position can be 
>> appreciated.
>> What he wanted is:
>> - Center widget.
>> - Set the space to the sides (horizontal) up and down (vertical) so 
>> that it occupies less.
>>
>> In the gtk3 documentation I did not find much about this.
>> Any idea of where do I have to look?
>>
>>
>> Here's an image of how it looks with the current code
>>
>> https://ibb.co/dcb17w
>> https://image.ibb.co/n0sKub/xfce4_timer_plugin.png
>>
>>
>> The code is this, there are many commented parties, they are proof 
>> that they did not work ...
>>
>> static void add_pbar(XfcePanelPlugin *plugin, plugin_data *pd){
>>
>>   gdouble frac;
>>
>>   GtkCssProvider *css_provider;
>>
>>   gtk_widget_hide(GTK_WIDGET(plugin));
>>
>>   /* Always true except at initialization */
>>   if(pd->box){
>>     g_object_ref(G_OBJECT(pd->pbar));
>> gtk_container_remove(GTK_CONTAINER(pd->box),pd->pbar);
>>     gtk_widget_destroy(pd->box);
>>   }
>>
>>   if (pd -> box) {
>>     frac = gtk_progress_bar_get_fraction (GTK_PROGRESS_BAR (pd->pbar));
>>     gtk_widget_destroy(pd->box);
>>     pd->pbar = gtk_progress_bar_new ();
>>     //gtk_progress_bar_set_bar_style (GTK_PROGRESS_BAR(pd->pbar),
>>     //                GTK_PROGRESS_CONTINUOUS);
>> gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(pd->pbar),frac);
>>   }
>>
>>   gtk_progress_bar_set_inverted (GTK_PROGRESS_BAR(pd->pbar), TRUE);
>>
>>
>>
>>   /* vertical bar */
>> if(xfce_panel_plugin_get_orientation(plugin)==GTK_ORIENTATION_HORIZONTAL){ 
>>
>>     pd->box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
>>     gtk_widget_set_name (GTK_WIDGET (pd->box ), "xfce4-timer-plugin-v");
>>     //gtk_container_set_border_width (GTK_CONTAINER(pd->box), BORDER/2);
>>     gtk_container_set_border_width (GTK_CONTAINER(pd->box), 0);
>>
>>     gtk_container_add(GTK_CONTAINER(plugin),pd->box);
>> gtk_orientable_set_orientation(GTK_ORIENTABLE(pd->pbar),
>> GTK_ORIENTATION_VERTICAL);
>> gtk_widget_set_size_request(GTK_WIDGET(pd->pbar),PBAR_THICKNESS,0);
>>     //gtk_box_pack_start(GTK_BOX(pd->box),
>>     // gtk_separator_new(GTK_ORIENTATION_VERTICAL),
>>     //                   FALSE, FALSE, 0);
>>
>>
>>
>>         /* Sane default Gtk style */
>>         css_provider = gtk_css_provider_new ();
>>         gtk_css_provider_load_from_data (css_provider,
>> "#xfce4-timer-plugin-v {"
>> //"-GtkWidget-focus-padding: 0;"
>> //"-GtkWidget-focus-line-width: 0;"
>> //"-GtkButton-default-border: 0;"
>> //"-GtkButton-inner-border: 0;"
>> //"-GtkButton-background-color: red;"
>> "background-color: red;"
>>                                          //"padding: 0px;"
>> //"padding‑right: -10px;"
>>                                          //"margin‑right: -10px;"
>>                                          //"border‑right: -10px;"
>>                                          //"width: 20px;"
>>                                          "border-left: solid 15px blue;"
>>                                          "border-right: solid 5px pink;"
>>                                          "}",
>>                                          -1, NULL);
>>         gtk_style_context_add_provider (GTK_STYLE_CONTEXT 
>> (gtk_widget_get_style_context (GTK_WIDGET (pd->box ))),
>> GTK_STYLE_PROVIDER (css_provider), 
>> GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
>>
>> gtk_box_pack_start(GTK_BOX(pd->box),pd->pbar,FALSE,FALSE,0);
>>     //gtk_box_pack_start(GTK_BOX(pd->box),
>>     // gtk_separator_new(GTK_ORIENTATION_VERTICAL),
>>     //                   FALSE, FALSE, 0);
>>
>>
>>
>>   }
>>   else{ /* horizontal bar */
>>     pd->box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
>>     gtk_widget_set_name (GTK_WIDGET (pd->box ), "xfce4-timer-plugin-h");
>>     //gtk_container_set_border_width (GTK_CONTAINER(pd->box), BORDER/2);
>>     gtk_container_set_border_width (GTK_CONTAINER(pd->box), BORDER/2);
>>     gtk_container_add(GTK_CONTAINER(plugin),pd->box);
>>
>> gtk_orientable_set_orientation(GTK_ORIENTABLE(pd->pbar),
>>                     GTK_ORIENTATION_HORIZONTAL);
>> gtk_widget_set_size_request(GTK_WIDGET(pd->pbar),0,PBAR_THICKNESS);
>>     //gtk_box_pack_start(GTK_BOX(pd->box),
>>     // gtk_separator_new(GTK_ORIENTATION_HORIZONTAL),
>>     //                   FALSE, FALSE, 0);
>>
>>     gtk_widget_set_name (GTK_WIDGET (pd->pbar ), 
>> "xfce4-timer-plugin-h-pbar");
>>     /* Sane default Gtk style */
>>     css_provider = gtk_css_provider_new ();
>>     gtk_css_provider_load_from_data (css_provider,
>> "#xfce4-timer-plugin-h {"
>> //"-GtkWidget-focus-padding: 0;"
>> //"-GtkWidget-focus-line-width: 0;"
>> //"-GtkButton-default-border: 0;"
>> //"-GtkButton-inner-border: 0;"
>> //"-GtkButton-background-color: red;"
>>                                      "background-color: green;"
>>                                      //"padding: 0px;"
>>                                      "padding‑right: 20px;"
>>                                      "margin‑right: 20px;"
>>                                      "border-width: 20px;"
>>                                      "border-top-color: rgb(128,57,0);"
>>                                      "border-left-color: 
>> rgba(10%,20%,30%,0.5);"
>>                                      "border-right-color: #ff00cc;"
>> "border-bottom-color: #ffff0000cccc;} #xfce4-timer-plugin-h-pbar 
>> {border: solid 5px pink;}",
>>                                      -1, NULL);
>>     gtk_style_context_add_provider (GTK_STYLE_CONTEXT 
>> (gtk_widget_get_style_context (GTK_WIDGET (pd->box ))),
>>                                     GTK_STYLE_PROVIDER (css_provider), 
>> GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
>>
>> gtk_box_pack_start(GTK_BOX(pd->box),pd->pbar,FALSE,FALSE,0);
>>     //gtk_box_pack_start(GTK_BOX(pd->box),
>>     // gtk_separator_new(GTK_ORIENTATION_HORIZONTAL),
>>     //                   FALSE, FALSE, 0);
>>
>>   }
>>
>>
>>   gtk_widget_show_all(GTK_WIDGET(plugin));
>>
>> }
>>
>>
>> Very thanks
>>
>> -- 
>> Dani
>>
>>
>> _______________________________________________
>> Xfce4-dev mailing list
>> Xfce4-dev at xfce.org
>> https://mail.xfce.org/mailman/listinfo/xfce4-dev
> 
> 
> 
> 
> _______________________________________________
> Xfce4-dev mailing list
> Xfce4-dev at xfce.org
> https://mail.xfce.org/mailman/listinfo/xfce4-dev
> 



More information about the Xfce4-dev mailing list