Skip to content

Implementing Apps > PDF #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 182 additions & 0 deletions css/common/pdf.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
.vp-pdf {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1200;
background-color: rgba(0,0,0,.4);
}
.vp-pdf-container {
position: relative;
left: 50%;
top: 50%;
transform:translate(-50%, -50%);
min-width: 470px;
min-height: 420px;
width: 50%;
height: 60%;
background-color: white;
}
.vp-pdf-title {
height: 40px;
padding: 5px 0px 5px 10px;
background-color: #EEE;
border: 1px solid #ddd;;
display: flex;
flex-direction: row;
position: relative;
align-items: center;
font-size: 16px;
font-weight: 700;
}
.vp-pdf-close,
.vp-pdf-popup-close {
position: fixed;
z-index: 3;
right: 5px;
width: 30px;
height: 20px;
line-height: 20px;
top: 10px;
text-align: center;
cursor: pointer;
}
.vp-pdf-body {
width: 100%;
height: calc(100% - 90px);
padding: 10px;
}
.vp-pdf-grid-box {
display: grid;
width: 100%;
height: 100%;
grid-row-gap: 5px;
/* grid-template-rows: 60px calc(100% - 80px); */
/* grid-template-rows: 80px calc(100% - 100px); */
/* grid-template-rows: 80px min-content; */
grid-template-rows: 60px 140px 150px;
}
.vp-pdf-prepare-box {
display: grid;
grid-template-columns: 50% 50%;
align-items: baseline;
align-content: center;
border: 1px solid #E4E4E4;
border-radius: 5px;
box-sizing: border-box;
padding: 15px;
}
.vp-pdf-link {
color: var(--highlight-color);
}
.vp-pdf-install-btn{
margin-left: 7px;
}
.vp-pdf-check-btn {
display: inline-block;
margin-left: 5px;
}
.vp-pdf-import-btn {
margin-left: 10px;
}
.vp-pdf-show-box {
display: grid;
/* grid-template-rows: min-content min-content; */
grid-row-gap: 10px;
border: 1px solid #E4E4E4;
border-radius: 5px;
box-sizing: border-box;
padding: 15px;
}
.vp-pdf-df-box {
display: grid;
grid-template-columns: 95px auto;
grid-row-gap: 3px;
align-items: baseline;
align-content: space-evenly;
}
.vp-pdf #vp_pdfVariable {
width: 62%;
height: 30px;
}
.vp-pdf-input {
width: 62%;
}
.vp-pdf-run-btn {
width: 112px !important;
margin-left: 5px;
}
.vp-pdf-preview-box {
display: none;
width: 100%;
height: 100px;
position: absolute;
bottom: 50px;

background: #F7F7F7;
border: 0.25px solid #E4E4E4;
padding: 10px;
}
/** Buttons */
.vp-pdf-btn-box {
position: relative;
height: 50px;
border-top: 0.25px solid var(--border-gray-color);
}
.vp-pdf-btn {
position: absolute;
}
.vp-pdf-btn-preview {
left: 15px;
top: 9px;
}
.vp-pdf-btn-dataview {
left: 105px;
top: 9px;
}
.vp-pdf-btn-cancel {
top: 9px;
right: 105px;
}
.vp-pdf-btn-runadd {
position: absolute;
top: 9px;
right: 15px;
width: fit-content;
height: 30px;
background: #F38504;
border-radius: 2px;
}
.vp-pdf-btn-run {
display: inline-block;
width: 60px;
border-radius: 2px 0px 0px 2px;
border-right: 0.25px solid var(--border-gray-color) !important;
}
.vp-pdf-btn-detail {
display: inline-block;
width: 20px;
height: 28px;
border-radius: 0px 2px 2px 0px;
padding: 0;
}
.vp-pdf-detail-box {
display: none;
background: white;
border: 0.25px solid var(--border-gray-color);
position: absolute;
bottom: 35px;
right: 1px;
width: 84px;
height: 62px;
text-align: center;
line-height: 30px;
}
.vp-pdf-detail-item {
color: var(--font-primary);
}
.vp-pdf-detail-item:hover {
color: var(--font-hightlight);
background: var(--light-gray-color);
}
5 changes: 4 additions & 1 deletion src/api_block/constData.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ define([
const STR_CODE = 'code';
const STR_COMMENT = 'comment';
const STR_NODE = 'node';
const STR_TEXT = 'text';
const STR_TEXT = 'Markdown';
const STR_PRINT = 'print';
const STR_ELIF = 'elif';
const STR_ELSE = 'else';
Expand Down Expand Up @@ -776,6 +776,9 @@ define([
},
'profiling': {
file: 'nbextensions/visualpython/src/common/vpProfiling'
},
'pdf': {
file: 'nbextensions/visualpython/src/common/vpPDF'
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/api_block/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@
<img src="/nbextensions/visualpython/resource/apps/apps_white.svg">
<div class="vp-apiblock-menu-apps-name">Profiling</div>
</div>
<div class="vp-apiblock-menu-apps-item line3" data-menu="pdf" title="PDF">
<img src="/nbextensions/visualpython/resource/apps/apps_white.svg">
<div class="vp-apiblock-menu-apps-name">PDF</div>
</div>
<div class="vp-apiblock-menu-apps-item preparing" data-menu="merge" title="Work In Progress">
<img src="/nbextensions/visualpython/resource/apps/apps_merge.svg">
<div class="vp-apiblock-menu-apps-name">Merge</div>
Expand Down
3 changes: 2 additions & 1 deletion src/api_block/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ define([
case 'frame':
case 'chart':
case 'profiling':
case 'pdf':
blockContainer.setSelectBlock(null);
blockContainer.createAppsPage(menu, file, config);
break;
Expand Down Expand Up @@ -379,7 +380,7 @@ define([
});

/** Apps Menu Apply event */
$(document).on('subset_run frame_run', '#vp_appsCode', function(evt) {
$(document).on('subset_run frame_run pdf_run', '#vp_appsCode', function(evt) {
var code = evt.code;
var title = evt.title;
var state = evt.state;
Expand Down
79 changes: 79 additions & 0 deletions src/common/pycode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Project Name : Visual Python
* Description : GUI-based Python code generator
* File Name : pycode.js
* Author : Black Logic
* Note : Define constant value
* License : GNU GPLv3 with Visual Python special exception
* Date : 2021. 08. 14
* Change Date :
*/

//============================================================================
// Define constant
//============================================================================
define ([
], function() {
'use strict';

//========================================================================
// vpPDF
//========================================================================
const PDF_SHOW = '!pip show PyMuPDF nltk'
const PDF_INSTALL1 = '!pip install PyMuPDF'
const PDF_INSTALL2 = '!pip install nltk'

const PDF_IMPORT = `import pandas as pd
import fitz
from nltk.tokenize import sent_tokenize`;

const PDF_FUNC = `def vp_pdf_get_sentence(fname_lst):
'''
Get sentence from pdf file by PyMuPDF
'''
df = pd.DataFrame()
for fname in fname_lst:
if fname.split('.')[-1] != 'pdf': continue
try:
doc = fitz.open(fname)
sentence_lst = []
for page in doc:
block_lst = page.getText('blocks')

text_lst = [block[4] for block in block_lst if block[6] == 0]
text = '\\n'.join(text_lst)

sentence_lst.extend([sentence for sentence in sent_tokenize(text)])

doc.close()
except:
continue

df_doc = pd.DataFrame({
'fname': fname,
'sentence': sentence_lst
})
df = pd.concat([df,df_doc])

return df.reset_index().drop('index', axis=1)`;

const PDF_CMD = 'df = vp_pdf_get_sentence(pdf_lst)\ndf'



//========================================================================
// return value
//========================================================================
return {
PDF_SHOW,
PDF_INSTALL1,
PDF_INSTALL2,
PDF_IMPORT,
PDF_FUNC,
PDF_CMD
};

}); /* function, define */

/* End of file */

Loading