| ... |
... |
@@ -1441,7 +1441,7 @@ class FileChooserDialog(Gtk.FileChooserDialog): |
|
1441
|
1441
|
"""
|
|
1442
|
1442
|
def __init__(self, title_text, action, buttons, default_response,
|
|
1443
|
1443
|
select_multiple=False, current_folder=None, on_response_ok=None,
|
|
1444
|
|
- on_response_cancel=None, transient_for=None):
|
|
|
1444
|
+ on_response_cancel=None, preview=False, transient_for=None):
|
|
1445
|
1445
|
|
|
1446
|
1446
|
Gtk.FileChooserDialog.__init__(self, title=title_text,
|
|
1447
|
1447
|
parent=transient_for, action=action)
|
| ... |
... |
@@ -1459,6 +1459,12 @@ class FileChooserDialog(Gtk.FileChooserDialog): |
|
1459
|
1459
|
# in gtk+-2.10 clicked signal on some of the buttons in a dialog
|
|
1460
|
1460
|
# is emitted twice, so we cannot rely on 'clicked' signal
|
|
1461
|
1461
|
self.connect('response', self.on_dialog_response)
|
|
|
1462
|
+
|
|
|
1463
|
+ if preview:
|
|
|
1464
|
+ self.set_use_preview_label(False)
|
|
|
1465
|
+ self.set_preview_widget(Gtk.Image())
|
|
|
1466
|
+ self.connect('selection-changed', self.update_preview)
|
|
|
1467
|
+
|
|
1462
|
1468
|
self.show_all()
|
|
1463
|
1469
|
|
|
1464
|
1470
|
def on_dialog_response(self, dialog, response):
|
| ... |
... |
@@ -1479,6 +1485,21 @@ class FileChooserDialog(Gtk.FileChooserDialog): |
|
1479
|
1485
|
else:
|
|
1480
|
1486
|
self.just_destroy(dialog)
|
|
1481
|
1487
|
|
|
|
1488
|
+ def update_preview(self, widget):
|
|
|
1489
|
+ path_to_file = widget.get_preview_filename()
|
|
|
1490
|
+ preview = widget.get_preview_widget()
|
|
|
1491
|
+ if path_to_file is None or os.path.isdir(path_to_file):
|
|
|
1492
|
+ # nothing to preview or directory
|
|
|
1493
|
+ # make sure you clean image do show nothing
|
|
|
1494
|
+ preview.clear()
|
|
|
1495
|
+ return
|
|
|
1496
|
+ try:
|
|
|
1497
|
+ pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(path_to_file, 200, 200)
|
|
|
1498
|
+ except GObject.GError:
|
|
|
1499
|
+ preview.clear()
|
|
|
1500
|
+ return
|
|
|
1501
|
+ widget.get_preview_widget().set_from_pixbuf(pixbuf)
|
|
|
1502
|
+
|
|
1482
|
1503
|
def just_destroy(self, widget):
|
|
1483
|
1504
|
self.destroy()
|
|
1484
|
1505
|
|