remove display of debug messages from gui by default
authorgc <gc>
Mon, 28 Mar 2005 17:28:27 +0000 (17:28 +0000)
committergc <gc>
Mon, 28 Mar 2005 17:28:27 +0000 (17:28 +0000)
bin/booh-gui
lib/booh/GtkAutoTable.rb

index c6a8358b090956cb91c58f6a1840bf79e384587a..20742f021bb7150a5047f4a80d60d92db3af728f 100755 (executable)
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
+require 'getoptlong'
 
 require 'gtk2'
-class Gtk::Allocation
-    def to_s; "x:#{x} y:#{y} width:#{width} height:#{height}"; end
-end
 require 'booh/GtkAutoTable'
 
 require 'gettext'
@@ -37,6 +35,42 @@ require 'booh/booh-lib'
 include Booh
 
 
+#- options
+$options = [
+    [ '--help',          '-h', GetoptLong::NO_ARGUMENT,       _("Get help message") ],
+
+    [ '--verbose-level', '-v', GetoptLong::REQUIRED_ARGUMENT, _("Set max verbosity level (0: errors, 1: warnings, 2: important messages, 3: other messages)") ],
+]
+
+def usage
+    puts __("Usage: %s [OPTION]...", File.basename($0))
+    $options.each { |ary|
+        printf " %3s, %-15s %s\n", ary[1], ary[0], ary[3]
+    }
+end
+
+def handle_options
+    parser = GetoptLong.new
+    parser.set_options(*$options.collect { |ary| ary[0..2] })
+    begin
+        parser.each_option do |name, arg|
+            case name
+            when '--help'
+                usage
+                exit(0)
+
+            when '--verbose-level'
+                $verbose_level = arg.to_i
+
+            end
+        end
+    rescue
+        puts $!
+        usage
+        exit(1)
+    end
+end
+
 def read_config
     $config = {}
     $config_file = File.expand_path('~/.booh-gui-rc')
@@ -88,7 +122,7 @@ def view_element(filename)
     w = Gtk::Window.new
 
     default_size = $images_size.detect { |sizeobj| sizeobj['default'] }
-    puts "filename: #{filename}"
+    msg 3, "filename: #{filename}"
     dest_img = build_full_dest_filename(filename).sub(/\.[^\.]+$/, '') + "-#{default_size['fullscreen']}.jpg"
     #- typically this file won't exist in case of videos; try with the largest thumbnail around
     if !File.exists?(dest_img)
@@ -316,7 +350,7 @@ def show_thumbnails
     xmldir.elements.each { |element|
         if element.name == 'image' || element.name == 'video'
             dest_img = build_full_dest_filename(element.attributes['filename']).sub(/\.[^\.]+$/, '') + "-#{default_size['thumbnails']}.jpg"
-            puts "dest_img: #{dest_img}"
+            msg 3, "dest_img: #{dest_img}"
             add_thumbnail($autotable, element.attributes['filename'], element.name, dest_img, from_utf8(element.attributes['caption']))
         end
     }
@@ -346,7 +380,7 @@ def open_file(filename)
 
     $filename = filename
     select_theme('simple')
-    puts "source: #{source}"
+    msg 3, "source: #{source}"
 
     xmldir = $xmldoc.elements["//dir[@path='#{source}']"]
     if !xmldir
@@ -359,7 +393,7 @@ def open_file(filename)
         child_iter = $albums_ts.append(parent_iter)
         child_iter[0] = File.basename(location)
         child_iter[1] = location
-        puts "puttin location: #{location}"
+        msg 3, "puttin location: #{location}"
         $xmldoc.elements.each("//dir[@path='#{location}']/dir") { |elem|
             append_dir_elem.call(child_iter, elem.attributes['path'])
         }
@@ -439,7 +473,7 @@ def create_main_window
         save_changes
        iter = w.selected
         if !iter
-            puts "no selection"
+            msg 3, "no selection"
         else
             $current_path = $albums_ts.get_value(iter, 1)
             show_thumbnails
@@ -469,10 +503,10 @@ def create_main_window
     else
         $main_window.window_position = Gtk::Window::POS_CENTER
     end
-    puts "width: #{$config['width']}\n\n"
+    msg 3, "width: #{$config['width']}\n\n"
     $main_window.set_default_size(($config['width'] || 600).to_i, ($config['height'] || 400).to_i)
     $main_window.signal_connect('configure-event') {
-        puts "configure: pos: #{$main_window.window.root_origin.inspect} size: #{$main_window.window.size.inspect}"
+        msg 3, "configure: pos: #{$main_window.window.root_origin.inspect} size: #{$main_window.window.size.inspect}"
         x, y = $main_window.window.root_origin
         width, height = $main_window.window.size
         $config['pos-x'] = x
@@ -487,6 +521,7 @@ def create_main_window
 end
 
 
+handle_options
 read_config
 
 Gtk.init
index 9c2e1f96cbbc9355d99b1f5ecee226795583e608..c2fc7cfa9cc1ad56baf5edcd98cd073b6eb7bf80 100644 (file)
@@ -1,5 +1,8 @@
 require 'gtk2'
 
+require 'booh/booh-lib'
+include Booh
+
 class Gtk::AutoTable < Gtk::VBox
 
     def initialize(row_spacings)
@@ -12,7 +15,7 @@ class Gtk::AutoTable < Gtk::VBox
         super
         recreate_table
         signal_connect('size-allocate') { |w, allocation|
-            puts "got self allocation: #{allocation}"
+            msg 3, "got self allocation: #{allocation}"
             if @width != allocation.width
                 if !@old_widths.include?(allocation.width)
                     @width = allocation.width
@@ -20,7 +23,7 @@ class Gtk::AutoTable < Gtk::VBox
                     @old_widths = @old_widths[0..2]
                     redistribute(false)
                 else
-                    puts "\tDISABLING: #{allocation.width} - #{@old_widths.join(',')}"
+                    msg 3, "\tDISABLING: #{allocation.width} - #{@old_widths.join(',')}"
                 end
             end
         }
@@ -53,15 +56,15 @@ class Gtk::AutoTable < Gtk::VBox
 
         #- connect 'size-allocate' signal to be sure to update allocation when received
         widget.signal_connect('size-allocate') { |w, allocation|
-            puts "got allocation for #{w.hash}: #{allocation} (#{allocation.hash})"
+            msg 3, "got allocation for #{w.hash}: #{allocation} (#{allocation.hash})"
             chld = @children.find { |e| e[:widget] == w }
             if chld
                 old = chld[:allocation]
                 #- need to copy values because the object will be magically exploded when widget is removed
                 chld[:allocation] = { :width => allocation.width, :height => allocation.height }
                 if !old #|| old[:width] != allocation.width # || old[:height] != allocation.height
-                    puts "redistribute!"
-                    chld == @children[0] && old and puts "************ old was #{old[:width]} #{old[:height]}"
+                    msg 3, "redistribute!"
+                    chld == @children[0] && old and msg 3, "************ old was #{old[:width]} #{old[:height]}"
                     redistribute(true)
                 end
             else
@@ -237,13 +240,13 @@ class Gtk::AutoTable < Gtk::VBox
     private
 
     def put(element, x, y)
-        puts "putting #{element[:widget].hash} at #{x},#{y}"
+        msg 3, "putting #{element[:widget].hash} at #{x},#{y}"
         element[:x] = x
         element[:y] = y
         container = @containers.find { |e| e[:x] == x && e[:y] == y }
         if !container
             container = { :x => x, :y => y, :widget => Gtk::VBox.new, :fake => Gtk::Label.new('fake') }
-            puts "attaching at #{x},#{y}"
+            msg 3, "attaching at #{x},#{y}"
             @table.attach(container[:widget], x, x + 1, y, y + 1, Gtk::FILL, Gtk::FILL, 5, 0)
             @containers << container
         end
@@ -258,9 +261,6 @@ class Gtk::AutoTable < Gtk::VBox
     def recreate_table
         @containers.each { |e|
             if e[:contained_element]
-                if e[:contained_element][:widget].focus?
-                    puts "I HAVE A FOCUS!"
-                end
                 e[:widget].remove(e[:contained_element][:widget])
             end
         }
@@ -274,8 +274,8 @@ class Gtk::AutoTable < Gtk::VBox
     end
 
     def redistribute(force)
-        puts "redistribute: "
-        @children.each { |e| print e[:allocation] ? 'O' : '.' }; puts
+        msg 3, "redistribute: "
+        @children.each { |e| msg_ 3, e[:allocation] ? 'O' : '.' }; msg 3, ''
         if unallocated = @children.find { |e| !e[:allocation] }
             #- waiting for allocations. replace last displayed widget with first unallocated.
             last_container = @containers[-1]
@@ -303,7 +303,7 @@ class Gtk::AutoTable < Gtk::VBox
                     xpix += 5 + e[:allocation][:width] + 5
                 }
                 if @children[1..-1].find { |e| e[:xnew] != e[:x] || e[:ynew] != e[:y] } || force
-                    puts "I can proceed with #{allocation}"
+                    msg 3, "I can proceed with #{allocation}"
                     recreate_table
                     put(@children[0], 0, 0)
                     @children[1..-1].each { |e|