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()
def combine_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 + '_combined' + filext cd = CombineDialog(_('Combine 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] filas = cd.get_rows() columnas = cd.get_columns() byrows = cd.is_sort_by_rows() margen = cd.get_margin() file_out = cd.get_file_out() cd.destroy() if file_out: dialog = Progreso(_('Convert pdfs to png'), None, 1) diboo = DoitInBackgroundOnlyOne( pdfapi.combine, file_in, file_out, filas, columnas, width, height, margen, byrows) diboo.connect('done', dialog.increase) diboo.start() dialog.run()
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()
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()
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()
def combine_pdf_pages(selected, window): files = tools.get_files(selected) if files: cd = CombineDialog(_('Combine PDF pages'), window) 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] filas = cd.get_rows() columnas = cd.get_columns() byrows = cd.is_sort_by_rows() margen = cd.get_margin() extension = cd.get_extension() cd.hide() if extension: dialog = Progreso(_('Combine PDF pages'), window, 1) diboo = doitinbackground.DoItInBackgroundCombine( files, extension, filas, columnas, width, height, margen, byrows) dialog.connect('i-want-stop', diboo.stop_it) diboo.connect('start', dialog.set_max_value) diboo.connect('todo', dialog.set_todo_label) diboo.connect('donef', dialog.set_fraction) diboo.connect('finished', dialog.end_progress) diboo.connect('interrupted', dialog.end_progress) diboo.start() dialog.run() cd.destroy()
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()
def resize_pdf_pages(selected, window): files = tools.get_files(selected) if files: cd = ResizeDialog(_('Resize PDF'), window) if cd.run() == Gtk.ResponseType.ACCEPT: size = cd.get_resize() if cd.is_vertical(): width = size[0] height = size[1] else: width = size[1] height = size[0] extension = cd.get_extension() cd.hide() if extension: dialog = Progreso(_('Resize PDF'), window, 1) diboo = doitinbackground.DoItInBackgroundResizePages( files, extension, width, height) dialog.connect('i-want-stop', diboo.stop_it) diboo.connect('start', dialog.set_max_value) diboo.connect('todo', dialog.set_todo_label) diboo.connect('donef', dialog.set_fraction) diboo.connect('finished', dialog.end_progress) diboo.connect('interrupted', dialog.end_progress) diboo.start() dialog.run() cd.destroy()
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()
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()
def convert_pdf_file_to_png(self, selected): files = tools.get_files(selected) dialog = Progreso(_('Convert pdfs to png'), None, len(files)) dib = DoitInBackground(tools.convert_pdf_to_png, files) dialog.connect('i-want-stop', dib.stop_it) dib.connect('done', dialog.increase) dib.connect('todo', dialog.set_todo_label) dib.start() dialog.run()
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()
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()
def convert_pdf_file_to_png(selected, window): files = tools.get_files(selected) if files: dialog = Progreso(_('Convert PDF to PNG'), window, len(files)) diboo = doitinbackground.DoItInBackgroundToPNG(files) dialog.connect('i-want-stop', diboo.stop_it) diboo.connect('start', dialog.set_max_value) diboo.connect('todo', dialog.set_todo_label) diboo.connect('donef', dialog.set_fraction) diboo.connect('finished', dialog.end_progress) diboo.connect('interrupted', dialog.end_progress) diboo.start() dialog.run()
def split_pdf_files(selected, window): files = tools.get_files(selected) if files: dialog = Progreso(_('Split PDF'), window, len(files)) diboo = doitinbackground.DoitInBackground( pdfapi.split_pdf, files) diboo.connect('done', dialog.increase) diboo.connect('todo', dialog.set_todo_label) diboo.connect('finished', dialog.end_progress) diboo.connect('interrupted', dialog.end_progress) dialog.connect('i-want-stop', diboo.stop_it) diboo.start() dialog.run()
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()
def main(): sl = SL() if sl.run() == Gtk.ResponseType.ACCEPT: sl.hide() if sl.button.get_label() != 'Select folder': folder = sl.button.get_label() url = sl.entry11.get_text() if len(url) > 0: urls = get_image_urls(url) total = len(urls) if total > 0: p = Progreso('Prueba', None, len(urls)) dib = DoitInBackground(urls, folder) dib.connect('started_one', p.set_start_one) dib.connect('finished_one', p.increase) dib.connect('finished', p.close) dib.connect('stopit', p.close) dib.start() p.run()
def encrypt_files(selected, window): if selected: files = tools.get_files(selected) pd = PasswordDialog(_('Encrypt files'), window) if pd.run() == Gtk.ResponseType.ACCEPT: password = pd.get_password() pd.hide() dialog = Progreso(_('Encrypt files'), window, len(files)) diboo = doitinbackground.DoitInBackgroundEncrypt(files, password) dialog.connect('i-want-stop', diboo.stop_it) diboo.connect('start', dialog.set_max_value) diboo.connect('todo', dialog.set_todo_label) diboo.connect('done', dialog.increase) diboo.connect('finished', dialog.end_progress) diboo.connect('interrupted', dialog.end_progress) diboo.start() dialog.run() pd.destroy()
def operate(operation, selected, window): dialog = None title = '' extension = '' files = tools.get_files(selected) file_in = files[0] if file_in and os.path.exists(file_in): if operation == 'rotate': dialog = FlipDialog(file_in, window) title = _('Rotate and flip PDF') extension = '_rotated' elif operation == 'watermark': dialog = WatermarkDialog(filename=file_in, window=window) title = _('Watermark PDF') extension = '_watermarked' elif operation == 'textmark': dialog = TextmarkDialog(filename=file_in, window=window) title = _('Textmark PDF') extension = '_textmarked' elif operation == 'paginate': dialog = PaginateDialog(filename=file_in, window=window) title = _('Paginate PDF') extension = '_paginated' elif operation == 'sign': dialog = SignDialog(filename=file_in, window=window) title = _('Sign PDF') extension = '_signed' if dialog is not None: if dialog.run() == Gtk.ResponseType.ACCEPT: dialog.hide() pageOptions = dialog.pages progress_dialog = Progreso(title, window, 1) diboo = doitinbackground.DoitInBackgroundPages( extension, file_in, pageOptions) diboo.connect('todo', progress_dialog.set_todo_label) diboo.connect('donef', progress_dialog.set_fraction) diboo.connect('finished', progress_dialog.end_progress) diboo.connect('interrupted', progress_dialog.end_progress) progress_dialog.connect('i-want-stop', diboo.stop_it) diboo.start() progress_dialog.run() dialog.destroy()
def reduce(selected, window): files = tools.get_files(selected) if files: rd = ReduceDialog(_('Reduce PDF'), window) if rd.run() == Gtk.ResponseType.ACCEPT: dpi = rd.get_dpi() append = rd.get_append() rd.hide() if dpi and dpi != '0' and dpi.isdigit() and append: dialog = Progreso(_('Reduce PDF size'), window, len(files)) diboo = doitinbackground.DoitInBackgroundWithArgs(tools.reduce_pdf, files, dpi, append) diboo.connect('done', dialog.increase) diboo.connect('todo', dialog.set_todo_label) diboo.connect('finished', dialog.end_progress) diboo.connect('interrupted', dialog.end_progress) dialog.connect('i-want-stop', diboo.stop_it) diboo.start() dialog.run() rd.destroy()
def on_button_ok_clicked(self, widget): start_position = self.spinbutton_begin.get_value() end_position = self.spinbutton_end.get_value() duration = end_position - start_position output_file = self.button_output.get_label() if os.path.exists(output_file): os.remove(output_file) if os.path.exists(output_file + ".tmp"): os.remove(output_file + ".tmp") if self.filename is not None and os.path.exists(self.filename) and duration > 0: configuration = Configuration() frames = configuration.get("frames") scale = configuration.get("scale") modify_width = configuration.get("modify-width") width = configuration.get("width") modify_height = configuration.get("modify-height") height = configuration.get("height") if scale is True: if modify_width is True: t_width = str(width) else: t_width = "-1" if modify_height is True: t_height = str(height) else: t_height = "-1" if t_width != "-1" or t_height != "-1": scale_t = " -vf scale=%s:%s " % (t_width, t_height) else: scale_t = "" else: scale_t = "" # input_file, output_file, start_position, duration, # frames, scale_t): progreso = Progreso(_("Converting video"), self, 100) convertVideo = ConvertVideo(self.filename, output_file, start_position, duration, frames, scale_t) progreso.connect("i-want-stop", convertVideo.stop_it) convertVideo.connect("processed", progreso.set_value) convertVideo.connect("interrupted", progreso.close) convertVideo.start() progreso.run()
def extract_some_pages(selected, window): files = tools.get_files(selected) if files: spd = SelectPagesDialog(_('Extract pages from PDF'), None, window) if spd.run() == Gtk.ResponseType.ACCEPT: ranges = tools.get_ranges(spd.entry1.get_text()) spd.hide() if ranges: dialog = Progreso(_('Extract pages from PDF'), window, 1) diboo = doitinbackground.DoitInBackgroundExtractSomePages( files, ranges) diboo.connect('todo', dialog.set_todo_label) diboo.connect('donef', dialog.set_fraction) diboo.connect('finished', dialog.end_progress) diboo.connect('interrupted', dialog.end_progress) dialog.connect('i-want-stop', diboo.stop_it) diboo.start() dialog.run() spd.destroy()
class DoItInBackground(GObject.GObject): __gsignals__ = { 'started': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, (int,)), 'ended': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, (bool,)), 'start_one': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, (str,)), 'end_one': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, (float,)), } def __init__(self, title, parent, elements): GObject.GObject.__init__(self) self.elements = elements self.stopit = False self.ok = True self.progreso = Progreso(title, parent) self.progreso.set_total_size(len(elements)) self.progreso.connect('i-want-stop', self.stop) self.connect('start_one', self.progreso.set_element) self.connect('end_one', self.progreso.increase) self.connect('ended', self.progreso.close) self.downloaders = [] def emit(self, *args): GLib.idle_add(GObject.GObject.emit, self, *args) def stop(self, *args): if len(self.downloaders) > 0: for downloader in self.downloaders: downloader.cancel() self.emit('end_one', 1.0) def run(self): try: executor = futures.ThreadPoolExecutor() for element in self.elements: downloader = executor.submit(download, element, self) self.downloaders.append(downloader) self.progreso.run() except Exception as e: self.ok = False print(e)
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()
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()
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()
def join_pdf_files(selected, window): files = tools.get_files(selected) if files: file_in = files[0] filename = os.path.splitext(file_in)[0] file_out = filename + '_joined_files.pdf' jpd = JoinPdfsDialog(_('Join PDF files'), files, file_out, window) if jpd.run() == Gtk.ResponseType.ACCEPT: files = jpd.get_pdf_files() file_out = jpd.get_file_out() jpd.hide() if files and file_out: dialog = Progreso(_('Join PDF files'), window, len(files)) diboo = doitinbackground.DoItInBackgroundJoinPdf( files, file_out) dialog.connect('i-want-stop', diboo.stop_it) diboo.connect('todo', dialog.set_todo_label) diboo.connect('donef', dialog.set_fraction) diboo.connect('finished', dialog.end_progress) diboo.connect('interrupted', dialog.end_progress) diboo.start() dialog.run() jpd.destroy()
def create_pdf_from_images(selected, window): files = tools.get_files(selected) if files: file_in = files[0] filename = os.path.splitext(file_in)[0] file_out = filename + '_from_images.pdf' cpfi = CreatePDFFromImagesDialog( _('Create PDF from images'), files, file_out, window) if cpfi.run() == Gtk.ResponseType.ACCEPT: cpfi.hide() files = cpfi.get_png_files() if cpfi.is_vertical(): width, height = cpfi.get_dimensions() else: height, width = cpfi.get_dimensions() margin = cpfi.get_margin() file_out = cpfi.get_file_out() cpfi.destroy() if file_out: dialog = Progreso(_('Create PDF from images'), window, len(files)) diboo = doitinbackground\ .DoItInBackgroundCreatePDFFromImages(file_out, files, width, height, margin) dialog.connect('i-want-stop', diboo.stop_it) diboo.connect('start', dialog.set_max_value) diboo.connect('todo', dialog.set_todo_label) diboo.connect('done', dialog.increase) diboo.connect('finished', dialog.end_progress) diboo.connect('interrupted', dialog.end_progress) diboo.start() dialog.run() cpfi.destroy()
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()
def remove_some_pages(selected, window): files = tools.get_files(selected) if files: file0 = files[0] filename = os.path.splitext(file0)[0] file_out = filename + '_removed_pages.pdf' spd = SelectPagesDialog(_('Remove PDF'), file_out, window) if spd.run() == Gtk.ResponseType.ACCEPT: ranges = tools.get_ranges(spd.entry1.get_text()) file_out = spd.get_file_out() spd.hide() if ranges: dialog = Progreso(_('Remove PDF'), window, 1) diboo = doitinbackground.DoitInBackgroundRemoveSomePages( file0, file_out, ranges) diboo.connect('start', dialog.set_max_value) diboo.connect('done', dialog.increase) diboo.connect('finished', dialog.end_progress) diboo.connect('interrupted', dialog.end_progress) dialog.connect('i-want-stop', diboo.stop_it) diboo.start() dialog.run() spd.destroy()
class Antiviral(Gtk.Window): def __init__(self, from_filebrowser=False, folders=[]): Gtk.Window.__init__(self) self.set_title(_('Antiviral')) self.set_modal(True) # try: self.scanner = pyclamd.ClamdUnixSocket() self.scanner.ping() except pyclamd.ConnectionError: self.scanner = pyclamd.ClamdNetworkSocket() try: self.scanner.ping() except pyclamd.ConnectionError as e: print(e) exit(0) # print(self.scanner.reload()) print(self.scanner.stats()) # self.set_position(Gtk.WindowPosition.CENTER_ALWAYS) self.set_title(comun.APP) self.set_icon_from_file(comun.ICON) self.connect('destroy', self.on_close_application) # vbox = Gtk.VBox(spacing=5) vbox.set_border_width(5) self.add(vbox) # frame0 = Gtk.Frame() vbox.pack_start(frame0, True, True, 0) vbox0 = Gtk.VBox(spacing=5) vbox0.set_border_width(5) frame0.add(vbox0) # label1 = Gtk.Label() label1.set_text(_('ClamAV version')+': ' + self.scanner.version().split(' ')[1].split('/')[0]) label1.set_alignment(0, 0.5) vbox0.pack_start(label1, False, False, 0) # frame1 = Gtk.Frame() vbox.pack_start(frame1, True, True, 0) hbox1 = Gtk.HBox(spacing=5) hbox1.set_border_width(5) frame1.add(hbox1) # vbox0 = Gtk.VBox() hbox1.pack_start(vbox0, False, False, 0) button_b0 = ButtonWithTextAndIcon( _('Scan home'), Gtk.Image.new_from_stock( Gtk.STOCK_FIND, Gtk.IconSize.BUTTON)) button_b0.set_tooltip_text(_('Scan home now')) button_b0.connect('clicked', self.on_button_scan_home_clicked) vbox0.pack_start(button_b0, False, False, 0) button_b1 = ButtonWithTextAndIcon( _('Scan folders'), Gtk.Image.new_from_stock( Gtk.STOCK_FIND, Gtk.IconSize.BUTTON)) button_b1.set_tooltip_text(_('Scan selected folders now')) button_b1.connect('clicked', self.on_button_scan_clicked) vbox0.pack_start(button_b1, False, False, 0) button_quit = ButtonWithTextAndIcon( _('Exit'), Gtk.Image.new_from_stock( Gtk.STOCK_QUIT, Gtk.IconSize.BUTTON)) button_quit.set_tooltip_text(_('Exit')) button_quit.connect('clicked', self.on_close_application) vbox0.pack_end(button_quit, False, False, 0) # button_about = ButtonWithTextAndIcon( _('About'), Gtk.Image.new_from_stock( Gtk.STOCK_ABOUT, Gtk.IconSize.BUTTON)) button_quit.set_tooltip_text(_('About')) button_about.connect('clicked', self.on_button_about_clicked) vbox0.pack_end(button_about, False, False, 0) # button_update = ButtonWithTextAndIcon( _('Update'), Gtk.Image.new_from_stock( Gtk.STOCK_REFRESH, Gtk.IconSize.BUTTON)) button_update.set_tooltip_text(_('Update virus database')) button_update.connect('clicked', self.on_button_update_clicked) vbox0.pack_end(button_update, False, False, 0) scrolledwindow = Gtk.ScrolledWindow() scrolledwindow.set_policy( Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) scrolledwindow.set_shadow_type(Gtk.ShadowType.ETCHED_OUT) scrolledwindow.set_size_request(500, 300) hbox1.pack_start(scrolledwindow, True, True, 0) model = Gtk.ListStore(bool, bool, str) self.treeview = Gtk.TreeView() self.treeview.set_model(model) scrolledwindow.add(self.treeview) crt0 = Gtk.CellRendererToggle() crt0.set_property('activatable', True) column0 = Gtk.TreeViewColumn(_('Scan'), crt0, active=0) crt0.connect("toggled", self.toggled_cb, (model, 0)) self.treeview.append_column(column0) crt1 = Gtk.CellRendererToggle() crt1.set_property('activatable', True) column1 = Gtk.TreeViewColumn(_('Rec.'), crt1, active=1) crt1.connect("toggled", self.toggled_cb, (model, 1)) self.treeview.append_column(column1) # column = Gtk.TreeViewColumn( _('Folder'), Gtk.CellRendererText(), text=2) self.treeview.append_column(column) # vbox1 = Gtk.VBox() hbox1.pack_end(vbox1, False, False, 0) button1 = Gtk.Button() button1.set_size_request(40, 40) button1.set_tooltip_text(_('Add new folder')) button1.set_image(Gtk.Image.new_from_stock( Gtk.STOCK_ADD, Gtk.IconSize.BUTTON)) button1.connect('clicked', self.on_button1_clicked) vbox1.pack_start(button1, False, False, 0) button2 = Gtk.Button() button2.set_size_request(40, 40) button2.set_tooltip_text(_('Remove selected folder')) button2.set_image(Gtk.Image.new_from_stock( Gtk.STOCK_REMOVE, Gtk.IconSize.BUTTON)) button2.connect('clicked', self.on_button2_clicked) vbox1.pack_start(button2, False, False, 0) button3 = Gtk.Button() button3.set_size_request(40, 40) button3.set_tooltip_text(_('Remove all folders')) button3.set_image(Gtk.Image.new_from_stock( Gtk.STOCK_CLEAR, Gtk.IconSize.BUTTON)) button3.connect('clicked', self.on_button3_clicked) vbox1.pack_end(button3, False, False, 0) # self.from_filebrowser = from_filebrowser if not self.from_filebrowser: self.load_preferences() # self.progreso_dialog = None self.files = [] # if len(folders) > 0: model = self.treeview.get_model() model.clear() for folder in folders: model.append([True, True, folder]) # self.show_all() def on_close_application(self, widget): self.save_preferences() self.hide() self.destroy() def toggled_cb(self, cell, path, user_data): model, column = user_data model[path][column] = not model[path][column] self.save_preferences() return def load_preferences(self): configuration = Configuration() model = self.treeview.get_model() model.clear() folders = configuration.get('folders') for folder in folders: scan = folder['scan'] recursive = folder['recursive'] folder_name = folder['name'] model.append([scan, recursive, folder_name]) def save_preferences(self): if not self.from_filebrowser: folders = [] model = self.treeview.get_model() itera = model.get_iter_first() while(itera is not None): folder = {} folder['scan'] = model.get(itera, 0)[0] folder['recursive'] = model.get(itera, 1)[0] folder['name'] = model.get(itera, 2)[0] folders.append(folder) itera = model.iter_next(itera) if len(folders) > 0: configuration = Configuration() configuration.set('folders', folders) configuration.save() def on_button1_clicked(self, widget): dialog = Gtk.FileChooserDialog(_( 'Select Folder...'), None, Gtk.FileChooserAction.SELECT_FOLDER, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) dialog.set_default_response(Gtk.ResponseType.OK) response = dialog.run() if response == Gtk.ResponseType.OK: if not self.exists_folder(dialog.get_filename()): model = self.treeview.get_model() model.append([True, False, dialog.get_filename()]) dialog.destroy() def exists_folder(self, folder): exists = False model = self.treeview.get_model() itera = model.get_iter_first() while(itera is not None): value = model.get(itera, 2)[0] itera = model.iter_next(itera) if value == folder: itera = None exists = True return exists def on_button2_clicked(self, widget): selected = self.treeview.get_selection() model = self.treeview.get_model() if selected is not None: if selected.get_selected()[1] is not None: model.remove(selected.get_selected()[1]) def on_button3_clicked(self, widget): model = self.treeview.get_model() model.clear() def on_button_scan_home_clicked(self, widget): fp = FolderProcessor(ishome=True) self.progreso_dialog = Progreso( _('Processing folders...'), self, 1) self.progreso_dialog.connect( 'i-want-stop', fp.stop_it) fp.connect('to-process', self.on_to_process_folder) fp.connect('processed', self.on_processed_folder) fp.connect('finished', self.on_processed_folders) fp.start() self.progreso_dialog.run() def on_button_scan_clicked(self, widget): model = self.treeview.get_model() fp = FolderProcessor(model) if self.progreso_dialog is not None: self.progreso_dialog.destroy() self.progreso_dialog = None self.progreso_dialog = Progreso( _('Processing folders...'), self, len(model)) self.progreso_dialog.connect( 'i-want-stop', fp.stop_it) fp.connect('to-process', self.on_to_process_folder) fp.connect('processed', self.on_processed_folder) fp.connect('finished', self.on_processed_folders) fp.start() self.progreso_dialog.run() def on_to_process_folder(self, processor, afile): # GLib.idle_add(self.progreso_dialog.set_scanning_file, afile) self.progreso_dialog.set_scanning_file(afile) def on_processed_folder(self, processor): # GLib.idle_add(self.progreso_dialog.increase) self.progreso_dialog.increase() def on_processed_folders(self, processor, container): files = container.get_data() if len(files) > 0: scanner = Scanner(self.scanner, files) scanner.connect('to-scan', self.going_to_scan) scanner.connect('scanned', self.on_progress) scanner.connect('infected', self.on_infected_detect) scanner.connect('finished', self.on_scan_finished) print(2) if self.progreso_dialog is not None: self.progreso_dialog.destroy() self.progreso_dialog = None print(3) self.progreso_dialog = Progreso(_('Scanning...'), self, len(files)) print(4) self.progreso_dialog.connect( 'i-want-stop', scanner.stop_it) print(5) self.infected = [] print(6) scanner.start() self.progreso_dialog.run() def going_to_scan(self, scanner, afile): # GLib.idle_add(self.progreso_dialog.set_scanning_file, afile) self.progreso_dialog.set_scanning_file(afile) def on_progress(self, scanner): # GLib.idle_add(self.progreso_dialog.increase) self.progreso_dialog.increase() def on_infected_detect(self, scanner, infected): self.infected.append(infected) def on_scan_finished(self, scanner): # GLib.idle_add(self._on_scan_finished) if self.progreso_dialog is not None: self.progreso_dialog.destroy() self.progreso_dialog = None md = Gtk.MessageDialog(parent=self) md.set_title('Antiviral') md.set_property('message_type', Gtk.MessageType.INFO) md.add_button(Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT) md.set_property('text', _('Antiviral')) if len(self.infected) > 0: md.format_secondary_text( _('What a pity!, In this machine there are viruses!')) md.run() md.destroy() actions = Actions(self, self.infected) actions.run() actions.destroy() else: md.format_secondary_text(_('Congratulations!!, no viruses found')) md.run() md.destroy() def on_button_update_clicked(self, widget): self.update_database() def on_button_about_clicked(self, widget): ad = Gtk.AboutDialog() ad.set_name(comun.APPNAME) ad.set_version(comun.VERSION) ad.set_copyright(''' Copyrignt (c) 2010 - 2016 Lorenzo Carbonell Cerezo ''') ad.set_comments(_('A graphical interface for\nClamAV')) ad.set_license(''' This program 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. This program 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/>. ''') ad.set_logo(GdkPixbuf.Pixbuf.new_from_file(comun.ICON)) ad.set_icon(GdkPixbuf.Pixbuf.new_from_file(comun.ICON)) ad.set_website('http://www.atareao.es') ad.set_website_label('http://www.atareao.es') ad.set_authors([ 'Lorenzo Carbonell <*****@*****.**>']) ad.set_documenters([ 'Lorenzo Carbonell <*****@*****.**>']) ad.set_program_name(_('Antiviral')) ad.run() ad.hide() ad.destroy() def update_database(self): p = subprocess.Popen([ 'gksu', 'freshclam'], bufsize=10000, stdout=subprocess.PIPE) output = p.communicate()[0] # store stdout msg = '' print(output) for line in output.decode().split('\n'): if line.find('main') != -1: if line.find('is up to date') != -1: msg = _('main is up to date\n') else: msg = _('main updated\n') if line.find('daily') != -1: if line.find('is up to date') != -1: msg += _('daily is up to date\n') else: msg += _('daily updated\n') if line.find('bytecode') != -1: if line.find('is up to date') != -1: msg += _('bytecode is up to date\n') else: msg += _('bytecode updated\n') if msg == '': msg = output tipo = Gtk.MessageType.ERROR md = Gtk.MessageDialog(self, 0, tipo, Gtk.ButtonsType.CLOSE, msg) md.set_title('Antiviral') md.run() md.destroy() else: tipo = Gtk.MessageType.INFO msg += '\n\n'+_('Reloading')+'...' md = Gtk.MessageDialog(self, 0, tipo, Gtk.ButtonsType.CLOSE, msg) md.set_title('Antiviral') md.run() md.destroy() print(self.scanner.reload())