add popup menu on elements. provide a way to flip and swap colors for videos
authorgc <gc>
Wed, 6 Apr 2005 22:10:11 +0000 (22:10 +0000)
committergc <gc>
Wed, 6 Apr 2005 22:10:11 +0000 (22:10 +0000)
bin/booh-gui
data/booh/images/stock-color-triangle-16.png [new file with mode: 0644]
data/booh/images/stock-rotate-180-16.png [new file with mode: 0644]
lib/booh/booh-lib.rb

index 5531b71ff4564d9247f2ec68e900dbb153a42290..c8f4f8645ccd0ad223b5a3f7e667501280754c97 100755 (executable)
@@ -150,29 +150,17 @@ def view_element(filename)
                 end
         end
     end
-    i = Gtk::Image.new(dest_img)
-    f = Gtk::Frame.new
-    f.add(i)
-    f.set_shadow_type(Gtk::SHADOW_ETCHED_OUT)
-    hb = Gtk::HBox.new
-    hb.pack_start(Gtk::Label.new, true, true)
-    hb.pack_start(f, false, false)
-    hb.pack_end(Gtk::Label.new, true, true)
-    evt = Gtk::EventBox.new
-    evt.add(hb)
+    evt = Gtk::EventBox.new.add(Gtk::Alignment.new(0.5, 0.5, 0, 0).add(Gtk::Frame.new.add(Gtk::Image.new(dest_img)).set_shadow_type(Gtk::SHADOW_ETCHED_OUT)))
 
     tooltips = Gtk::Tooltips.new
     tooltips.set_tip(evt, utf8(File.basename(filename).gsub(/\.jpg/, '')), nil)
-    
-    hb2 = Gtk::HBox.new
-    hb2.pack_start(Gtk::Label.new, true, true)
-    hb2.pack_start(b = Gtk::Button.new(Gtk::Stock::CLOSE), false, false)
+
+    bottom = Gtk::Alignment.new(0.5, 0.5, 0, 0).add(b = Gtk::Button.new(Gtk::Stock::CLOSE))
     b.signal_connect('clicked') { w.destroy }
-    hb2.pack_end(Gtk::Label.new, true, true)
 
     vb = Gtk::VBox.new
     vb.pack_start(evt, false, false)
-    vb.pack_end(hb2, false, false)
+    vb.pack_end(bottom, false, false)
 
     w.add(vb)
     w.signal_connect('delete-event') { w.destroy }
@@ -226,24 +214,28 @@ end
 
 def add_thumbnail(autotable, filename, type, thumbnail_img, caption)
 
-    frame1 = Gtk::Frame.new
-    #- generate the thumbnail if missing (if image was rotated but booh was not relaunched)
-    if !$rotated_pixbufs[thumbnail_img] && !File.exists?(thumbnail_img)
-        frame1.add(img = Gtk::Image.new)
+    img = nil
+    gen_real_thumbnail = Proc.new {
         Thread.new {
             gen_thumbnails_element(from_utf8("#{$current_path}/#{filename}"), $xmldir, false, [ { 'filename' => thumbnail_img, 'size' => $default_size['thumbnails'] } ])
             img.set(thumbnail_img)
+            $rotated_pixbufs[thumbnail_img] = { :orig => img.pixbuf, :angle_to_orig => 0 }
+            if type == 'video'
+                #- cleanup temp for videos
+                system("rm -f #{current_dest_dir}/screenshot.jpg00000*")
+            end
         }
+    }
+
+    frame1 = Gtk::Frame.new
+    #- generate the thumbnail if missing (if image was rotated but booh was not relaunched)
+    if !$rotated_pixbufs[thumbnail_img] && !File.exists?(thumbnail_img)
+        frame1.add(img = Gtk::Image.new)
+        gen_real_thumbnail.call
     else
         frame1.add(img = Gtk::Image.new($rotated_pixbufs[thumbnail_img] ? $rotated_pixbufs[thumbnail_img][:pixbuf] : thumbnail_img))
     end
-    frame1.set_shadow_type(Gtk::SHADOW_ETCHED_OUT)
-    hbox1 = Gtk::HBox.new
-    hbox1.pack_start(Gtk::Label.new, true, true)
-    hbox1.pack_start(frame1, false, false)
-    hbox1.pack_end(Gtk::Label.new, true, true)
-    evtbox = Gtk::EventBox.new
-    evtbox.add(hbox1)
+    evtbox = Gtk::EventBox.new.add(Gtk::Alignment.new(0.5, 0.5, 0, 0).add(frame1.set_shadow_type(Gtk::SHADOW_ETCHED_OUT)))
 
     tooltips = Gtk::Tooltips.new
     tipname = File.basename(thumbnail_img).gsub(/-\d+x\d+\.jpg/, '')
@@ -274,6 +266,24 @@ def add_thumbnail(autotable, filename, type, thumbnail_img, caption)
         end
     }
 
+    color_swap_and_cleanup = Proc.new {
+        xmlelem = $xmldir.elements["[@filename='#{filename}']"]
+        if xmlelem.attributes['color-swap']
+            xmlelem.delete_attribute('color-swap')
+        else
+            xmlelem.add_attribute('color-swap', '1')
+        end
+        system("rm -f '#{thumbnail_img}'")
+
+        #- remove out of sync images
+        dest_img_base = build_full_dest_filename(filename).sub(/\.[^\.]+$/, '')
+        for sizeobj in $images_size
+            system("rm -f #{dest_img_base}-#{sizeobj['thumbnails']}.jpg")
+        end
+
+        gen_real_thumbnail.call
+    }
+
     delete = Proc.new {
         after = autotable.get_next_widget(vbox)
         if !after
@@ -367,6 +377,29 @@ def add_thumbnail(autotable, filename, type, thumbnail_img, caption)
                 textview.grab_focus
             end
         end
+        if event.event_type == Gdk::Event::BUTTON_PRESS && event.button == 3
+            menu = Gtk::Menu.new
+            menu.append(    r90 = Gtk::ImageMenuItem.new(utf8(_("Rotate clockwise"))))
+            menu.append(   r270 = Gtk::ImageMenuItem.new(utf8(_("Rotate counter-clockwise"))))
+            r90.image = Gtk::Image.new("#{$FPATH}/images/stock-rotate-90-16.png")
+            r90.signal_connect('activate') { rotate_and_cleanup.call(90) }
+            r270.image = Gtk::Image.new("#{$FPATH}/images/stock-rotate-270-16.png")
+            r270.signal_connect('activate') { rotate_and_cleanup.call(270) }
+            if type == 'video'
+                menu.append(             Gtk::SeparatorMenuItem.new)
+                menu.append(color_swap = Gtk::ImageMenuItem.new(utf8(_("Red/blue color swap"))))
+                menu.append(      flip = Gtk::ImageMenuItem.new(utf8(_("Flip upside-down"))))
+                color_swap.image = Gtk::Image.new("#{$FPATH}/images/stock-color-triangle-16.png")
+                color_swap.signal_connect('activate') { color_swap_and_cleanup.call }
+                flip.image = Gtk::Image.new("#{$FPATH}/images/stock-rotate-180-16.png")
+                flip.signal_connect('activate') { rotate_and_cleanup.call(180) }
+            end
+            menu.append(          Gtk::SeparatorMenuItem.new)
+            menu.append(delete  = Gtk::ImageMenuItem.new(Gtk::Stock::DELETE))
+            delete.signal_connect('activate') { delete.call }
+            menu.show_all
+            menu.popup(nil, nil, event.button, event.time)
+        end
         if event.event_type == Gdk::Event::BUTTON2_PRESS && event.button == 1
             view_element(filename)
         else
@@ -495,6 +528,11 @@ def change_dir
 
     $xmldir = $xmldoc.elements["//dir[@path='#{$current_path}']"]
     $subalbums_edits = {}
+
+    find_infotype = Proc.new { |xmldir|
+        xmldir == $xmldir ? 'thumbnails' : find_subalbum_info_type(xmldir)
+    }
+
     add_subalbum = Proc.new { |xmldir|
         if xmldir == $xmldir
             thumbnail_file = "#{current_dest_dir}/thumbnails-thumbnail.jpg"
@@ -506,19 +544,27 @@ def change_dir
         end
         msg 3, "add subdir: #{xmldir.attributes['path']} with file: #{thumbnail_file}"
         hbox = Gtk::HBox.new
-        hbox.pack_start(Gtk::Label.new, true, true)
-        hbox.pack_start(Gtk::Label.new.set_markup('<i>' + File.basename(xmldir.attributes['path']) + ':</i>'), false, false)
+        hbox.pack_start(Gtk::Alignment.new(1, 0.5, 0, 0).add(Gtk::Label.new.set_markup('<i>' + File.basename(xmldir.attributes['path']) + ':</i>')))
         f = Gtk::Frame.new
         f.set_shadow_type(Gtk::SHADOW_ETCHED_OUT)
 
-        if !$rotated_pixbufs[thumbnail_file] && !File.exists?(thumbnail_file)
-            f.add(img = Gtk::Image.new)
+        img = nil
+        gen_real_thumbnail = Proc.new {
             Thread.new {
-                infotype = xmldir == $xmldir ? 'thumbnails' : find_subalbum_info_type(xmldir)
+                system("rm -f '#{thumbnail_file}'")
                 gen_thumbnails_subdir(from_utf8(captionfile), xmldir, false,
-                                      [ { 'filename' => thumbnail_file, 'size' => $albums_thumbnail_size } ], infotype)
+                                      [ { 'filename' => thumbnail_file, 'size' => $albums_thumbnail_size } ], find_infotype.call(xmldir))
                 img.set(thumbnail_file)
+                $rotated_pixbufs[thumbnail_file] = { :orig => img.pixbuf, :angle_to_orig => 0 }
+                if entry2type(captionfile) == 'video'
+                    system("rm -f #{current_dest_dir}/screenshot.jpg00000*")
+                end
             }
+        }
+
+        if !$rotated_pixbufs[thumbnail_file] && !File.exists?(thumbnail_file)
+            f.add(img = Gtk::Image.new)
+            gen_real_thumbnail.call
         else
             f.add(img = Gtk::Image.new($rotated_pixbufs[thumbnail_file] ? $rotated_pixbufs[thumbnail_file][:pixbuf] : thumbnail_file))
         end
@@ -527,11 +573,21 @@ def change_dir
                           0, 1, current_y_sub_albums, current_y_sub_albums + 1, Gtk::FILL, Gtk::FILL, 2, 2)
 
         rotate_and_cleanup = Proc.new { |angle|
-            rotate(angle, thumbnail_file, img, xmldir, ( xmldir == $xmldir ? 'thumbnails' : find_subalbum_info_type(xmldir) ) + '-',
+            rotate(angle, thumbnail_file, img, xmldir, find_infotype.call(xmldir) + '-',
                    $default_albums_thumbnails[:x], $default_albums_thumbnails[:y])
             system("rm -f '#{thumbnail_file}'")
         }
 
+        color_swap_and_cleanup = Proc.new {
+            infotype = find_infotype.call(xmldir)
+            if xmldir.attributes["#{infotype}-color-swap"]
+                xmldir.delete_attribute("#{infotype}-color-swap")
+            else
+                xmldir.add_attribute("#{infotype}-color-swap", '1')
+            end
+            gen_real_thumbnail.call
+        }
+
         evtbox.signal_connect('button-press-event') { |w, event|
             if event.event_type == Gdk::Event::BUTTON_PRESS && event.button == 1
                 if $r90.active?
@@ -541,6 +597,26 @@ def change_dir
                     rotate_and_cleanup.call(270)
                 end
             end
+            if event.event_type == Gdk::Event::BUTTON_PRESS && event.button == 3
+                menu = Gtk::Menu.new
+                menu.append(    r90 = Gtk::ImageMenuItem.new(utf8(_("Rotate clockwise"))))
+                menu.append(   r270 = Gtk::ImageMenuItem.new(utf8(_("Rotate counter-clockwise"))))
+                r90.image = Gtk::Image.new("#{$FPATH}/images/stock-rotate-90-16.png")
+                r90.signal_connect('activate') { rotate_and_cleanup.call(90) }
+                r270.image = Gtk::Image.new("#{$FPATH}/images/stock-rotate-270-16.png")
+                r270.signal_connect('activate') { rotate_and_cleanup.call(270) }
+                if entry2type(captionfile) == 'video'
+                    menu.append(             Gtk::SeparatorMenuItem.new)
+                    menu.append(color_swap = Gtk::ImageMenuItem.new(utf8(_("Red/blue color swap"))))
+                    menu.append(      flip = Gtk::ImageMenuItem.new(utf8(_("Flip upside-down"))))
+                    color_swap.image = Gtk::Image.new("#{$FPATH}/images/stock-color-triangle-16.png")
+                    color_swap.signal_connect('activate') { color_swap_and_cleanup.call }
+                    flip.image = Gtk::Image.new("#{$FPATH}/images/stock-rotate-180-16.png")
+                    flip.signal_connect('activate') { rotate_and_cleanup.call(180) }
+                end
+                menu.show_all
+                menu.popup(nil, nil, event.button, event.time)
+            end
             if event.event_type == Gdk::Event::BUTTON2_PRESS && event.button == 1
                 fc = Gtk::FileChooserDialog.new(utf8(_("Select image for caption")),
                                                 nil,
@@ -564,16 +640,12 @@ def change_dir
                 }
                 if fc.run == Gtk::Dialog::RESPONSE_ACCEPT
                     msg 3, "new captionfile is: #{fc.filename}"
-                    $subalbums_edits[xmldir.attributes['path']][:captionfile] = utf8(fc.filename)
-                    Thread.new(fc.filename) { |filename|
-                        system("rm -f '#{thumbnail_file}'")
-                        $rotated_pixbufs.delete(thumbnail_file)
-                        infotype = xmldir == $xmldir ? 'thumbnails' : find_subalbum_info_type(xmldir)
-                        xmldir.delete_attribute("#{infotype}-rotate")
-                        gen_thumbnails_subdir(filename, xmldir, false,
-                                              [ { 'filename' => thumbnail_file, 'size' => $albums_thumbnail_size } ], infotype)
-                        img.set(thumbnail_file)
-                    }
+                    $subalbums_edits[xmldir.attributes['path']][:captionfile] = captionfile = utf8(fc.filename)
+                    $rotated_pixbufs.delete(thumbnail_file)
+                    infotype = find_infotype.call(xmldir)
+                    xmldir.delete_attribute("#{infotype}-rotate")
+                    xmldir.delete_attribute("#{infotype}-color-swap")
+                    gen_real_thumbnail.call
                 end
                 fc.destroy
                 true   #- handled
@@ -596,13 +668,9 @@ def change_dir
             $gesture_press = nil
         }
         
-        vbox = Gtk::VBox.new
-        vbox.pack_start(Gtk::Label.new, true, true)
         frame, textview = create_editzone($subalbums_sw)
         textview.buffer.text = caption
-        vbox.pack_start(frame, false, false)
-        vbox.pack_end(Gtk::Label.new, true, true)
-        $subalbums.attach(vbox,
+        $subalbums.attach(Gtk::Alignment.new(0, 0.5, 0.5, 0).add(frame),
                           1, 2, current_y_sub_albums, current_y_sub_albums + 1, Gtk::FILL, Gtk::FILL, 2, 2)
         
         $subalbums_edits[xmldir.attributes['path']] = { :editzone => textview, :captionfile => captionfile }
@@ -614,11 +682,7 @@ def change_dir
         frame, $subalbums_title = create_editzone($subalbums_sw)
         $subalbums_title.buffer.text = $xmldir.attributes['subdirs-caption']
         $subalbums_title.set_justification(Gtk::Justification::CENTER)
-        hbox = Gtk::HBox.new
-        hbox.add(Gtk::Label.new)
-        hbox.add(frame)
-        hbox.add(Gtk::Label.new)
-        $subalbums_vb.pack_start(hbox, false, false)
+        $subalbums_vb.pack_start(Gtk::Alignment.new(0.5, 0.5, 0.5, 0).add(frame), false, false)
         #- this album image/caption
         if $xmldir.attributes['thumbnails-caption']
             add_subalbum.call($xmldir)
diff --git a/data/booh/images/stock-color-triangle-16.png b/data/booh/images/stock-color-triangle-16.png
new file mode 100644 (file)
index 0000000..21791ed
Binary files /dev/null and b/data/booh/images/stock-color-triangle-16.png differ
diff --git a/data/booh/images/stock-rotate-180-16.png b/data/booh/images/stock-rotate-180-16.png
new file mode 100644 (file)
index 0000000..f8af520
Binary files /dev/null and b/data/booh/images/stock-rotate-180-16.png differ
index 52a5506cac38be7b1b26f5989fe377181315d7be..d8ed41d4bc54f95dddf4c31b26e463624cbbecf5 100644 (file)
@@ -227,7 +227,13 @@ module Booh
             frame_offset = (frame_offset || 5).to_i
             for dest in dests
                 if !File.exists?("#{dest_dir}/screenshot.jpg000004.jpg")
-                    cmd = "transcode -a 0 -c #{frame_offset-5}-#{frame_offset} -i '#{orig}' -y jpg -o '#{dest_dir}/screenshot.jpg' 2>&1"
+                    transcode_options = ''
+                    if felem
+                        if felem.attributes["#{attributes_prefix}color-swap"]
+                            transcode_options += '-k '
+                        end
+                    end
+                    cmd = "transcode -a 0 -c #{frame_offset-5}-#{frame_offset} -i '#{orig}' -y jpg -o '#{dest_dir}/screenshot.jpg' #{transcode_options} 2>&1"
                     msg 2, cmd
                     if subproc_runaway_aware(cmd) =~ /V: import format.*unknown/ || !File.exists?("#{dest_dir}/screenshot.jpg000004.jpg")
                         msg 2, _("* could not extract first image of video %s with transcode, will try first converting with mencoder") % orig
@@ -235,7 +241,7 @@ module Booh
                         msg 2, cmd
                         system cmd
                         if File.exists?("#{dest_dir}/foo.avi")
-                            cmd = "transcode -a 0 -c #{frame_offset-5}-#{frame_offset} -i '#{dest_dir}/foo.avi' -y jpg -o '#{dest_dir}/screenshot.jpg' 2>&1"
+                            cmd = "transcode -a 0 -c #{frame_offset-5}-#{frame_offset} -i '#{dest_dir}/foo.avi' -y jpg -o '#{dest_dir}/screenshot.jpg' #{transcode_options} 2>&1"
                             msg 2, cmd
                             results = subproc_runaway_aware(cmd)
                             system("rm -f '#{dest_dir}/foo.avi'")