Skip to content

Commit 8cd0673

Browse files
authored
Merge pull request #94 from visualpython/release
Release v1.1.12
2 parents 52acf16 + 36e2a58 commit 8cd0673

File tree

9 files changed

+780
-7
lines changed

9 files changed

+780
-7
lines changed

css/common/pdf.css

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
.vp-pdf {
2+
position: absolute;
3+
top: 0;
4+
left: 0;
5+
width: 100%;
6+
height: 100%;
7+
z-index: 1200;
8+
background-color: rgba(0,0,0,.4);
9+
}
10+
.vp-pdf-container {
11+
position: relative;
12+
left: 50%;
13+
top: 50%;
14+
transform:translate(-50%, -50%);
15+
min-width: 470px;
16+
min-height: 420px;
17+
width: 50%;
18+
height: 60%;
19+
background-color: white;
20+
}
21+
.vp-pdf-title {
22+
height: 40px;
23+
padding: 5px 0px 5px 10px;
24+
background-color: #EEE;
25+
border: 1px solid #ddd;;
26+
display: flex;
27+
flex-direction: row;
28+
position: relative;
29+
align-items: center;
30+
font-size: 16px;
31+
font-weight: 700;
32+
}
33+
.vp-pdf-close,
34+
.vp-pdf-popup-close {
35+
position: fixed;
36+
z-index: 3;
37+
right: 5px;
38+
width: 30px;
39+
height: 20px;
40+
line-height: 20px;
41+
top: 10px;
42+
text-align: center;
43+
cursor: pointer;
44+
}
45+
.vp-pdf-body {
46+
width: 100%;
47+
height: calc(100% - 90px);
48+
padding: 10px;
49+
}
50+
.vp-pdf-grid-box {
51+
display: grid;
52+
width: 100%;
53+
height: 100%;
54+
grid-row-gap: 5px;
55+
/* grid-template-rows: 60px calc(100% - 80px); */
56+
/* grid-template-rows: 80px calc(100% - 100px); */
57+
/* grid-template-rows: 80px min-content; */
58+
grid-template-rows: 60px 140px 150px;
59+
}
60+
.vp-pdf-prepare-box {
61+
display: grid;
62+
grid-template-columns: 50% 50%;
63+
align-items: baseline;
64+
align-content: center;
65+
border: 1px solid #E4E4E4;
66+
border-radius: 5px;
67+
box-sizing: border-box;
68+
padding: 15px;
69+
}
70+
.vp-pdf-link {
71+
color: var(--highlight-color);
72+
}
73+
.vp-pdf-install-btn{
74+
margin-left: 7px;
75+
}
76+
.vp-pdf-check-btn {
77+
display: inline-block;
78+
margin-left: 5px;
79+
}
80+
.vp-pdf-import-btn {
81+
margin-left: 10px;
82+
}
83+
.vp-pdf-show-box {
84+
display: grid;
85+
/* grid-template-rows: min-content min-content; */
86+
grid-row-gap: 10px;
87+
border: 1px solid #E4E4E4;
88+
border-radius: 5px;
89+
box-sizing: border-box;
90+
padding: 15px;
91+
}
92+
.vp-pdf-df-box {
93+
display: grid;
94+
grid-template-columns: 95px auto;
95+
grid-row-gap: 3px;
96+
align-items: baseline;
97+
align-content: space-evenly;
98+
}
99+
.vp-pdf #vp_pdfVariable {
100+
width: 62%;
101+
height: 30px;
102+
}
103+
.vp-pdf-input {
104+
width: 62%;
105+
}
106+
.vp-pdf-run-btn {
107+
width: 112px !important;
108+
margin-left: 5px;
109+
}
110+
.vp-pdf-preview-box {
111+
display: none;
112+
width: 100%;
113+
height: 100px;
114+
position: absolute;
115+
bottom: 50px;
116+
117+
background: #F7F7F7;
118+
border: 0.25px solid #E4E4E4;
119+
padding: 10px;
120+
}
121+
/** Buttons */
122+
.vp-pdf-btn-box {
123+
position: relative;
124+
height: 50px;
125+
border-top: 0.25px solid var(--border-gray-color);
126+
}
127+
.vp-pdf-btn {
128+
position: absolute;
129+
}
130+
.vp-pdf-btn-preview {
131+
left: 15px;
132+
top: 9px;
133+
}
134+
.vp-pdf-btn-dataview {
135+
left: 105px;
136+
top: 9px;
137+
}
138+
.vp-pdf-btn-cancel {
139+
top: 9px;
140+
right: 105px;
141+
}
142+
.vp-pdf-btn-runadd {
143+
position: absolute;
144+
top: 9px;
145+
right: 15px;
146+
width: fit-content;
147+
height: 30px;
148+
background: #F38504;
149+
border-radius: 2px;
150+
}
151+
.vp-pdf-btn-run {
152+
display: inline-block;
153+
width: 60px;
154+
border-radius: 2px 0px 0px 2px;
155+
border-right: 0.25px solid var(--border-gray-color) !important;
156+
}
157+
.vp-pdf-btn-detail {
158+
display: inline-block;
159+
width: 20px;
160+
height: 28px;
161+
border-radius: 0px 2px 2px 0px;
162+
padding: 0;
163+
}
164+
.vp-pdf-detail-box {
165+
display: none;
166+
background: white;
167+
border: 0.25px solid var(--border-gray-color);
168+
position: absolute;
169+
bottom: 35px;
170+
right: 1px;
171+
width: 84px;
172+
height: 62px;
173+
text-align: center;
174+
line-height: 30px;
175+
}
176+
.vp-pdf-detail-item {
177+
color: var(--font-primary);
178+
}
179+
.vp-pdf-detail-item:hover {
180+
color: var(--font-hightlight);
181+
background: var(--light-gray-color);
182+
}

src/api_block/blockContainer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2649,7 +2649,7 @@ define([
26492649
this.hideOptionPreviewBox();
26502650
$(VP_ID_PREFIX + VP_APIBLOCK_BOARD_OPTION_PREVIEW_BUTTON).removeClass('enabled');
26512651

2652-
this.setNavigator(BLOCK_CODELINE_TYPE.NONE, 'Visual Python 1.1.11');
2652+
this.setNavigator(BLOCK_CODELINE_TYPE.NONE, 'Visual Python 1.1.12');
26532653
this.setFocusedPageType(FOCUSED_PAGE_TYPE.BOARD);
26542654
$('.vp-apiblock-option-tab-none').css(STR_DISPLAY, STR_BLOCK);
26552655
}

src/api_block/constData.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ define([
287287
const STR_CODE = 'code';
288288
const STR_COMMENT = 'comment';
289289
const STR_NODE = 'node';
290-
const STR_TEXT = 'text';
290+
const STR_TEXT = 'Markdown';
291291
const STR_PRINT = 'print';
292292
const STR_ELIF = 'elif';
293293
const STR_ELSE = 'else';
@@ -776,6 +776,9 @@ define([
776776
},
777777
'profiling': {
778778
file: 'nbextensions/visualpython/src/common/vpProfiling'
779+
},
780+
'pdf': {
781+
file: 'nbextensions/visualpython/src/common/vpPDF'
779782
}
780783
}
781784

src/api_block/index.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@
9494
<img src="/nbextensions/visualpython/resource/apps/apps_white.svg">
9595
<div class="vp-apiblock-menu-apps-name">Profiling</div>
9696
</div>
97+
<div class="vp-apiblock-menu-apps-item line3" data-menu="pdf" title="PDF">
98+
<img src="/nbextensions/visualpython/resource/apps/apps_white.svg">
99+
<div class="vp-apiblock-menu-apps-name">PDF</div>
100+
</div>
97101
<div class="vp-apiblock-menu-apps-item preparing" data-menu="merge" title="Work In Progress">
98102
<img src="/nbextensions/visualpython/resource/apps/apps_merge.svg">
99103
<div class="vp-apiblock-menu-apps-name">Merge</div>
@@ -175,7 +179,7 @@
175179
id='vp_apiblock_option_page'>
176180
<div class="vp-apiblock-option-navigator">
177181
<div class="vp-apiblock-option-navigator-label">
178-
<span class="vp-orange-text">Visual Python 1.1.11</span>
182+
<span class="vp-orange-text">Visual Python 1.1.12</span>
179183
</div>
180184
<div class="vp-apiblock-option-new-to-save" title="something modified...">
181185

src/api_block/init.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ define([
266266
case 'frame':
267267
case 'chart':
268268
case 'profiling':
269+
case 'pdf':
269270
blockContainer.setSelectBlock(null);
270271
blockContainer.createAppsPage(menu, file, config);
271272
break;
@@ -379,7 +380,7 @@ define([
379380
});
380381

381382
/** Apps Menu Apply event */
382-
$(document).on('subset_run frame_run', '#vp_appsCode', function(evt) {
383+
$(document).on('subset_run frame_run pdf_run', '#vp_appsCode', function(evt) {
383384
var code = evt.code;
384385
var title = evt.title;
385386
var state = evt.state;

src/common/constant.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ define ([
4848
* toolbar btn properties
4949
*/
5050
const TOOLBAR_BTN_INFO = {
51-
HELP: "Visual Python 1.1.11"
51+
HELP: "Visual Python 1.1.12"
5252
// , ICON: "fa-angellist"
5353
, ICON: "vp-main-icon"
5454
, ID: "vpBtnToggle"

src/common/pycode.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Project Name : Visual Python
3+
* Description : GUI-based Python code generator
4+
* File Name : pycode.js
5+
* Author : Black Logic
6+
* Note : Define constant value
7+
* License : GNU GPLv3 with Visual Python special exception
8+
* Date : 2021. 08. 14
9+
* Change Date :
10+
*/
11+
12+
//============================================================================
13+
// Define constant
14+
//============================================================================
15+
define ([
16+
], function() {
17+
'use strict';
18+
19+
//========================================================================
20+
// vpPDF
21+
//========================================================================
22+
const PDF_SHOW = '!pip show PyMuPDF nltk'
23+
const PDF_INSTALL1 = '!pip install PyMuPDF'
24+
const PDF_INSTALL2 = '!pip install nltk'
25+
26+
const PDF_IMPORT = `import pandas as pd
27+
import fitz
28+
from nltk.tokenize import sent_tokenize`;
29+
30+
const PDF_FUNC = `def vp_pdf_get_sentence(fname_lst):
31+
'''
32+
Get sentence from pdf file by PyMuPDF
33+
'''
34+
df = pd.DataFrame()
35+
for fname in fname_lst:
36+
if fname.split('.')[-1] != 'pdf': continue
37+
try:
38+
doc = fitz.open(fname)
39+
sentence_lst = []
40+
for page in doc:
41+
block_lst = page.getText('blocks')
42+
43+
text_lst = [block[4] for block in block_lst if block[6] == 0]
44+
text = '\\n'.join(text_lst)
45+
46+
sentence_lst.extend([sentence for sentence in sent_tokenize(text)])
47+
48+
doc.close()
49+
except:
50+
continue
51+
52+
df_doc = pd.DataFrame({
53+
'fname': fname,
54+
'sentence': sentence_lst
55+
})
56+
df = pd.concat([df,df_doc])
57+
58+
return df.reset_index().drop('index', axis=1)`;
59+
60+
const PDF_CMD = 'df = vp_pdf_get_sentence(pdf_lst)\ndf'
61+
62+
63+
64+
//========================================================================
65+
// return value
66+
//========================================================================
67+
return {
68+
PDF_SHOW,
69+
PDF_INSTALL1,
70+
PDF_INSTALL2,
71+
PDF_IMPORT,
72+
PDF_FUNC,
73+
PDF_CMD
74+
};
75+
76+
}); /* function, define */
77+
78+
/* End of file */
79+

0 commit comments

Comments
 (0)