gtk-demo: Allow locking of icon count in fishbowl demo
authorBenjamin Otte <otte@redhat.com>
Sun, 20 Nov 2016 04:29:03 +0000 (05:29 +0100)
committerBenjamin Otte <otte@redhat.com>
Sat, 7 Jan 2017 02:41:33 +0000 (03:41 +0100)
I'm not sure I'm proud of the hack to get the changing icon into the UI
file without having to write code. But it works.

demos/gtk-demo/fishbowl.c
demos/gtk-demo/fishbowl.ui

index 9350e4e5c2181ab76d17308baa810cc726c5c8af..766bcdc595049da6b57e4c044e6d51678d0c2dc8 100644 (file)
@@ -10,6 +10,8 @@
 char **icon_names = NULL;
 gsize n_icon_names = 0;
 
+GtkWidget *allow_changes;
+
 static void
 init_icon_names (GtkIconTheme *theme)
 {
@@ -24,7 +26,7 @@ init_icon_names (GtkIconTheme *theme)
 
   for (l = icon_list; l; l = l->next)
     {
-      if (g_str_has_suffix (l->data, "-symbolic"))
+      if (g_str_has_suffix (l->data, "symbolic"))
         continue;
 
       g_ptr_array_add (icons, g_strdup (l->data));
@@ -119,7 +121,6 @@ do_stats (GtkWidget *widget,
             stats->last_suggestion *= 2;
           else
             stats->last_suggestion = 1;
-          *suggested_change = stats->last_suggestion;
         }
       else
         {
@@ -128,17 +129,22 @@ do_stats (GtkWidget *widget,
           else
             stats->last_suggestion = -1;
           stats->last_suggestion = MAX (stats->last_suggestion, 1 - (int) stats->item_counter[stats->stats_index]);
-          *suggested_change = stats->last_suggestion;
         }
 
       stats->stats_index = (stats->stats_index + 1) % N_STATS;
       stats->frame_counter[stats->stats_index] = 0;
       stats->item_counter[stats->stats_index] = stats->item_counter[(stats->stats_index + N_STATS - 1) % N_STATS];
       stats->last_stats = frame_time;
+      
+      if (suggested_change)
+        *suggested_change = stats->last_suggestion;
+      else
+        stats->last_suggestion = 0;
     }
   else
     {
-      *suggested_change = 0;
+      if (suggested_change)
+        *suggested_change = 0;
     }
 
   stats->last_frame = frame_time;
@@ -284,9 +290,11 @@ move_fish (GtkWidget     *bowl,
            gpointer       info_label)
 {
   gint64 elapsed;
-  gint suggested_change;
+  gint suggested_change = 0;
   
-  elapsed = do_stats (bowl, info_label, &suggested_change);
+  elapsed = do_stats (bowl,
+                      info_label,
+                      !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (allow_changes)) ? &suggested_change : NULL);
 
   gtk_container_foreach (GTK_CONTAINER (bowl), move_one_fish, &elapsed);
 
@@ -313,6 +321,7 @@ do_fishbowl (GtkWidget *do_widget)
       window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
       bowl = GTK_WIDGET (gtk_builder_get_object (builder, "bowl"));
       info_label = GTK_WIDGET (gtk_builder_get_object (builder, "info_label"));
+      allow_changes = GTK_WIDGET (gtk_builder_get_object (builder, "changes_allow"));
       gtk_window_set_screen (GTK_WINDOW (window),
                              gtk_widget_get_screen (do_widget));
       g_signal_connect (window, "destroy",
@@ -320,12 +329,10 @@ do_fishbowl (GtkWidget *do_widget)
 
       gtk_widget_realize (window);
       gtk_widget_add_tick_callback (bowl, move_fish, info_label, NULL);
-
-      //add_fish (bowl, 300);
     }
 
   if (!gtk_widget_get_visible (window))
-    gtk_widget_show_all (window);
+    gtk_widget_show (window);
   else
     gtk_widget_destroy (window);
 
index e46851b17d2c8a9506691e683df7f019a979860f..c8b2a7c4137d68e714b467531d4b00fc63a6d75a 100644 (file)
             <property name="pack_type">end</property>
           </packing>
         </child>
+        <child>
+          <object class="GtkToggleButton" id="changes_allow">
+            <property name="active">False</property>
+            <property name="visible" bind-source="changes_allow" bind-property="active" bind-flags="invert-boolean">True</property>
+            <property name="relief">none</property>
+            <child>
+              <object class="GtkImage">
+                <property name="icon-name">changes-allow</property>
+                <property name="visible">True</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="pack_type">end</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkToggleButton" id="changes_prevent">
+            <property name="active" bind-source="changes_allow" bind-property="active" bind-flags="bidirectional|invert-boolean">True</property>
+            <property name="visible" bind-source="changes_prevent" bind-property="active" bind-flags="invert-boolean">False</property>
+            <property name="relief">none</property>
+            <child>
+              <object class="GtkImage">
+                <property name="icon-name">changes-prevent</property>
+                <property name="visible">True</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="pack_type">end</property>
+          </packing>
+        </child>
       </object>
     </child>
     <child>