示例#1
0
 def resize_pdf_pages(self, selected):
     files = tools.get_files(selected)
     if files:
         file_in = files[0]
         filename, filext = os.path.splitext(file_in)
         file_out = filename + '_resized' + filext
         cd = ResizeDialog(_('Resize pages'), file_out)
         if cd.run() == Gtk.ResponseType.ACCEPT:
             size = cd.get_size()
             if cd.is_vertical():
                 width = size[0]
                 height = size[1]
             else:
                 width = size[1]
                 height = size[0]
             file_out = cd.get_file_out()
             cd.destroy()
             if file_out:
                 dialog = Progreso(_('Convert pdfs to png'), None, 1)
                 diboo = DoitInBackgroundOnlyOne(
                     pdfapi.resize, file_in, file_out, width, height)
                 diboo.connect('done', dialog.increase)
                 diboo.start()
                 dialog.run()
         cd.destroy()
示例#2
0
 def rotate_or_flip(self, selected):
     files = tools.get_files(selected)
     if len(files) > 0:
         file0 = files[0]
         fd = FlipDialog(_('Rotate files'), file0)
         degrees = 0
         if fd.run() == Gtk.ResponseType.ACCEPT:
             fd.hide()
             if fd.rbutton1.get_active():
                 rotate = ROTATE_000
             elif fd.rbutton2.get_active():
                 rotate = ROTATE_090
             elif fd.rbutton3.get_active():
                 rotate = ROTATE_180
             elif fd.rbutton4.get_active():
                 rotate = ROTATE_270
             flip_vertical = fd.switch1.get_active()
             flip_horizontal = fd.switch2.get_active()
             overwrite = fd.rbutton0.get_active()
             dialog = Progreso(_('Rotate pdf files'), None, len(files))
             diboo = DoitInBackgroundWithArgs(
                 cairoapi.rotate_and_flip_pages, files, rotate,
                 flip_vertical, flip_horizontal, overwrite)
             diboo.connect('done', dialog.increase)
             diboo.connect('todo', dialog.set_todo_label)
             dialog.connect('i-want-stop', diboo.stop_it)
             diboo.start()
             dialog.run()
         fd.destroy()
示例#3
0
 def rotate_some_pages(self, selected):
     files = tools.get_files(selected)
     if files:
         file0 = files[0]
         filename, filext = os.path.splitext(file0)
         file_out = filename + '_rotated.pdf'
         last_page = cairoapi.get_num_of_pages(file0)
         spd = SelectPagesRotateDialog(_('Rotate some pages'), last_page,
                                       file_out)
         if spd.run() == Gtk.ResponseType.ACCEPT:
             ranges = tools.get_ranges(spd.entry1.get_text())
             if spd.rbutton1.get_active():
                 degrees = 270
             elif spd.rbutton2.get_active():
                 degrees = 90
             else:
                 degrees = 180
             spd.destroy()
             if len(ranges) > 0:
                 dialog = Progreso(_('Rotate some pages in pdf'), None, 1)
                 diboo = DoitInBackgroundOnlyOne(
                     pdfapi.rotate_ranges_in_pdf, file0, file_out,
                     degrees, ranges)
                 diboo.connect('done', dialog.increase)
                 diboo.start()
                 dialog.run()
         else:
             spd.destroy()
示例#4
0
 def textmark(self, selected):
     files = tools.get_files(selected)
     if len(files) > 0:
         file0 = files[0]
         wd = TextmarkDialog(file0)
         if wd.run() == Gtk.ResponseType.ACCEPT:
             wd.hide()
             text = wd.get_text()
             color = wd.get_color()
             font = wd.get_font()
             size = wd.get_size()
             hoption = wd.get_horizontal_option()
             voption = wd.get_vertical_option()
             horizontal_margin = wd.get_horizontal_margin()
             vertical_margin = wd.get_vertical_margin()
             dialog = Progreso(_('Textmark pdf files'), None, len(files))
             diboo = DoitInBackgroundWithArgs(
                 cairoapi.add_textmark_to_all_pages, files, text, color,
                 font, size, hoption, voption, horizontal_margin,
                 vertical_margin, wd.rbutton0.get_active())
             diboo.connect('done', dialog.increase)
             diboo.connect('todo', dialog.set_todo_label)
             dialog.connect('i-want-stop', diboo.stop_it)
             diboo.start()
             dialog.run()
         wd.destroy()
示例#5
0
 def watermark(self, selected, window):
     files = tools.get_files(selected)
     if files:
         file0 = files[0]
         wd = WatermarkDialog(file0, window)
         if wd.run() == Gtk.ResponseType.ACCEPT:
             wd.hide()
             hoption = wd.get_horizontal_option()
             voption = wd.get_vertical_option()
             horizontal_margin = wd.get_horizontal_margin()
             vertical_margin = wd.get_vertical_margin()
             zoom = float(wd.get_watermark_zoom() / 100.0)
             image = wd.get_image_filename()
             extension = wd.get_extension()
             dialog = Progreso(_('Watermark PDF'), window, len(files))
             diboo = doitinbackground.DoitInBackgroundWaterMark(
                 files, image, hoption, voption, horizontal_margin,
                 vertical_margin, zoom, extension)
             diboo.connect('todo', dialog.set_todo_label)
             diboo.connect('donef', dialog.set_fraction)
             diboo.connect('finished', dialog.close)
             diboo.connect('interrupted', dialog.close)
             dialog.connect('i-want-stop', diboo.stop_it)
             diboo.start()
             dialog.run()
         wd.destroy()
示例#6
0
 def create_pdf_from_images(self, selected):
     files = tools.get_files(selected)
     if files:
         file_in = files[0]
         filename, filext = os.path.splitext(file_in)
         file_out = filename + '_from_images.pdf'
         cpfi = CreatePDFFromImagesDialog(
             _('Create pdf from images'), files, file_out)
         if cpfi.run() == Gtk.ResponseType.ACCEPT:
             cpfi.hide()
             files = cpfi.get_png_files()
             if cpfi.is_vertical():
                 width, height = cpfi.get_size()
             else:
                 height, width = cpfi.get_size()
             margin = cpfi.get_margin()
             file_out = cpfi.get_file_out()
             cpfi.destroy()
             if file_out:
                 dialog = Progreso(_('Convert pdfs to png'), None, 1)
                 diboo = DoitInBackgroundOnlyOne(
                     tools.create_from_images, file_out, files, width,
                     height, margin)
                 diboo.connect('done', dialog.increase)
                 diboo.start()
                 dialog.run()
         cpfi.destroy()
示例#7
0
 def textmark(self, selected, window):
     files = tools.get_files(selected)
     if files:
         file0 = files[0]
         wd = TextmarkDialog(file0, window)
         if wd.run() == Gtk.ResponseType.ACCEPT:
             wd.hide()
             text = wd.get_text()
             color = wd.get_color()
             font = wd.get_font()
             size = wd.get_size()
             hoption = wd.get_horizontal_option()
             voption = wd.get_vertical_option()
             horizontal_margin = wd.get_horizontal_margin()
             vertical_margin = wd.get_vertical_margin()
             extension = wd.get_extension()
             dialog = Progreso(_('Textmark PDF'), window, len(files))
             diboo = doitinbackground.DoitInBackgroundTextMark(
                 files, text, color, font, size, hoption, voption,
                 horizontal_margin, vertical_margin, extension)
             diboo.connect('todo', dialog.set_todo_label)
             diboo.connect('donef', dialog.set_fraction)
             diboo.connect('finished', dialog.close)
             diboo.connect('interrupted', dialog.close)
             dialog.connect('i-want-stop', diboo.stop_it)
             diboo.start()
             dialog.run()
         wd.destroy()
示例#8
0
 def execute(self, commands):
     diib = DoItInBackground(self, commands)
     progreso = Progreso('Adding new ppa', self.parent, len(commands))
     diib.connect('done_one', progreso.increase)
     diib.connect('ended', progreso.close)
     diib.connect('ended', self.on_ended)
     progreso.connect('i-want-stop', diib.stop)
     diib.start()
示例#9
0
 def split_pdf_files(self, selected):
     files = tools.get_files(selected)
     if files:
         dialog = Progreso(_('Split pdf files'), None, len(files))
         diboo = DoitInBackground(cairoapi.split_pdf, files)
         diboo.connect('done', dialog.increase)
         diboo.connect('todo', dialog.set_todo_label)
         dialog.connect('i-want-stop', diboo.stop_it)
         diboo.start()
         dialog.run()
示例#10
0
 def reduce(self, selected):
     files = tools.get_files(selected)
     dialog = Progreso(_('Reduce pdf files size'), None, len(files))
     diboo = DoitInBackground(
         tools.reduce_pdf, files)
     diboo.connect('done', dialog.increase)
     diboo.connect('todo', dialog.set_todo_label)
     dialog.connect('i-want-stop', diboo.stop_it)
     diboo.start()
     dialog.run()
示例#11
0
 def join_pdf_files(self, selected):
     files = tools.get_files(selected)
     if files:
         file_in = files[0]
         filename, filext = os.path.splitext(file_in)
         file_out = filename + '_joined_files.pdf'
         jpd = JoinPdfsDialog(_('Join pdf files'), files, file_out)
         if jpd.run() == Gtk.ResponseType.ACCEPT:
             files = jpd.get_pdf_files()
             file_out = jpd.get_file_out()
             jpd.destroy()
             if len(files) > 0 and file_out:
                 dialog = Progreso(_('Join pdf files'), None, 1)
                 diboo = DoitInBackgroundOnlyOne(
                     pdfapi.join_files, files, file_out)
                 diboo.connect('done', dialog.increase)
                 diboo.start()
                 dialog.run()
         jpd.destroy()
示例#12
0
 def extract_some_pages(self, selected):
     files = tools.get_files(selected)
     if files:
         file0 = files[0]
         filename, filext = os.path.splitext(file0)
         file_out = filename + '_extracted_pages.pdf'
         last_page = cairoapi.get_num_of_pages(file0)
         spd = SelectPagesDialog(_('Extract some pages'), last_page,
                                 file_out)
         if spd.run() == Gtk.ResponseType.ACCEPT:
             ranges = tools.get_ranges(spd.entry1.get_text())
             file_out = spd.get_file_out()
             spd.destroy()
             if len(ranges) > 0:
                 dialog = Progreso(_('Extract some pages in pdf'), None, 1)
                 diboo = DoitInBackgroundOnlyOne(
                     pdfapi.extract_ranges, file0, file_out, ranges)
                 diboo.connect('done', dialog.increase)
                 diboo.start()
                 dialog.run()
         else:
             spd.destroy()
示例#13
0
 def rotate_or_flip(self, selected, window):
     files = tools.get_files(selected)
     if files:
         file0 = files[0]
         fd = FlipDialog(file0, window)
         if fd.run() == Gtk.ResponseType.ACCEPT:
             fd.hide()
             rotate = fd.get_rotate()
             flip_vertical = fd.get_flip_vertical()
             flip_horizontal = fd.get_flip_horizontal()
             extension = fd.get_extension()
             dialog = Progreso(_('Rotate and flip PDF'), window, len(files))
             diboo = doitinbackground.DoitInBackgroundRotateAndFlip(
                 files, rotate, flip_vertical, flip_horizontal, extension)
             diboo.connect('todo', dialog.set_todo_label)
             diboo.connect('donef', dialog.set_fraction)
             diboo.connect('finished', dialog.close)
             diboo.connect('interrupted', dialog.close)
             dialog.connect('i-want-stop', diboo.stop_it)
             diboo.start()
             dialog.run()
         fd.destroy()
示例#14
0
 def sign(self, selected, window):
     files = tools.get_files(selected)
     if files:
         file0 = files[0]
         sd = SignDialog(file0, window)
         if sd.run() == Gtk.ResponseType.ACCEPT:
             sd.hide()
             position_x = sd.original_position_x
             position_y = sd.original_position_y
             zoom = sd.get_watermark_zoom()
             image = sd.get_image_filename()
             extension = sd.get_extension()
             dialog = Progreso(_('Sign PDF'), window, len(files))
             diboo = doitinbackground.DoitInBackgroundSign(
                 files, image, position_x, position_y, zoom, extension)
             diboo.connect('todo', dialog.set_todo_label)
             diboo.connect('donef', dialog.set_fraction)
             diboo.connect('finished', dialog.close)
             diboo.connect('interrupted', dialog.close)
             dialog.connect('i-want-stop', diboo.stop_it)
             diboo.start()
             dialog.run()
         sd.destroy()
示例#15
0
 def watermark(self, selected):
     files = tools.get_files(selected)
     if len(files) > 0:
         file0 = files[0]
         wd = WatermarkDialog(file0)
         if wd.run() == Gtk.ResponseType.ACCEPT:
             wd.hide()
             hoption = wd.get_horizontal_option()
             voption = wd.get_vertical_option()
             horizontal_margin = wd.get_horizontal_margin()
             vertical_margin = wd.get_vertical_margin()
             zoom = float(wd.get_watermark_zoom()/100.0)
             dialog = Progreso(_('Watermark pdf files'), None, len(files))
             diboo = DoitInBackgroundWithArgs(
                 cairoapi.add_watermark_to_all_pages, files,
                 wd.get_image_filename(), hoption, voption,
                 horizontal_margin, vertical_margin, zoom,
                 wd.rbutton0.get_active())
             diboo.connect('done', dialog.increase)
             diboo.connect('todo', dialog.set_todo_label)
             dialog.connect('i-want-stop', diboo.stop_it)
             diboo.start()
             dialog.run()
         wd.destroy()
示例#16
0
    def run(self):
        total = len(self.commands)
        self.emit('started')
        for index, command in enumerate(self.commands):
            if self.stopit is True:
                break
            self.execute(command)
            self.emit('done_one', command)
        self.emit('ended', self.ok)


if __name__ == '__main__':
    from progreso import Progreso

    class testclass():
        def __init__(self):
            pass

        def feed(self, astring):
            print(astring.decode())

    tc = testclass()
    commands = ['ls', 'ls -la', 'ls']
    diib = DoItInBackground(tc, commands)
    progreso = Progreso('Adding new ppa', None, len(commands))
    diib.connect('done_one', progreso.increase)
    diib.connect('ended', progreso.close)
    progreso.connect('i-want-stop', diib.stop)
    diib.start()