-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmirage.py
executable file
·4743 lines (4464 loc) · 204 KB
/
mirage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python2
# $HeadURL$
# $Id$
__version__ = "1.0-svn"
__appname__ = "Mirage"
__license__ = """
Mirage, a fast GTK+ Image Viewer
Copyright 2007 Scott Horowitz <[email protected]>
Copyright 2010-2011 Fredric Johansson <[email protected]>
This file is part of Mirage.
Mirage is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mirage is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import traceback
import pygtk
pygtk.require('2.0')
import gtk
import os, sys, getopt, string, gc
import random, urllib, gobject, gettext, locale
import stat, time, subprocess, shutil, filecmp
import tempfile, socket, threading, copy
from fractions import Fraction
import json
gettext.install("mirage", unicode=1)
try:
import mirage_numacomp as numacomp
HAVE_NUMACOMP = True
except:
HAVE_NUMACOMP = False
print _("mirage_numacomp.so not found, unable to do numerical aware sorting.")
try:
import hashlib
HAS_HASHLIB = True
except:
HAS_HASHLIB= False
import md5
try:
import imgfuncs
HAS_IMGFUNCS = True
except:
HAS_IMGFUNCS = False
print _("imgfuncs.so module not found, rotating/flipping images will be disabled.")
try:
import xmouse
HAS_XMOUSE = True
except:
HAS_XMOUSE = False
print _("xmouse.so module not found, some screenshot capabilities will be disabled.")
try:
import pyexiv2
HAS_EXIF = True
except:
HAS_EXIF = False
print _("pyexiv2 module not found, exifdata reading/writing are disabled")
try:
import gconf
except:
pass
if gtk.gtk_version < (2, 10, 0):
sys.stderr.write(_("Mirage requires GTK+ %s or newer..\n") % "2.10.0")
sys.exit(1)
if gtk.pygtk_version < (2, 12, 0):
sys.stderr.write(_("Mirage requires PyGTK %s or newer.\n") % "2.12.0")
sys.exit(1)
def valid_int(inputstring):
try:
x = int(inputstring)
return True
except:
return False
class Base:
def __init__(self):
gtk.gdk.threads_init()
# Constants
self.open_mode_smart = 0
self.open_mode_fit = 1
self.open_mode_1to1 = 2
self.open_mode_last = 3
self.min_zoomratio = 0.02
# Current image:
self.curr_img_in_list = 0
# This is the actual pixbuf that is loaded in Mirage. This will
# usually be the same as self.curr_img_in_list except for scenarios
# like when the user presses 'next image' multiple times in a row.
# In this case, self.curr_img_in_list will increment while
# self.loaded_img_in_list will retain the current loaded image.
self.loaded_img_in_list = -2
self.currimg = ImageData(index=0)
# Next preloaded image:
self.nextimg = ImageData(index=-1)
# Previous preloaded image:
self.previmg = ImageData(index=-1)
# Create a dictionary with all settings the users can do in the interface
self.usettings = {}
# Window settings
self.usettings['window_width'] = 600
self.usettings['window_height'] = 400
self.usettings['toolbar_show'] = True
self.usettings['thumbpane_show'] = True
self.usettings['statusbar_show'] = True
# Settings, Behavior
self.usettings['open_mode'] = self.open_mode_smart
self.usettings['last_mode'] = self.open_mode_smart
self.usettings['open_all_images'] = True # open all images in the directory(ies)
self.usettings['open_hidden_files'] = False
self.usettings['use_numacomp'] = False
self.usettings['case_numacomp'] = False
self.usettings['use_last_dir'] = True
self.usettings['last_dir'] = os.path.expanduser("~")
self.usettings['fixed_dir'] = os.path.expanduser("~")
# Settings, Navigation
self.usettings['listwrap_mode'] = 0 # 0=no, 1=yes, 2=ask
self.usettings['preloading_images'] = True
# Settings, Interface
self.usettings['simple_bgcolor'] = False
self.usettings['bgcolor'] = {'r':0, 'g':0, 'b': 0}
self.usettings['thumbnail_size'] = 128 # Default to 128 x 128
self.usettings['start_in_fullscreen'] = False
# Settings, Slideshow
self.usettings['slideshow_delay'] = 1 # seconds
self.usettings['disable_screensaver'] = False
self.usettings['slideshow_in_fullscreen'] = False
self.usettings['slideshow_random'] = False
# Settings, Editing:
self.usettings['zoomvalue'] = 2
self.usettings['savemode'] = 2
self.usettings['quality_save'] = 90
self.usettings['confirm_delete'] = True
# Action settings
self.usettings['action_names'] = [_("Open in GIMP"), _("Create Thumbnail"), _("Create Thumbnails"), _("Move to Favorites")]
self.usettings['action_shortcuts'] = ["<Control>e", "<Alt>t", "<Control><Alt>t", "<Control><Alt>f"]
self.usettings['action_commands'] = ["gimp %F", "convert %F -thumbnail 150x150 %Pt_%N.jpg", "convert %F -thumbnail 150x150 %Pt_%N.jpg", "mkdir -p ~/mirage-favs; mv %F ~/mirage-favs; [NEXT]"]
self.usettings['action_batch'] = [False, False, True, False]
# Determine config dir, first try the environment variable XDG_CONFIG_HOME
# according to XDG specification and as a fallback use ~/.config/mirage
self.config_dir = (os.getenv('XDG_CONFIG_HOME') or os.path.expanduser('~/.config')) + '/mirage'
# Load config from disk:
self.read_config_and_set_settings()
# Set the bg color variable
bgc = self.usettings['bgcolor']
self.bgcolor = gtk.gdk.Color(red=bgc['r'], green=bgc['g'], blue=bgc['b'])
self.going_random = False
self.fullscreen_mode = False
self.opendialogpath = ""
self.zoom_quality = gtk.gdk.INTERP_BILINEAR
self.recursive = False
self.verbose = False
self.image_loaded = False
self.image_list = []
self.firstimgindex_subfolders_list = []
self.user_prompt_visible = False # the "wrap?" prompt
self.slideshow_mode = False
self.slideshow_controls_visible = False # fullscreen slideshow controls
self.controls_moving = False
self.updating_adjustments = False
self.closing_app = False
self.onload_cmd = None
self.searching_for_images = False
self.preserve_aspect = True
self.ignore_preserve_aspect_callback = False
self.image_modified = False
self.image_zoomed = False
self.running_custom_actions = False
self.merge_id = None
self.actionGroupCustom = None
self.merge_id_recent = None
self.actionGroupRecent = None
self.thumbnail_sizes = ["128", "96", "72", "64", "48", "32"]
self.thumbnail_loaded = []
self.thumbpane_updating = False
self.usettings['recentfiles'] = ["", "", "", "", ""]
self.usettings['screenshot_delay'] = 2
self.thumbpane_bottom_coord_loaded = 0
self.no_sort = False
# Read any passed options/arguments:
try:
opts, args = getopt.getopt(sys.argv[1:], "hRvVsfno:", ["help", "version", "recursive", "verbose", "slideshow", "fullscreen", "no-sort", "onload="])
except getopt.GetoptError:
# print help information and exit:
self.print_usage()
sys.exit(2)
# If options were passed, perform action on them.
go_into_fullscreen = False
start_slideshow = False
if opts != []:
for o, a in opts:
if o in ("-v", "--version"):
self.print_version()
sys.exit(2)
elif o in ("-h", "--help"):
self.print_usage()
sys.exit(2)
elif o in ("-R", "--recursive"):
self.recursive = True
elif o in ("-V", "--verbose"):
self.verbose = True
elif o in ("-f", "--fullscreen"):
go_into_fullscreen = True
elif o in ("-s", "--slideshow", "-f", "--fullscreen"):
start_slideshow = True
elif o in ("-n", "--no-sort"):
self.no_sort = True
elif o in ("-o", "--onload"):
self.onload_cmd = a
else:
self.print_usage()
sys.exit(2)
# slideshow_delay is the user's preference, whereas curr_slideshow_delay is
# the current delay (which can be changed without affecting the 'default')
self.curr_slideshow_delay = self.usettings['slideshow_delay']
# Same for randomization:
self.curr_slideshow_random = self.usettings['slideshow_random']
# Find application images/pixmaps
self.resource_path_list = False
self.blank_image = gtk.gdk.pixbuf_new_from_file(self.find_path("mirage_blank.png"))
# Define the main menubar and toolbar:
self.iconfactory = gtk.IconFactory()
icon = gtk.gdk.pixbuf_new_from_file(self.find_path('stock_leave-fullscreen.png'))
self.iconfactory.add('leave-fullscreen', gtk.IconSet(icon))
icon = gtk.gdk.pixbuf_new_from_file(self.find_path('stock_fullscreen.png'))
self.iconfactory.add('fullscreen', gtk.IconSet(icon))
self.iconfactory.add_default()
try:
test = gtk.Button("", gtk.STOCK_LEAVE_FULLSCREEN)
leave_fullscreen_icon = gtk.STOCK_LEAVE_FULLSCREEN
fullscreen_icon = gtk.STOCK_FULLSCREEN
except:
# This will allow gtk 2.6 users to run Mirage
leave_fullscreen_icon = 'leave-fullscreen'
fullscreen_icon = 'fullscreen'
# Note. Stock items intentionally set to None to use standard stock defaults
actions = (
('FileMenu', None, _('_File')),
('EditMenu', None, _('_Edit')),
('ViewMenu', None, _('_View')),
('GoMenu', None, _('_Go')),
('HelpMenu', None, _('_Help')),
('ActionSubMenu', None, _('Custom _Actions')),
('Open Image', gtk.STOCK_FILE, _('_Open Image...'), None, _('Open Image'), self.open_file),
('Open Remote Image', gtk.STOCK_NETWORK, _('Open _Remote image...'), None, _('Open Remote Image'), self.open_file_remote),
('Open Folder', gtk.STOCK_DIRECTORY, _('Open _Folder...'), '<Ctrl>F', _('Open Folder'), self.open_folder),
('Reload', None, _('Reload'), '<Ctrl>F5', _('Reload'), self.reload),
('Save', gtk.STOCK_SAVE, _('_Save Image'), None, None, self.save_image),
('Save As', gtk.STOCK_SAVE_AS, _('Save Image _As...'), '<Ctrl><Shift>S', None, self.save_image_as),
('Copy', gtk.STOCK_COPY, _('Copy to Clipboard...'), '<Ctrl>C', None, self.copy_to_clipboard),
('Crop', None, _('C_rop...'), None, _('Crop Image'), self.crop_image),
('Resize', None, _('R_esize...'), '<Ctrl>R', _('Resize Image'), self.resize_image),
('Saturation', None, _('_Saturation...'), None, _('Modify saturation'), self.saturation),
('Quit', gtk.STOCK_QUIT, None, None, None, self.exit_app),
('Previous Image', gtk.STOCK_GO_BACK, _('_Previous Image'), 'Left', _('Previous Image'), self.goto_prev_image),
('Previous Subfolder', gtk.STOCK_MEDIA_REWIND, _('Pre_vious Subfolder'), '<Shift>Left', _('Previous Subfolder'), self.goto_first_image_prev_subfolder),
('Next Image', gtk.STOCK_GO_FORWARD, _('_Next Image'), 'Right', _('Next Image'), self.goto_next_image),
('Next Subfolder', gtk.STOCK_MEDIA_FORWARD, _('Ne_xt Subfolder'), '<Shift>Right', _('Next Subfolder'), self.goto_first_image_next_subfolder),
('Previous2', gtk.STOCK_GO_BACK, _('_Previous'), 'Left', _('Previous'), self.goto_prev_image),
('Next2', gtk.STOCK_GO_FORWARD, _('_Next'), 'Right', _('Next'), self.goto_next_image),
('Random Image', None, _('_Random Image'), 'R', _('Random Image'), self.goto_random_image),
('First Image', gtk.STOCK_GOTO_FIRST, _('_First Image'), 'Home', _('First Image'), self.goto_first_image),
('Last Image', gtk.STOCK_GOTO_LAST, _('_Last Image'), 'End', _('Last Image'), self.goto_last_image),
('In', gtk.STOCK_ZOOM_IN, _('Zoom _In'), '<Ctrl>Up', _('Zoom In'), self.zoom_in),
('Out', gtk.STOCK_ZOOM_OUT, _('Zoom _Out'), '<Ctrl>Down', _('Zoom Out'), self.zoom_out),
('Fit', gtk.STOCK_ZOOM_FIT, _('Zoom To _Fit'), '<Ctrl>1', _('Fit'), self.zoom_to_fit_window_action),
('1:1', gtk.STOCK_ZOOM_100, _('_1:1'), '<Ctrl>0', _('1:1'), self.zoom_1_to_1_action),
('Rotate Left', None, _('Rotate _Left'), '<Ctrl>Left', _('Rotate Left'), self.rotate_left),
('Rotate Right', None, _('Rotate _Right'), '<Ctrl>Right', _('Rotate Right'), self.rotate_right),
('Flip Vertically', None, _('Flip _Vertically'), '<Ctrl>V', _('Flip Vertically'), self.flip_image_vert),
('Flip Horizontally', None, _('Flip _Horizontally'), '<Ctrl>H', _('Flip Horizontally'), self.flip_image_horiz),
('About', gtk.STOCK_ABOUT, None, None, None, self.show_about),
('Contents', gtk.STOCK_HELP, _('_Contents'), 'F1', _('Contents'), self.show_help),
('Preferences', gtk.STOCK_PREFERENCES, _('Pr_eferences...'), None, _('Preferences'), self.show_prefs),
('Full Screen', gtk.STOCK_FULLSCREEN, None, 'F11', None, self.enter_fullscreen),
('Exit Full Screen', leave_fullscreen_icon, _('E_xit Full Screen'), None, _('Exit Full Screen'), self.leave_fullscreen),
('Start Slideshow', gtk.STOCK_MEDIA_PLAY, _('_Start Slideshow'), 'F5', _('Start Slideshow'), self.toggle_slideshow),
('Stop Slideshow', gtk.STOCK_MEDIA_STOP, _('_Stop Slideshow'), 'F5', _('Stop Slideshow'), self.toggle_slideshow),
('Delete Image', gtk.STOCK_DELETE, _('_Delete...'), 'Delete', _('Delete Image'), self.delete_image),
('Rename Image', None, _('Re_name...'), 'F2', _('Rename Image'), self.rename_image),
('Take Screenshot', None, _('_Take Screenshot...'), None, _('Take Screenshot'), self.screenshot),
('Properties', gtk.STOCK_PROPERTIES, _('_Properties...'), None, _('Properties'), self.show_properties),
('Custom Actions', None, _('_Configure...'), None, _('Custom Actions'), self.show_custom_actions),
('MiscKeysMenuHidden', None, 'Keys'),
('Escape', None, '', 'Escape', _('Exit Full Screen'), self.leave_fullscreen),
('Minus', None, '', 'minus', _('Zoom Out'), self.zoom_out),
('Plus', None, '', 'plus', _('Zoom In'), self.zoom_in),
('Equal', None, '', 'equal', _('Zoom In'), self.zoom_in),
('Space', None, '', 'space', _('Next Image'), self.goto_next_image),
('Ctrl-KP_Insert', None, '', '<Ctrl>KP_Insert', _('Fit'), self.zoom_to_fit_window_action),
('Ctrl-KP_End', None, '', '<Ctrl>KP_End', _('1:1'), self.zoom_1_to_1_action),
('Ctrl-KP_Subtract', None, '', '<Ctrl>KP_Subtract', _('Zoom Out'), self.zoom_out),
('Ctrl-KP_Add', None, '', '<Ctrl>KP_Add', _('Zoom In'), self.zoom_in),
('Ctrl-KP_0', None, '', '<Ctrl>KP_0', _('Fit'), self.zoom_to_fit_window_action),
('Ctrl-KP_1', None, '', '<Ctrl>KP_1', _('1:1'), self.zoom_1_to_1_action),
('Full Screen Key', None, '', '<Shift>Return', None, self.enter_fullscreen),
('Prev', None, '', 'Up', _('Previous Image'), self.goto_prev_image),
('Next', None, '', 'Down', _('Next Image'), self.goto_next_image),
('PgUp', None, '', 'Page_Up', _('Previous Image'), self.goto_prev_image),
('PgDn', None, '', 'Page_Down', _('Next Image'), self.goto_next_image),
('BackSpace', None, '', 'BackSpace', _('Previous Image'), self.goto_prev_image),
('Prev Subfolder 2', None, '', '<Shift>Up', _('Previous Subfolder'), self.goto_first_image_prev_subfolder),
('Next Subfolder 2', None, '', '<Shift>Down', _('Next Subfolder'), self.goto_first_image_next_subfolder),
('Prev Subfolder 3', None, '', '<Shift>Page_Up', _('Previous Subfolder'), self.goto_first_image_prev_subfolder),
('Next Subfolder 3', None, '', '<Shift>Page_Down', _('Next Subfolder'), self.goto_first_image_next_subfolder),
('OriginalSize', None, '', '1', _('1:1'), self.zoom_1_to_1_action),
('ZoomIn', None, '', 'KP_Add', _('Zoom In'), self.zoom_in),
('ZoomOut', None, '', 'KP_Subtract', _('Zoom Out'), self.zoom_out)
)
toggle_actions = (
('Status Bar', None, _('_Status Bar'), None, _('Status Bar'), self.toggle_status_bar, self.usettings['statusbar_show']),
('Toolbar', None, _('_Toolbar'), None, _('Toolbar'), self.toggle_toolbar, self.usettings['toolbar_show']),
('Thumbnails Pane', None, _('Thumbnails _Pane'), 'F9', _('Thumbnails Pane'), self.toggle_thumbpane, self.usettings['thumbpane_show']),
('Randomize list', None, _('_Randomize list'), None, _('Randomize list'), self.shall_we_randomize, self.going_random),
)
# Populate keys[]:
self.keys=[]
for i in range(len(actions)):
if len(actions[i]) > 3:
if actions[i][3] != None:
self.keys.append([actions[i][4], actions[i][3]])
uiDescription = """
<ui>
<popup name="Popup">
<menuitem action="Next Image"/>
<menuitem action="Previous Image"/>
<separator name="FM1"/>
<menuitem action="Out"/>
<menuitem action="In"/>
<menuitem action="1:1"/>
<menuitem action="Fit"/>
<separator name="FM4"/>
<menuitem action="Start Slideshow"/>
<menuitem action="Stop Slideshow"/>
<separator name="FM3"/>
<menuitem action="Exit Full Screen"/>
<menuitem action="Full Screen"/>
</popup>
<menubar name="MainMenu">
<menu action="FileMenu">
<menuitem action="Open Image"/>
<menuitem action="Open Folder"/>
<menuitem action="Open Remote Image"/>
<menuitem action="Reload"/>
<separator name="FM1"/>
<menuitem action="Save"/>
<menuitem action="Save As"/>
<separator name="FM2"/>
<menuitem action="Take Screenshot"/>
<separator name="FM3"/>
<menuitem action="Properties"/>
<separator name="FM4"/>
<placeholder name="Recent Files">
</placeholder>
<separator name="FM5"/>
<menuitem action="Quit"/>
</menu>
<menu action="EditMenu">
<menuitem action="Rotate Left"/>
<menuitem action="Rotate Right"/>
<menuitem action="Flip Vertically"/>
<menuitem action="Flip Horizontally"/>
<separator name="FM1"/>
<menuitem action="Copy"/>
<menuitem action="Crop"/>
<menuitem action="Resize"/>
<menuitem action="Saturation"/>
<separator name="FM2"/>
<menuitem action="Rename Image"/>
<menuitem action="Delete Image"/>
<separator name="FM3"/>
<menu action="ActionSubMenu">
<separator name="FM4" position="bot"/>
<menuitem action="Custom Actions" position="bot"/>
</menu>
<menuitem action="Preferences"/>
</menu>
<menu action="ViewMenu">
<menuitem action="Out"/>
<menuitem action="In"/>
<menuitem action="1:1"/>
<menuitem action="Fit"/>
<separator name="FM2"/>
<menuitem action="Toolbar"/>
<menuitem action="Thumbnails Pane"/>
<menuitem action="Status Bar"/>
<separator name="FM1"/>
<menuitem action="Full Screen"/>
</menu>
<menu action="GoMenu">
<menuitem action="Next Image"/>
<menuitem action="Previous Image"/>
<menuitem action="Random Image"/>
<menuitem action="Randomize list"/>
<separator name="FM1"/>
<menuitem action="First Image"/>
<menuitem action="Last Image"/>
<separator name="FM2"/>
<menuitem action="Next Subfolder"/>
<menuitem action="Previous Subfolder"/>
<separator name="FM3"/>
<menuitem action="Start Slideshow"/>
<menuitem action="Stop Slideshow"/>
</menu>
<menu action="HelpMenu">
<menuitem action="Contents"/>
<menuitem action="About"/>
</menu>
<menu action="MiscKeysMenuHidden">
<menuitem action="Minus"/>
<menuitem action="Escape"/>
<menuitem action="Plus"/>
<menuitem action="Equal"/>
<menuitem action="Space"/>
<menuitem action="Ctrl-KP_Insert"/>
<menuitem action="Ctrl-KP_End"/>
<menuitem action="Ctrl-KP_Subtract"/>
<menuitem action="Ctrl-KP_Add"/>
<menuitem action="Ctrl-KP_0"/>
<menuitem action="Ctrl-KP_1"/>
<menuitem action="Full Screen Key"/>
<menuitem action="Prev"/>
<menuitem action="Next"/>
<menuitem action="PgUp"/>
<menuitem action="PgDn"/>
<menuitem action="Prev Subfolder 2"/>
<menuitem action="Next Subfolder 2"/>
<menuitem action="Prev Subfolder 3"/>
<menuitem action="Next Subfolder 3"/>
<menuitem action="OriginalSize"/>
<menuitem action="BackSpace"/>
<menuitem action="ZoomIn"/>
<menuitem action="ZoomOut"/>
</menu>
</menubar>
<toolbar name="MainToolbar">
<toolitem action="Open Image"/>
<separator name="FM1"/>
<toolitem action="Previous2"/>
<toolitem action="Next2"/>
<separator name="FM2"/>
<toolitem action="Out"/>
<toolitem action="In"/>
<toolitem action="1:1"/>
<toolitem action="Fit"/>
</toolbar>
</ui>
"""
# Create interface
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.update_title()
try:
gtk.window_set_default_icon_from_file(self.find_path('mirage.png'))
except:
pass
vbox = gtk.VBox(False, 0)
self.UIManager = gtk.UIManager()
actionGroup = gtk.ActionGroup('Actions')
actionGroup.add_actions(actions)
actionGroup.add_toggle_actions(toggle_actions)
self.UIManager.insert_action_group(actionGroup, 0)
self.UIManager.add_ui_from_string(uiDescription)
self.refresh_custom_actions_menu()
self.refresh_recent_files_menu()
self.window.add_accel_group(self.UIManager.get_accel_group())
self.menubar = self.UIManager.get_widget('/MainMenu')
vbox.pack_start(self.menubar, False, False, 0)
self.toolbar = self.UIManager.get_widget('/MainToolbar')
vbox.pack_start(self.toolbar, False, False, 0)
self.layout = gtk.Layout()
self.vscroll = gtk.VScrollbar(None)
self.vscroll.set_adjustment(self.layout.get_vadjustment())
self.hscroll = gtk.HScrollbar(None)
self.hscroll.set_adjustment(self.layout.get_hadjustment())
self.table = gtk.Table(3, 2, False)
self.thumblist = gtk.ListStore(gtk.gdk.Pixbuf)
self.thumbpane = gtk.TreeView(self.thumblist)
self.thumbcolumn = gtk.TreeViewColumn(None)
self.thumbcell = gtk.CellRendererPixbuf()
self.thumbcolumn.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
self.thumbpane_set_size()
self.thumbpane.append_column(self.thumbcolumn)
self.thumbcolumn.pack_start(self.thumbcell, True)
self.thumbcolumn.set_attributes(self.thumbcell, pixbuf=0)
self.thumbpane.get_selection().set_mode(gtk.SELECTION_SINGLE)
self.thumbpane.set_headers_visible(False)
self.thumbpane.set_property('can-focus', False)
self.thumbscroll = gtk.ScrolledWindow()
self.thumbscroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
self.thumbscroll.add(self.thumbpane)
self.table.attach(self.thumbscroll, 0, 1, 0, 1, 0, gtk.FILL|gtk.EXPAND, 0, 0)
self.table.attach(self.layout, 1, 2, 0, 1, gtk.FILL|gtk.EXPAND, gtk.FILL|gtk.EXPAND, 0, 0)
self.table.attach(self.hscroll, 1, 2, 1, 2, gtk.FILL|gtk.SHRINK, gtk.FILL|gtk.SHRINK, 0, 0)
self.table.attach(self.vscroll, 2, 3, 0, 1, gtk.FILL|gtk.SHRINK, gtk.FILL|gtk.SHRINK, 0, 0)
vbox.pack_start(self.table, True, True, 0)
if self.usettings['simple_bgcolor']:
self.layout.modify_bg(gtk.STATE_NORMAL, None)
else:
self.layout.modify_bg(gtk.STATE_NORMAL, self.bgcolor)
self.imageview = gtk.Image()
self.layout.add(self.imageview)
self.statusbar = gtk.Statusbar()
self.statusbar2 = gtk.Statusbar()
self.statusbar.set_has_resize_grip(False)
self.statusbar2.set_has_resize_grip(True)
self.statusbar2.set_size_request(200, -1)
hbox_statusbar = gtk.HBox()
hbox_statusbar.pack_start(self.statusbar, expand=True)
hbox_statusbar.pack_start(self.statusbar2, expand=False)
vbox.pack_start(hbox_statusbar, False, False, 0)
self.window.add(vbox)
self.window.set_property('allow-shrink', False)
self.window.set_default_size(self.usettings['window_width'],self.usettings['window_height'])
# Create slideshow window:
self.slideshow_setup()
# Connect signals
self.window.connect("delete_event", self.delete_event)
self.window.connect("destroy", self.destroy)
self.window.connect("size-allocate", self.window_resized)
self.window.connect('key-press-event', self.topwindow_keypress)
self.toolbar.connect('focus', self.toolbar_focused)
self.layout.drag_dest_set(gtk.DEST_DEFAULT_HIGHLIGHT | gtk.DEST_DEFAULT_DROP, [("text/uri-list", 0, 80)], gtk.gdk.ACTION_DEFAULT)
self.layout.connect('drag_motion', self.motion_cb)
self.layout.connect('drag_data_received', self.drop_cb)
self.layout.add_events(gtk.gdk.KEY_PRESS_MASK | gtk.gdk.POINTER_MOTION_MASK | gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_MOTION_MASK | gtk.gdk.SCROLL_MASK)
self.layout.connect("scroll-event", self.mousewheel_scrolled)
self.layout.add_events(gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.KEY_PRESS_MASK)
self.layout.connect("button_press_event", self.button_pressed)
self.layout.add_events(gtk.gdk.POINTER_MOTION_MASK | gtk.gdk.POINTER_MOTION_HINT_MASK | gtk.gdk.BUTTON_RELEASE_MASK)
self.layout.connect("motion-notify-event", self.mouse_moved)
self.layout.connect("button-release-event", self.button_released)
self.imageview.connect("expose-event", self.expose_event)
self.thumb_sel_handler = self.thumbpane.get_selection().connect('changed', self.thumbpane_selection_changed)
self.thumb_scroll_handler = self.thumbscroll.get_vscrollbar().connect("value-changed", self.thumbpane_scrolled)
# Since GNOME does its own thing for the toolbar style...
# Requires gnome-python installed to work (but optional)
try:
client = gconf.client_get_default()
style = client.get_string('/desktop/gnome/interface/toolbar_style')
if style == "both":
self.toolbar.set_style(gtk.TOOLBAR_BOTH)
elif style == "both-horiz":
self.toolbar.set_style(gtk.TOOLBAR_BOTH_HORIZ)
elif style == "icons":
self.toolbar.set_style(gtk.TOOLBAR_ICONS)
elif style == "text":
self.toolbar.set_style(gtk.TOOLBAR_TEXT)
client.add_dir("/desktop/gnome/interface", gconf.CLIENT_PRELOAD_NONE)
client.notify_add("/desktop/gnome/interface/toolbar_style", self.gconf_key_changed)
except:
pass
# Show GUI:
if not self.usettings['toolbar_show']:
self.toolbar.set_property('visible', False)
self.toolbar.set_no_show_all(True)
if not self.usettings['statusbar_show']:
self.statusbar.set_property('visible', False)
self.statusbar.set_no_show_all(True)
self.statusbar2.set_property('visible', False)
self.statusbar2.set_no_show_all(True)
if not self.usettings['thumbpane_show']:
self.thumbscroll.set_property('visible', False)
self.thumbscroll.set_no_show_all(True)
self.hscroll.set_no_show_all(True)
self.vscroll.set_no_show_all(True)
if ((go_into_fullscreen or self.usettings['start_in_fullscreen'])
or (start_slideshow and self.usettings['slideshow_in_fullscreen']) and args != []):
self.enter_fullscreen(None)
self.statusbar.set_no_show_all(True)
self.statusbar2.set_no_show_all(True)
self.toolbar.set_no_show_all(True)
self.menubar.set_no_show_all(True)
self.thumbscroll.set_no_show_all(True)
self.window.show_all()
#self.ss_exit.set_size_request(self.ss_start.size_request()[0]*2, self.ss_start.size_request()[1]*2)
#self.ss_randomize.set_size_request(self.ss_start.size_request()[0]*2, -1)
self.ss_start.set_size_request(self.ss_start.size_request()[0]*2, -1)
self.ss_stop.set_size_request(self.ss_stop.size_request()[0]*2, -1)
self.UIManager.get_widget('/Popup/Exit Full Screen').hide()
self.layout.set_flags(gtk.CAN_FOCUS)
self.window.set_focus(self.layout)
#sets the visibility of some menu entries
self.set_slideshow_sensitivities()
self.UIManager.get_widget('/MainMenu/MiscKeysMenuHidden').set_property('visible', False)
if go_into_fullscreen:
self.UIManager.get_widget('/Popup/Exit Full Screen').show()
# If arguments (filenames) were passed, try to open them:
self.image_list = []
if args != []:
for i in range(len(args)):
args[i] = urllib.url2pathname(args[i]).decode('utf-8')
gtk.gdk.threads_enter()
self.expand_filelist_and_load_image(args)
gtk.gdk.threads_leave()
else:
self.set_go_sensitivities(False)
self.set_image_sensitivities(False)
if start_slideshow:
self.toggle_slideshow(None)
def read_config_and_set_settings(self):
config = os.path.join(self.config_dir, 'mirage1.conf')
if os.path.isfile(config):
# Add each entry one by one in case of missing entries in the config
cf = open(config)
confdict = json.load(cf)
for k,v in confdict.items():
self.usettings[k] = v
# Additional work needed
cf.close()
# Read accel_map file, if it exists
accel = os.path.join(self.config_dir, 'accel_map')
if os.path.isfile(accel):
gtk.accel_map_load(accel)
def slideshow_setup(self):
# Create the left-side controls
self.slideshow_window = gtk.Window(gtk.WINDOW_POPUP)
self.slideshow_controls = gtk.HBox()
# Back button
self.ss_back = gtk.Button()
self.ss_back.add(gtk.image_new_from_stock(gtk.STOCK_GO_BACK, gtk.ICON_SIZE_BUTTON))
self.ss_back.set_property('can-focus', False)
self.ss_back.connect('clicked', self.goto_prev_image)
# Start/Stop buttons
self.ss_start = gtk.Button()
self.ss_start.add(gtk.image_new_from_stock(gtk.STOCK_MEDIA_PLAY, gtk.ICON_SIZE_BUTTON))
self.ss_start.set_property('can-focus', False)
self.ss_start.connect('clicked', self.toggle_slideshow)
self.ss_stop = gtk.Button()
self.ss_stop.add(gtk.image_new_from_stock(gtk.STOCK_MEDIA_STOP, gtk.ICON_SIZE_BUTTON))
self.ss_stop.set_property('can-focus', False)
self.ss_stop.connect('clicked', self.toggle_slideshow)
# Forward button
self.ss_forward = gtk.Button()
self.ss_forward.add(gtk.image_new_from_stock(gtk.STOCK_GO_FORWARD, gtk.ICON_SIZE_BUTTON))
self.ss_forward.set_property('can-focus', False)
self.ss_forward.connect('clicked', self.goto_next_image)
# Pack controls into the slideshow window
self.slideshow_controls.pack_start(self.ss_back, False, False, 0)
self.slideshow_controls.pack_start(self.ss_start, False, False, 0)
self.slideshow_controls.pack_start(self.ss_stop, False, False, 0)
self.slideshow_controls.pack_start(self.ss_forward, False, False, 0)
self.slideshow_window.add(self.slideshow_controls)
if self.usettings['simple_bgcolor']:
self.slideshow_window.modify_bg(gtk.STATE_NORMAL, None)
else:
self.slideshow_window.modify_bg(gtk.STATE_NORMAL, self.bgcolor)
# Create the right-side controls
self.slideshow_window2 = gtk.Window(gtk.WINDOW_POPUP)
self.slideshow_controls2 = gtk.HBox()
try:
self.ss_exit = gtk.Button()
self.ss_exit.add(gtk.image_new_from_stock(gtk.STOCK_LEAVE_FULLSCREEN, gtk.ICON_SIZE_BUTTON))
except:
self.ss_exit = gtk.Button()
self.ss_exit.set_image(gtk.image_new_from_stock('leave-fullscreen', gtk.ICON_SIZE_BUTTON))
self.ss_exit.set_property('can-focus', False)
self.ss_exit.connect('clicked', self.leave_fullscreen)
self.ss_randomize = gtk.ToggleButton()
try:
pixbuf = gtk.gdk.pixbuf_new_from_file(self.find_path('stock_shuffle.png'))
self.iconfactory.add('stock-shuffle', gtk.IconSet(pixbuf))
self.ss_randomize.set_image(gtk.image_new_from_stock('stock-shuffle', gtk.ICON_SIZE_BUTTON))
except:
self.ss_randomize.set_label("Rand")
self.ss_randomize.connect('toggled', self.random_changed)
spin_adj = gtk.Adjustment(self.usettings['slideshow_delay'], 0, 50000, 1,100, 0)
self.ss_delayspin = gtk.SpinButton(spin_adj, 1.0, 0)
self.ss_delayspin.set_numeric(True)
self.ss_delayspin.connect('changed', self.delay_changed)
self.slideshow_controls2.pack_start(self.ss_randomize, False, False, 0)
self.slideshow_controls2.pack_start(self.ss_delayspin, False, False, 0)
self.slideshow_controls2.pack_start(self.ss_exit, False, False, 0)
self.slideshow_window2.add(self.slideshow_controls2)
if self.usettings['simple_bgcolor']:
self.slideshow_window2.modify_bg(gtk.STATE_NORMAL, None)
else:
self.slideshow_window2.modify_bg(gtk.STATE_NORMAL, self.bgcolor)
def refresh_recent_files_menu(self):
if self.merge_id_recent:
self.UIManager.remove_ui(self.merge_id_recent)
if self.actionGroupRecent:
self.UIManager.remove_action_group(self.actionGroupRecent)
self.actionGroupRecent = None
self.actionGroupRecent = gtk.ActionGroup('RecentFiles')
self.UIManager.ensure_update()
for i, file_path in enumerate(self.usettings['recentfiles']):
if file_path:
filename = os.path.basename(file_path)
if filename:
base, ext = os.path.splitext(filename)
if len(base) > 27:
# Replace end of file name (excluding extension) with ..
try:
menu_name = base[:25] + '..' + ext
except:
menu_name = filename
else:
menu_name = filename
menu_name = menu_name.replace('_','__')
action_id = str(i)
action = [(action_id, None, menu_name, '<Alt>' + str(i+1), None, self.recent_action_click)]
self.actionGroupRecent.add_actions(action)
uiDescription = """
<ui>
<menubar name="MainMenu">
<menu action="FileMenu">
<placeholder name="Recent Files">
"""
for i, file_path in enumerate(self.usettings['recentfiles']):
if file_path:
action_id = str(i)
uiDescription = uiDescription + """<menuitem action=\"""" + action_id + """\"/>"""
uiDescription = uiDescription + """</placeholder></menu></menubar></ui>"""
self.merge_id_recent = self.UIManager.add_ui_from_string(uiDescription)
self.UIManager.insert_action_group(self.actionGroupRecent, 0)
self.UIManager.get_widget('/MainMenu/MiscKeysMenuHidden').set_property('visible', False)
def refresh_custom_actions_menu(self):
if self.merge_id:
self.UIManager.remove_ui(self.merge_id)
if self.actionGroupCustom:
self.UIManager.remove_action_group(self.actionGroupCustom)
self.actionGroupCustom = None
self.actionGroupCustom = gtk.ActionGroup('CustomActions')
self.UIManager.ensure_update()
for i in range(len(self.usettings['action_names'])):
action = [(self.usettings['action_names'][i], None, self.usettings['action_names'][i], self.usettings['action_shortcuts'][i], None, self.custom_action_click)]
self.actionGroupCustom.add_actions(action)
uiDescription = """
<ui>
<menubar name="MainMenu">
<menu action="EditMenu">
<menu action="ActionSubMenu">
"""
for i in range(len(self.usettings['action_names'])):
uiDescription = uiDescription + """<menuitem action=\"""" + self.usettings['action_names'][len(self.usettings['action_names'])-i-1].replace('&','&') + """\" position="top"/>"""
uiDescription = uiDescription + """</menu></menu></menubar></ui>"""
self.merge_id = self.UIManager.add_ui_from_string(uiDescription)
self.UIManager.insert_action_group(self.actionGroupCustom, 0)
self.UIManager.get_widget('/MainMenu/MiscKeysMenuHidden').set_property('visible', False)
def thumbpane_update_images(self, clear_first=False, force_upto_imgnum=-1):
self.stop_now = False
# When first populating the thumbpane, make sure we go up to at least
# force_upto_imgnum so that we can show this image selected:
if clear_first:
self.thumbpane_clear_list()
# Load all images up to the bottom ofo the visible thumbpane rect:
rect = self.thumbpane.get_visible_rect()
bottom_coord = rect.y + rect.height + self.usettings['thumbnail_size']
if bottom_coord > self.thumbpane_bottom_coord_loaded:
self.thumbpane_bottom_coord_loaded = bottom_coord
# update images:
if not self.thumbpane_updating:
thread = threading.Thread(target=self.thumbpane_update_pending_images, args=(force_upto_imgnum, None))
thread.setDaemon(True)
thread.start()
def thumbpane_create_dir(self):
if not os.path.exists(os.path.expanduser('~/.thumbnails/')):
os.mkdir(os.path.expanduser('~/.thumbnails/'))
if not os.path.exists(os.path.expanduser('~/.thumbnails/normal/')):
os.mkdir(os.path.expanduser('~/.thumbnails/normal/'))
def thumbpane_update_pending_images(self, force_upto_imgnum, foo):
self.thumbpane_updating = True
self.thumbpane_create_dir()
# Check to see if any images need their thumbnails generated.
curr_coord = 0
imgnum = 0
while curr_coord < self.thumbpane_bottom_coord_loaded or imgnum <= force_upto_imgnum:
if self.closing_app or self.stop_now or not self.usettings['thumbpane_show']:
break
if imgnum >= len(self.image_list):
break
self.thumbpane_set_image(self.image_list[imgnum], imgnum)
curr_coord += self.thumbpane.get_background_area((imgnum,),self.thumbcolumn).height
if force_upto_imgnum == imgnum:
# Verify that the user hasn't switched images while we're loading thumbnails:
if force_upto_imgnum == self.curr_img_in_list:
gobject.idle_add(self.thumbpane_select, force_upto_imgnum)
imgnum += 1
self.thumbpane_updating = False
def thumbpane_clear_list(self):
self.thumbpane_bottom_coord_loaded = 0
self.thumbscroll.get_vscrollbar().handler_block(self.thumb_scroll_handler)
self.thumblist.clear()
self.thumbscroll.get_vscrollbar().handler_unblock(self.thumb_scroll_handler)
for image in self.image_list:
blank_pix = self.get_blank_pix_for_image(image)
self.thumblist.append([blank_pix])
self.thumbnail_loaded = [False]*len(self.image_list)
def thumbpane_set_image(self, image_name, imgnum, force_update=False):
if self.usettings['thumbpane_show']:
if not self.thumbnail_loaded[imgnum] or force_update:
filename, thumbfile = self.thumbnail_get_name(image_name)
pix = self.thumbpane_get_pixbuf(thumbfile, filename, force_update)
if pix:
if self.usettings['thumbnail_size'] != 128:
# 128 is the size of the saved thumbnail, so convert if different:
pix, image_width, image_height = self.get_pixbuf_of_size(pix, self.usettings['thumbnail_size'], gtk.gdk.INTERP_TILES)
self.thumbnail_loaded[imgnum] = True
self.thumbscroll.get_vscrollbar().handler_block(self.thumb_scroll_handler)
pix = self.pixbuf_add_border(pix)
try:
self.thumblist[imgnum] = [pix]
except:
pass
self.thumbscroll.get_vscrollbar().handler_unblock(self.thumb_scroll_handler)
def thumbnail_get_name(self, image_name):
filename = os.path.expanduser('file://' + image_name)
uriname = os.path.expanduser('file://' + urllib.pathname2url(image_name.encode('utf-8')))
if HAS_HASHLIB:
m = hashlib.md5()
else:
m = md5.new()
m.update(uriname)
mhex = m.hexdigest()
mhex_filename = os.path.expanduser('~/.thumbnails/normal/' + mhex + '.png')
return filename, mhex_filename
def thumbpane_get_pixbuf(self, thumb_url, image_url, force_generation):
# Returns a valid pixbuf or None if a pixbuf cannot be generated. Tries to re-use
# a thumbnail from ~/.thumbails/normal/, otherwise generates one with the
# XDG filename: md5(file:///full/path/to/image).png
imgfile = image_url
if imgfile[:7] == 'file://':
imgfile = imgfile[7:]
try:
if os.path.exists(thumb_url) and not force_generation:
pix = gtk.gdk.pixbuf_new_from_file(thumb_url)
pix_mtime = pix.get_option('tEXt::Thumb::MTime')
if pix_mtime:
st = os.stat(imgfile)
file_mtime = str(st[stat.ST_MTIME])
# If the mtimes match, we're good. if not, regenerate the thumbnail..
if pix_mtime == file_mtime:
return pix
# Create the 128x128 thumbnail:
uri = 'file://' + urllib.pathname2url(imgfile.encode('utf-8'))
#pix = gtk.gdk.pixbuf_new_from_file(imgfile)
pix = ImageData()
pix.load_pixbuf(imgfile)
pix, image_width, image_height = self.get_pixbuf_of_size(pix.pixbuf, 128, gtk.gdk.INTERP_TILES)
st = os.stat(imgfile)
file_mtime = str(st[stat.ST_MTIME])
# Save image to .thumbnails:
pix.save(thumb_url, "png", {'tEXt::Thumb::URI':uri, 'tEXt::Thumb::MTime':file_mtime, 'tEXt::Software':'Mirage' + __version__})
return pix
except:
return None
def thumbpane_load_image(self, treeview, imgnum):
if imgnum != self.curr_img_in_list:
gobject.idle_add(self.goto_image, str(imgnum), None)
def thumbpane_selection_changed(self, treeview):
cancel = self.autosave_image()
if cancel:
# Revert selection...
gobject.idle_add(self.thumbpane_select, self.curr_img_in_list)
return True
try:
model, paths = self.thumbpane.get_selection().get_selected_rows()
imgnum = paths[0][0]
if not self.thumbnail_loaded[imgnum]:
self.thumbpane_set_image(self.image_list[imgnum], imgnum)
gobject.idle_add(self.thumbpane_load_image, treeview, imgnum)
except:
pass
def thumbpane_select(self, imgnum):
if self.usettings['thumbpane_show']:
self.thumbpane.get_selection().handler_block(self.thumb_sel_handler)
try:
self.thumbpane.get_selection().select_path((imgnum,))
self.thumbpane.scroll_to_cell((imgnum,))
except:
pass
self.thumbpane.get_selection().handler_unblock(self.thumb_sel_handler)
def thumbpane_set_size(self):
self.thumbcolumn.set_fixed_width(self.thumbpane_get_size())
self.window_resized(None, self.window.allocation, True)
def thumbpane_get_size(self):
return int(self.usettings['thumbnail_size'] * 1.3)
def thumbpane_scrolled(self, range):
self.thumbpane_update_images()
def get_blank_pix_for_image(self, image):
# Sizes the "blank image" icon for the thumbpane. This will ensure that we don't
# load a humongous icon for a small pix, for example, and will keep the thumbnails
# from shifting around when they are actually loaded.
try:
info = gtk.gdk.pixbuf_get_file_info(image)
imgwidth = float(info[1])
imgheight = float(info[2])
if imgheight > self.usettings['thumbnail_size']:
if imgheight > imgwidth:
imgheight = self.usettings['thumbnail_size']
else:
imgheight = imgheight/imgwidth * self.usettings['thumbnail_size']
imgheight = 2 + int(imgheight) # Account for border that will be added to thumbnails..
imgwidth = self.usettings['thumbnail_size']
except:
imgheight = 2 + self.usettings['thumbnail_size']
imgwidth = self.usettings['thumbnail_size']
blank_pix = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, imgwidth, imgheight)
blank_pix.fill(0x00000000)
imgwidth2 = int(imgheight*0.8)
imgheight2 = int(imgheight*0.8)
composite_pix = self.blank_image.scale_simple(imgwidth2, imgheight2, gtk.gdk.INTERP_BILINEAR)
leftcoord = int((imgwidth - imgwidth2)/2)
topcoord = int((imgheight - imgheight2)/2)
composite_pix.copy_area(0, 0, imgwidth2, imgheight2, blank_pix, leftcoord, topcoord)
return blank_pix
def find_path(self, filename, exit_on_fail=True):
""" Find a pixmap or icon by looking through standard dirs.
If the image isn't found exit with error status 1 unless
exit_on_fail is set to False, then return None """
if not self.resource_path_list:
#If executed from mirage in bin this points to the basedir
basedir_mirage = os.path.split(sys.path[0])[0]
#If executed from mirage.py module in python lib this points to the basedir
f0 = os.path.split(__file__)[0].split('/lib')[0]
self.resource_path_list = list(set(filter(os.path.isdir, [
os.path.join(basedir_mirage, 'share', 'mirage'),
os.path.join(basedir_mirage, 'share', 'pixmaps'),
os.path.join(sys.prefix, 'share', 'mirage'),
os.path.join(sys.prefix, 'share', 'pixmaps'),
os.path.join(sys.prefix, 'local', 'share', 'mirage'),
os.path.join(sys.prefix, 'local', 'share', 'pixmaps'),
sys.path[0], #If it's run non-installed
os.path.join(f0, 'share', 'mirage'),
os.path.join(f0, 'share', 'pixmaps'),
])))
for path in self.resource_path_list: