Skip to content

Commit

Permalink
oscplot: Add option to enable/disable all channels at once
Browse files Browse the repository at this point in the history
This can be handy when there are many channels.

Signed-off-by: Dan Nechita <[email protected]>
  • Loading branch information
dNechita committed Jul 27, 2020
1 parent d066de3 commit 1afec5c
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 13 deletions.
61 changes: 48 additions & 13 deletions glade/oscplot.glade
Original file line number Diff line number Diff line change
Expand Up @@ -784,25 +784,60 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkHBox" id="box3">
<object class="GtkAlignment" id="alignment9">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="top_padding">3</property>
<child>
<object class="GtkLabel" id="label3">
<object class="GtkHBox" id="box3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0.10000000149011612</property>
<property name="label" translatable="yes">&lt;b&gt;Plot Channels&lt;/b&gt;</property>
<property name="use_markup">True</property>
<child>
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0.10000000149011612</property>
<property name="label" translatable="yes">&lt;b&gt;Plot Channels&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox8">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkToggleButton" id="togglebutton_enable_all">
<property name="label" translatable="yes">Enable All</property>
<property name="width_request">90</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
Expand Down
41 changes: 41 additions & 0 deletions oscplot.c
Original file line number Diff line number Diff line change
Expand Up @@ -6697,6 +6697,44 @@ static bool set_channel_state_in_tree_model(GtkTreeModel *model, GtkTreeIter* ch
return false;
}

static void set_channel_state_via_iter(GtkTreeModel *model,
GtkTreeIter *iter, void *user_data)
{
gboolean enable_state = *(gboolean *)user_data;
set_channel_state_in_tree_model(model, iter, enable_state);
}

static void enable_all_button_toggled_cb(GtkToggleButton *btn, OscPlot *plot)
{
OscPlotPrivate *priv = plot->priv;
gboolean toggled = gtk_toggle_button_get_active(btn);

if (toggled) {
gtk_button_set_label(GTK_BUTTON(btn), "Disable All");
} else {
gtk_button_set_label(GTK_BUTTON(btn), "Enable All");
}

// Enable/disable by going through all channels of each device
GtkTreeView *treeview = GTK_TREE_VIEW(priv->channel_list_view);
GtkTreeModel *model;
GtkTreeIter iter;
gboolean next_iter;
gchar *dev_name;

model = gtk_tree_view_get_model(treeview);
next_iter = gtk_tree_model_get_iter_first(model, &iter);
while (next_iter) {
gtk_tree_model_get(model, &iter,
ELEMENT_NAME, &dev_name, -1);
foreach_channel_iter_of_device(treeview, dev_name,
*set_channel_state_via_iter, &toggled);
g_free(dev_name);
next_iter = gtk_tree_model_iter_next(model, &iter);
}
check_valid_setup(plot);
}

static void create_plot(OscPlot *plot)
{
OscPlotPrivate *priv = plot->priv;
Expand Down Expand Up @@ -7011,6 +7049,9 @@ static void create_plot(OscPlot *plot)
g_signal_connect(key_fullscale, "clicked",
G_CALLBACK(math_chooser_fullscale_key_pressed_cb), plot);

g_builder_connect_signal(builder, "togglebutton_enable_all", "toggled",
G_CALLBACK(enable_all_button_toggled_cb), plot);

/* Create Bindings */
g_object_bind_property_full(priv->capture_button, "active", priv->capture_button,
"stock-id", 0, capture_button_icon_transform, NULL, plot, NULL);
Expand Down

0 comments on commit 1afec5c

Please sign in to comment.