Picky (image viewer) patches
Ken Hayber <ken <at> hayber.us>
2007-05-11 22:54:27 GMT
Do people out there actually use Picky?
Picky is stable at 0.4.5, but the development version is stuck and
unfinished at 0.5.1. The author 'Rds' seems to have left us.
I've made various small changes over the past 3 years which are in the
attached patch.
* Added ability to set the window background color for when the image is
smaller than the window. I like to have a dark grey as many other
image/photo viewers do
* Fixed the image loading so that the window updates immediately when
multiple files are dropped on it. In 0.4.5 this only works if a
directory was dropped.
* Various other little things which I honestly can't remember why I
changed them :)
If people show some interest I may revive this sucker and make a more
official update.
Comments/Suggestions?
Ken
diff -urN Picky-0.4.5/AppInfo.xml /home/ken/Apps/Graphics/Picky/AppInfo.xml
--- Picky-0.4.5/AppInfo.xml 2004-05-27 12:52:48.000000000 -0700
+++ /home/ken/Apps/Graphics/Picky/AppInfo.xml 2007-05-11 15:36:48.000000000 -0700
@@ -3,7 +3,7 @@
<Summary>A image viewer/slideshow app</Summary>
<About>
<Purpose>A image viewer capable of displaying a entire directory of images</Purpose>
- <Version>0.4.5 (28-May-2004)</Version>
+ <Version>0.4.6 (11-May-2007)</Version>
<Author>rds</Author>
<License>GPL Version 2</License>
<Homepage>http://www.rdsarts.com/code/picky/</Homepage>
diff -urN Picky-0.4.5/AppRun /home/ken/Apps/Graphics/Picky/AppRun
--- Picky-0.4.5/AppRun 2004-05-28 07:57:27.000000000 -0700
+++ /home/ken/Apps/Graphics/Picky/AppRun 2007-05-11 08:25:34.000000000 -0700
@@ -23,24 +23,23 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
'''
-import sys, os, findrox, threading, time, gc
+import sys, os, findrox, time
from debug_utils import *
findrox.version(1,9,12)
import rox
-from rox import Menu, mime, filer
+from rox import Menu, mime, filer, tasks
from rox.options import Option
from rox import g as gtk
-# from img_logic import ImageLogic
from img_logic import *
APP_NAME = 'Picky'
'''
# Constants for scaling.
-SCALE_NORM = 0
+SCALE_NORM = 0
SCALE_UP = 1
-SCALE_DOWN = -1
+SCALE_DOWN = -1
SCALE_FIT = 2
RATIO_NORMAL = 1.0
RATIO_FIT = -1.0
@@ -60,6 +59,7 @@
scale_to_window = Option('scale', False)
resize_on_load = Option('resize', 'Never')
recursive_load = Option('recursive_load', False)
+ bg_color = Option('bg_color', '#A6A699')
rox.app_options.notify()
def __init__(self, argv=None):
@@ -75,22 +75,20 @@
self.set_scale(SCALE_FIT)
self.options_init()
-
- # TODO: Readd background engine. This will not show anything until it
- # loads, and tossing big ol' directories won't show a thing for awhile.
- self.show_all()
- gtk.main_iteration()
- gtk.main_iteration()
- gtk.main_iteration()
+ rox.app_options.add_notify(self.get_options)
if len(argv) > 1:
- for iteration in argv[1:]:
- # TODO: Fix.
- self.append(iteration)
+ tasks.Task(self.add_images())
# Leaving inits, set startup to false.
self.update_window()
self.startup = False
+ self.show_all()
+
+ def add_images(self):
+ for image in sys.argv[1:]:
+ self.append(image)
+ yield tasks.IdleBlocker()
def ui_init(self):
self.image = gtk.Image()
@@ -101,13 +99,18 @@
self.image.set_size_request(10, 10)
self.add(box)
- box.pack_start(self.toolbar, gtk.FALSE, gtk.TRUE)
+ box.pack_start(self.toolbar, False, True)
box.pack_start(self.scrolled_window)
- self.scrolled_window.add_with_viewport(self.image)
+ self.view = gtk.Viewport()
+ self.view.add(self.image)
+ self.scrolled_window.add(self.view)
self.scrolled_window.set_shadow_type(gtk.SHADOW_NONE)
- self.set_default_size(gtk.gdk.screen_width() / 3, gtk.gdk.screen_height() / 3)
+ self.set_default_size(gtk.gdk.screen_width()/3*2, gtk.gdk.screen_height()/3*2)
self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
+ bg_color = gtk.gdk.color_parse(self.bg_color.value)
+ self.view.modify_bg(gtk.STATE_NORMAL, bg_color)
+
self.add_events(gtk.gdk.BUTTON_PRESS_MASK)
self.connect('button-press-event', self.button_press)
self.connect('key-press-event', self.key_press_event)
@@ -120,6 +123,12 @@
self.update_scrollbars()
self.update_window()
+ def get_options(self):
+ if self.bg_color.has_changed:
+ bg_color = gtk.gdk.color_parse(self.bg_color.value)
+ self.view.modify_bg(gtk.STATE_NORMAL, bg_color)
+
+
def data_init(self):
self.toolbar_buttons = []
self.sensitive = True
@@ -196,12 +205,12 @@
if scale_amount == SCALE_FIT:
if self.ratio == RATIO_FIT:
self.ratio = RATIO_NORMAL
- self.scale_toggle_button.set_active(gtk.FALSE)
+ self.scale_toggle_button.set_active(False)
else:
self.ratio = RATIO_FIT
- self.scale_toggle_button.set_active(gtk.TRUE)
+ self.scale_toggle_button.set_active(True)
else:
- self.scale_toggle_button.set_active(gtk.FALSE)
+ self.scale_toggle_button.set_active(False)
if self.ratio == -1:
self.ratio = 1.0
if scale_amount == SCALE_UP:
@@ -273,7 +282,7 @@
temp = gtk.ImageMenuItem(name)
temp.set_image(image)
- temp.set_right_justified(gtk.TRUE)
+ temp.set_right_justified(True)
temp.connect('activate', self.set_index, iter)
temp.show()
file_menu.add(temp)
@@ -281,7 +290,7 @@
file_menu.popup(None, None, None, 0, 0)
# TODO: Place menu at current image.
- return gtk.TRUE
+ return True
def close_quit(self, *dummy):
''' Callback to destroy window. '''
@@ -303,7 +312,7 @@
y_adj = self.scrolled_window.get_hadjustment()
x_range = self.pixbuf.get_height() - x_adj.page_size
y_range = self.pixbuf.get_width() - y_adj.page_size
-
+
def update_adj(adj, change, range):
if change > range:
adj.set_value(range)
@@ -328,7 +337,7 @@
i_width, i_height = self.pixbuf.get_width(), self.pixbuf.get_height()
if (i_width, i_height) == (0, 0): return
- # style can be 'scale', 'stretch', 'tile', or 'centre', NOTHING ELSE!!!1!1!!one!11!eleven
+ # style can be 'scale', 'stretch', 'tile', or 'centre', NOTHING ELSE
if (width == i_width and height == i_height) or height == int(width * .75):
style = 'stretch'
elif width > i_width and height > i_height:
diff -urN Picky-0.4.5/Help/ChangeLog /home/ken/Apps/Graphics/Picky/Help/ChangeLog
--- Picky-0.4.5/Help/ChangeLog 2004-05-28 08:53:08.000000000 -0700
+++ /home/ken/Apps/Graphics/Picky/Help/ChangeLog 2007-05-11 15:40:32.000000000 -0700
@@ -1,3 +1,12 @@
+Changes from 0.4.5 to 0.4.6
+
+2007-05-11 - Ken Hayber <ken <at> hayber.us>
+ * Fixed - Loading multiple files (not in a directory) at startup did not
+ update the display until all files were loaded. Used rox-lib's Tasks
+ module to do this.
+ * Fixed - various image scaling code in img_logic.py
+ * Added - Ability to set background color of the window outside of the image.
+
Changes from 0.4.4 to 0.4.5
2004-05-27 - rds <rds <at> rds.rds>
diff -urN Picky-0.4.5/img_logic.py /home/ken/Apps/Graphics/Picky/img_logic.py
--- Picky-0.4.5/img_logic.py 2004-05-28 08:38:07.000000000 -0700
+++ /home/ken/Apps/Graphics/Picky/img_logic.py 2006-08-06 10:00:08.000000000 -0700
@@ -8,15 +8,15 @@
SCALE_DOWN = -1
SCALE_FIT = 2
RATIO_NORMAL = 1.0
-RATIO_FIT = -1.0
+RATIO_FIT = -1.0
RATIO_STEP = 0.1
class ImageLogic(loading.XDSLoader):
def __init__(self):
loading.XDSLoader.__init__(self, None)
self.imgs = []
- self.fit_w = 10
- self.fit_h = 10
+ self.fit_w = 60
+ self.fit_h = 60
self.idx = -1
self.setting_image = False
self.thumbnails = []
@@ -32,7 +32,9 @@
''' Takes in filename. Adds all images found within. '''
filename = os.path.abspath(filename)
self.set_title('Loading ' + filename + '...')
- gtk.main_iteration()
+
+ while gtk.events_pending():
+ gtk.main_iteration()
if os.path.isdir(filename):
# Load all files in directory.
@@ -57,12 +59,12 @@
type = str(rox.mime.get_type(filename)).split('/')[0]
if type == 'image':
try:
- pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
- thumbnail = self.scale_to_size(pixbuf, 30)
+ thumbnail = gtk.gdk.pixbuf_new_from_file_at_size(filename, 30, 30)
self.imgs.append(filename)
self.thumbnails.append(thumbnail)
del pixbuf
del thumbnail
+
except:
# Can't load the image. Image is probably broken, just ignore it.
pass
@@ -71,7 +73,7 @@
#Show the first image as soon as possible
if self.idx < 0:
self.set_idx(0)
- # self.update_image()
+
def set_idx(self, idx):
''' Sets self.idx to idx, and updates the UI'''
@@ -90,64 +92,33 @@
self.update_scrollbars()
self.update_window()
- def scale_to_size(self, pixbuf, size):
- ''' Returns a pixmap scaled in width and height to, at most, 'size.' '''
- size_h = float(pixbuf.get_height())
- size_w = float(pixbuf.get_width())
- ratio = float(1)
- size = float(size)
- if size_h > size_w:
- # Height larger.
- ratio = float(size_h / size)
- else:
- # Sizes equal, or width larger
- ratio = float(size_w / size)
- if ratio <= 0.0:
- ratio = 1.0
- size_h, size_w = int(size_h / ratio), int(size_w / ratio)
- return pixbuf.scale_simple(size_w, size_h, gtk.gdk.INTERP_BILINEAR)
-
- def scale_to_ratio(self, pixbuf, ratio):
- '''Returns pixbuf scaled to ratio... 'ratio' '''
- size_h = int(pixbuf.get_height() * ratio)
- size_w = int(pixbuf.get_width() * ratio)
- return pixbuf.scale_simple(size_w, size_h, gtk.gdk.INTERP_BILINEAR)
-
- def scale_to_fit(self, pixbuf):
- ''' Updates displayed image to scaled version of self.pixbuf '''
- if self.fit_w < 10 or self.fit_h < 10:
- return
- img_w = pixbuf.get_width()
- img_h = pixbuf.get_height()
+ def scale_to_ratio(self):
+ '''Returns pixbuf scaled to ratio...'''
+ filename = self.imgs[self.idx]
+ subtype = str(rox.mime.get_type(filename)).split('/')[1]
+ if subtype == 'svg+xml':
+ width, height = self.fit_w, self.fit_h
+ else:
+ #this dies on my system with svg, try again later (gtk+ 2.4.13)
+ (other, width, height) = gtk.gdk.pixbuf_get_file_info(filename)
+ size_w = int(width * self.ratio)
+ size_h = int(height * self.ratio)
+ return gtk.gdk.pixbuf_new_from_file_at_size(filename, size_w, size_h)
- size_w = float(self.fit_w)
- size_h = float(self.fit_h)
- resize_w = size_w / img_w
- resize_h = size_h / img_h
-
- if img_h * resize_w > size_h:
- #resize_w = (img_h * resize_w) / size_h
- size = resize_h
- elif img_w * resize_h > size_w:
- #resize_h = (img_w * resize_h) / size_w
- size = resize_w
- elif resize_w < resize_h:
- size = resize_w
- else:
- size = resize_h
+ def scale_to_fit(self):
+ ''' Updates displayed image to scaled version of self.pixbuf '''
+ return gtk.gdk.pixbuf_new_from_file_at_size(self.imgs[self.idx], self.fit_w, self.fit_h)
- # debugger('Setting image to size %f'%size)
- return self.scale_to_ratio(pixbuf, size)
def resize_event(self, widget, rec = None):
''' Called when the window is resized. Should update the image's scaling accordingly.'''
if self.ratio != -1:
return
-
+
width, height = rec.width, rec.height
-
+
if self.fit_w == width and self.fit_h == height:
# debugger('nothing to scale')
return
@@ -164,6 +135,7 @@
# debugger("fit_size w %d h %d"%(self.fit_w, self.fit_h))
self.update_image()
+
def resize_to_pixbuf(self, pixbuf):
''' Resizes the window if options are OK with it, or dies trying.'''
if self.ratio == RATIO_FIT:
@@ -173,13 +145,11 @@
width = pixbuf.get_width()
height = pixbuf.get_height()
tool_h = self.toolbar.get_child_requisition()[1]
- # debugger('image w %d h %d - toolbar h %d'%(width, height, tool_h))
# Add the toolbar's size, and add some extra pixels to avoid the scrollbars.
- width += 8
- height += (tool_h + 8)
- screen_w, screen_h = (gtk.gdk.screen_width() / 4) * 3, (gtk.gdk.screen_height() / 4) * 3
- # debugger('image w %d h %d - screen w %d h %d'%(width, height, screen_w, screen_h))
+ width += 20
+ height += (tool_h + 40)
+ screen_w, screen_h = (gtk.gdk.screen_width() * 0.9, gtk.gdk.screen_height() * 0.9)
if width > screen_w: width = screen_w
if height > screen_h: height = screen_h
@@ -187,6 +157,7 @@
self.resize(width, height)
self.move_window_onscreen(width, height)
+
def move_window_onscreen(self, size_x, size_y):
''' Moves the window back within screen bounds, assuming it isn't already.'''
BOARDER = 40
@@ -204,7 +175,6 @@
move_x = loc_x
if not move_y:
move_y = loc_y
- # debugger('x %d - y %d'%(move_x, move_y))
self.move(move_x, move_y)
def make_idx_sane(self):
@@ -216,13 +186,11 @@
def make_image(self, filename):
''' Attempts to return a Pixbuf of 'filename.' Does not sanity check!'''
- pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
if self.ratio == RATIO_FIT:
- pixbuf = self.scale_to_fit(pixbuf)
- elif self.ratio != RATIO_NORMAL:
- assert self.ratio > 0.0
- pixbuf = self.scale_to_ratio(pixbuf, self.ratio)
- return pixbuf
+ return self.scale_to_fit()
+ else:
+ return self.scale_to_ratio()
+
def update_scrollbars(self):
''' Show/hide scrollbars, and position them at 0, 0'''
@@ -248,9 +216,6 @@
# Deleted image. Remove from filelist.
del self.imgs[self.idx]
self.update_image()
-
- if self.pixbuf:
- del self.pixbuf
self.pixbuf = self.make_image( self.imgs[self.idx] )
self.image.set_from_pixbuf(self.pixbuf)
diff -urN Picky-0.4.5/Options.xml /home/ken/Apps/Graphics/Picky/Options.xml
--- Picky-0.4.5/Options.xml 2004-05-23 01:09:55.000000000 -0700
+++ /home/ken/Apps/Graphics/Picky/Options.xml 2007-05-11 07:52:03.000000000 -0700
@@ -14,5 +14,7 @@
<item value='Startup' label='First image loaded only'/>
<item value='Never' label='Never'/>
</menu>
+ <colour name='bg_color' label='Background Color:'>The background color of the main display area.</colour>
+
</section>
</options>
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
rox-users mailing list
rox-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rox-users