PK! l1eepdf_shuffle/__init__.pyfrom flask import Flask import os import json app = Flask(__name__) from .views import index, send_pdf from .util import open_browser_tab def init(filename, start=1, end=None, step=1, random=True, host='localhost', port=5000): """ :param filename: :param start: :param end: :param step: :param bool|list|tuple random: :param host: :param port: :return: """ os.environ.update({ 'FILENAME': filename, 'PAGE_START': str(start), 'PAGE_END': json.dumps(end), 'PAGE_STEP': str(step), 'PAGE_RANDOM': json.dumps(random), 'HOST': host, 'PORT': str(port) }) open_browser_tab('http://{}:{}/'.format(os.getenv('HOST'), os.getenv('PORT'))) app.run(host=os.getenv('HOST'), port=os.getenv('PORT')) def init_quiz(filename, start=2, end=None, step=2, random=True, host='localhost', port=5000): """ :param filename: :param start: :param end: :param step: :param bool|list|tuple random: :param host: :param port: :return: """ init(filename, start, end, step, random, host, port) PK!ۿpdf_shuffle/__main__.pyimport click import os from . import init @click.command() @click.argument('filename') @click.option('--start', default=1, envvar='PAGE_START') @click.option('--end', default=None, envvar='PAGE_END') @click.option('--step', default=1, envvar='PAGE_STEP') @click.option('--random/--no-random', default=True, envvar='PAGE_RANDOM') @click.option('--host', default='localhost', envvar='HOST') @click.option('--port', default=5000, envvar='PORT') def pdf_shuffle(filename, start, end, step, random, host, port): init(filename, start, end, step, random, host, port) def pdf_quiz(): os.environ.update({ 'PAGE_START': '2', 'PAGE_STEP': '2' }) pdf_shuffle() PK!s"pdf_shuffle/static/index.css* { margin: 0px; } body { width: 100%; min-width: 100%; } #nav-area { border: 1px solid #ccc; background-color: #f1f1f1; display: inline-table; width: 100%; } /* Style the buttons that are used to open the tab content */ #new-record, .page-button { background-color: inherit; border: none; outline: none; padding: 14px 16px; margin: 0px; transition: 0.3s; font-size: 17px; } .page-button:disabled { color: white; } #nav-page-button, #nav-page-button > *, #page-label > * { display: inherit; } #page-label > * { margin-left: 0.5em; margin-right: 0.5em; } #pdf-container { position: relative; overflow: scroll; } #pdf-area { position: absolute; height: auto; width: 100%; } PK!p4>9  pdf_shuffle/static/index.jslet pdfCache; const SCALING = 2; config.stepped = 1; if(Array.isArray(config.random) && config.random.length > 0){ config.current = config.random[0] } else { config.current = config.start; } document.getElementById('title').innerHTML = config.filename; Object.assign(document.getElementById('pdf-container').style, getTrueWindowDimension()); pdfjsLib.getDocument('/file?filename=' + encodeURIComponent(config.filename)) .then(pdf=>{ pdfCache = pdf; config.end = config.end || pdfCache.numPages; document.getElementById('page-label-total').innerHTML = pdfCache.numPages; randomizePages(); }); document.getElementById('previous-all').onclick = ()=>{ config.current = config.start; renderPage(); } document.getElementById('previous').onclick = ()=>{ config.current -= config.step; renderPage(); } document.getElementById('next-all').onclick = ()=>{ config.current = config.end; renderPage(); } document.getElementById('next').onclick = ()=>{ config.current += config.step; renderPage(); } document.getElementById('pdf-area').onclick = ()=>{ if(config.end && config.stepped < config.step && config.current < config.end){ config.current++; config.stepped++; renderPage(false); } else { config.stepped = 1; randomizePages(); } } document.body.addEventListener('keydown', (e)=>{ e = e || window.event; const key = e.which || e.keyCode; }); window.addEventListener('resize', ()=>{ Object.assign(document.getElementById('pdf-container').style, getTrueWindowDimension()); }); function getTrueWindowDimension(){ return { height: (window.innerHeight - document.getElementById('nav-area').offsetHeight) + 'px', width: window.innerWidth + 'px' }; } function setPageNav(){ if(config.current >= config.step + config.start){ document.getElementById('previous-all').disabled = false; document.getElementById('previous').disabled = false; } else { document.getElementById('previous-all').disabled = true; document.getElementById('previous').disabled = true; } if((!config.end) || config.current <= config.end - config.step){ document.getElementById('next-all').disabled = false; document.getElementById('next').disabled = false; } else { document.getElementById('next-all').disabled = true; document.getElementById('next').disabled = true; } } function randomizePages(){ const oldCurrent = config.current; if(config.random){ if(Array.isArray(config.random)){ config.current = config.random[Math.floor(Math.random() * config.random.length)]; } else { if(pdfCache){ config.current = (Math.floor(Math.random() * (config.end - config.start + 1)/config.step) * config.step) + config.start; } } } else { if((!config.end) || config.current <= config.end - config.step){ config.current++; } } if(config.current !== oldCurrent){ renderPage(); } } function renderPage(resetStep){ if(resetStep !== false){ config.stepped = 1; } if(pdfCache === undefined){ return; } pdfCache.getPage(config.current) .then(page=>{ const canvas = document.getElementById('pdf-area'); const context = canvas.getContext('2d'); const viewport = page.getViewport(SCALING); const trueHeight = parseInt(getTrueWindowDimension().height); canvas.width = viewport.width; canvas.height = viewport.height; if(canvas.offsetHeight > trueHeight){ Object.assign(canvas.style, { top: '0', left: '50%', transform: 'translateX(-50%)' }); } else if (canvas.offsetHeight < trueHeight){ Object.assign(canvas.style, { top: '50%', left: '0', transform: 'translateY(-50%)' }); } if(viewport.height > viewport.width){ Object.assign(canvas.style, { height: 'auto', width: '100%' }); } else { Object.assign(canvas.style, { height: '100%', width: 'auto' }); } page.render({canvasContext: context, viewport: viewport}); document.getElementById('page-label-current').innerHTML = config.current; Object.assign(document.getElementById('pdf-container'), { scrollTop: 0, scrollLeft: 0 }); setPageNav(); }); } PK!:H11 pdf_shuffle/templates/index.html
PK!Yylpdf_shuffle/util.pyimport webbrowser from threading import Thread from time import sleep def open_browser_tab(url): def _open_tab(): sleep(1) webbrowser.open_new_tab(url) thread = Thread(target=_open_tab) thread.daemon = True thread.start() PK!d,u``pdf_shuffle/views.pyfrom flask import render_template, send_file, request import os import json from urllib.parse import unquote from . import app @app.route('/') def index(): return render_template('index.html', config={ 'filename': os.getenv('FILENAME'), 'start': json.loads(os.getenv('PAGE_START', '1')), 'end': json.loads(os.getenv('PAGE_END', 'null')), 'step': json.loads(os.getenv('PAGE_STEP', '1')), 'random': json.loads(os.getenv('PAGE_RANDOM', '1')) }) @app.route('/file') def send_pdf(): return send_file(os.path.abspath(unquote(request.args.get('filename')))) PK!H :>g,pdf_shuffle-0.1.1.dist-info/entry_points.txtN+I/N.,()*HI-,ͬ23JrRs3@ Y2,nPA..PK! ::#pdf_shuffle-0.1.1.dist-info/LICENSEMIT License Copyright (c) 2018 Pacharapol Withayasakpunt Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!HMWX!pdf_shuffle-0.1.1.dist-info/WHEEL A н#Z@Z|Jl~6蓅 Λ MU4[PYBpYD*Mͯ#ڪ/̚?ݭ'%nPK!HFaU$pdf_shuffle-0.1.1.dist-info/METADATAUmo6_q@ $9qa^vۈCĬtH$KRv_,;v 5iHwt<厇Xd 蜍y14 m^eYl>)`V%7u ^͗%=pR|C2 7)|7Ȍ*{LP%Cq.>G*{2\bZ$(-AnFs'keR۴JAreȺњB,(-Wd"Hȶ 1Lf#hm SMԨe)\V TYőGxu4ш v6Ő"y^Gۋy?&<: }Hᥒ &8z$T%c'Rg?ivr#i/ 2X, Bjyec{. I5mz\kbIk]=DXh:^LxvGfDԙq0χe yF}0=zj ճAo5\X}@  =ѡu6 d,4=4$#Tb DRS^/;mnvkIVXQCn\ [Et.p?-Ӷ ~4Ã޺\teBwlمkH1UXlD6 fJG̈́!m!RWhI({-p@e Ydg n+,n)Nr<Ŝ:N,}+\ xי> nM5QZv Uo8?2ӜX jtlMb,;26ʚsJ=zJt oǐCshR,sYcC[yJ"aIe ]EMg$PK!HC1H"pdf_shuffle-0.1.1.dist-info/RECORD}˒@} tc%.f"X>),^Rbh7Fĩ4%ɏ SnF ?nnc CW riS~tX+;hGo+kTLռye7o8 @'f%DnV^d7H рWqreʳDWCۑ&*n,7C`Y'˝GhC1(_FfҤlH@Ӓ`n{ nؓףU1.9 P\V;fƒ|2fzFGk~/%9VET42c8}z /KEE,ZrO,+:Qq?kro'ωqGY\OR75hMd/OzUndqPd[ _YP i[>ohW{*–ZMQU >q·[3OY_wٓGk9?lt8;4TEU_ )T',fis/Uy/Mk#BnwEu< QV6b\)[GePK! l1eepdf_shuffle/__init__.pyPK!ۿpdf_shuffle/__main__.pyPK!s"}pdf_shuffle/static/index.cssPK!p4>9   pdf_shuffle/static/index.jsPK!:H11 pdf_shuffle/templates/index.htmlPK!YylA!pdf_shuffle/util.pyPK!d,u``s"pdf_shuffle/views.pyPK!H :>g,%pdf_shuffle-0.1.1.dist-info/entry_points.txtPK! ::#%pdf_shuffle-0.1.1.dist-info/LICENSEPK!HMWX!*pdf_shuffle-0.1.1.dist-info/WHEELPK!HFaU$*pdf_shuffle-0.1.1.dist-info/METADATAPK!HC1H"A.pdf_shuffle-0.1.1.dist-info/RECORDPK 0