Web · Wiki · Activities · Blog · Lists · Chat · Meeting · Bugs · Git · Translate · Archive · People · Donate

Commit deb187b9d665771683964c76e2f0932d79cc16d3

Allow changing the order of pages via drag&drop

By storing everything in the GTK ListStore, we can have the TreeView swap
columns and allow the user to rearrange pages before saving the PDF.
  • scan.py 45 -------------++++++++++++++++++++++++++++++++
  • Diff rendering mode:
  • inline
  • side by side

scan.py

433 'scanning': _('Scanning...'),433 'scanning': _('Scanning...'),
434 'error': _('Error: %s'),434 'error': _('Error: %s'),
435 }435 }
436 _MODEL_COLUMNS = [
437 ('preview', gtk.gdk.Pixbuf),
438 ('file', object),
439 ('width_pixel', int),
440 ('height_pixel', int),
441 ('dpi', int),
442 ]
443 _MODEL_COLUMNS_MAP = dict([(name, idx)
444 for idx, (name, type_) in enumerate(_MODEL_COLUMNS)])
436445
437 def __init__(self, handle):446 def __init__(self, handle):
438 activity.Activity.__init__(self, handle)447 activity.Activity.__init__(self, handle)
449 self._scanner_name = None449 self._scanner_name = None
450 self._scanners = []450 self._scanners = []
451 self._scanner_options = {'source': 'ADF'}451 self._scanner_options = {'source': 'ADF'}
452 self._image_infos = []
453 self._status = 'init'452 self._status = 'init'
454 self._msg_box_buf = None453 self._msg_box_buf = None
455 self._status_entry = None454 self._status_entry = None
466 self._scan_thread.stop_thread()466 self._scan_thread.stop_thread()
467 self._scan_thread.join()467 self._scan_thread.join()
468 logging.debug('ScanThread finished')468 logging.debug('ScanThread finished')
469 [info['file'].close() for info in self._image_infos]
469 self._remove_image_files()
470 activity.Activity.destroy(self)470 activity.Activity.destroy(self)
471471
472 def read_file(self, file_path):472 def read_file(self, file_path):
579579
580 images_window = gtk.ScrolledWindow()580 images_window = gtk.ScrolledWindow()
581 images_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)581 images_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
582 self._images_model = gtk.ListStore(gtk.gdk.Pixbuf)
582 model_types = [_type for name_, _type in self._MODEL_COLUMNS]
583 self._images_model = gtk.ListStore(*model_types)
583 self._images_view = gtk.TreeView(self._images_model)584 self._images_view = gtk.TreeView(self._images_model)
584 image_column = gtk.TreeViewColumn('Image', gtk.CellRendererPixbuf(),585 image_column = gtk.TreeViewColumn('Image', gtk.CellRendererPixbuf(),
585 pixbuf=0)586 pixbuf=0)
586 self._images_view.append_column(image_column)587 self._images_view.append_column(image_column)
587 self._images_view.set_headers_visible(False)588 self._images_view.set_headers_visible(False)
589 self._images_view.set_reorderable(True)
588 images_window.add(self._images_view)590 images_window.add(self._images_view)
589 images_window.show_all()591 images_window.show_all()
590 vbox.pack_start(images_window, expand=True)592 vbox.pack_start(images_window, expand=True)
673 self._reopen_scanner()673 self._reopen_scanner()
674674
675 def _add_images(self, image_infos):675 def _add_images(self, image_infos):
676 self._image_infos += image_infos
677 for info in image_infos:676 for info in image_infos:
678 self._images_model.append([info['preview']])
677 row = [info[name] for name, type_ in self._MODEL_COLUMNS]
678 self._images_model.append(row)
679679
680 @trace()680 @trace()
681 def _save_button_cb(self, *args):681 def _save_button_cb(self, *args):
698698
699 @trace()699 @trace()
700 def _save_pdf(self, f):700 def _save_pdf(self, f):
701 width_idx = self._MODEL_COLUMNS_MAP['width_pixel']
702 height_idx = self._MODEL_COLUMNS_MAP['height_pixel']
703 dpi_idx = self._MODEL_COLUMNS_MAP['dpi']
704 file_idx = self._MODEL_COLUMNS_MAP['file']
705
701 max_width_inch = reduce(max,706 max_width_inch = reduce(max,
702 [info['width_pixel']/info['dpi'] for info in self._image_infos])
707 [row[width_idx] / row[dpi_idx] for row in self._images_model])
703 max_height_inch = reduce(max,708 max_height_inch = reduce(max,
704 [info['height_pixel']/info['dpi'] for info in self._image_infos])
709 [row[height_idx] / row[dpi_idx] for row in self._images_model])
705 canvas = reportlab.pdfgen.canvas.Canvas(f,710 canvas = reportlab.pdfgen.canvas.Canvas(f,
706 pagesize=(max_width_inch*units.inch, max_height_inch*units.inch))711 pagesize=(max_width_inch*units.inch, max_height_inch*units.inch))
707712
708 for info in self._image_infos:
709 width_inch = float(info['width_pixel'])/info['dpi']
710 height_inch = float(info['height_pixel'])/info['dpi']
713 for row in self._images_model:
714 width_inch = float(row[width_idx]) / row[dpi_idx]
715 height_inch = float(row[height_idx]) / row[dpi_idx]
711 canvas.setFillColorRGB(1, 1, 1)716 canvas.setFillColorRGB(1, 1, 1)
712 canvas.rect(0, 0, max_width_inch*units.inch,717 canvas.rect(0, 0, max_width_inch*units.inch,
713 max_height_inch*units.inch, fill=1)718 max_height_inch*units.inch, fill=1)
714 canvas.drawImage(info['file'].name, 0, 0, width_inch*units.inch,
719 canvas.drawImage(row[file_idx].name, 0, 0, width_inch*units.inch,
715 height_inch*units.inch)720 height_inch*units.inch)
716 canvas.showPage()721 canvas.showPage()
717722
718 canvas.save()723 canvas.save()
719724
725 def _remove_image_files(self):
726 for row in self._images_model:
727 row[self._MODEL_COLUMNS_MAP['file']].close()
728
720 @trace()729 @trace()
721 def _save_reply_cb(self, *args):730 def _save_reply_cb(self, *args):
722 [info['file'].close() for info in self._image_infos]
723 self._image_infos = []
731 self._remove_image_files()
732 self._images_model.clear()
724733
725 @trace()734 @trace()
726 def _save_error_cb(self, error):735 def _save_error_cb(self, error):