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!sslpdf_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%; } #pdf-area:focus { outline: none; } PK!.DTTpdf_shuffle/static/index.jslet pdfCache; const SCALING = 2; init(); document.getElementById('previous-all').onclick = ()=>{ config.current = config.start; renderPage(); } document.getElementById('previous').onclick = ()=>{ config.current--; renderPage(); } document.getElementById('next-all').onclick = ()=>{ config.current = config.end; renderPage(); } document.getElementById('next').onclick = ()=>{ config.current++; 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 keyPressed = e.which || e.keyCode; const key = { left: 37, // up: 38, right: 39, // down: 40, space: 32, backspace: 8, enter: 13 } switch (keyPressed) { case key.left: document.getElementById('previous').click(); break; case key.right: document.getElementById('next').click(); break; case key.space: case key.enter: document.getElementById('pdf-area').click(); break; case key.backspace: if(config.last && /(?:^|\/).*\.pdf/i.test(config.filename)){ config.current = config.last; renderPage(); } break; default: } }); window.addEventListener('resize', ()=>{ Object.assign(document.getElementById('pdf-container').style, getTrueWindowDimension()); }); function init(){ config.stepped = 1; config.userEnd = config.end; 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()); randomizePages(); } 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; } } async function randomizePages(){ if(!pdfCache || config.random === true || !(/(?:^|\/).*\.pdf/i.test(config.filename))){ await pdfjsLib.getDocument('/file?filename=' + encodeURIComponent(config.filename)) .then(pdf=>{ pdfCache = pdf; config.end = config.userEnd || pdfCache.numPages; document.getElementById('page-label-total').innerHTML = pdfCache.numPages; }); } config.last = config.current; if(config.random){ if(Array.isArray(config.random)){ config.current = config.random[Math.floor(Math.random() * config.random.length)]; } else { 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 !== config.last){ renderPage(); } } function renderPage(resetStep){ if(resetStep !== false){ config.stepped = config.step; } if(pdfCache === undefined){ return; } pdfCache.getPage(config.current) .then(page=>{ console.log('Page', config.current); 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(); canvas.focus(); }); } PK!BBB pdf_shuffle/templates/index.html
PK!ι  pdf_shuffle/util.pyimport webbrowser from threading import Thread from time import sleep import os 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() def list_pdf(path): for (dirpath, dirnames, filenames) in os.walk(path): for filename in filenames: if os.path.splitext(filename)[1].lower() == '.pdf' and filename[0] != '.': yield os.path.join(dirpath, filename) PK!t{ffpdf_shuffle/views.pyfrom flask import render_template, send_file, request import os import json from urllib.parse import unquote import random from . import app from .util import list_pdf @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(): filename = os.path.abspath(unquote(request.args.get('filename'))) cache_timeout = None if os.path.isdir(filename): filename = random.choice(tuple(list_pdf(filename))) print(filename) cache_timeout = 0 return send_file(filename, cache_timeout=cache_timeout) PK!H :>g,pdf_shuffle-0.2.1.dist-info/entry_points.txtN+I/N.,()*HI-,ͬ23JrRs3@ Y2,nPA..PK! ::#pdf_shuffle-0.2.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.2.1.dist-info/WHEEL A н#Z@Z|Jl~6蓅 Λ MU4[PYBpYD*Mͯ#ڪ/̚?ݭ'%nPK!H $pdf_shuffle-0.2.1.dist-info/METADATAV[o6~8CtIuٌu6bo`1+QdIʮw(ɷtiyPs?s;hJ cr%Џ.Ʉl:BY&٫/"o0/jCݼM,>Pb&e  5)|('Ȍ*zS r񚻼|%5eVbq&-܍VmIm]jOE˕A>F+ YA8V\g٦1 6jRwQkC5R.=h?0os3=^k}sǫ==3a6 GLhR:adoƷnDT2`G!C YRT HzBrgoaińji!Ѥ/ʹGþkFxu[c돶|*jg0.5]a2l RRVVxTOD]̸S6X"L%Z 0tڷ^&=U~$ f&v($9)V7Im kⷲ~8uumemwe>JhfzWH9nqV%zp"!Oz[SǂsT, ;`s04/1Q1$_PK!H?E"pdf_shuffle-0.2.1.dist-info/RECORD}9@|~ 8Ҷʭ`㦹_`M+^uq-MQ/ajR5mЂp*w#(~t*{=9w%A ѽxuÒ 5Ysj216uY 75q2-ax[IsiPd#c0L WIkYN+ɍY޴ݥL9d%"-b>"Xz5qRwUz‡Fy\VvcFKR2s Gaf%{nUTTe\\x"p 8maq{$B(,Аqs*ݞ MPCGnfpMHj,EL&m?ߵOٱewG]%HEL?UUs~ hjCţ%>iJFYlӴT[^nJ11S FMC}މ=t8ö"C%:t ɱY[ ڜhneARXRG w{3Z:UjS5S PK! l1eepdf_shuffle/__init__.pyPK!ۿpdf_shuffle/__main__.pyPK!ssl}pdf_shuffle/static/index.cssPK!.DTT pdf_shuffle/static/index.jsPK!BBB @pdf_shuffle/templates/index.htmlPK!ι  $pdf_shuffle/util.pyPK!t{ff&pdf_shuffle/views.pyPK!H :>g,*pdf_shuffle-0.2.1.dist-info/entry_points.txtPK! ::#+pdf_shuffle-0.2.1.dist-info/LICENSEPK!HMWX!/pdf_shuffle-0.2.1.dist-info/WHEELPK!H $,0pdf_shuffle-0.2.1.dist-info/METADATAPK!H?E"04pdf_shuffle-0.2.1.dist-info/RECORDPK 6