Skip to content

Commit

Permalink
plugins/scpi.c: replace deprecated gtk3 functions
Browse files Browse the repository at this point in the history
use CSS style provider to set box widget color instead of gtk_widget_override_color
add box colors to style sheet

Signed-off-by: Cristina Suteu <[email protected]>
  • Loading branch information
cristina-suteu committed Jan 29, 2024
1 parent 23860db commit ab96f59
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
33 changes: 19 additions & 14 deletions plugins/scpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1127,18 +1127,22 @@ static void instrument_type_cb (GtkComboBox *box)

static void scpi_text_entry_cb (GtkEntry *box, int data)
{
GdkRGBA green = {
.red = 0,
.green = 0xFFFF,
.blue = 0,
.alpha = 1.0
};
GdkRGBA red = {
.red = 0xFFFF,
.green = 0,
.blue = 0,
.alpha = 1.0
};
// use css style provider to set box color
GtkStyleContext *style_context;
GdkDisplay *display;
GdkScreen *screen;
GError *err = NULL;
display = gdk_display_get_default ();
screen = gdk_display_get_default_screen (display);
GtkCssProvider *provider;
provider = gtk_css_provider_new ();
gtk_css_provider_load_from_path(GTK_CSS_PROVIDER(provider),OSC_STYLE_FILE_PATH"styles.css",&err);
if ( err ) {
g_error_free(err);
gtk_css_provider_load_from_path(GTK_CSS_PROVIDER(provider),"./styles.css",NULL);
}
gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_USER);
style_context = gtk_widget_get_style_context(GTK_WIDGET(box));

switch (data) {
case 0:
Expand All @@ -1163,9 +1167,9 @@ static void scpi_text_entry_cb (GtkEntry *box, int data)
current_instrument->id_regex = strdup(gtk_entry_get_text(box));

if (strstr(gtk_label_get_text(GTK_LABEL(scpi_id)), current_instrument->id_regex))
gtk_widget_override_color(GTK_WIDGET(box), GTK_STATE_FLAG_NORMAL, &green);
gtk_style_context_add_class(style_context,"spci_box_g");
else
gtk_widget_override_color(GTK_WIDGET(box), GTK_STATE_FLAG_NORMAL, &red);
gtk_style_context_add_class(style_context,"spci_box_r");
break;
case 4:
if (cmd_to_send)
Expand All @@ -1177,6 +1181,7 @@ static void scpi_text_entry_cb (GtkEntry *box, int data)
__FILE__, __func__, data);
break;
}
g_object_unref(provider);
}

static void init_scpi_device(struct scpi_instrument *device)
Expand Down
6 changes: 6 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
.data_box {
background: #000000;
}
.spci_box_r {
background: #FF0000
}
.spci_box_g {
background: #008000
}

0 comments on commit ab96f59

Please sign in to comment.