show counters for all categories
authorGuillaume Cottenceau <gcottenc@gmail.com>
Fri, 23 Apr 2010 20:47:30 +0000 (22:47 +0200)
committerGuillaume Cottenceau <gcottenc@gmail.com>
Fri, 23 Apr 2010 20:47:30 +0000 (22:47 +0200)
bin/booh-classifier

index 1397168..43abe08 100644 (file)
@@ -245,7 +245,7 @@ $colors = [ Gdk::Color.new(0, 65535, 0),
             Gdk::Color.new(65535, 0, 65535) ]
 
 class Label
-    attr_accessor :color, :name, :button
+    attr_accessor :color, :name, :button, :counter
     def initialize(name)
         @name = name
     end
@@ -950,6 +950,32 @@ def view_entry(entry)
     end
 end
 
+def update_counters
+    value = 0
+    $allentries.each { |entry|
+        if ! entry.removed && entry.labeled.nil?
+            value += 1
+        end
+    }
+    $unlabelled_counter.set_markup('<tt>' + value.to_s + '</tt>')
+    value = 0
+    $allentries.each { |entry|
+        if entry.removed 
+            value += 1
+        end
+    }
+    $toremove_counter.set_markup('<tt>' + value.to_s + '</tt>')
+    $labels.values.each { |label|
+        value = 0
+        $allentries.each { |entry|
+            if entry.labeled == label
+                value += 1
+            end
+        }
+        label.counter.set_markup('<tt>' + value.to_s + '</tt>')
+    }
+end
+
 def thumbnail_keypressed(entry, event)
     if event.state & Gdk::Window::MOD1_MASK != 0
         #- ALT pressed: Alt-Left and Alft-Right rotate
@@ -995,6 +1021,7 @@ def thumbnail_keypressed(entry, event)
             entry.labeled = nil
             entry.show_bg
             update_visibility(entry)
+            update_counters
             $mainview.show_next_entry(entry)
 
             save_undo(_("set for removal"),
@@ -1003,6 +1030,7 @@ def thumbnail_keypressed(entry, event)
                           entry.labeled = label_before
                           entry.show_bg
                           update_visibility(entry)
+                          update_counters
                           if entry.button.visible?
                               $mainview.try_show_entry(entry)
                           end
@@ -1011,6 +1039,7 @@ def thumbnail_keypressed(entry, event)
                               entry.labeled = nil
                               entry.show_bg
                               update_visibility(entry)
+                              update_counters
                               if entry.button.visible?
                                   $mainview.try_show_entry(entry)
                               end
@@ -1026,6 +1055,7 @@ def thumbnail_keypressed(entry, event)
             entry.removed = false
             entry.labeled = nil
             entry.show_bg
+            update_counters
             $mainview.show_next_entry(entry)
 
             save_undo(msg,
@@ -1033,11 +1063,13 @@ def thumbnail_keypressed(entry, event)
                           entry.removed = removed_before
                           entry.labeled = label_before
                           entry.show_bg
+                          update_counters
                           $mainview.try_show_entry(entry)
                           proc {
                               entry.removed = false
                               entry.labeled = nil
                               entry.show_bg
+                              update_counters
                               $mainview.try_show_entry(entry)
                           }
                       })
@@ -1093,7 +1125,9 @@ def thumbnail_keypressed(entry, event)
                             $labels[char] = label
                             $ordered_labels << label
                             lbl = Gtk::Label.new.set_markup('<b>(' + char + ')</b>' + text[1..-1]).set_justify(Gtk::Justification::CENTER)
-                            $labels_vbox.pack_start(label.button = Gtk::CheckButton.new.add(evt = Gtk::EventBox.new.add(lbl)).show_all)
+                            $labels_vbox.pack_start(Gtk::HBox.new(false, 5).pack_start(label.button = Gtk::CheckButton.new.add(evt = Gtk::EventBox.new.add(lbl))).
+                                                                            pack_start(Gtk::Label.new, true, true).
+                                                                            pack_start(label.counter = Gtk::Label.new.set_markup('<tt>0</tt>'), false, false).show_all)
                             label.button.active = true
                             label.button.signal_connect('toggled') { update_all_visibilities }
                             evt.modify_bg(Gtk::StateType::NORMAL, label.color)
@@ -1108,6 +1142,7 @@ def thumbnail_keypressed(entry, event)
                     entry.labeled = label
                     entry.show_bg
                     update_visibility(entry)
+                    update_counters
                     $mainview.show_next_entry(entry)
 
                     save_undo(_("set label"),
@@ -1116,6 +1151,7 @@ def thumbnail_keypressed(entry, event)
                                   entry.labeled = label_before
                                   entry.show_bg
                                   update_visibility(entry)
+                                  update_counters
                                   if entry.button.visible?
                                       $mainview.try_show_entry(entry)
                                   end
@@ -1124,6 +1160,7 @@ def thumbnail_keypressed(entry, event)
                                       entry.labeled = label
                                       entry.show_bg
                                       update_visibility(entry)
+                                      update_counters
                                       if entry.button.visible?
                                           $mainview.try_show_entry(entry)
                                       end
@@ -1180,6 +1217,7 @@ def show_entry(entry, i, tips)
 end
 
 def show_entries(allentries)
+    update_counters
     sb_msg(_("Loading images..."))
     $loading_progressbar.fraction = 0
     $loading_progressbar.text = utf8(_("Loading... %d%") % 0)
@@ -1901,11 +1939,15 @@ def reset_labels
     $labels = {}
     $ordered_labels = []
     lbl = Gtk::Label.new.set_markup(utf8(_("<i>unlabelled</i>")))
-    $labels_vbox.pack_start($unlabelled_button = Gtk::CheckButton.new.add(Gtk::EventBox.new.add(lbl)).show_all)
+    $labels_vbox.pack_start(Gtk::HBox.new(false, 5).pack_start($unlabelled_button = Gtk::CheckButton.new.add(Gtk::EventBox.new.add(lbl)), false, false).
+                                                    pack_start(Gtk::Label.new, true, true).  #- I suck
+                                                    pack_start($unlabelled_counter = Gtk::Label.new.set_markup('<tt>0</tt>'), false, false).show_all)
     $unlabelled_button.active = true
     $unlabelled_button.signal_connect('toggled') { update_all_visibilities }
-    lbl = Gtk::Label.new.set_markup(utf8(_("<i>to remove</i>")))
-    $labels_vbox.pack_start($toremove_button = Gtk::CheckButton.new.add(evt = Gtk::EventBox.new.add(lbl)).show_all)
+    lbl = Gtk::Label.new.set_markup(utf8(_("<i>to rem</i>")))
+    $labels_vbox.pack_start(Gtk::HBox.new(false, 5).pack_start($toremove_button = Gtk::CheckButton.new.add(evt = Gtk::EventBox.new.add(lbl)), false, false).
+                                                    pack_start(Gtk::Label.new, true, true).
+                                                    pack_start($toremove_counter = Gtk::Label.new.set_markup('<tt>0</tt>'), false, false).show_all)
     $toremove_button.active = true
     $toremove_button.signal_connect('toggled') { update_all_visibilities }
     evt.modify_bg(Gtk::StateType::NORMAL, $color_red)